From 76ec4ab895976d361f2b14d1198ef20e93033e04 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Sun, 11 Feb 2007 16:39:09 +0000 Subject: [PATCH] #11 routing between clients implemented. clients need to poll more often to get reasonable packetloss due to no queue --- src/iodined.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/iodined.c b/src/iodined.c index 4e0bf39..da90f99 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -129,12 +129,14 @@ tunnel_dns(int tun_fd, int dns_fd) { struct in_addr tempip; struct user dummy; + struct ip *hdr; unsigned long outlen; char logindata[16]; char out[64*1024]; char in[64*1024]; char *tmp[2]; int userid; + int touser; int version; int read; int code; @@ -248,8 +250,20 @@ tunnel_dns(int tun_fd, int dns_fd) uncompress((uint8_t*)out, &outlen, (uint8_t*)users[userid].inpacket.data, users[userid].inpacket.len); - write_tun(tun_fd, out, outlen); + hdr = (struct ip*) (out + 4); + touser = find_user_by_ip(hdr->ip_dst.s_addr); + if (touser == -1) { + /* send the uncompressed packet to tun device */ + write_tun(tun_fd, out, outlen); + } else { + /* send the compressed packet to other client + * if another packet is queued, throw away this one. TODO build queue */ + if (users[touser].outpacket.len == 0) { + memcpy(users[touser].outpacket.data, users[userid].inpacket.data, users[userid].inpacket.len); + users[touser].outpacket.len = users[userid].inpacket.len; + } + } users[userid].inpacket.len = users[userid].inpacket.offset = 0; } }