-net tap tap0 - vx32 - Local 9vx git repository for patches.
Log
Files
Refs
---
commit f86dffdd8e2770c38a34e668de7f9a07377a0a89
parent 5654a648070778957c68e7d1246cf545ae88e510
Author: Jesus Galan Lopez (yiyus) 
Date:   Sun,  6 Jun 2010 01:22:48 +0200

-net tap tap0

Diffstat:
  src/9vx/ethertap.c                  |      29 ++++++++++++-----------------

1 file changed, 12 insertions(+), 17 deletions(-)
---
diff --git a/src/9vx/ethertap.c b/src/9vx/ethertap.c
@@ -41,20 +41,15 @@ setup(char *dev)
 {
         int fd;
         struct ifreq ifr;
-        char *defaultdev = "/dev/net/tun";
 
-        if(!netdev)
-                netdev = defaultdev;
-        if((fd = open(netdev, O_RDWR)) < 0)
+        if((fd = open("/dev/net/tun", O_RDWR)) < 0)
+                return -1;
+        memset(&ifr, 0, sizeof ifr);
+        strncpy(ifr.ifr_name, dev, sizeof ifr.ifr_name);
+        ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+        if(ioctl(fd, TUNSETIFF, &ifr) < 0){
+                close(fd);
                 return -1;
-        if(dev){
-                memset(&ifr, 0, sizeof ifr);
-                strncpy(ifr.ifr_name, dev, sizeof ifr.ifr_name);
-                ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
-                if(ioctl(fd, TUNSETIFF, &ifr) < 0){
-                        close(fd);
-                        return -1;
-                }
         }
 
         return fd;
@@ -136,22 +131,22 @@ static uchar eatab[] = {
         0x00, 0x48, 0x01, 0x23, 0x45, 0x60,
 };
 
-static char *tapdevtab[] = {
-        "tap0",
-};
-
 static int
 ttappnp(Ether* e)
 {
         uchar *ea;
         Ctlr c;
         static int nctlr;
+        char *dev = "tap0";
 
         if(nctlr >= nelem(eatab)/Eaddrlen)
                 return -1;
         ea = eatab + Eaddrlen*nctlr;
         memset(&c, 0, sizeof c);
-        c.fd = setup(tapdevtab[nctlr++]);
+        if(netdev)
+                dev = netdev;
+        c.fd = setup(dev);
+        nctlr++;
         memcpy(c.ea, ea, Eaddrlen);
         if(c.fd== -1){
                 print("tap: failed to initialize\n");