New encoder, this one works

This commit is contained in:
Erik Ekman 2006-06-05 23:34:44 +00:00
parent c816cb71d3
commit f436823146

32
dns.c
View File

@ -225,14 +225,25 @@ dns_query(int fd, int id, char *host, int type)
sendto(fd, buf, len, 0, (struct sockaddr*)&peer, peerlen); sendto(fd, buf, len, 0, (struct sockaddr*)&peer, peerlen);
} }
static char to_hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
static void
put_hex(char *p, char h)
{
int t;
t = (h & 0xF0) >> 4;
p[0] = to_hex[t];
t = h & 0x0F;
p[1] = to_hex[t];
}
int int
dns_write(int fd, int id, char *buf, int len) dns_write(int fd, int id, char *buf, int len)
{ {
int avail; int avail;
int i; int i;
int final; int final;
int parts;
int p;
char data[257]; char data[257];
char *d; char *d;
@ -253,20 +264,17 @@ dns_write(int fd, int id, char *buf, int len)
*d = '0' + final; *d = '0' + final;
d++; d++;
parts = avail / CHUNK; for (i = 0; i < avail; i++) {
for (p = 0; p < parts; p++) { if (i > 0 && i % 31 == 0) {
for (i = 0; i < CHUNK; i++) { *d = '.';
snprintf(d, 3, "%02X", buf[p*CHUNK + i]); d++;
}
put_hex(d, buf[i]);
d += 2; d += 2;
} }
if (*d != '.') {
*d++ = '.'; *d++ = '.';
} }
parts = avail % CHUNK;
for (i = 0; i < parts; i++) {
snprintf(d, 3, "%02X", buf[p*CHUNK + i]);
d += 2;
}
*d++ = '.';
strncpy(d, topdomain, strlen(topdomain)+1); strncpy(d, topdomain, strlen(topdomain)+1);
printf("Resolving %s\n", data); printf("Resolving %s\n", data);