NetBSD fixes from Sergey Svishchev
authorDavid Woodhouse <David.Woodhouse@intel.com>
Fri, 5 Dec 2008 14:41:50 +0000 (14:41 +0000)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Fri, 5 Dec 2008 14:41:50 +0000 (14:41 +0000)
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
dtls.c
tun.c

diff --git a/dtls.c b/dtls.c
index 4e4bf07..002ee16 100644 (file)
--- a/dtls.c
+++ b/dtls.c
@@ -27,6 +27,7 @@
 #include <sys/socket.h>
 #include <netdb.h>
 #include <unistd.h>
+#include <netinet/in.h>
 #include <openssl/err.h>
 #include <fcntl.h>
 #include <string.h>
diff --git a/tun.c b/tun.c
index 89e498d..a84f89d 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -24,9 +24,8 @@
 
 #include <string.h>
 #include <sys/socket.h>
-#include <net/if.h>
 #include <sys/ioctl.h>
-#ifndef __APPLE__
+#ifdef __linux__
 #include <linux/if_tun.h>
 #endif
 #include <sys/types.h>
@@ -34,6 +33,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <netinet/in.h>
+#include <net/if.h>
 #include <arpa/inet.h>
 #include <errno.h>
 
@@ -243,22 +243,7 @@ int setup_tun(struct openconnect_info *vpninfo)
                vpninfo->script_tun = child;
                vpninfo->ifname = "(script)";
        } else {
-#ifdef __APPLE__
-               static char tun_name[80];
-               int i;
-               for (i=0; i < 255; i++) {
-                       sprintf(tun_name, "/dev/tun%d", i);
-                       tun_fd = open(tun_name, O_RDWR);
-                       if (tun_fd >= 0)
-                               break;
-               }
-               if (tun_fd < 0) {
-                       perror("open tun");
-                       exit(1);
-               }
-               vpninfo->ifname = tun_name + 5;
-#else
-
+#ifdef IFF_TUN /* Linux */
                tun_fd = open("/dev/net/tun", O_RDWR);
                if (tun_fd < 0) {
                        vpninfo->progress(vpninfo, PRG_ERR,
@@ -280,6 +265,20 @@ int setup_tun(struct openconnect_info *vpninfo)
                if (!vpninfo->ifname)
                        vpninfo->ifname = strdup(ifr.ifr_name);
 
+#else /* BSD et al have /dev/tun$x devices */
+               static char tun_name[80];
+               int i;
+               for (i=0; i < 255; i++) {
+                       sprintf(tun_name, "/dev/tun%d", i);
+                       tun_fd = open(tun_name, O_RDWR);
+                       if (tun_fd >= 0)
+                               break;
+               }
+               if (tun_fd < 0) {
+                       perror("open tun");
+                       exit(1);
+               }
+               vpninfo->ifname = tun_name + 5;
 #endif
                if (vpninfo->vpnc_script) {
                        script_config_tun(vpninfo);