compression in server response

This commit is contained in:
Bjorn Andersson 2006-06-24 12:44:26 +00:00
parent d2f691a21b
commit ae37edcb77

15
dns.c
View File

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