changeset 7:fd7c60905b13

BSD support
author ivo <Ivo@UCIS.nl>
date Wed, 13 Oct 2010 21:07:44 +0200
parents cf9b44b46be5
children 6d86596d8884
files build.sh src/common.c
diffstat 2 files changed, 24 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/build.sh	Fri Oct 08 23:29:56 2010 +0000
+++ b/build.sh	Wed Oct 13 21:07:44 2010 +0200
@@ -24,7 +24,7 @@
 echo Done.
 
 export CPATH=./include/
-export LIBRARY_PATH=./lib/
+export LIBRARY_PATH=/usr/local/lib/:./lib/
 
 echo Building combined binary...
 gcc -c -DCOMBINED_BINARY	src/proto.raw.c		-o obj/proto.raw.o
@@ -48,7 +48,7 @@
 ##echo Building frontends...
 ##gcc -o out/quicktun.debian	src/run.debian.c -ldl
 
-if [ -x /usr/bin/dpkg-deb ]; then
+if [ -x /usr/bin/dpkg-deb -a -x /usr/bin/fakeroot ]; then
 	echo Building debian binary...
 	gcc -c -DCOMBINED_BINARY -DDEBIAN_BINARY src/run.combined.c -o obj/run.debian.o
 	gcc -o out/quicktun.debian obj/common.o obj/run.debian.o obj/proto.raw.o obj/proto.nacl0.o obj/proto.nacltai.o obj/crypto_scalarmult_curve25519.o -lnacl
--- 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;
 }