Automatic tun device naming
authorDavid Woodhouse <David.Woodhouse@intel.com>
Sat, 4 Oct 2008 13:41:13 +0000 (14:41 +0100)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Sat, 4 Oct 2008 13:41:13 +0000 (14:41 +0100)
main.c
tun.c

diff --git a/main.c b/main.c
index 19116f4..cff3c23 100644 (file)
--- a/main.c
+++ b/main.c
@@ -104,7 +104,6 @@ int main(int argc, char **argv)
        memset(vpninfo, 0, sizeof(*vpninfo));
 
        /* Set up some defaults */
-       vpninfo->ifname = "cisco0";
        vpninfo->tun_fd = vpninfo->ssl_fd = vpninfo->dtls_fd = vpninfo->new_dtls_fd = -1;
        vpninfo->useragent = "Open AnyConnect VPN Agent " ANYCONNECT_VERSION;
        vpninfo->mtu = 1406;
diff --git a/tun.c b/tun.c
index 63eaee1..8e8f689 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -156,11 +156,15 @@ int setup_tun(struct anyconnect_info *vpninfo)
        }
        memset(&ifr, 0, sizeof(ifr));
        ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
-       strncpy(ifr.ifr_name, vpninfo->ifname, sizeof(ifr.ifr_name) - 1);
+       if (vpninfo->ifname)
+               strncpy(ifr.ifr_name, vpninfo->ifname,
+                       sizeof(ifr.ifr_name) - 1);
        if (ioctl(tun_fd, TUNSETIFF, (void *) &ifr) < 0) {
                perror("TUNSETIFF");
                exit(1);
        }
+       if (!vpninfo->ifname)
+               vpninfo->ifname = strdup(ifr.ifr_name);
 
        fcntl(tun_fd, F_SETFD, FD_CLOEXEC);