version 1.3.2.3, 2003/04/03 22:35:17 |
version 1.4, 2002/07/01 16:15:25 |
|
|
#include "msg.h" |
#include "msg.h" |
|
|
void |
void |
ssh_msg_send(int fd, u_char type, Buffer *m) |
msg_send(int fd, u_char type, Buffer *m) |
{ |
{ |
u_char buf[5]; |
u_char buf[5]; |
u_int mlen = buffer_len(m); |
u_int mlen = buffer_len(m); |
|
|
debug3("ssh_msg_send: type %u", (unsigned int)type & 0xff); |
debug3("msg_send: type %u", (unsigned int)type & 0xff); |
|
|
PUT_32BIT(buf, mlen + 1); |
PUT_32BIT(buf, mlen + 1); |
buf[4] = type; /* 1st byte of payload is mesg-type */ |
buf[4] = type; /* 1st byte of payload is mesg-type */ |
if (atomicio(write, fd, buf, sizeof(buf)) != sizeof(buf)) |
if (atomicio(write, fd, buf, sizeof(buf)) != sizeof(buf)) |
fatal("ssh_msg_send: write"); |
fatal("msg_send: write"); |
if (atomicio(write, fd, buffer_ptr(m), mlen) != mlen) |
if (atomicio(write, fd, buffer_ptr(m), mlen) != mlen) |
fatal("ssh_msg_send: write"); |
fatal("msg_send: write"); |
} |
} |
|
|
int |
int |
ssh_msg_recv(int fd, Buffer *m) |
msg_recv(int fd, Buffer *m) |
{ |
{ |
u_char buf[4]; |
u_char buf[4]; |
ssize_t res; |
ssize_t res; |
u_int msg_len; |
u_int msg_len; |
|
|
debug3("ssh_msg_recv entering"); |
debug3("msg_recv entering"); |
|
|
res = atomicio(read, fd, buf, sizeof(buf)); |
res = atomicio(read, fd, buf, sizeof(buf)); |
if (res != sizeof(buf)) { |
if (res != sizeof(buf)) { |
if (res == 0) |
if (res == 0) |
return -1; |
return -1; |
fatal("ssh_msg_recv: read: header %ld", (long)res); |
fatal("msg_recv: read: header %ld", (long)res); |
} |
} |
msg_len = GET_32BIT(buf); |
msg_len = GET_32BIT(buf); |
if (msg_len > 256 * 1024) |
if (msg_len > 256 * 1024) |
fatal("ssh_msg_recv: read: bad msg_len %u", msg_len); |
fatal("msg_recv: read: bad msg_len %u", msg_len); |
buffer_clear(m); |
buffer_clear(m); |
buffer_append_space(m, msg_len); |
buffer_append_space(m, msg_len); |
res = atomicio(read, fd, buffer_ptr(m), msg_len); |
res = atomicio(read, fd, buffer_ptr(m), msg_len); |
if (res != msg_len) |
if (res != msg_len) |
fatal("ssh_msg_recv: read: %ld != msg_len", (long)res); |
fatal("msg_recv: read: %ld != msg_len", (long)res); |
return 0; |
return 0; |
} |
} |