/* -*-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.
*
/*----- 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.
*
#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 --------------------------------------------------*/
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
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\
{ 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':