From a9d64715c3c09e735f858fc77ad4a8c9ab1340f6 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Sat, 24 Jun 2006 10:28:24 +0000 Subject: [PATCH] Choose tunnel device name --- iodine.c | 14 ++++++++++---- iodined.c | 15 +++++++++++---- tun.c | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/iodine.c b/iodine.c index 64ed7f8..a8daa29 100644 --- a/iodine.c +++ b/iodine.c @@ -164,7 +164,7 @@ extern char *__progname; static void usage() { - printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] " + printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device]" "nameserver topdomain\n", __progname); exit(2); } @@ -172,13 +172,14 @@ usage() { static void help() { printf("iodine IP over DNS tunneling client\n"); - printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] " + printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device]" "nameserver topdomain\n", __progname); printf(" -v to print version info and exit\n"); printf(" -h to print this help and exit\n"); printf(" -f to keep running in foreground\n"); printf(" -u name to drop privileges and run as user 'name'\n"); printf(" -t dir to chroot to directory dir\n"); + printf(" -d device to set tunnel device name\n"); printf("nameserver is the IP number of the relaying nameserver\n"); printf("topdomain is the FQDN that is delegated to the tunnel endpoint.\n"); exit(0); @@ -198,14 +199,16 @@ main(int argc, char **argv) int choice; char *newroot; char *username; + char *device; int foreground; struct passwd *pw; newroot = NULL; username = NULL; + device = NULL; foreground = 0; - while ((choice = getopt(argc, argv, "vfhu:t:")) != -1) { + while ((choice = getopt(argc, argv, "vfhu:t:d:")) != -1) { switch(choice) { case 'v': version(); @@ -222,6 +225,9 @@ main(int argc, char **argv) case 't': newroot = optarg; break; + case 'd': + device = optarg; + break; default: usage(); break; @@ -247,7 +253,7 @@ main(int argc, char **argv) } } - if ((tun_fd = open_tun(NULL)) == -1) + if ((tun_fd = open_tun(device)) == -1) goto cleanup1; if ((dns_fd = open_dns(argv[1], 0)) == -1) goto cleanup2; diff --git a/iodined.c b/iodined.c index 1a4c2f6..6d0a347 100644 --- a/iodined.c +++ b/iodined.c @@ -163,7 +163,7 @@ extern char *__progname; static void usage() { - printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-m mtu] " + printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] [-m mtu] " "tunnel_ip topdomain\n", __progname); exit(2); } @@ -171,13 +171,15 @@ usage() { static void help() { printf("iodine IP over DNS tunneling server\n"); - printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-m mtu] " + printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] [-m mtu] " "tunnel_ip topdomain\n", __progname); printf(" -v to print version info and exit\n"); printf(" -h to print this help and exit\n"); printf(" -f to keep running in foreground\n"); printf(" -u name to drop privileges and run as user 'name'\n"); printf(" -t dir to chroot to directory dir\n"); + printf(" -d device to set tunnel device name\n"); + printf(" -m mtu to set tunnel device mtu\n"); printf("tunnel_ip is the IP number of the local tunnel interface.\n"); printf("topdomain is the FQDN that is delegated to this server.\n"); exit(0); @@ -199,12 +201,14 @@ main(int argc, char **argv) int dnsd_fd; char *newroot; char *username; + char *device; int foreground; int mtu; struct passwd *pw; username = NULL; newroot = NULL; + device = NULL; foreground = 0; mtu = 1024; @@ -213,7 +217,7 @@ main(int argc, char **argv) outpacket.len = 0; q.id = 0; - while ((choice = getopt(argc, argv, "vfhu:t:m:")) != -1) { + while ((choice = getopt(argc, argv, "vfhu:t:d:m:")) != -1) { switch(choice) { case 'v': version(); @@ -230,6 +234,9 @@ main(int argc, char **argv) case 't': newroot = optarg; break; + case 'd': + device = optarg; + break; case 'm': mtu = atoi(optarg); break; @@ -263,7 +270,7 @@ main(int argc, char **argv) usage(); } - if ((tun_fd = open_tun(NULL)) == -1) + if ((tun_fd = open_tun(device)) == -1) goto cleanup0; if (tun_setip(argv[0]) != 0 || tun_setmtu(mtu) != 0) goto cleanup1; diff --git a/tun.c b/tun.c index e9d3b92..05a4ae3 100644 --- a/tun.c +++ b/tun.c @@ -58,10 +58,10 @@ open_tun(const char *tun_device) if (tun_device != NULL) { strncpy(ifreq.ifr_name, tun_device, IFNAMSIZ); + strncpy(if_name, tun_device, sizeof(if_name)); if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) { printf("Opened %s\n", ifreq.ifr_name); - snprintf(if_name, sizeof(if_name), "dns%d", i); return tun_fd; }