mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-27 12:05:15 +00:00
New encoder, this one works
This commit is contained in:
parent
c816cb71d3
commit
f436823146
34
dns.c
34
dns.c
@ -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++;
|
||||||
d += 2;
|
|
||||||
}
|
}
|
||||||
*d++ = '.';
|
put_hex(d, buf[i]);
|
||||||
}
|
|
||||||
parts = avail % CHUNK;
|
|
||||||
for (i = 0; i < parts; i++) {
|
|
||||||
snprintf(d, 3, "%02X", buf[p*CHUNK + i]);
|
|
||||||
d += 2;
|
d += 2;
|
||||||
}
|
}
|
||||||
*d++ = '.';
|
if (*d != '.') {
|
||||||
|
*d++ = '.';
|
||||||
|
}
|
||||||
strncpy(d, topdomain, strlen(topdomain)+1);
|
strncpy(d, topdomain, strlen(topdomain)+1);
|
||||||
|
|
||||||
printf("Resolving %s\n", data);
|
printf("Resolving %s\n", data);
|
||||||
|
Loading…
Reference in New Issue
Block a user