mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-25 23:41:29 +00:00
Fix handling of answers from real dns
This commit is contained in:
parent
74a778fdf0
commit
5a224ee71a
13
dns.c
13
dns.c
|
@ -293,6 +293,7 @@ dns_read(int fd, char *buf, int buflen)
|
|||
short rlen;
|
||||
short type;
|
||||
short class;
|
||||
short qdcount;
|
||||
short ancount;
|
||||
char *data;
|
||||
char name[255];
|
||||
|
@ -312,10 +313,16 @@ dns_read(int fd, char *buf, int buflen)
|
|||
data = packet + sizeof(HEADER);
|
||||
|
||||
if(header->qr) { /* qr=1 => response */
|
||||
qdcount = ntohs(header->qdcount);
|
||||
ancount = ntohs(header->ancount);
|
||||
|
||||
rlen = 0;
|
||||
|
||||
if(qdcount == 1) {
|
||||
READNAME(packet, name, data);
|
||||
READSHORT(type, data);
|
||||
READSHORT(class, data);
|
||||
}
|
||||
if(ancount == 1) {
|
||||
READNAME(packet, name, data);
|
||||
READSHORT(type, data);
|
||||
|
@ -339,10 +346,12 @@ dns_read(int fd, char *buf, int buflen)
|
|||
}
|
||||
}
|
||||
|
||||
if(ttl == T_NULL && rlen)
|
||||
if(type == T_NULL && rlen) {
|
||||
memcpy(buf, rdata, rlen);
|
||||
|
||||
return rlen;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
10
dnstun.c
10
dnstun.c
|
@ -47,15 +47,24 @@ tunnel(int tun_fd, int dns_fd)
|
|||
{
|
||||
int i;
|
||||
int read;
|
||||
int fastpoll;
|
||||
fd_set fds;
|
||||
struct timeval tv;
|
||||
struct tun_frame *frame;
|
||||
|
||||
frame = malloc(FRAMESIZE);
|
||||
fastpoll = 0;
|
||||
|
||||
while (running) {
|
||||
if (fastpoll) {
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 5000;
|
||||
fastpoll = 0;
|
||||
printf("Fast poll\n");
|
||||
} else {
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
}
|
||||
|
||||
FD_ZERO(&fds);
|
||||
if (!dns_sending()) {
|
||||
|
@ -95,6 +104,7 @@ tunnel(int tun_fd, int dns_fd)
|
|||
#endif
|
||||
|
||||
write_tun(tun_fd, frame, read + 4);
|
||||
fastpoll = 1; // make sure we send packet real soon
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue