diff src/common.c @ 32:51c6d2fc712f V2.1.8

Fixes contributed by Daniel Dickinson <daniel@cshore.neomailbox.net>
author Ivo Smits <Ivo@UCIS.nl>
date Wed, 12 Oct 2011 01:34:46 +0200
parents 6f0e6b7dc088
children 422f3582bd38
line wrap: on
line diff
--- a/src/common.c	Wed Oct 12 01:11:48 2011 +0200
+++ b/src/common.c	Wed Oct 12 01:34:46 2011 +0200
@@ -146,16 +146,21 @@
 	char* envval;
 	fprintf(stderr, "Initializing tun/tap device...\n");
 	int ttfd; //Tap device file descriptor
-#ifdef linux
+#if defined linux
 	struct ifreq ifr; //required for tun/tap setup
 	memset(&ifr, 0, sizeof(ifr));
 	if ((ttfd = open("/dev/net/tun", O_RDWR)) < 0) return errorexitp("Could not open tun/tap device file");
 	if (envval = getconf("INTERFACE")) strcpy(ifr.ifr_name, envval);
-	ifr.ifr_flags = getconf("TUN_MODE") ? IFF_TUN : IFF_TAP;
-	ifr.ifr_flags |= getconf("USE_PI") ? 0 : IFF_NO_PI;
+	if ((envval = getconf("TUN_MODE")) && atoi(envval)) {
+		ifr.ifr_flags = IFF_TUN;
+	} else {
+		ifr.ifr_flags = IFF_TAP;
+	}
+	if (!(envval = getconf("USE_PI")) || !atoi(envval)) {
+		ifr.ifr_flags |= IFF_NO_PI;
+	}
 	if (ioctl(ttfd, TUNSETIFF, (void *)&ifr) < 0) return errorexitp("TUNSETIFF ioctl failed");
-#else
-#ifdef SOLARIS
+#elif defined SOLARIS
 	int ip_fd = -1, if_fd = -1, ppa = 0;
 	if ((ttfd = open("/dev/tun", O_RDWR)) < 0) return errorexitp("Could not open tun device file");
 	if ((ip_fd = open("/dev/ip", O_RDWR, 0)) < 0) return errorexitp("Could not open /dev/ip");
@@ -172,7 +177,6 @@
 	if (!(envval = getconf("INTERFACE"))) envval = "/dev/tun0";
 	if ((ttfd = open(envval, O_RDWR)) < 0) return errorexitp("Could not open tun device file");
 #endif
-#endif
 	return ttfd;
 }