From 45af515f193dd8bc060bcb212ba3a4d61d02bb15 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Thu, 8 Jun 2006 16:30:50 +0000 Subject: [PATCH] Exit if tun device cannot be opened --- tun.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tun.c b/tun.c index 9bb4783..12e5d3b 100644 --- a/tun.c +++ b/tun.c @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -48,7 +49,7 @@ open_tun() if ((tun_fd = open(tun_device, O_RDWR)) < 0) { warn("open_tun: %s: %s", tun_device, strerror(errno)); - return 0; + exit(1); } bzero(&ifreq, sizeof(ifreq)); @@ -70,7 +71,8 @@ open_tun() } warn("open_tun: Couldn't set interface name.\n"); - + exit(1); + return 0; } @@ -86,7 +88,7 @@ open_tun() if (tun_device != NULL) { if ((tun_fd = open(tun_device, O_RDWR)) < 0) { warn("open_tun: %s: %s", tun_device, strerror(errno)); - return 0; + exit(1); } } else { for (i = 0; i < TUN_MAX_TRY; i++) { @@ -102,7 +104,7 @@ open_tun() } warn("open_tun: Failed to open tunneling device."); - return 0; + exit(1); } return 0;