server ok

This commit is contained in:
Bjorn Andersson 2006-06-06 02:27:10 +00:00
parent e6da8c66d8
commit 1fd044cbff
2 changed files with 25 additions and 20 deletions

40
dnsd.c
View File

@ -39,6 +39,7 @@ char topdomain[256];
int packetlen; int packetlen;
char activepacket[4096]; char activepacket[4096];
int outid;
int outbuflen; int outbuflen;
char outbuf[64*1024]; char outbuf[64*1024];
@ -174,10 +175,11 @@ dnsd_queuepacket(const char *buf, const int buflen)
memcpy(outbuf, buf, buflen); memcpy(outbuf, buf, buflen);
outbuflen = buflen; outbuflen = buflen;
outid++;
} }
static void 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; int len;
char *p; char *p;
@ -189,7 +191,7 @@ dnsd_respond(int fd, short id, struct sockaddr_in from)
len = 0; len = 0;
header = (HEADER*)buf; header = (HEADER*)buf;
header->id = id; header->id = htons(id);
header->qr = 1; header->qr = 1;
header->opcode = 0; header->opcode = 0;
header->aa = 1; header->aa = 1;
@ -197,22 +199,28 @@ dnsd_respond(int fd, short id, struct sockaddr_in from)
header->rd = 0; header->rd = 0;
header->ra = 0; header->ra = 0;
if(outbuflen > 0) header->qdcount = htons(1);
header->ancount = htons(1); header->ancount = htons(1);
else
header->ancount = htons(0);
p = buf + sizeof(HEADER); p = buf + sizeof(HEADER);
p += host2dns("fluff", p, 5); p += host2dns(name, p, strlen(name));
PUTSHORT(T_NULL, p); PUTSHORT(type, p);
PUTSHORT(C_IN, 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); if(outbuflen > 0) {
PUTSHORT(outbuflen, p); printf("%d\n", outid);
memcpy(p, outbuf, outbuflen); PUTSHORT(outbuflen, p);
p += outbuflen; memcpy(p, outbuf, outbuflen);
p += outbuflen;
} else {
PUTSHORT(0, p);
}
len = p - buf; len = p - buf;
printf("Responding with %d\n", len); printf("Responding with %d\n", len);
@ -224,7 +232,6 @@ dnsd_respond(int fd, short id, struct sockaddr_in from)
int int
dnsd_read(int fd, char *buf, int buflen) dnsd_read(int fd, char *buf, int buflen)
{ {
int i;
int r; int r;
short id; short id;
short type; short type;
@ -261,12 +268,14 @@ dnsd_read(int fd, char *buf, int buflen)
if(!header->qr) { if(!header->qr) {
qdcount = ntohs(header->qdcount); qdcount = ntohs(header->qdcount);
for(i=0;i<qdcount;i++) { if(qdcount == 1) {
bzero(name, sizeof(name)); bzero(name, sizeof(name));
READNAME(packet, name, data); READNAME(packet, name, data);
READSHORT(type, data); READSHORT(type, data);
READSHORT(class, data); READSHORT(class, data);
dnsd_respond(fd, name, type, id, from);
lastblock = name[0] - '0'; lastblock = name[0] - '0';
np = name; np = name;
np++; // skip first byte, it has only fragmentation info np++; // skip first byte, it has only fragmentation info
@ -289,7 +298,6 @@ dnsd_read(int fd, char *buf, int buflen)
packetp++; packetp++;
packetlen++; packetlen++;
} }
dnsd_respond(fd, id, from);
if (lastblock && packetlen < 2) { if (lastblock && packetlen < 2) {
// Skipping ping packet // Skipping ping packet
packetlen = 0; packetlen = 0;

View File

@ -57,10 +57,8 @@ tunnel(int tun_fd, int dns_fd)
tv.tv_usec = 0; tv.tv_usec = 0;
FD_ZERO(&fds); FD_ZERO(&fds);
if(!dnsd_haspacket()) { if(!dnsd_haspacket())
printf("There is room for more\n");
FD_SET(tun_fd, &fds); FD_SET(tun_fd, &fds);
}
FD_SET(dns_fd, &fds); FD_SET(dns_fd, &fds);
i = select(MAX(tun_fd, dns_fd) + 1, &fds, NULL, NULL, &tv); i = select(MAX(tun_fd, dns_fd) + 1, &fds, NULL, NULL, &tv);
@ -77,7 +75,6 @@ tunnel(int tun_fd, int dns_fd)
printf("data on tun\n"); printf("data on tun\n");
read = read_tun(tun_fd, frame, 64*1024); read = read_tun(tun_fd, frame, 64*1024);
if(read > 0) { if(read > 0) {
printf("Sending response\n");
dnsd_queuepacket(frame->data, read - 4); dnsd_queuepacket(frame->data, read - 4);
} }
} }