|
Lines 31-73
Link Here
|
| 31 |
#include "msg.h" |
31 |
#include "msg.h" |
| 32 |
|
32 |
|
| 33 |
void |
33 |
void |
| 34 |
msg_send(int fd, u_char type, Buffer *m) |
34 |
ssh_msg_send(int fd, u_char type, Buffer *m) |
| 35 |
{ |
35 |
{ |
| 36 |
u_char buf[5]; |
36 |
u_char buf[5]; |
| 37 |
u_int mlen = buffer_len(m); |
37 |
u_int mlen = buffer_len(m); |
| 38 |
|
38 |
|
| 39 |
debug3("msg_send: type %u", (unsigned int)type & 0xff); |
39 |
debug3("ssh_msg_send: type %u", (unsigned int)type & 0xff); |
| 40 |
|
40 |
|
| 41 |
PUT_32BIT(buf, mlen + 1); |
41 |
PUT_32BIT(buf, mlen + 1); |
| 42 |
buf[4] = type; /* 1st byte of payload is mesg-type */ |
42 |
buf[4] = type; /* 1st byte of payload is mesg-type */ |
| 43 |
if (atomicio(write, fd, buf, sizeof(buf)) != sizeof(buf)) |
43 |
if (atomicio(write, fd, buf, sizeof(buf)) != sizeof(buf)) |
| 44 |
fatal("msg_send: write"); |
44 |
fatal("ssh_msg_send: write"); |
| 45 |
if (atomicio(write, fd, buffer_ptr(m), mlen) != mlen) |
45 |
if (atomicio(write, fd, buffer_ptr(m), mlen) != mlen) |
| 46 |
fatal("msg_send: write"); |
46 |
fatal("ssh_msg_send: write"); |
| 47 |
} |
47 |
} |
| 48 |
|
48 |
|
| 49 |
int |
49 |
int |
| 50 |
msg_recv(int fd, Buffer *m) |
50 |
ssh_msg_recv(int fd, Buffer *m) |
| 51 |
{ |
51 |
{ |
| 52 |
u_char buf[4]; |
52 |
u_char buf[4]; |
| 53 |
ssize_t res; |
53 |
ssize_t res; |
| 54 |
u_int msg_len; |
54 |
u_int msg_len; |
| 55 |
|
55 |
|
| 56 |
debug3("msg_recv entering"); |
56 |
debug3("ssh_msg_recv entering"); |
| 57 |
|
57 |
|
| 58 |
res = atomicio(read, fd, buf, sizeof(buf)); |
58 |
res = atomicio(read, fd, buf, sizeof(buf)); |
| 59 |
if (res != sizeof(buf)) { |
59 |
if (res != sizeof(buf)) { |
| 60 |
if (res == 0) |
60 |
if (res == 0) |
| 61 |
return -1; |
61 |
return -1; |
| 62 |
fatal("msg_recv: read: header %ld", (long)res); |
62 |
fatal("ssh_msg_recv: read: header %ld", (long)res); |
| 63 |
} |
63 |
} |
| 64 |
msg_len = GET_32BIT(buf); |
64 |
msg_len = GET_32BIT(buf); |
| 65 |
if (msg_len > 256 * 1024) |
65 |
if (msg_len > 256 * 1024) |
| 66 |
fatal("msg_recv: read: bad msg_len %u", msg_len); |
66 |
fatal("ssh_msg_recv: read: bad msg_len %u", msg_len); |
| 67 |
buffer_clear(m); |
67 |
buffer_clear(m); |
| 68 |
buffer_append_space(m, msg_len); |
68 |
buffer_append_space(m, msg_len); |
| 69 |
res = atomicio(read, fd, buffer_ptr(m), msg_len); |
69 |
res = atomicio(read, fd, buffer_ptr(m), msg_len); |
| 70 |
if (res != msg_len) |
70 |
if (res != msg_len) |
| 71 |
fatal("msg_recv: read: %ld != msg_len", (long)res); |
71 |
fatal("ssh_msg_recv: read: %ld != msg_len", (long)res); |
| 72 |
return 0; |
72 |
return 0; |
| 73 |
} |
73 |
} |