Mercurial > hg > quicktun
comparison 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 |
comparison
equal
deleted
inserted
replaced
31:a51d07ac3f1b | 32:51c6d2fc712f |
---|---|
144 | 144 |
145 int init_tuntap() { | 145 int init_tuntap() { |
146 char* envval; | 146 char* envval; |
147 fprintf(stderr, "Initializing tun/tap device...\n"); | 147 fprintf(stderr, "Initializing tun/tap device...\n"); |
148 int ttfd; //Tap device file descriptor | 148 int ttfd; //Tap device file descriptor |
149 #ifdef linux | 149 #if defined linux |
150 struct ifreq ifr; //required for tun/tap setup | 150 struct ifreq ifr; //required for tun/tap setup |
151 memset(&ifr, 0, sizeof(ifr)); | 151 memset(&ifr, 0, sizeof(ifr)); |
152 if ((ttfd = open("/dev/net/tun", O_RDWR)) < 0) return errorexitp("Could not open tun/tap device file"); | 152 if ((ttfd = open("/dev/net/tun", O_RDWR)) < 0) return errorexitp("Could not open tun/tap device file"); |
153 if (envval = getconf("INTERFACE")) strcpy(ifr.ifr_name, envval); | 153 if (envval = getconf("INTERFACE")) strcpy(ifr.ifr_name, envval); |
154 ifr.ifr_flags = getconf("TUN_MODE") ? IFF_TUN : IFF_TAP; | 154 if ((envval = getconf("TUN_MODE")) && atoi(envval)) { |
155 ifr.ifr_flags |= getconf("USE_PI") ? 0 : IFF_NO_PI; | 155 ifr.ifr_flags = IFF_TUN; |
156 } else { | |
157 ifr.ifr_flags = IFF_TAP; | |
158 } | |
159 if (!(envval = getconf("USE_PI")) || !atoi(envval)) { | |
160 ifr.ifr_flags |= IFF_NO_PI; | |
161 } | |
156 if (ioctl(ttfd, TUNSETIFF, (void *)&ifr) < 0) return errorexitp("TUNSETIFF ioctl failed"); | 162 if (ioctl(ttfd, TUNSETIFF, (void *)&ifr) < 0) return errorexitp("TUNSETIFF ioctl failed"); |
157 #else | 163 #elif defined SOLARIS |
158 #ifdef SOLARIS | |
159 int ip_fd = -1, if_fd = -1, ppa = 0; | 164 int ip_fd = -1, if_fd = -1, ppa = 0; |
160 if ((ttfd = open("/dev/tun", O_RDWR)) < 0) return errorexitp("Could not open tun device file"); | 165 if ((ttfd = open("/dev/tun", O_RDWR)) < 0) return errorexitp("Could not open tun device file"); |
161 if ((ip_fd = open("/dev/ip", O_RDWR, 0)) < 0) return errorexitp("Could not open /dev/ip"); | 166 if ((ip_fd = open("/dev/ip", O_RDWR, 0)) < 0) return errorexitp("Could not open /dev/ip"); |
162 if ((envval = getconf("INTERFACE"))) { | 167 if ((envval = getconf("INTERFACE"))) { |
163 while (*envval && !isdigit((int)*envval)) envval++; | 168 while (*envval && !isdigit((int)*envval)) envval++; |
169 if (ioctl(if_fd, IF_UNITSEL, (char *)&ppa) < 0) return errorexitp("Could not set PPA"); | 174 if (ioctl(if_fd, IF_UNITSEL, (char *)&ppa) < 0) return errorexitp("Could not set PPA"); |
170 if (ioctl(ip_fd, I_LINK, if_fd) < 0) return errorexitp("Could not link TUN device to IP"); | 175 if (ioctl(ip_fd, I_LINK, if_fd) < 0) return errorexitp("Could not link TUN device to IP"); |
171 #else | 176 #else |
172 if (!(envval = getconf("INTERFACE"))) envval = "/dev/tun0"; | 177 if (!(envval = getconf("INTERFACE"))) envval = "/dev/tun0"; |
173 if ((ttfd = open(envval, O_RDWR)) < 0) return errorexitp("Could not open tun device file"); | 178 if ((ttfd = open(envval, O_RDWR)) < 0) return errorexitp("Could not open tun device file"); |
174 #endif | |
175 #endif | 179 #endif |
176 return ttfd; | 180 return ttfd; |
177 } | 181 } |
178 | 182 |
179 void hex2bin(unsigned char* dest, unsigned char* src, int count) { | 183 void hex2bin(unsigned char* dest, unsigned char* src, int count) { |