From: Christian L. <xi...@bo...> - 2002-09-06 15:21:27
|
Here is a small patch that adds a -b switch to tunctl. When used the output will be brief meaning that just the device name will be printed out on a line by itself. This allows me to easily get the device name in a shell script like this: TUNDEV=`tunctl -b -u uml02` The patch: Index: tunctl.c =================================================================== RCS file: /cvsroot/user-mode-linux/tools/tunctl/tunctl.c,v retrieving revision 1.2 diff -u -w -r1.2 tunctl.c --- tunctl.c 18 Mar 2002 19:38:49 -0000 1.2 +++ tunctl.c 6 Sep 2002 15:02:25 -0000 @@ -15,12 +15,13 @@ static void Usage(char *name) { - fprintf(stderr, "Create: %s [-u owner] [-t device-name] " + fprintf(stderr, "Create: %s [-b] [-u owner] [-t device-name] " "[-f tun-clone-device]\n", name); fprintf(stderr, "Delete: %s -d device-name [-f tun-clone-device]\n\n", name); fprintf(stderr, "The default tun clone device is /dev/net/tun - some systems" - " use\n/dev/misc/net/tun instead\n"); + " use\n/dev/misc/net/tun instead\n\n"); + fprintf(stderr, "-b will result in brief output (just the device name)\n"); exit(1); } @@ -29,11 +30,14 @@ struct ifreq ifr; struct passwd *pw; long owner = geteuid(); - int tap_fd, opt, delete = 0; + int tap_fd, opt, delete = 0, brief = 0; char *tun = "", *file = "/dev/net/tun", *name = argv[0], *end; - while((opt = getopt(argc, argv, "df:ht:u:")) > 0){ + while((opt = getopt(argc, argv, "bdf:ht:u:")) > 0){ switch(opt) { + case 'b': + brief = 1; + break; case 'd': delete = 1; break; @@ -101,6 +105,9 @@ perror("TUNSETPERSIST"); exit(1); } + if(brief) + printf("%s\n", ifr.ifr_name); + else printf("Set '%s' persistent and owned by uid %ld\n", ifr.ifr_name, owner); } return(0); -- Best regards Christian Laursen |