Mercurial > hg > quicktun
diff src/common.c @ 7:fd7c60905b13
BSD support
author | ivo <Ivo@UCIS.nl> |
---|---|
date | Wed, 13 Oct 2010 21:07:44 +0200 |
parents | cf9b44b46be5 |
children | 6d86596d8884 |
line wrap: on
line diff
--- a/src/common.c Fri Oct 08 23:29:56 2010 +0000 +++ b/src/common.c Wed Oct 13 21:07:44 2010 +0200 @@ -31,12 +31,18 @@ #include <netinet/in.h> #endif #include <sys/ioctl.h> -#include <linux/if.h> -#include <linux/if_tun.h> -#include <linux/if_ether.h> +#include <net/if.h> +#include <sys/socket.h> #include <poll.h> #include <netdb.h> #include <stdlib.h> +#ifdef linux + #include <linux/if_tun.h> + #include <linux/if_ether.h> +#else + #define ETH_FRAME_LEN 1514 + #include <net/if_tun.h> +#endif #define MAX_PACKET_LEN (ETH_FRAME_LEN+4) //Some space for optional packet information @@ -132,15 +138,20 @@ int init_tuntap() { char* envval; - fprintf(stderr, "Initializing tap device...\n"); + fprintf(stderr, "Initializing tun/tap device...\n"); int ttfd; //Tap device file descriptor - 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 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 (ioctl(ttfd, TUNSETIFF, (void *)&ifr) < 0) return errorexitp("TUNSETIFF ioctl failed"); +#ifdef 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 (ioctl(ttfd, TUNSETIFF, (void *)&ifr) < 0) return errorexitp("TUNSETIFF ioctl failed"); +#else + if (!(envval = getconf("INTERFACE"))) envval = "/dev/tun0"; + if ((ttfd = open(envval, O_RDWR)) < 0) return errorexitp("Could not open tun device file"); +#endif return ttfd; }