Choose tunnel device name

This commit is contained in:
Erik Ekman 2006-06-24 10:28:24 +00:00
parent 9a6ad85240
commit a9d64715c3
3 changed files with 22 additions and 9 deletions

View file

@ -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;

View file

@ -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;

2
tun.c
View file

@ -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;
}