#3 remove dnsd_send from dns.c, move to iodined.c

This commit is contained in:
Erik Ekman 2007-02-05 17:49:30 +00:00
parent 1cba145310
commit 9b438c20d4
2 changed files with 20 additions and 20 deletions

View file

@ -254,15 +254,3 @@ dns_encode_hostname(const char *host, char *buffer, int size)
return p - buffer; return p - buffer;
} }
void
dnsd_send(int fd, struct query *q, char *data, int datalen)
{
char buf[64*1024];
int len;
len = dns_encode(buf, sizeof(buf), q, QR_ANSWER, data, datalen);
sendto(fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen);
}

View file

@ -56,6 +56,7 @@ int my_mtu;
in_addr_t my_ip; in_addr_t my_ip;
static int read_dns(int, struct query *, char *, int); static int read_dns(int, struct query *, char *, int);
static void write_dns(int, struct query *, char *, int);
static void static void
sigint(int sig) sigint(int sig)
@ -112,18 +113,18 @@ tunnel_dns(int tun_fd, int dns_fd)
nseed = htonl(seed); nseed = htonl(seed);
strncpy(out, "VACK", sizeof(out)); strncpy(out, "VACK", sizeof(out));
memcpy(out+4, &nseed, 4); memcpy(out+4, &nseed, 4);
dnsd_send(dns_fd, &q, out, 8); write_dns(dns_fd, &q, out, 8);
} else { } else {
version = htonl(VERSION); version = htonl(VERSION);
strncpy(out, "VNAK", sizeof(out)); strncpy(out, "VNAK", sizeof(out));
memcpy(out+4, &version, 4); memcpy(out+4, &version, 4);
dnsd_send(dns_fd, &q, out, 8); write_dns(dns_fd, &q, out, 8);
} }
} else { } else {
version = htonl(VERSION); version = htonl(VERSION);
strncpy(out, "VNAK", sizeof(out)); strncpy(out, "VNAK", sizeof(out));
memcpy(out+4, &version, 4); memcpy(out+4, &version, 4);
dnsd_send(dns_fd, &q, out, 8); write_dns(dns_fd, &q, out, 8);
} }
} else if(in[0] == 'L' || in[0] == 'l') { } else if(in[0] == 'L' || in[0] == 'l') {
/* Login phase, handle auth */ /* Login phase, handle auth */
@ -143,13 +144,13 @@ tunnel_dns(int tun_fd, int dns_fd)
memcpy(&(u.host), &(q.from), q.fromlen); memcpy(&(u.host), &(q.from), q.fromlen);
u.addrlen = q.fromlen; u.addrlen = q.fromlen;
dnsd_send(dns_fd, &q, out, read); write_dns(dns_fd, &q, out, read);
q.id = 0; q.id = 0;
free(tmp[1]); free(tmp[1]);
free(tmp[0]); free(tmp[0]);
} else { } else {
dnsd_send(dns_fd, &q, "LNAK", 4); write_dns(dns_fd, &q, "LNAK", 4);
} }
} else if((in[0] >= '0' && in[0] <= '9') } else if((in[0] >= '0' && in[0] <= '9')
|| (in[0] >= 'a' && in[0] <= 'f') || (in[0] >= 'a' && in[0] <= 'f')
@ -164,7 +165,7 @@ tunnel_dns(int tun_fd, int dns_fd)
/* Check sending ip number */ /* Check sending ip number */
if (q.fromlen != u.addrlen || if (q.fromlen != u.addrlen ||
memcmp(&(u.host), &(q.from), q.fromlen) != 0) { memcmp(&(u.host), &(q.from), q.fromlen) != 0) {
dnsd_send(dns_fd, &q, "BADIP", 5); write_dns(dns_fd, &q, "BADIP", 5);
} else { } else {
memcpy(packetbuf.data + packetbuf.offset, in + 1, read - 1); memcpy(packetbuf.data + packetbuf.offset, in + 1, read - 1);
packetbuf.len += read - 1; packetbuf.len += read - 1;
@ -184,7 +185,7 @@ tunnel_dns(int tun_fd, int dns_fd)
memcmp(&(u.host), &(q.from), q.fromlen) == 0 && memcmp(&(u.host), &(q.from), q.fromlen) == 0 &&
outpacket.len > 0) { outpacket.len > 0) {
dnsd_send(dns_fd, &q, outpacket.data, outpacket.len); write_dns(dns_fd, &q, outpacket.data, outpacket.len);
outpacket.len = 0; outpacket.len = 0;
q.id = 0; q.id = 0;
} }
@ -223,7 +224,7 @@ tunnel(int tun_fd, int dns_fd)
if (i==0) { if (i==0) {
if (q.id != 0) { if (q.id != 0) {
dnsd_send(dns_fd, &q, outpacket.data, outpacket.len); write_dns(dns_fd, &q, outpacket.data, outpacket.len);
outpacket.len = 0; outpacket.len = 0;
q.id = 0; q.id = 0;
} }
@ -270,6 +271,17 @@ read_dns(int fd, struct query *q, char *buf, int buflen)
return rv; return rv;
} }
static void
write_dns(int fd, struct query *q, char *data, int datalen)
{
char buf[64*1024];
int len;
len = dns_encode(buf, sizeof(buf), q, QR_ANSWER, data, datalen);
sendto(fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen);
}
static void static void
usage() { usage() {
extern char *__progname; extern char *__progname;