diff options
Diffstat (limited to 'openbsd-compat/port-tun.c')
-rw-r--r-- | openbsd-compat/port-tun.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/openbsd-compat/port-tun.c b/openbsd-compat/port-tun.c index 7579c608..0e75c911 100644 --- a/openbsd-compat/port-tun.c +++ b/openbsd-compat/port-tun.c @@ -56,12 +56,15 @@ #include <linux/if_tun.h> int -sys_tun_open(int tun, int mode) +sys_tun_open(int tun, int mode, char **ifname) { struct ifreq ifr; int fd = -1; const char *name = NULL; + if (ifname != NULL) + *ifname = NULL; + if ((fd = open("/dev/net/tun", O_RDWR)) == -1) { debug("%s: failed to open tunnel control interface: %s", __func__, strerror(errno)); @@ -99,6 +102,9 @@ sys_tun_open(int tun, int mode) else debug("%s: %s mode %d fd %d", __func__, ifr.ifr_name, mode, fd); + if (ifname != NULL && (*ifname = strdup(ifr.ifr_name))) + goto failed; + return (fd); failed: @@ -116,13 +122,16 @@ sys_tun_open(int tun, int mode) #endif int -sys_tun_open(int tun, int mode) +sys_tun_open(int tun, int mode, char **ifname) { struct ifreq ifr; char name[100]; int fd = -1, sock, flag; const char *tunbase = "tun"; + if (ifname != NULL) + *ifname = NULL; + if (mode == SSH_TUNMODE_ETHERNET) { #ifdef SSH_TUN_NO_L2 debug("%s: no layer 2 tunnelling support", __func__); @@ -180,6 +189,9 @@ sys_tun_open(int tun, int mode) goto failed; } + if (ifname != NULL && (*ifname = strdup(ifr.ifr_name))) + goto failed; + close(sock); return (fd); |