From 3c644e9a88db9a507f54335a7e5a1d42bc2760bf Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Sat, 1 Dec 2007 22:19:54 +0000 Subject: [PATCH] Renamed packet_sending to packet_empty --- src/iodine.c | 15 ++++++--------- src/iodined.c | 6 ++---- src/packet.c | 2 +- src/packet.h | 9 ++++++--- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/iodine.c b/src/iodine.c index 9830c7d..c9b2e90 100644 --- a/src/iodine.c +++ b/src/iodine.c @@ -160,10 +160,10 @@ read_dns(int fd, char *buf, int buflen) rv = dns_decode(buf, buflen, &q, QR_ANSWER, data, r); - if (packet_sending(&packet) && chunkid == q.id) { + if (packet_empty(&packet) == 0 && chunkid == q.id) { /* Got ACK on sent packet */ packet_advance(&packet); - if (packet_sending(&packet)) { + if (!packet_empty(&packet)) { /* More to send */ send_chunk(fd); } @@ -213,7 +213,7 @@ tunnel_dns(int tun_fd, int dns_fd) return -1; write_tun(tun_fd, out, outlen); - if (!packet_sending(&packet)) + if (packet_empty(&packet)) send_ping(dns_fd); return read; @@ -234,7 +234,7 @@ tunnel(int tun_fd, int dns_fd) tv.tv_usec = 0; FD_ZERO(&fds); - if (!packet_sending(&packet)) + if (packet_empty(&packet)) FD_SET(tun_fd, &fds); FD_SET(dns_fd, &fds); @@ -314,11 +314,8 @@ send_ping(int fd) { char data[3]; - if (packet_sending(&packet)) { - packet.sentlen = 0; - packet.offset = 0; - packet.len = 0; - } + /* clear any packet not sent */ + packet_init(&packet); data[0] = userid; data[1] = (rand_seed >> 8) & 0xff; diff --git a/src/iodined.c b/src/iodined.c index bda3b7a..844d705 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -82,10 +82,8 @@ tunnel_tun(int tun_fd, int dns_fd) compress2((uint8_t*)out, &outlen, (uint8_t*)in, read, 9); /* if another packet is queued, throw away this one. TODO build queue */ - if (users[userid].outpacket.len == 0) { - memcpy(users[userid].outpacket.data, out, outlen); - users[userid].outpacket.len = outlen; - return outlen; + if (packet_empty(&(users[userid].outpacket)) == 0) { + return packet_fill(&(users[userid].outpacket), out, outlen); } else { return 0; } diff --git a/src/packet.c b/src/packet.c index 28a1ba1..ac4a0b7 100644 --- a/src/packet.c +++ b/src/packet.c @@ -23,7 +23,7 @@ * Is some part of this packet sent? */ int -packet_sending(struct packet *packet) +packet_empty(struct packet *packet) { return (packet->len != 0); } diff --git a/src/packet.h b/src/packet.h index 9008659..90aab97 100644 --- a/src/packet.h +++ b/src/packet.h @@ -28,10 +28,13 @@ struct packet }; void packet_init(struct packet *); -int packet_sending(struct packet *); + +int packet_empty(struct packet *); + void packet_advance(struct packet *); -int packet_len_to_send(struct packet *); -int packet_fill(struct packet *, char *, unsigned long); void packet_send_len(struct packet *, int); +int packet_len_to_send(struct packet *); + +int packet_fill(struct packet *, char *, unsigned long); #endif