From e1c0a595df415ffcb842b9be94ac2d90abd31c57 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Mon, 5 Jun 2006 14:46:10 +0000 Subject: [PATCH] signal fluff for qujitting --- dnstun.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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);