diff --git a/sbotc.c b/sbotc.c index 8972a38..4e88681 100644 --- a/sbotc.c +++ b/sbotc.c @@ -73,11 +73,6 @@ enum pkt_flags { pkt_flags_stream = 8, }; -struct pkt_header { - uint32_t len; - int32_t req; -} __attribute__((packed)); - enum muxrpc_type { muxrpc_type_async, muxrpc_type_source, @@ -689,9 +684,11 @@ static enum stream_state bs_write_in_1(struct boxs *bs, int fd) { static void ps_write(struct boxs *bs, const char *data, size_t len, enum pkt_type type, int req_id, bool stream, bool end) { size_t out_len = 9 + len; unsigned char out_buf[out_len]; - struct pkt_header header = {htonl(len), htonl(req_id)}; + uint32_t len_n = htonl(len); + int32_t req_n = htonl(req_id); out_buf[0] = (stream << 3) | (end << 2) | (type & 3); - memcpy(out_buf+1, &header, 8); + memcpy(out_buf+1, &len_n, 4); + memcpy(out_buf+5, &req_n, 4); memcpy(out_buf+9, data, len); bs_write(bs, out_buf, out_len); } @@ -704,11 +701,13 @@ static void ps_goodbye(struct boxs *bs) { static int ps_read_header(struct boxs *bs, size_t *len, int *req_id, enum pkt_flags *flags) { char buf[9]; - struct pkt_header header; + uint32_t len_n; + int32_t req_n; if (bs_read(bs, buf, sizeof(buf)) < 0) return -1; - memcpy(&header, buf+1, 8); - if (len) *len = ntohl(header.len); - if (req_id) *req_id = ntohl(header.req); + memcpy(&len_n, buf+1, 4); + memcpy(&req_n, buf+5, 4); + if (len) *len = ntohl(len_n); + if (req_id) *req_id = ntohl(req_n); if (flags) *flags = buf[0]; return 0; }