changeset 13:f7e0145d8e2a

solaris support
author Gabor Adam Toth <tg@tgbit.net>
date Sat, 08 Jan 2011 02:25:17 +0100
parents e4b60d041491
children d9dfeeaff7e8
files build.sh src/common.c
diffstat 2 files changed, 65 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/build.sh	Sun Dec 05 23:12:04 2010 +0100
+++ b/build.sh	Sat Jan 08 02:25:17 2011 +0100
@@ -1,16 +1,26 @@
 #!/bin/sh
+
+tar=tar
+
+if [ `uname -s` == "SunOS" ]; then
+	echo "Detected SunOS"
+	tar=gtar
+	CFLAGS="$CFLAGS -DSOLARIS -m64"
+	LDFLAGS="$LDFLAGS -lnsl -lsocket"
+fi
+
 echo Cleaning up...
 rm -rf out/ obj/ tmp/
 
 mkdir -p out
 echo Creating source archive...
-tar --transform "s,^\.,quicktun-`cat version`/," -czf "out/quicktun-`cat version`.tgz" . --exclude "./out" --exclude "./lib" --exclude "./debian/data"
+$tar --transform "s,^\.,quicktun-`cat version`," -czf "out/quicktun-`cat version`.tgz" . --exclude "./out" --exclude "./lib" --exclude "./debian/data"
 
 mkdir -p obj tmp lib
 
-echo -n Checking for NaCl library...
+echo Checking for NaCl library...
 if [ ! -e lib/libnacl.a ]; then
-	echo -n building...
+	echo building...
 	mkdir tmp/nacl
 	cd tmp/nacl
 	wget -q -O- http://hyperelliptic.org/nacl/nacl-20090405.tar.bz2 | bunzip2 | tar -xf - --strip-components 1
@@ -27,31 +37,31 @@
 export LIBRARY_PATH=/usr/local/lib/:./lib/
 
 echo Building combined binary...
-gcc -c -DCOMBINED_BINARY	src/proto.raw.c		-o obj/proto.raw.o
-gcc -c -DCOMBINED_BINARY	src/crypto_scalarmult_curve25519.c	-o obj/crypto_scalarmult_curve25519.o 
-gcc -c -DCOMBINED_BINARY	src/proto.nacl0.c	-o obj/proto.nacl0.o
-gcc -c -DCOMBINED_BINARY	src/proto.nacltai.c	-o obj/proto.nacltai.o
-gcc -c -DCOMBINED_BINARY	src/run.combined.c	-o obj/run.combined.o
-gcc -c 				src/common.c		-o obj/common.o
-gcc -o out/quicktun.combined obj/common.o obj/run.combined.o obj/proto.raw.o obj/proto.nacl0.o obj/proto.nacltai.o obj/crypto_scalarmult_curve25519.o -lnacl
+gcc $CFLAGS -c -DCOMBINED_BINARY	src/proto.raw.c		-o obj/proto.raw.o
+gcc $CFLAGS -c -DCOMBINED_BINARY	src/crypto_scalarmult_curve25519.c	-o obj/crypto_scalarmult_curve25519.o
+gcc $CFLAGS -c -DCOMBINED_BINARY	src/proto.nacl0.c	-o obj/proto.nacl0.o
+gcc $CFLAGS -c -DCOMBINED_BINARY	src/proto.nacltai.c	-o obj/proto.nacltai.o
+gcc $CFLAGS -c -DCOMBINED_BINARY	src/run.combined.c	-o obj/run.combined.o
+gcc $CFLAGS -c 				src/common.c		-o obj/common.o
+gcc $CFLAGS -o out/quicktun.combined obj/common.o obj/run.combined.o obj/proto.raw.o obj/proto.nacl0.o obj/proto.nacltai.o obj/crypto_scalarmult_curve25519.o -lnacl $LDFLAGS
 
 echo Building single protocol binaries...
-gcc -o out/quicktun.raw		src/proto.raw.c
-gcc -o out/quicktun.nacl0	src/proto.nacl0.c	-lnacl
-gcc -o out/quicktun.nacltai	src/proto.nacltai.c src/crypto_scalarmult_curve25519.c	-lnacl
-gcc -o out/quicktun.keypair	src/keypair.c		-lnacl
+gcc $CFLAGS -o out/quicktun.raw		src/proto.raw.c $LDFLAGS
+gcc $CFLAGS -o out/quicktun.nacl0	src/proto.nacl0.c	-lnacl $LDFLAGS
+gcc $CFLAGS -o out/quicktun.nacltai	src/proto.nacltai.c src/crypto_scalarmult_curve25519.c	-lnacl $LDFLAGS
+gcc $CFLAGS -o out/quicktun.keypair	src/keypair.c		-lnacl $LDFLAGS
 
 echo Building shared libraries...
-gcc -fPIC -shared -Wl,-soname,quicktun.raw -o out/libquicktun.raw src/proto.raw.c
-##gcc -fPIC -shared -Wl,-soname,quicktun.nacl0 -o out/libquicktun.nacl0 src/proto.nacl0.c -lnacl
+gcc $CFLAGS -fPIC -shared -Wl,-soname,quicktun.raw -o out/libquicktun.raw src/proto.raw.c
+##gcc $CFLAGS -fPIC -shared -Wl,-soname,quicktun.nacl0 -o out/libquicktun.nacl0 src/proto.nacl0.c -lnacl $LDFLAGS
 
 ##echo Building frontends...
-##gcc -o out/quicktun.debian	src/run.debian.c -ldl
+##gcc $CFLAGS -o out/quicktun.debian	src/run.debian.c -ldl
 
 if [ -f /etc/network/interfaces ]; 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
+	gcc $CFLAGS -c -DCOMBINED_BINARY -DDEBIAN_BINARY src/run.combined.c -o obj/run.debian.o
+	gcc $CFLAGS -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 $LDFLAGS
 	if [ -x /usr/bin/dpkg-deb -a -x /usr/bin/fakeroot ]; then
 		echo -n Building debian package...
 		cd debian
--- a/src/common.c	Sun Dec 05 23:12:04 2010 +0100
+++ b/src/common.c	Sat Jan 08 02:25:17 2011 +0100
@@ -42,6 +42,10 @@
 #else
 	#define ETH_FRAME_LEN 1514
 	#include <net/if_tun.h>
+	#ifdef SOLARIS
+		#include <sys/stropts.h>
+		#include <sys/sockio.h>
+	#endif
 #endif
 
 #define MAX_PACKET_LEN (ETH_FRAME_LEN+4) //Some space for optional packet information
@@ -140,6 +144,9 @@
 	char* envval;
 	fprintf(stderr, "Initializing tun/tap device...\n");
 	int ttfd; //Tap device file descriptor
+#ifdef SOLARIS
+	int ip_fd = -1, if_fd = -1, ppa = 0;
+#endif
 #ifdef linux
 		struct ifreq ifr; //required for tun/tap setup
 		memset(&ifr, 0, sizeof(ifr));
@@ -149,8 +156,37 @@
 		ifr.ifr_flags |= getconf("USE_PI") ? 0 : IFF_NO_PI;
 		if (ioctl(ttfd, TUNSETIFF, (void *)&ifr) < 0) return errorexitp("TUNSETIFF ioctl failed");
 #else
+	#ifdef SOLARIS
+		if ((ttfd = open("/dev/tun", O_RDWR)) < 0)
+			return errorexitp("Could not open tun device file");
+
+		if ((ip_fd = open("/dev/ip", O_RDWR, 0)) < 0)
+			return errorexitp("Could not open /dev/ip");
+
+		if ((envval = getconf("INTERFACE"))) {
+			while (*envval && !isdigit((int)*envval))
+				envval++;
+			ppa = atoi(envval);
+		}
+
+		if ((ppa = ioctl(ttfd, TUNNEWPPA, ppa)) < 0)
+			return errorexitp("Could not assign new PPA");
+
+		if ((if_fd = open("/dev/tun", O_RDWR, 0)) < 0)
+			return errorexitp("Could not open tun device file again");
+
+		if (ioctl(if_fd, I_PUSH, "ip") < 0)
+			return errorexitp("Could not push IP module");
+
+		if (ioctl(if_fd, IF_UNITSEL, (char *)&ppa) < 0)
+			return errorexitp("Could not set PPA");
+
+		if (ioctl(ip_fd, I_LINK, if_fd) < 0)
+			return errorexitp("Could not link TUN device to IP");
+	#else
 		if (!(envval = getconf("INTERFACE"))) envval = "/dev/tun0";
 		if ((ttfd = open(envval, O_RDWR)) < 0) return errorexitp("Could not open tun device file");
+	#endif
 #endif
 	return ttfd;
 }