Mercurial > hg > quicktun
comparison src/common.c @ 13:f7e0145d8e2a
solaris support
author | Gabor Adam Toth <tg@tgbit.net> |
---|---|
date | Sat, 08 Jan 2011 02:25:17 +0100 |
parents | e4b60d041491 |
children | 1fa5b5fa49e1 |
comparison
equal
deleted
inserted
replaced
12:e4b60d041491 | 13:f7e0145d8e2a |
---|---|
40 #include <linux/if_tun.h> | 40 #include <linux/if_tun.h> |
41 #include <linux/if_ether.h> | 41 #include <linux/if_ether.h> |
42 #else | 42 #else |
43 #define ETH_FRAME_LEN 1514 | 43 #define ETH_FRAME_LEN 1514 |
44 #include <net/if_tun.h> | 44 #include <net/if_tun.h> |
45 #ifdef SOLARIS | |
46 #include <sys/stropts.h> | |
47 #include <sys/sockio.h> | |
48 #endif | |
45 #endif | 49 #endif |
46 | 50 |
47 #define MAX_PACKET_LEN (ETH_FRAME_LEN+4) //Some space for optional packet information | 51 #define MAX_PACKET_LEN (ETH_FRAME_LEN+4) //Some space for optional packet information |
48 | 52 |
49 struct qtsession; | 53 struct qtsession; |
138 | 142 |
139 int init_tuntap() { | 143 int init_tuntap() { |
140 char* envval; | 144 char* envval; |
141 fprintf(stderr, "Initializing tun/tap device...\n"); | 145 fprintf(stderr, "Initializing tun/tap device...\n"); |
142 int ttfd; //Tap device file descriptor | 146 int ttfd; //Tap device file descriptor |
147 #ifdef SOLARIS | |
148 int ip_fd = -1, if_fd = -1, ppa = 0; | |
149 #endif | |
143 #ifdef linux | 150 #ifdef linux |
144 struct ifreq ifr; //required for tun/tap setup | 151 struct ifreq ifr; //required for tun/tap setup |
145 memset(&ifr, 0, sizeof(ifr)); | 152 memset(&ifr, 0, sizeof(ifr)); |
146 if ((ttfd = open("/dev/net/tun", O_RDWR)) < 0) return errorexitp("Could not open tun/tap device file"); | 153 if ((ttfd = open("/dev/net/tun", O_RDWR)) < 0) return errorexitp("Could not open tun/tap device file"); |
147 if (envval = getconf("INTERFACE")) strcpy(ifr.ifr_name, envval); | 154 if (envval = getconf("INTERFACE")) strcpy(ifr.ifr_name, envval); |
148 ifr.ifr_flags = getconf("TUN_MODE") ? IFF_TUN : IFF_TAP; | 155 ifr.ifr_flags = getconf("TUN_MODE") ? IFF_TUN : IFF_TAP; |
149 ifr.ifr_flags |= getconf("USE_PI") ? 0 : IFF_NO_PI; | 156 ifr.ifr_flags |= getconf("USE_PI") ? 0 : IFF_NO_PI; |
150 if (ioctl(ttfd, TUNSETIFF, (void *)&ifr) < 0) return errorexitp("TUNSETIFF ioctl failed"); | 157 if (ioctl(ttfd, TUNSETIFF, (void *)&ifr) < 0) return errorexitp("TUNSETIFF ioctl failed"); |
151 #else | 158 #else |
159 #ifdef SOLARIS | |
160 if ((ttfd = open("/dev/tun", O_RDWR)) < 0) | |
161 return errorexitp("Could not open tun device file"); | |
162 | |
163 if ((ip_fd = open("/dev/ip", O_RDWR, 0)) < 0) | |
164 return errorexitp("Could not open /dev/ip"); | |
165 | |
166 if ((envval = getconf("INTERFACE"))) { | |
167 while (*envval && !isdigit((int)*envval)) | |
168 envval++; | |
169 ppa = atoi(envval); | |
170 } | |
171 | |
172 if ((ppa = ioctl(ttfd, TUNNEWPPA, ppa)) < 0) | |
173 return errorexitp("Could not assign new PPA"); | |
174 | |
175 if ((if_fd = open("/dev/tun", O_RDWR, 0)) < 0) | |
176 return errorexitp("Could not open tun device file again"); | |
177 | |
178 if (ioctl(if_fd, I_PUSH, "ip") < 0) | |
179 return errorexitp("Could not push IP module"); | |
180 | |
181 if (ioctl(if_fd, IF_UNITSEL, (char *)&ppa) < 0) | |
182 return errorexitp("Could not set PPA"); | |
183 | |
184 if (ioctl(ip_fd, I_LINK, if_fd) < 0) | |
185 return errorexitp("Could not link TUN device to IP"); | |
186 #else | |
152 if (!(envval = getconf("INTERFACE"))) envval = "/dev/tun0"; | 187 if (!(envval = getconf("INTERFACE"))) envval = "/dev/tun0"; |
153 if ((ttfd = open(envval, O_RDWR)) < 0) return errorexitp("Could not open tun device file"); | 188 if ((ttfd = open(envval, O_RDWR)) < 0) return errorexitp("Could not open tun device file"); |
189 #endif | |
154 #endif | 190 #endif |
155 return ttfd; | 191 return ttfd; |
156 } | 192 } |
157 | 193 |
158 void hex2bin(unsigned char* dest, unsigned char* src, int count) { | 194 void hex2bin(unsigned char* dest, unsigned char* src, int count) { |