diff --git a/dns.c b/dns.c index 30a87a8..588d372 100644 --- a/dns.c +++ b/dns.c @@ -288,17 +288,14 @@ dns_write(int fd, int id, char *buf, int len) int dns_read(int fd, char *buf, int buflen) { - int i; int r; long ttl; short rlen; short type; short class; - short port; short ancount; char *data; char name[255]; - char host[255]; char rdata[256]; HEADER *header; char packet[64*1024]; @@ -319,17 +316,13 @@ dns_read(int fd, char *buf, int buflen) rlen = 0; - for(i=0;iid)) { // Got ACK on sent packet @@ -346,6 +339,9 @@ dns_read(int fd, char *buf, int buflen) } } + if(ttl == T_NULL && rlen) + memcpy(buf, rdata, rlen); + // TODO is any data attached? find out and copy into buf and return length return rlen; } diff --git a/dnsd.c b/dnsd.c index 63fa389..887c0a7 100644 --- a/dnsd.c +++ b/dnsd.c @@ -215,6 +215,7 @@ dnsd_respond(int fd, short id, struct sockaddr_in from) p += outbuflen; len = p - buf; + printf("Responding with %d\n", len); sendto(fd, buf, len, 0, (struct sockaddr*)&from, sizeof(from)); outbuflen = 0; diff --git a/dnstun.c b/dnstun.c index 0bd568c..7bff8cc 100644 --- a/dnstun.c +++ b/dnstun.c @@ -88,8 +88,11 @@ tunnel(int tun_fd, int dns_fd) if (read > 0) { printf("Got data on dns! %d bytes\n", read); - //frame->flags = htons(0x0000); - //frame->proto = htons(0x0200); +#ifdef LINUX + frame->proto = htons(0x0800); +#else + frame->proto = htons(0x0002); +#endif write_tun(tun_fd, frame, read + 4); } diff --git a/dnstund.c b/dnstund.c index e84c51f..5f990e1 100644 --- a/dnstund.c +++ b/dnstund.c @@ -57,8 +57,10 @@ tunnel(int tun_fd, int dns_fd) tv.tv_usec = 0; FD_ZERO(&fds); - if(!dnsd_haspacket()) + if(!dnsd_haspacket()) { + printf("There is room for more\n"); FD_SET(tun_fd, &fds); + } FD_SET(dns_fd, &fds); i = select(MAX(tun_fd, dns_fd) + 1, &fds, NULL, NULL, &tv); @@ -72,15 +74,22 @@ tunnel(int tun_fd, int dns_fd) if(i != 0) { if(FD_ISSET(tun_fd, &fds)) { + printf("data on tun\n"); read = read_tun(tun_fd, frame, 64*1024); - if(read > 0) + if(read > 0) { + printf("Sending response\n"); dnsd_queuepacket(frame->data, read - 4); + } } if(FD_ISSET(dns_fd, &fds)) { read = dnsd_read(dns_fd, frame->data, 64*1024-4); if(read > 0) { frame->flags = htons(0x0000); +#ifdef LINUX frame->proto = htons(0x0800); +#else + frame->proto = htons(0x0002); +#endif write_tun(tun_fd, frame, read + 4); } }