diff --git a/dnstun.c b/dnstun.c index bf761f0..f6938a4 100644 --- a/dnstun.c +++ b/dnstun.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "tun.h" @@ -24,6 +25,13 @@ #define MAX(a,b) ((a)>(b)?(a):(b)) +int running = 1; + +static void +sigint(int sig) { + running = 0; +} + static int tunnel(int tun_fd, int dns_fd) { @@ -31,7 +39,7 @@ tunnel(int tun_fd, int dns_fd) fd_set fds; struct timeval tv; - for (;;) { + while (running) { tv.tv_sec = 1; tv.tv_usec = 0; @@ -69,11 +77,16 @@ main() tun_fd = open_tun(); dns_fd = open_dns(); + + signal(SIGINT, sigint); + dns_set_peer("192.168.11.101"); dns_query(dns_fd, "kryo.se", 1); tunnel(tun_fd, dns_fd); + printf("Closing tunnel\n"); + close_dns(dns_fd); close_tun(tun_fd);