diff --git a/Makefile b/Makefile index 67fb533..89f14b0 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ CC = gcc DNS = dnstun -DNSOBJS = dnstun.o tun.o dns.o +DNSOBJS = dnstun.o tun.o dns.o read.o DNSD = dnstund -DNSDOBJS = dnstund.o tun.o dnsd.o +DNSDOBJS = dnstund.o tun.o dnsd.o read.o OS = `uname | tr "a-z" "A-Z"` diff --git a/dns.c b/dns.c index efb041e..aabac2b 100644 --- a/dns.c +++ b/dns.c @@ -29,6 +29,7 @@ #include #include "dns.h" +#include "read.h" static int host2dns(const char *, char *, int); @@ -44,55 +45,6 @@ uint16_t chunkid; uint16_t pingid; -static int -readname(char *packet, char *dst, char *src) -{ - char l; - int len; - int offset; - - len = 0; - - while(*src) { - l = *src++; - len++; - - if(l & 0x80 && l & 0x40) { - offset = ((src[-1] & 0x3f) << 8) | src[0]; - readname(packet, dst, packet + offset); - dst += strlen(dst); - break; - } - - while(l) { - *dst++ = *src++; - l--; - len++; - } - - *dst++ = '.'; - } - - *dst = '\0'; - src++; - len++; - - return len; -} - -#define READNAME(packet, dst, src) (src) += readname((packet), (dst), (src)); - -#define READSHORT(dst, src) \ - memcpy(&dst, src, 2); \ - (dst) = ntohs(dst); (src)+=2; - -#define READLONG(dst, src) \ - memcpy(&dst, src, 2); \ - (dst) = ntohl(dst); (src)+=4; - -#define READDATA(dst, src, len) \ - memcpy((dst), (src), (len)); (src)+=(len); - int open_dns(const char *host, const char *domain) { diff --git a/dnsd.c b/dnsd.c index 32f13fe..179a17b 100644 --- a/dnsd.c +++ b/dnsd.c @@ -31,6 +31,7 @@ #include #include "dns.h" +#include "read.h" static int host2dns(const char *, char *, int); @@ -50,55 +51,6 @@ short delayed_q_id; struct sockaddr_in delayed_q_from; int delayed_q_fromlen; -static int -readname(char *packet, char *dst, char *src) -{ - char l; - int len; - int offset; - - len = 0; - - while(*src) { - l = *src++; - len++; - - if(l & 0x80 && l & 0x40) { - offset = ((src[-1] & 0x3f) << 8) | src[0]; - readname(packet, dst, packet + offset); - dst += strlen(dst); - break; - } - - while(l) { - *dst++ = *src++; - l--; - len++; - } - - *dst++ = '.'; - } - - *dst = '\0'; - src++; - len++; - - return len; -} - -#define READNAME(packet, dst, src) (src) += readname((packet), (dst), (src)); - -#define READSHORT(dst, src) \ - memcpy(&dst, src, 2); \ - (dst) = ntohs(dst); (src)+=2; - -#define READLONG(dst, src) \ - memcpy(&dst, src, 2); \ - (dst) = ntohl(dst); (src)+=4; - -#define READDATA(dst, src, len) \ - memcpy((dst), (src), (len)); (src)+=(len); - int open_dnsd(const char *domain) {