From f7fa522e95b52a6e94e2f48adc518be3d21154b9 Mon Sep 17 00:00:00 2001 From: Bill Paul Date: Sun, 12 Mar 1995 19:05:03 +0000 Subject: [PATCH] Impliment -ad and -au flags in addition to -a and document the change in the man page. ifconfig -au affects all interfaces marked as up, and ifconfig -ad affects only the interfaces marked down. ifconfig -a still handles everything. This change is purely for compatibility with SunOS, for those who might be accustomed to the SunOS ifconfig's behavior. --- sbin/ifconfig/ifconfig.8 | 17 ++++++++++++++++- sbin/ifconfig/ifconfig.c | 33 ++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index 6cdb45929e11..cb97093f2879 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -50,6 +50,10 @@ .Op Ar protocol_family .Nm ifconfig .Ar -a +.Nm ifconfig +.Ar -au +.Nm ifconfig +.Ar -ad .Sh DESCRIPTION .Nm Ifconfig is used to assign an address @@ -264,7 +268,18 @@ the hardware will be re-initialized. .Nm Ifconfig .Ar -a displays information on all interfaces. When followed by a configuration -parameter, will also set the configuration on all interfaces. +parameter, it will also set the configuration on all interfaces. +.Pp +.Nm Ifconfig +.Ar -au +is similar to +.Nm ifconfig +.Ar -a , +except it only affects interfaces that are currently marked as up. +Conversely, +.Nm ifconfig +.Ar -ad +affects only interfaces that are marked down. .Pp .Nm Ifconfig displays the current configuration for a network interface diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 66de006a4284..f62761ccfaad 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -207,13 +207,17 @@ main(argc, argv) perror("ifconfig: socket"); exit(1); } - if (!strcmp(name, "-a")) { + if (strstr(name, "-a")) { struct ifconf ifc; #define MAX_INTERFACES 50 /* Yeah right. */ char buffer[MAX_INTERFACES * sizeof(struct ifreq)]; struct ifreq *ifptr, *end; - int ifflags; + int ifflags, selectflag = -1; + if (strstr(name, "-au")) + selectflag = 1; + if (strstr(name, "-ad")) + selectflag = 0; ifc.ifc_len = sizeof(buffer); ifc.ifc_buf = buffer; if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0) { @@ -227,13 +231,12 @@ main(argc, argv) sprintf(ifr.ifr_name,"%s",ifptr->ifr_name); sprintf(name,"%s",ifptr->ifr_name); close(s); - s = socket(af, SOCK_DGRAM, 0); - if (s < 0) { + if ((s = socket(af, SOCK_DGRAM, 0)) < 0) { perror("ifconfig: socket"); exit(1); } if (ifptr->ifr_flags == ifflags) - ifconfig(argc,argv,af,rafp); + ifconfig(argc,argv,af,rafp,selectflag); if(ifptr->ifr_addr.sa_len) /* Dohw! */ ifptr = (struct ifreq *) ((caddr_t) ifptr + ifptr->ifr_addr.sa_len - @@ -241,23 +244,39 @@ main(argc, argv) ifptr++; } } else - ifconfig(argc,argv,af,rafp); + ifconfig(argc,argv,af,rafp, -1); exit (0); } -ifconfig(argc,argv,af,rafp) +ifconfig(argc,argv,af,rafp,flag) int argc; char *argv[]; int af; struct afswtch *rafp; + int flag; { if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) { Perror("ioctl (SIOCGIFFLAGS)"); exit(1); } + + switch(flag) { + case 0: + if (ifr.ifr_flags & IFF_UP) + return(0); + break; + case 1: + if (!(ifr.ifr_flags & IFF_UP)) + return(0); + break; + case -1: + default: + break; + } + strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); flags = ifr.ifr_flags; if (ioctl(s, SIOCGIFMETRIC, (caddr_t)&ifr) < 0)