X-Git-Url: https://git.distorted.org.uk/~mdw/unet/blobdiff_plain/4e3819cf328abf9cb0e43d76ef1b294a3bffa720..refs/heads/master:/unetcfg.c diff --git a/unetcfg.c b/unetcfg.c index dec5a9a..a51d452 100644 --- a/unetcfg.c +++ b/unetcfg.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: unetcfg.c,v 1.1 2001/01/25 22:03:39 mdw Exp $ + * $Id: unetcfg.c,v 1.3 2001/02/19 19:10:28 mdw Exp $ * * User-space network device support. * @@ -29,6 +29,12 @@ /*----- Revision history --------------------------------------------------* * * $Log: unetcfg.c,v $ + * Revision 1.3 2001/02/19 19:10:28 mdw + * New option to allow changing interface flags. + * + * Revision 1.2 2001/02/03 18:39:59 mdw + * Setting the maximum interface count now does the right thing. + * * Revision 1.1 2001/01/25 22:03:39 mdw * Initial check-in (somewhat belated). * @@ -43,8 +49,6 @@ #include #include -#include - #include #include #include @@ -52,6 +56,12 @@ #include #include +#include +#include + +#include +#include + #include "unet.h" /*----- Static variables --------------------------------------------------*/ @@ -524,6 +534,49 @@ static int cmd_maxif(char **av) return (run(av)); } +/* --- @cmd_ifflags@ --- */ + +static int cmd_ifflags(char **av) +{ + static const struct iftab { + const char *name; + unsigned f; + } iftab[] = { + { "broadcast", IFF_BROADCAST }, + { "loopback", IFF_LOOPBACK }, + { "pointopoint", IFF_POINTOPOINT }, + { 0, 0 } + }; + + char *p; + int sense; + struct iftab *ift; + int f; + + check(); + if ((f = ioctl(fd, UNIOCGIFFLAGS)) < 0) + die("error reading interface flags: %s", strerror(errno)); + + for (p = strtok(*av++, ","); p; p = strtok(0, ",")) { + sense = 1; + switch (*p) { + case '-': sense = 0; + case '+': p++; + break; + } + ift = LOOKUP(iftab, p); + if (!ift) + die("unknown interface flag `%s'", p); + if (sense) + f |= ift->f; + else + f &= ~ift->f; + } + if (ioctl(fd, UNIOCSIFFLAGS, f)) + die("error setting interface flags: %s", strerror(errno)); + return (run(av)); +} + /* --- @run@ --- * * * Arguments: @char **av@ = array of command line arguments @@ -607,8 +660,13 @@ attachments inherit their debug flags from the global flag.\n\ { "maxif", 0, cmd_maxif, "maxif [MAX]", "set maximum number of interfaces allowed", "\ -Configures the maximum number of interfaces allowed (actually, the highest\n\ -number of any interface).\n\ +Configures the maximum number of interfaces allowed.\n\ +" }, + + { "ifflags", 1, cmd_ifflags, + "ifflags [-]FLAG,[-]FLAG,...", "set interface flags", "\ +Configures the network interface flags, because `ifconfig' is prevented\n\ +from doing the job properly.\n\ " }, { "help", 0, cmd_help, @@ -734,7 +792,7 @@ int main(int argc, char *argv[]) { 0, 0, 0, 0 } }; - if ((i = getopt_long(argc, argv, "hVv", opt, 0)) < 0) + if ((i = getopt_long(argc, argv, "+hVv", opt, 0)) < 0) break; switch (i) { case 'h':