diff --git a/dns.c b/dns.c index 1a94524..451823a 100644 --- a/dns.c +++ b/dns.c @@ -293,6 +293,7 @@ dns_read(int fd, char *buf, int buflen) short rlen; short type; short class; + short qdcount; short ancount; char *data; char name[255]; @@ -312,10 +313,16 @@ dns_read(int fd, char *buf, int buflen) data = packet + sizeof(HEADER); if(header->qr) { /* qr=1 => response */ + qdcount = ntohs(header->qdcount); ancount = ntohs(header->ancount); rlen = 0; + if(qdcount == 1) { + READNAME(packet, name, data); + READSHORT(type, data); + READSHORT(class, data); + } if(ancount == 1) { READNAME(packet, name, data); READSHORT(type, data); @@ -339,10 +346,12 @@ dns_read(int fd, char *buf, int buflen) } } - if(ttl == T_NULL && rlen) - memcpy(buf, rdata, rlen); - - return rlen; + if(type == T_NULL && rlen) { + memcpy(buf, rdata, rlen); + return rlen; + } else { + return 0; + } } } diff --git a/dnstun.c b/dnstun.c index 7bff8cc..2d75004 100644 --- a/dnstun.c +++ b/dnstun.c @@ -47,15 +47,24 @@ tunnel(int tun_fd, int dns_fd) { int i; int read; + int fastpoll; fd_set fds; struct timeval tv; struct tun_frame *frame; frame = malloc(FRAMESIZE); + fastpoll = 0; while (running) { - tv.tv_sec = 1; - tv.tv_usec = 0; + if (fastpoll) { + tv.tv_sec = 0; + tv.tv_usec = 5000; + fastpoll = 0; + printf("Fast poll\n"); + } else { + tv.tv_sec = 1; + tv.tv_usec = 0; + } FD_ZERO(&fds); if (!dns_sending()) { @@ -95,6 +104,7 @@ tunnel(int tun_fd, int dns_fd) #endif write_tun(tun_fd, frame, read + 4); + fastpoll = 1; // make sure we send packet real soon } } }