1
0
mirror of https://github.com/yarrick/iodine.git synced 2024-11-29 16:36:03 +03:00

cleanup and stuff

This commit is contained in:
Bjorn Andersson 2006-06-06 00:39:29 +00:00
parent b91fb102d3
commit 34b8ee6794
4 changed files with 21 additions and 12 deletions

12
dns.c
View File

@ -288,17 +288,14 @@ dns_write(int fd, int id, char *buf, int len)
int
dns_read(int fd, char *buf, int buflen)
{
int i;
int r;
long ttl;
short rlen;
short type;
short class;
short port;
short ancount;
char *data;
char name[255];
char host[255];
char rdata[256];
HEADER *header;
char packet[64*1024];
@ -319,17 +316,13 @@ dns_read(int fd, char *buf, int buflen)
rlen = 0;
for(i=0;i<ancount;i++) {
if(ancount == 1) {
READNAME(packet, name, data);
READSHORT(type, data);
READSHORT(class, data);
READLONG(ttl, data);
READSHORT(rlen, data);
READDATA(rdata, data, rlen);
if(type == T_NULL) {
memcpy(buf, rdata, rlen);
}
}
if (dns_sending() && chunkid == ntohs(header->id)) {
// Got ACK on sent packet
@ -346,6 +339,9 @@ dns_read(int fd, char *buf, int buflen)
}
}
if(ttl == T_NULL && rlen)
memcpy(buf, rdata, rlen);
// TODO is any data attached? find out and copy into buf and return length
return rlen;
}

1
dnsd.c
View File

@ -215,6 +215,7 @@ dnsd_respond(int fd, short id, struct sockaddr_in from)
p += outbuflen;
len = p - buf;
printf("Responding with %d\n", len);
sendto(fd, buf, len, 0, (struct sockaddr*)&from, sizeof(from));
outbuflen = 0;

View File

@ -88,8 +88,11 @@ tunnel(int tun_fd, int dns_fd)
if (read > 0) {
printf("Got data on dns! %d bytes\n", read);
//frame->flags = htons(0x0000);
//frame->proto = htons(0x0200);
#ifdef LINUX
frame->proto = htons(0x0800);
#else
frame->proto = htons(0x0002);
#endif
write_tun(tun_fd, frame, read + 4);
}

View File

@ -57,8 +57,10 @@ tunnel(int tun_fd, int dns_fd)
tv.tv_usec = 0;
FD_ZERO(&fds);
if(!dnsd_haspacket())
if(!dnsd_haspacket()) {
printf("There is room for more\n");
FD_SET(tun_fd, &fds);
}
FD_SET(dns_fd, &fds);
i = select(MAX(tun_fd, dns_fd) + 1, &fds, NULL, NULL, &tv);
@ -72,15 +74,22 @@ tunnel(int tun_fd, int dns_fd)
if(i != 0) {
if(FD_ISSET(tun_fd, &fds)) {
printf("data on tun\n");
read = read_tun(tun_fd, frame, 64*1024);
if(read > 0)
if(read > 0) {
printf("Sending response\n");
dnsd_queuepacket(frame->data, read - 4);
}
}
if(FD_ISSET(dns_fd, &fds)) {
read = dnsd_read(dns_fd, frame->data, 64*1024-4);
if(read > 0) {
frame->flags = htons(0x0000);
#ifdef LINUX
frame->proto = htons(0x0800);
#else
frame->proto = htons(0x0002);
#endif
write_tun(tun_fd, frame, read + 4);
}
}