From 7dd38fec1717374ea990604051fe38ac8be61038 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Sun, 4 Jan 2009 13:53:32 +0000 Subject: [PATCH] Create send_chunk() on server --- src/iodined.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/iodined.c b/src/iodined.c index 5db94a0..b30e659 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -116,6 +116,8 @@ tunnel_tun(int tun_fd, int dns_fd) if (users[userid].outpacket.len == 0) { memcpy(users[userid].outpacket.data, out, outlen); users[userid].outpacket.len = outlen; + users[userid].outpacket.offset = 0; + users[userid].outpacket.sentlen = 0; users[userid].outpacket.seqno++; users[userid].outpacket.fragment = 0; return outlen; @@ -156,6 +158,18 @@ send_version_response(int fd, version_ack_t ack, uint32_t payload, int userid, s write_dns(fd, q, out, sizeof(out)); } +static void +send_chunk(int dns_fd, int userid) { + if (debug >= 1) { + printf("OUT pkt seq# %d, frag %d (last=%d), fragsize %d, total %d, to user %d\n", + users[userid].outpacket.seqno & 7, users[userid].outpacket.fragment & 15, + 1, users[userid].outpacket.len, users[userid].outpacket.len, userid); + } + write_dns(dns_fd, &users[userid].q, users[userid].outpacket.data, users[userid].outpacket.len); + users[userid].outpacket.len = 0; + users[userid].q.id = 0; +} + static void update_downstream_seqno(int dns_fd, int userid, int down_seq, int down_frag) { @@ -173,14 +187,7 @@ update_downstream_seqno(int dns_fd, int userid, int down_seq, int down_frag) /* Send reply if waiting */ if (users[userid].outpacket.len > 0) { - if (debug >= 1) { - printf("OUT pkt seq# %d, frag %d (last=%d), fragsize %d, total %d, to user %d\n", - users[userid].outpacket.seqno & 7, users[userid].outpacket.fragment & 15, - 1, users[userid].outpacket.len, users[userid].outpacket.len, userid); - } - write_dns(dns_fd, &users[userid].q, users[userid].outpacket.data, users[userid].outpacket.len); - users[userid].outpacket.len = 0; - users[userid].q.id = 0; + send_chunk(dns_fd, userid); } } @@ -621,16 +628,7 @@ tunnel(int tun_fd, int dns_fd, int bind_fd) int j; for (j = 0; j < USERS; j++) { if (users[j].q.id != 0) { - if (debug >= 1 && users[j].outpacket.len > 0) { - printf("OUT pkt seq# %d, frag %d (last=%d), " - "fragsize %d of total %d, to user %d\n", - users[j].outpacket.seqno & 7, - users[j].outpacket.fragment & 15, 1, - users[j].outpacket.len, users[j].outpacket.len, j); - } - write_dns(dns_fd, &(users[j].q), users[j].outpacket.data, users[j].outpacket.len); - users[j].outpacket.len = 0; - users[j].q.id = 0; + send_chunk(dns_fd, j); } } } else {