Version bump.
[unet] / unetcfg.c
index 4b98e0e..a51d452 100644 (file)
--- a/unetcfg.c
+++ b/unetcfg.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: unetcfg.c,v 1.2 2001/02/03 18:39:59 mdw Exp $
+ * $Id: unetcfg.c,v 1.3 2001/02/19 19:10:28 mdw Exp $
  *
  * User-space network device support.
  *
@@ -29,6 +29,9 @@
 /*----- 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.
  *
@@ -46,8 +49,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <linux/if_ether.h>
-
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
 #include <unistd.h>
 
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include <linux/if.h>
+#include <linux/if_ether.h>
+
 #include "unet.h"
 
 /*----- Static variables --------------------------------------------------*/
@@ -527,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
@@ -613,6 +663,12 @@ attachments inherit their debug flags from the global flag.\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,
     "help [COMMAND]", "display help about COMMAND", "\
 If COMMAND is given, display help about it.  If no COMAMND is specified,\n\
@@ -736,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':