create the tun-interfaces with a name choosen by the user
authorPhilipp Tölke <toelke@in.tum.de>
Wed, 2 Feb 2011 22:42:11 +0000 (22:42 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Wed, 2 Feb 2011 22:42:11 +0000 (22:42 +0000)
src/vpn/gnunet-helper-vpn.c

index 37ec71868f0b369a7493cdf4aa427ee7703a1c2a..554019d7cb4fcc3e04e13a8997c40d5796812eac 100644 (file)
@@ -30,7 +30,6 @@
  * have your name added to the list):
  *
  * - Philipp Tölke
- * - Christian Grothoff
  */
 #include "platform.h"
 #include <linux/if_tun.h>
@@ -96,7 +95,7 @@ init_tun (char *dev)
   memset (&ifr, 0, sizeof (ifr));
   ifr.ifr_flags = IFF_TUN;
 
-  if ('\0' == *dev)
+  if ('\0' != *dev)
     strncpy (ifr.ifr_name, dev, IFNAMSIZ);
 
   if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr))
@@ -532,24 +531,26 @@ main (int argc, char **argv)
   char dev[IFNAMSIZ];
   int fd_tun;
 
-  memset (dev, 0, IFNAMSIZ);
-  if (-1 == (fd_tun = init_tun (dev)))
+  if (6 != argc)
     {
       fprintf (stderr, 
-              "Fatal: could not initialize tun-interface\n");
+              "Fatal: must supply 5 arguments!\n");
       return 1;
     }
 
-  if (5 != argc)
+  strncpy(dev, argv[1], IFNAMSIZ);
+  dev[IFNAMSIZ - 1] = '\0';
+
+  if (-1 == (fd_tun = init_tun (dev)))
     {
       fprintf (stderr, 
-              "Fatal: must supply 4 arguments!\n");
+              "Fatal: could not initialize tun-interface\n");
       return 1;
     }
 
   {
-    const char *address = argv[1];
-    long prefix_len = atol(argv[2]);
+    const char *address = argv[2];
+    long prefix_len = atol(argv[3]);
 
     if ( (prefix_len < 1) || (prefix_len > 127) )
       {
@@ -561,8 +562,8 @@ main (int argc, char **argv)
   }
   
   {
-    const char *address = argv[3];
-    const char *mask = argv[4];
+    const char *address = argv[4];
+    const char *mask = argv[5];
 
     set_address4 (dev, address, mask);
   }