From 1fd044cbff143e7a3b66c0c54368aa528e8102a1 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Tue, 6 Jun 2006 02:27:10 +0000 Subject: [PATCH] server ok --- dnsd.c | 40 ++++++++++++++++++++++++---------------- dnstund.c | 5 +---- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/dnsd.c b/dnsd.c index 887c0a7..24be5b9 100644 --- a/dnsd.c +++ b/dnsd.c @@ -39,6 +39,7 @@ char topdomain[256]; int packetlen; char activepacket[4096]; +int outid; int outbuflen; char outbuf[64*1024]; @@ -174,10 +175,11 @@ dnsd_queuepacket(const char *buf, const int buflen) memcpy(outbuf, buf, buflen); outbuflen = buflen; + outid++; } static void -dnsd_respond(int fd, short id, struct sockaddr_in from) +dnsd_respond(int fd, char *name, short type, short id, struct sockaddr_in from) { int len; char *p; @@ -189,7 +191,7 @@ dnsd_respond(int fd, short id, struct sockaddr_in from) len = 0; header = (HEADER*)buf; - header->id = id; + header->id = htons(id); header->qr = 1; header->opcode = 0; header->aa = 1; @@ -197,22 +199,28 @@ dnsd_respond(int fd, short id, struct sockaddr_in from) header->rd = 0; header->ra = 0; - if(outbuflen > 0) - header->ancount = htons(1); - else - header->ancount = htons(0); + header->qdcount = htons(1); + header->ancount = htons(1); p = buf + sizeof(HEADER); - p += host2dns("fluff", p, 5); - PUTSHORT(T_NULL, p); + p += host2dns(name, p, strlen(name)); + PUTSHORT(type, p); PUTSHORT(C_IN, p); - PUTLONG(htons(0), p); + + p += host2dns(name, p, strlen(name)); + PUTSHORT(type, p); + PUTSHORT(C_IN, p); + PUTLONG(0, p); - //size = host2dns(outbuf, p+2, outbuflen); - PUTSHORT(outbuflen, p); - memcpy(p, outbuf, outbuflen); - p += outbuflen; + if(outbuflen > 0) { + printf("%d\n", outid); + PUTSHORT(outbuflen, p); + memcpy(p, outbuf, outbuflen); + p += outbuflen; + } else { + PUTSHORT(0, p); + } len = p - buf; printf("Responding with %d\n", len); @@ -224,7 +232,6 @@ dnsd_respond(int fd, short id, struct sockaddr_in from) int dnsd_read(int fd, char *buf, int buflen) { - int i; int r; short id; short type; @@ -261,12 +268,14 @@ dnsd_read(int fd, char *buf, int buflen) if(!header->qr) { qdcount = ntohs(header->qdcount); - for(i=0;i 0) { - printf("Sending response\n"); dnsd_queuepacket(frame->data, read - 4); } }