Subject: suggested ifconfig(8) enhancement
To: None <tech-net@NetBSD.ORG>
From: Luke Mewburn <lukem@connect.com.au>
List: tech-net
Date: 04/16/1997 18:45:19
I've whipped up a quick modification to ifconfig(8) to limit the
display of -a and -l to just up (using -u) or down (using -d)
interfaces, a la Solaris's ifconfig.
I think this could be useful, potentially in /etc/netstart.
Also, if stuff like "ifconfig -a <some command>" ever works, limiting
it to up or down interfaces could be a big win.
In any case, the code is rather simple; diffs attached.
Problems with committing this?
Index: ifconfig.8
===================================================================
RCS file: /cvsroot/src/sbin/ifconfig/ifconfig.8,v
retrieving revision 1.16
diff -c -r1.16 ifconfig.8
*** ifconfig.8 1997/04/10 19:10:16 1.16
--- ifconfig.8 1997/04/16 08:44:08
***************
*** 33,39 ****
.\"
.\" @(#)ifconfig.8 8.4 (Berkeley) 6/1/94
.\"
! .Dd June 1, 1994
.Dt IFCONFIG 8
.Os BSD 4.2
.Sh NAME
--- 33,39 ----
.\"
.\" @(#)ifconfig.8 8.4 (Berkeley) 6/1/94
.\"
! .Dd April 16, 1997
.Dt IFCONFIG 8
.Os BSD 4.2
.Sh NAME
***************
*** 54,75 ****
.Nm ifconfig
.Fl a
.Op Fl m
.Op Ar protocol_family
.Nm ifconfig
.Fl l
.Sh DESCRIPTION
! .Nm Ifconfig
is used to assign an address
to a network interface and/or configure
network interface parameters.
! .Nm Ifconfig
must be used at boot time to define the network address
of each interface present on a machine; it may also be used at
a later time to redefine an interface's address
or other operating parameters.
.Pp
Available operands for
! .Nm ifconfig:
.Bl -tag -width Ds
.It Ar Address
For the
--- 54,79 ----
.Nm ifconfig
.Fl a
.Op Fl m
+ .Op Fl d
+ .Op Fl u
.Op Ar protocol_family
.Nm ifconfig
.Fl l
+ .Op Fl d
+ .Op Fl u
.Sh DESCRIPTION
! .Nm
is used to assign an address
to a network interface and/or configure
network interface parameters.
! .Nm
must be used at boot time to define the network address
of each interface present on a machine; it may also be used at
a later time to redefine an interface's address
or other operating parameters.
.Pp
Available operands for
! .Nm ifconfig :
.Bl -tag -width Ds
.It Ar Address
For the
***************
*** 290,297 ****
the hardware will be re-initialized.
.El
.Pp
! .Pp
! .Nm Ifconfig
displays the current configuration for a network interface
when no optional parameters are supplied.
If a protocol family is specified,
--- 294,300 ----
the hardware will be re-initialized.
.El
.Pp
! .Nm
displays the current configuration for a network interface
when no optional parameters are supplied.
If a protocol family is specified,
***************
*** 300,318 ****
If the
.Fl m
flag is passed before an interface name,
! .Nm ifconfig
will display all of the supported media for the specified interface.
Optionally, the
.Fl a
flag may be used instead of an interface name. This flag instructs
! .Nm ifconfig
to display information about all interfaces in the system.
.Pp
The
.Fl l
flag may be used to list all available interfaces on the system, with
no other additional information. Use of this flag is mutually exclusive
! with all other flags and commands.
.Pp
Only the super-user may modify the configuration of a network interface.
.Sh DIAGNOSTICS
--- 303,331 ----
If the
.Fl m
flag is passed before an interface name,
! .Nm
will display all of the supported media for the specified interface.
+ .Pp
Optionally, the
.Fl a
flag may be used instead of an interface name. This flag instructs
! .Nm
to display information about all interfaces in the system.
+ .Fl d
+ limits this to interfaces that are down, and
+ .Fl u
+ limits this to interfaces that are up.
.Pp
The
.Fl l
flag may be used to list all available interfaces on the system, with
no other additional information. Use of this flag is mutually exclusive
! with all other flags and commands, except for
! .Fl d
! (only list interfaces that are down)
! and
! .Fl u
! (only list interfaces that are up).
.Pp
Only the super-user may modify the configuration of a network interface.
.Sh DIAGNOSTICS
Index: ifconfig.c
===================================================================
RCS file: /cvsroot/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.33
diff -c -r1.33 ifconfig.c
*** ifconfig.c 1997/04/10 19:10:17 1.33
--- ifconfig.c 1997/04/16 08:44:14
***************
*** 121,127 ****
int newaddr = 1;
int nsellength = 1;
int af;
! int mflag, lflag;
void notealias __P((char *, int));
void notrailers __P((char *, int));
--- 121,127 ----
int newaddr = 1;
int nsellength = 1;
int af;
! int mflag, lflag, dflag, uflag;
void notealias __P((char *, int));
void notrailers __P((char *, int));
***************
*** 257,268 ****
/* Parse command-line options */
aflag = mflag = 0;
! while ((ch = getopt(argc, argv, "alm")) != -1) {
switch (ch) {
case 'a':
aflag = 1;
break;
case 'l':
lflag = 1;
break;
--- 257,272 ----
/* Parse command-line options */
aflag = mflag = 0;
! while ((ch = getopt(argc, argv, "adlmu")) != -1) {
switch (ch) {
case 'a':
aflag = 1;
break;
+ case 'd':
+ dflag = 1;
+ break;
+
case 'l':
lflag = 1;
break;
***************
*** 271,276 ****
--- 275,284 ----
mflag = 1;
break;
+ case 'u':
+ uflag = 1;
+ break;
+
default:
usage();
/* NOTREACHED */
***************
*** 467,473 ****
err(1, "SIOCGIFCONF");
ifr = ifc.ifc_req;
ifreq.ifr_name[0] = '\0';
! for (i = 0, idx = 0; i < ifc.ifc_len; idx++) {
ifr = (struct ifreq *)((caddr_t)ifc.ifc_req + i);
i += sizeof(ifr->ifr_name) +
(ifr->ifr_addr.sa_len > sizeof(struct sockaddr)
--- 475,481 ----
err(1, "SIOCGIFCONF");
ifr = ifc.ifc_req;
ifreq.ifr_name[0] = '\0';
! for (i = 0, idx = 0; i < ifc.ifc_len; ) {
ifr = (struct ifreq *)((caddr_t)ifc.ifc_req + i);
i += sizeof(ifr->ifr_name) +
(ifr->ifr_addr.sa_len > sizeof(struct sockaddr)
***************
*** 481,498 ****
(void) strncpy(name, ifr->ifr_name, sizeof(ifr->ifr_name));
ifreq = *ifr;
/*
* Are we just listing the interfaces?
*/
if (lflag) {
! if (idx)
putchar(' ');
! printf(name);
continue;
}
- if (getinfo(&ifreq) < 0)
- continue;
if (sdl == NULL) {
status(NULL, 0);
} else {
--- 489,512 ----
(void) strncpy(name, ifr->ifr_name, sizeof(ifr->ifr_name));
ifreq = *ifr;
+ if (getinfo(&ifreq) < 0)
+ continue;
+ if (dflag && (flags & IFF_UP) != 0)
+ continue;
+ if (uflag && (flags & IFF_UP) == 0)
+ continue;
+
+ idx++;
/*
* Are we just listing the interfaces?
*/
if (lflag) {
! if (idx > 1)
putchar(' ');
! fputs(name, stdout);
continue;
}
if (sdl == NULL) {
status(NULL, 0);
} else {
***************
*** 577,583 ****
char *vname;
int value;
{
! printf("Note: trailers are no longer sent, but always received\n");
}
/*ARGSUSED*/
--- 591,597 ----
char *vname;
int value;
{
! puts("Note: trailers are no longer sent, but always received");
}
/*ARGSUSED*/
***************
*** 1444,1450 ****
sns->sns_len = sizeof(*sns);
sns->sns_addr = ns_addr(addr);
if (which == MASK)
! printf("Attempt to set XNS netmask will be ineffectual\n");
}
#define SISO(x) ((struct sockaddr_iso *) &(x))
--- 1458,1464 ----
sns->sns_len = sizeof(*sns);
sns->sns_addr = ns_addr(addr);
if (which == MASK)
! puts("Attempt to set XNS netmask will be ineffectual");
}
#define SISO(x) ((struct sockaddr_iso *) &(x))
***************
*** 1522,1528 ****
"\t[ mediaopt mopts ]\n",
"\t[ -mediaopt mopts ]\n",
"\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ]\n",
! " ifconfig -a [ -m ] [ af ]\n",
! " ifconfig -l\n");
exit(1);
}
--- 1536,1542 ----
"\t[ mediaopt mopts ]\n",
"\t[ -mediaopt mopts ]\n",
"\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ]\n",
! " ifconfig -a [ -m ] [ -d ] [ -u ] [ af ]\n",
! " ifconfig -l [ -d ] [ -u ]\n");
exit(1);
}