compression in server response

This commit is contained in:
Bjorn Andersson 2006-06-24 12:44:26 +00:00
parent d2f691a21b
commit ae37edcb77
1 changed files with 9 additions and 12 deletions

21
dns.c
View File

@ -352,7 +352,6 @@ dns_read(int fd, char *buf, int buflen)
return 0;
}
static int
host2dns(const char *host, char *buffer, int size)
{
@ -386,6 +385,7 @@ dnsd_send(int fd, struct query *q, char *data, int datalen)
int len;
char *p;
char buf[64*1024];
short name;
HEADER *header;
memset(buf, 0, sizeof(buf));
@ -406,24 +406,21 @@ dnsd_send(int fd, struct query *q, char *data, int datalen)
p = buf + sizeof(HEADER);
name = 0xc000 | ((p - buf) & 0x3fff);
p += host2dns(q->name, p, strlen(q->name));
PUTSHORT(q->type, p);
PUTSHORT(C_IN, p);
p += host2dns(q->name, p, strlen(q->name));
PUTSHORT(name, p);
PUTSHORT(q->type, p);
PUTSHORT(C_IN, p);
PUTLONG(0, p);
q->id = 0;
if(datalen > 0) {
PUTSHORT(datalen, p);
memcpy(p, data, datalen);
p += datalen;
} else {
PUTSHORT(0, p);
}
PUTSHORT(datalen, p);
memcpy(p, data, datalen);
p += datalen;
len = p - buf;
sendto(fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen);
@ -481,9 +478,7 @@ dnsd_read(int fd, struct query *q, char *buf, int buflen)
addrlen = sizeof(struct sockaddr);
r = recvfrom(fd, packet, sizeof(packet), 0, (struct sockaddr*)&from, &addrlen);
if(r == -1) {
perror("recvfrom");
} else {
if (r >= sizeof(HEADER)) {
header = (HEADER*)packet;
id = ntohs(header->id);
@ -508,6 +503,8 @@ dnsd_read(int fd, struct query *q, char *buf, int buflen)
return decodepacket(name, buf, buflen);
}
}
} else {
perror("recvfrom");
}
return 0;