diff options
author | Philipp Tölke <toelke@in.tum.de> | 2011-02-02 22:42:11 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2011-02-02 22:42:11 +0000 |
commit | b13a84b528dc581a6c1a042317f8e9cc3874642e (patch) | |
tree | aa3634560272e8975e66f2254860921e6fa99b82 /src | |
parent | df4003f4dca054be8ca8c4d1c87dc9ba3df8a810 (diff) | |
download | gnunet-b13a84b528dc581a6c1a042317f8e9cc3874642e.tar.gz gnunet-b13a84b528dc581a6c1a042317f8e9cc3874642e.zip |
create the tun-interfaces with a name choosen by the user
Diffstat (limited to 'src')
-rw-r--r-- | src/vpn/gnunet-helper-vpn.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/vpn/gnunet-helper-vpn.c b/src/vpn/gnunet-helper-vpn.c index 37ec71868..554019d7c 100644 --- a/src/vpn/gnunet-helper-vpn.c +++ b/src/vpn/gnunet-helper-vpn.c | |||
@@ -30,7 +30,6 @@ | |||
30 | * have your name added to the list): | 30 | * have your name added to the list): |
31 | * | 31 | * |
32 | * - Philipp Tölke | 32 | * - Philipp Tölke |
33 | * - Christian Grothoff | ||
34 | */ | 33 | */ |
35 | #include "platform.h" | 34 | #include "platform.h" |
36 | #include <linux/if_tun.h> | 35 | #include <linux/if_tun.h> |
@@ -96,7 +95,7 @@ init_tun (char *dev) | |||
96 | memset (&ifr, 0, sizeof (ifr)); | 95 | memset (&ifr, 0, sizeof (ifr)); |
97 | ifr.ifr_flags = IFF_TUN; | 96 | ifr.ifr_flags = IFF_TUN; |
98 | 97 | ||
99 | if ('\0' == *dev) | 98 | if ('\0' != *dev) |
100 | strncpy (ifr.ifr_name, dev, IFNAMSIZ); | 99 | strncpy (ifr.ifr_name, dev, IFNAMSIZ); |
101 | 100 | ||
102 | if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr)) | 101 | if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr)) |
@@ -532,24 +531,26 @@ main (int argc, char **argv) | |||
532 | char dev[IFNAMSIZ]; | 531 | char dev[IFNAMSIZ]; |
533 | int fd_tun; | 532 | int fd_tun; |
534 | 533 | ||
535 | memset (dev, 0, IFNAMSIZ); | 534 | if (6 != argc) |
536 | if (-1 == (fd_tun = init_tun (dev))) | ||
537 | { | 535 | { |
538 | fprintf (stderr, | 536 | fprintf (stderr, |
539 | "Fatal: could not initialize tun-interface\n"); | 537 | "Fatal: must supply 5 arguments!\n"); |
540 | return 1; | 538 | return 1; |
541 | } | 539 | } |
542 | 540 | ||
543 | if (5 != argc) | 541 | strncpy(dev, argv[1], IFNAMSIZ); |
542 | dev[IFNAMSIZ - 1] = '\0'; | ||
543 | |||
544 | if (-1 == (fd_tun = init_tun (dev))) | ||
544 | { | 545 | { |
545 | fprintf (stderr, | 546 | fprintf (stderr, |
546 | "Fatal: must supply 4 arguments!\n"); | 547 | "Fatal: could not initialize tun-interface\n"); |
547 | return 1; | 548 | return 1; |
548 | } | 549 | } |
549 | 550 | ||
550 | { | 551 | { |
551 | const char *address = argv[1]; | 552 | const char *address = argv[2]; |
552 | long prefix_len = atol(argv[2]); | 553 | long prefix_len = atol(argv[3]); |
553 | 554 | ||
554 | if ( (prefix_len < 1) || (prefix_len > 127) ) | 555 | if ( (prefix_len < 1) || (prefix_len > 127) ) |
555 | { | 556 | { |
@@ -561,8 +562,8 @@ main (int argc, char **argv) | |||
561 | } | 562 | } |
562 | 563 | ||
563 | { | 564 | { |
564 | const char *address = argv[3]; | 565 | const char *address = argv[4]; |
565 | const char *mask = argv[4]; | 566 | const char *mask = argv[5]; |
566 | 567 | ||
567 | set_address4 (dev, address, mask); | 568 | set_address4 (dev, address, mask); |
568 | } | 569 | } |