summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--common.h6
-rw-r--r--config.h3
-rw-r--r--fatvpn.c14
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;