From 43787fae12bd77d4142daff926db7db2ed7ee88c Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Mon, 5 Jun 2006 15:13:30 +0000 Subject: [PATCH] nonworking read of dns reply --- dns.c | 21 +++++++++++++++++++-- dns.h | 3 ++- dnstun.c | 11 ++++++++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/dns.c b/dns.c index a156b52..031d0f4 100644 --- a/dns.c +++ b/dns.c @@ -33,6 +33,7 @@ static int host2dns(const char *, char *, int); struct sockaddr_in peer; +char topdomain[256]; int open_dns() @@ -87,9 +88,9 @@ dns_set_peer(const char *host) } void -dns_ping() +dns_ping(int dns_fd) { - + dns_query(dns_fd, "kryo.se", 1); } void @@ -128,6 +129,22 @@ dns_query(int fd, char *host, int type) sendto(fd, buf, len+1, 0, (struct sockaddr*)&peer, peerlen); } +int +dns_read(int fd, char *buf, int len) +{ + int r; + int fromlen; + struct sockaddr_in from; + + r = recvfrom(fd, buf, len, 0, (struct sockaddr*)&from, &fromlen); + if (r < 0) { + perror("recvfrom"); + } + printf("Read %d bytes DNS reply\n", r); + + return r; +} + static int host2dns(const char *host, char *buffer, int size) { diff --git a/dns.h b/dns.h index 74ff79f..2b9cf87 100644 --- a/dns.h +++ b/dns.h @@ -25,8 +25,9 @@ int open_dns(); void close_dns(int); void dns_set_peer(const char *); -void dns_ping(); +void dns_ping(int); void dns_query(int, char *, int); +int dns_read(int, char *, int); #endif /* _DNS_H_ */ diff --git a/dnstun.c b/dnstun.c index f6938a4..54fb172 100644 --- a/dnstun.c +++ b/dnstun.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include "tun.h" @@ -38,7 +40,11 @@ tunnel(int tun_fd, int dns_fd) int i; fd_set fds; struct timeval tv; + char buf[1024]; + int buflen; + int read; + buflen = 1024; while (running) { tv.tv_sec = 1; tv.tv_usec = 0; @@ -55,13 +61,13 @@ tunnel(int tun_fd, int dns_fd) } if(i == 0) { - dns_ping(); + dns_ping(dns_fd); } else { if(FD_ISSET(tun_fd, &fds)) { } if(FD_ISSET(dns_fd, &fds)) { - + read = dns_read(dns_fd, buf, buflen); } } } @@ -81,7 +87,6 @@ main() signal(SIGINT, sigint); dns_set_peer("192.168.11.101"); - dns_query(dns_fd, "kryo.se", 1); tunnel(tun_fd, dns_fd);