diff options
| author | Nakidai <nakidai@disroot.org> | 2025-12-05 14:30:53 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2025-12-05 14:30:53 +0300 |
| commit | 226096ac0275e6aadf3ff9459e130e6dd1821934 (patch) | |
| tree | 412e00eafa16477c5377f03fca011987d279f045 | |
| parent | 8231f3bef51e0d30eec41aab78631c29b00db491 (diff) | |
| download | fatvpn-dev.tar.gz fatvpn-dev.zip | |
Port fatvpn.c tp OpenBSD dev
Haven't tasted yet, though
| -rw-r--r-- | common.h | 6 | ||||
| -rw-r--r-- | config.h | 3 | ||||
| -rw-r--r-- | fatvpn.c | 14 |
3 files changed, 23 insertions, 0 deletions
diff --git a/common.h b/common.h index 9bb5912..38c5e0a 100644 --- a/common.h +++ b/common.h @@ -14,7 +14,13 @@ #include <net/if.h> #include <fcntl.h> +#ifdef __linux__ #include <linux/if_tun.h> +#elif __OpenBSD__ +#include <sys/stat.h> +#else +#error "unsupported system" +#endif #include "shorttypes.h" #include "sponge-bob.h" diff --git a/config.h b/config.h index f04c1d2..55d0c6c 100644 --- a/config.h +++ b/config.h @@ -4,6 +4,9 @@ /* do not forget to set MTU on tap: MAX_PKT_SZ - HMAC_SZ - NONCE_SZ - 14 */ #define MAX_PKT_SZ 1440 +#ifdef __OpenBSD__ +#define MAX_TAPPATH_SZ 32 +#endif /* comment line below to disable ipv6 entirely */ #define ENABLE_IPV6 diff --git a/fatvpn.c b/fatvpn.c index 59eaa10..01c6459 100644 --- a/fatvpn.c +++ b/fatvpn.c @@ -18,7 +18,11 @@ int main(int argc, char *argv[]){ struct timespec t; struct timeval slp; struct termios attr; +#ifdef __linux__ struct ifreq ifr; +#elif __OpenBSD__ + char *tappath; +#endif fd_set rset; /* arguments */ @@ -135,6 +139,10 @@ int main(int argc, char *argv[]){ /* cur pkt buf */ pkt = malloc(MAX_PKT_SZ); if (pkt == NULL) fputs("pkt = malloc() failed\n",stderr), exit(1); +#ifdef __OpenBSD__ + tappath = malloc(MAX_TAPPATH_SZ); + if (tappath == NULL) fputs("tappath = malloc() failed\n",stderr), exit(1); +#endif /* socket, setsockopt */ skt = socket(srv.ss_family, SOCK_DGRAM, 0); ERRDIE(skt, "socket"); @@ -143,6 +151,7 @@ int main(int argc, char *argv[]){ ERRDIE(res, "SO_REUSEADDR"); /* tap */ +#ifdef __linux__ tap = open("/dev/net/tun", O_RDWR); ERRDIE(tap, "/dev/net/tun"); @@ -151,6 +160,11 @@ int main(int argc, char *argv[]){ strncpy(ifr.ifr_name, argv[1], IFNAMSIZ); res = ioctl(tap, TUNSETIFF, &ifr); ERRDIE(res, "TUNSETIFF"); +#elif __OpenBSD__ + snprintf(tappath, MAX_TAPPATH_SZ, "/dev/%s", argv[1]); + tap = open(tappath, O_RDWR); + ERRDIE(tap, tappath); +#endif fdmax = (tap > skt) ? tap+1 : skt+1; |