Make display of media status information (e.g. carrier, etc.) table-driven

and easily extensible (by merely adding to the tables in ifmedia.h).
This commit is contained in:
thorpej 2000-01-25 00:59:39 +00:00
parent fe58a40561
commit 4e10c0202f

View File

@ -1,4 +1,4 @@
/* $NetBSD: ifconfig.c,v 1.62 2000/01/24 23:24:16 chopps Exp $ */ /* $NetBSD: ifconfig.c,v 1.63 2000/01/25 00:59:39 thorpej Exp $ */
/*- /*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@ -80,7 +80,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
#if 0 #if 0
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
#else #else
__RCSID("$NetBSD: ifconfig.c,v 1.62 2000/01/24 23:24:16 chopps Exp $"); __RCSID("$NetBSD: ifconfig.c,v 1.63 2000/01/25 00:59:39 thorpej Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -1261,6 +1261,11 @@ int carrier()
"\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS\7RUNNING\10NOARP\ "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS\7RUNNING\10NOARP\
\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2\20MULTICAST" \11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2\20MULTICAST"
const int ifm_status_valid_list[] = IFM_STATUS_VALID_LIST;
const struct ifmedia_status_description ifm_status_descriptions[] =
IFM_STATUS_DESCRIPTIONS;
/* /*
* Print the status of the interface. If an address family was * Print the status of the interface. If an address family was
* specified, show it and it only; otherwise, show them all. * specified, show it and it only; otherwise, show them all.
@ -1321,26 +1326,34 @@ status(ap, alen)
} }
putchar('\n'); putchar('\n');
if (ifmr.ifm_status & IFM_AVALID) { if (ifmr.ifm_status & IFM_STATUS_VALID) {
printf("\tstatus: "); const struct ifmedia_status_description *ifms;
switch (IFM_TYPE(ifmr.ifm_active)) { int bitno, found = 0;
case IFM_ETHER:
if (ifmr.ifm_status & IFM_ACTIVE)
printf("active");
else
printf("no carrier");
break;
case IFM_FDDI: printf("\tstatus: ");
case IFM_TOKEN: for (bitno = 0; ifm_status_valid_list[bitno] != 0; bitno++) {
if (ifmr.ifm_status & IFM_ACTIVE) for (ifms = ifm_status_descriptions;
printf("inserted"); ifms->ifms_valid != 0; ifms++) {
else if (ifms->ifms_type !=
printf("no ring"); IFM_TYPE(ifmr.ifm_active) &&
break; ifms->ifms_valid !=
default: ifm_status_valid_list[bitno])
printf("unknown"); continue;
printf("%s%s", found ? ", " : "",
IFM_STATUS_DESC(ifms, ifmr.ifm_status));
found = 1;
/*
* For each valid indicator bit, there's
* only one entry for each media type, so
* terminate the inner loop now.
*/
break;
}
} }
if (found == 0)
printf("unknown");
putchar('\n'); putchar('\n');
} }