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