Mercurial > hg > quicktun
comparison src/common.c @ 54:4ff8003d0973
Fix for OpenBSD tun/tap initialization
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sat, 23 Nov 2013 16:58:54 +0100 |
parents | 3115f8af98bb |
children | 5685fad38195 |
comparison
equal
deleted
inserted
replaced
53:15d651dec8e9 | 54:4ff8003d0973 |
---|---|
214 int ttfd; //Tap device file descriptor | 214 int ttfd; //Tap device file descriptor |
215 int tunmode = 0; | 215 int tunmode = 0; |
216 if (envval = getconf("TUN_MODE")) tunmode = atoi(envval); | 216 if (envval = getconf("TUN_MODE")) tunmode = atoi(envval); |
217 session->use_pi = 0; | 217 session->use_pi = 0; |
218 if (tunmode && (envval = getconf("USE_PI"))) session->use_pi = atoi(envval); | 218 if (tunmode && (envval = getconf("USE_PI"))) session->use_pi = atoi(envval); |
219 #if defined linux | 219 #if defined(__linux__) |
220 struct ifreq ifr; //required for tun/tap setup | 220 struct ifreq ifr; //required for tun/tap setup |
221 memset(&ifr, 0, sizeof(ifr)); | 221 memset(&ifr, 0, sizeof(ifr)); |
222 if ((ttfd = open("/dev/net/tun", O_RDWR)) < 0) return errorexitp("Could not open tun/tap device file"); | 222 if ((ttfd = open("/dev/net/tun", O_RDWR)) < 0) return errorexitp("Could not open tun/tap device file"); |
223 if (envval = getconf("INTERFACE")) strcpy(ifr.ifr_name, envval); | 223 if (envval = getconf("INTERFACE")) strcpy(ifr.ifr_name, envval); |
224 ifr.ifr_flags = tunmode ? IFF_TUN : IFF_TAP; | 224 ifr.ifr_flags = tunmode ? IFF_TUN : IFF_TAP; |
241 if (!(envval = getconf("INTERFACE"))) envval = "/dev/tun0"; | 241 if (!(envval = getconf("INTERFACE"))) envval = "/dev/tun0"; |
242 if ((ttfd = open(envval, O_RDWR)) < 0) return errorexitp("Could not open tun device file"); | 242 if ((ttfd = open(envval, O_RDWR)) < 0) return errorexitp("Could not open tun device file"); |
243 if (tunmode) { | 243 if (tunmode) { |
244 int i = IFF_POINTOPOINT | IFF_MULTICAST; | 244 int i = IFF_POINTOPOINT | IFF_MULTICAST; |
245 ioctl(ttfd, TUNSIFMODE, &i); | 245 ioctl(ttfd, TUNSIFMODE, &i); |
246 #if defined(__OpenBSD__) | |
247 if (!session->use_pi) session->use_pi = 2; | |
248 #else | |
246 i = session->use_pi ? 1 : 0; | 249 i = session->use_pi ? 1 : 0; |
247 ioctl(ttfd, TUNSIFHEAD, &i); | 250 ioctl(ttfd, TUNSIFHEAD, &i); |
251 #endif | |
248 } | 252 } |
249 #endif | 253 #endif |
250 if (envval = getconf("TUN_UP_SCRIPT")) system(envval); | 254 if (envval = getconf("TUN_UP_SCRIPT")) system(envval); |
251 session->fd_dev = ttfd; | 255 session->fd_dev = ttfd; |
252 return ttfd; | 256 return ttfd; |