Handle packet fragmentation in tunnel instead

This commit is contained in:
Bjorn Andersson 2006-06-11 18:43:37 +00:00
parent f76b8e410b
commit 5c01e8d8e3

View File

@ -56,6 +56,7 @@ tunnel(int tun_fd, int dns_fd)
{ {
int i; int i;
int read; int read;
int code;
fd_set fds; fd_set fds;
struct timeval tv; struct timeval tv;
char in[64*1024]; char in[64*1024];
@ -105,21 +106,28 @@ tunnel(int tun_fd, int dns_fd)
if(in[0] == 'H' || in[0] == 'h') { if(in[0] == 'H' || in[0] == 'h') {
read = snprintf(out, sizeof(out), "%s-%d", "172.30.5.2", 1023); read = snprintf(out, sizeof(out), "%s-%d", "172.30.5.2", 1023);
dnsd_queuepacket(out, read); dnsd_queuepacket(out, read);
} else if(in[0] == '0') { } else if((in[0] >= '0' && in[0] <= '9')
memcpy(packetbuf.data + packetbuf.offset, in, read); || (in[0] >= 'a' && in[0] <= 'f')
packetbuf.len += read; || (in[0] >= 'A' && in[0] <= 'F')) {
packetbuf.offset += read; if ((in[0] >= '0' && in[0] <= '9'))
} else if(in[0] == '1') { code = in[0] - '0';
memcpy(packetbuf.data + packetbuf.offset, in, read); if ((in[0] >= 'a' && in[0] <= 'f'))
packetbuf.len += read; code = in[0] - 'a' + 10;
packetbuf.offset += read; if ((in[0] >= 'A' && in[0] <= 'F'))
code = in[0] - 'A' + 10;
outlen = sizeof(out); memcpy(packetbuf.data + packetbuf.offset, in + 1, read - 1);
uncompress(out, &outlen, packetbuf.data, packetbuf.len); packetbuf.len += read - 1;
packetbuf.offset += read - 1;
write_tun(tun_fd, out, outlen); if (code & 1) {
outlen = sizeof(out);
uncompress(out, &outlen, packetbuf.data, packetbuf.len);
packetbuf.len = packetbuf.offset = 0; write_tun(tun_fd, out, outlen);
packetbuf.len = packetbuf.offset = 0;
}
} }
} }
} }
@ -175,6 +183,9 @@ main(int argc, char **argv)
foreground = 0; foreground = 0;
mtu = 1024; mtu = 1024;
packetbuf.len = 0;
packetbuf.offset = 0;
while ((choice = getopt(argc, argv, "vfhu:t:m:")) != -1) { while ((choice = getopt(argc, argv, "vfhu:t:m:")) != -1) {
switch(choice) { switch(choice) {
case 'v': case 'v':