From 1c34ba7fb8580949f3bd3a0d804747bbaea28e36 Mon Sep 17 00:00:00 2001
From: Guus Sliepen <guus@tinc-vpn.org>
Date: Mon, 11 Feb 2002 12:33:01 +0000
Subject: [PATCH] Sensible defaults for $INTERFACE.

---
 src/freebsd/device.c | 4 ++--
 src/linux/device.c   | 6 +++++-
 src/openbsd/device.c | 4 ++--
 src/solaris/device.c | 5 ++++-
 4 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/freebsd/device.c b/src/freebsd/device.c
index 492ba33d..e75076a9 100644
--- a/src/freebsd/device.c
+++ b/src/freebsd/device.c
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: device.c,v 1.1.2.2 2002/02/10 21:57:54 guus Exp $
+    $Id: device.c,v 1.1.2.3 2002/02/11 12:33:01 guus Exp $
 */
 
 #include "config.h"
@@ -62,7 +62,7 @@ cp
     device = DEFAULT_DEVICE;
 
   if(!get_config_string(lookup_config(config_tree, "Interface"), &interface))
-    interface = netname;
+    interface = rindex(device, '/')?rindex(device, '/')+1:device;
 cp
   if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0)
     {
diff --git a/src/linux/device.c b/src/linux/device.c
index a54647ec..88355caa 100644
--- a/src/linux/device.c
+++ b/src/linux/device.c
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: device.c,v 1.1.2.5 2002/02/10 21:57:54 guus Exp $
+    $Id: device.c,v 1.1.2.6 2002/02/11 12:33:01 guus Exp $
 */
 
 #include "config.h"
@@ -77,7 +77,11 @@ cp
     device = DEFAULT_DEVICE;
 
   if(!get_config_string(lookup_config(config_tree, "Interface"), &interface))
+#ifdef HAVE_TUNTAP
     interface = netname;
+#else
+    interface = rindex(device, '/')?rindex(device, '/')+1:device;
+#endif
 cp
   if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0)
     {
diff --git a/src/openbsd/device.c b/src/openbsd/device.c
index 1fccd14f..a24d2d0d 100644
--- a/src/openbsd/device.c
+++ b/src/openbsd/device.c
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: device.c,v 1.1.2.3 2002/02/10 21:57:54 guus Exp $
+    $Id: device.c,v 1.1.2.4 2002/02/11 12:33:01 guus Exp $
 */
 
 #include "config.h"
@@ -66,7 +66,7 @@ int setup_device(void)
     device = DEFAULT_DEVICE;
 
   if(!get_config_string(lookup_config(config_tree, "Interface"), &interface))
-    interface = netname;
+    interface = rindex(device, '/')?rindex(device, '/')+1:device;
 cp
   if((device_fd = open(device, O_RDWR | O_NONBLOCK)) < 0)
     {
diff --git a/src/solaris/device.c b/src/solaris/device.c
index dcfd8c44..5aacf3e5 100644
--- a/src/solaris/device.c
+++ b/src/solaris/device.c
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: device.c,v 1.1.2.4 2002/02/10 21:57:54 guus Exp $
+    $Id: device.c,v 1.1.2.5 2002/02/11 12:33:01 guus Exp $
 */
 
 
@@ -113,6 +113,9 @@ cp
      return -1;
   }
 
+  if(!get_config_string(lookup_config(config_tree, "Interface"), &interface))
+    asprintf(interface, "tun%d", ppa);
+
   device_info = _("Solaris tun device");
 
   /* Set default MAC address for ethertap devices */
-- 
2.39.5