version 1.81, 2001/12/28 14:13:13 |
version 1.82, 2001/12/28 14:50:54 |
|
|
*/ |
*/ |
|
|
int |
int |
packet_read_seqnr(int *payload_len_ptr, u_int32_t *seqnr_p) |
packet_read_seqnr(u_int32_t *seqnr_p) |
{ |
{ |
int type, len; |
int type, len; |
fd_set *setp; |
fd_set *setp; |
|
|
/* Stay in the loop until we have received a complete packet. */ |
/* Stay in the loop until we have received a complete packet. */ |
for (;;) { |
for (;;) { |
/* Try to read a packet from the buffer. */ |
/* Try to read a packet from the buffer. */ |
type = packet_read_poll_seqnr(payload_len_ptr, seqnr_p); |
type = packet_read_poll_seqnr(seqnr_p); |
if (!compat20 && ( |
if (!compat20 && ( |
type == SSH_SMSG_SUCCESS |
type == SSH_SMSG_SUCCESS |
|| type == SSH_SMSG_FAILURE |
|| type == SSH_SMSG_FAILURE |
|
|
} |
} |
|
|
int |
int |
packet_read(int *payload_len_ptr) |
packet_read(void) |
{ |
{ |
return packet_read_seqnr(payload_len_ptr, NULL); |
return packet_read_seqnr(NULL); |
} |
} |
|
|
/* |
/* |
|
|
*/ |
*/ |
|
|
void |
void |
packet_read_expect(int *payload_len_ptr, int expected_type) |
packet_read_expect(int expected_type) |
{ |
{ |
int type; |
int type; |
|
|
type = packet_read(payload_len_ptr); |
type = packet_read(); |
if (type != expected_type) |
if (type != expected_type) |
packet_disconnect("Protocol error: expected packet type %d, got %d", |
packet_disconnect("Protocol error: expected packet type %d, got %d", |
expected_type, type); |
expected_type, type); |
|
|
* SSH_MSG_DISCONNECT is handled specially here. Also, |
* SSH_MSG_DISCONNECT is handled specially here. Also, |
* SSH_MSG_IGNORE messages are skipped by this function and are never returned |
* SSH_MSG_IGNORE messages are skipped by this function and are never returned |
* to higher levels. |
* to higher levels. |
* |
|
* The returned payload_len does include space consumed by: |
|
* Packet length |
|
* Padding |
|
* Packet type |
|
* Check bytes |
|
*/ |
*/ |
|
|
static int |
static int |
packet_read_poll1(int *payload_len_ptr) |
packet_read_poll1(void) |
{ |
{ |
u_int len, padded_len; |
u_int len, padded_len; |
u_char *ucp, type; |
u_char *ucp, type; |
|
|
buffer_len(&compression_buffer)); |
buffer_len(&compression_buffer)); |
} |
} |
type = buffer_get_char(&incoming_packet); |
type = buffer_get_char(&incoming_packet); |
*payload_len_ptr = buffer_len(&incoming_packet); |
|
return type; |
return type; |
} |
} |
|
|
static int |
static int |
packet_read_poll2(int *payload_len_ptr, u_int32_t *seqnr_p) |
packet_read_poll2(u_int32_t *seqnr_p) |
{ |
{ |
static u_int32_t seqnr = 0; |
static u_int32_t seqnr = 0; |
static u_int packet_length = 0; |
static u_int packet_length = 0; |
|
|
type = buffer_get_char(&incoming_packet); |
type = buffer_get_char(&incoming_packet); |
if (type == SSH2_MSG_NEWKEYS) |
if (type == SSH2_MSG_NEWKEYS) |
set_newkeys(MODE_IN); |
set_newkeys(MODE_IN); |
*payload_len_ptr = buffer_len(&incoming_packet); |
|
#ifdef PACKET_DEBUG |
#ifdef PACKET_DEBUG |
fprintf(stderr, "read/plain[%d]:\r\n", type); |
fprintf(stderr, "read/plain[%d]:\r\n", type); |
buffer_dump(&incoming_packet); |
buffer_dump(&incoming_packet); |
|
|
} |
} |
|
|
int |
int |
packet_read_poll_seqnr(int *payload_len_ptr, u_int32_t *seqnr_p) |
packet_read_poll_seqnr(u_int32_t *seqnr_p) |
{ |
{ |
int reason; |
int reason; |
u_char type; |
u_char type; |
|
|
|
|
for (;;) { |
for (;;) { |
if (compat20) { |
if (compat20) { |
type = packet_read_poll2(payload_len_ptr, seqnr_p); |
type = packet_read_poll2(seqnr_p); |
if (type) |
if (type) |
DBG(debug("received packet type %d", type)); |
DBG(debug("received packet type %d", type)); |
switch (type) { |
switch (type) { |
|
|
break; |
break; |
} |
} |
} else { |
} else { |
type = packet_read_poll1(payload_len_ptr); |
type = packet_read_poll1(); |
switch (type) { |
switch (type) { |
case SSH_MSG_IGNORE: |
case SSH_MSG_IGNORE: |
break; |
break; |
|
|
} |
} |
|
|
int |
int |
packet_read_poll(int *payload_len_ptr) |
packet_read_poll(void) |
{ |
{ |
return packet_read_poll_seqnr(payload_len_ptr, NULL); |
return packet_read_poll_seqnr(NULL); |
} |
} |
|
|
/* |
/* |