From: ng0 Date: Fri, 22 Nov 2019 23:38:31 +0000 (+0000) Subject: exit: initial (very rough, builds) *BSD support - to the point X-Git-Tag: v0.12.0~100 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=00ddb1c1d483f8d870ed2293bf14da6b7b9259a1;p=oweals%2Fgnunet.git exit: initial (very rough, builds) *BSD support - to the point where the Linux specific binaries would still be used, thus marked as experimental. --- diff --git a/src/exit/Makefile.am b/src/exit/Makefile.am index c0323d0d6..811761ed0 100644 --- a/src/exit/Makefile.am +++ b/src/exit/Makefile.am @@ -17,6 +17,12 @@ dist_pkgcfg_DATA = \ if LINUX EXITBIN = gnunet-helper-exit endif +# For testing purposes: +if HAVE_EXPERIMENTAL +if XBSD +EXITBIN = gnunet-helper-exit +endif +endif libexec_PROGRAMS = \ diff --git a/src/exit/gnunet-helper-exit.c b/src/exit/gnunet-helper-exit.c index cf322725d..9d20a0c50 100644 --- a/src/exit/gnunet-helper-exit.c +++ b/src/exit/gnunet-helper-exit.c @@ -42,7 +42,15 @@ * - Philipp Tölke */ #include "platform.h" -#include + +#ifdef IF_TUN_HDR +#include IF_TUN_HDR +#endif + +#if defined(BSD) || defined(SOLARIS) +#define ifr_netmask ifr_ifru.ifru_addr +#define SIOGIFINDEX SIOCGIFINDEX +#endif /** * Need 'struct GNUNET_MessageHeader'. @@ -182,6 +190,7 @@ fork_and_exec (const char *file, * if *dev == '\\0', uses the name supplied by the kernel; * @return the fd to the tun or -1 on error */ +#ifdef IFF_TUN /* LINUX */ static int init_tun (char *dev) { @@ -225,7 +234,34 @@ init_tun (char *dev) strcpy (dev, ifr.ifr_name); return fd; } +#else /* BSD et al, including DARWIN */ +#ifdef SIOCIFCREATE +static int +init_tun(char *dev) +{ + int fd; + int s; + struct ifreq ifr; + + fd = open(dev, O_RDWR); + if(fd == -1) + { + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) + return -1; + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, dev + 5, sizeof(ifr.ifr_name) - 1); + if (!ioctl(s, SIOCIFCREATE, &ifr)) + fd = open(dev, O_RDWR); + close(s); + } + return fd; +} +#else +#define init_tun(dev) open(dev, O_RDWR) +#endif +#endif /* !IFF_TUN (BSD) */ /** * @brief Sets the IPv6-Address given in address on the interface dev