Added a new ifconfig flag, -h, allowing, in conjunction with -v, the display

of interface I/O bytes in human-format.

Reviewed by Christos Zoulas and Jason Thorpe.
This commit is contained in:
rpaulo 2005-08-11 20:56:05 +00:00
parent 9f1eb3e30f
commit 630caafc65
1 changed files with 37 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ifconfig.c,v 1.168 2005/05/02 15:35:16 yamt Exp $ */
/* $NetBSD: ifconfig.c,v 1.169 2005/08/11 20:56:05 rpaulo Exp $ */
/*-
* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@ -76,7 +76,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
#if 0
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
#else
__RCSID("$NetBSD: ifconfig.c,v 1.168 2005/05/02 15:35:16 yamt Exp $");
__RCSID("$NetBSD: ifconfig.c,v 1.169 2005/08/11 20:56:05 rpaulo Exp $");
#endif
#endif /* not lint */
@ -135,6 +135,7 @@ int newaddr = -1;
int conflicting = 0;
int af;
int aflag, bflag, Cflag, dflag, lflag, mflag, sflag, uflag, vflag, zflag;
int hflag;
#ifdef INET6
int Lflag;
#endif
@ -361,7 +362,7 @@ main(int argc, char *argv[])
/* Parse command-line options */
aflag = mflag = vflag = zflag = 0;
while ((ch = getopt(argc, argv, "AabCdlmsuvz"
while ((ch = getopt(argc, argv, "AabCdhlmsuvz"
#ifdef INET6
"L"
#endif
@ -386,7 +387,9 @@ main(int argc, char *argv[])
case 'd':
dflag = 1;
break;
case 'h':
hflag = 1;
break;
#ifdef INET6
case 'L':
Lflag = 1;
@ -1414,12 +1417,23 @@ status(const struct sockaddr_dl *sdl)
err(EXIT_FAILURE, zflag ? "SIOCZIFDATA" : "SIOCGIFDATA");
} else {
struct if_data * const ifi = &ifdr.ifdr_data;
char buf[5];
#define PLURAL(n) ((n) == 1 ? "" : "s")
printf("\tinput: %llu packet%s, %llu byte%s",
#define PLURALSTR(s) ((atof(s)) == 1.0 ? "" : "s")
printf("\tinput: %llu packet%s, ",
(unsigned long long) ifi->ifi_ipackets,
PLURAL(ifi->ifi_ipackets),
(unsigned long long) ifi->ifi_ibytes,
PLURAL(ifi->ifi_ibytes));
PLURAL(ifi->ifi_ipackets));
if (hflag) {
(void) humanize_number(buf, sizeof(buf),
(int64_t) ifi->ifi_ibytes, "", HN_AUTOSCALE,
HN_NOSPACE | HN_DECIMAL);
printf("%s byte%s", buf,
PLURALSTR(buf));
} else
printf("%llu byte%s",
(unsigned long long) ifi->ifi_ibytes,
PLURAL(ifi->ifi_ibytes));
if (ifi->ifi_imcasts)
printf(", %llu multicast%s",
(unsigned long long) ifi->ifi_imcasts,
@ -1435,11 +1449,19 @@ status(const struct sockaddr_dl *sdl)
if (ifi->ifi_noproto)
printf(", %llu unknown protocol",
(unsigned long long) ifi->ifi_noproto);
printf("\n\toutput: %llu packet%s, %llu byte%s",
printf("\n\toutput: %llu packet%s, ",
(unsigned long long) ifi->ifi_opackets,
PLURAL(ifi->ifi_opackets),
(unsigned long long) ifi->ifi_obytes,
PLURAL(ifi->ifi_obytes));
PLURAL(ifi->ifi_opackets));
if (hflag) {
(void) humanize_number(buf, sizeof(buf),
(int64_t) ifi->ifi_obytes, "", HN_AUTOSCALE,
HN_NOSPACE | HN_DECIMAL);
printf("%s byte%s", buf,
PLURALSTR(buf));
} else
printf("%llu byte%s",
(unsigned long long) ifi->ifi_obytes,
PLURAL(ifi->ifi_obytes));
if (ifi->ifi_omcasts)
printf(", %llu multicast%s",
(unsigned long long) ifi->ifi_omcasts,
@ -1454,6 +1476,7 @@ status(const struct sockaddr_dl *sdl)
PLURAL(ifi->ifi_collisions));
printf("\n");
#undef PLURAL
#undef PLURALSTR
}
ieee80211_statistics();
@ -1481,7 +1504,7 @@ usage(void)
const char *progname = getprogname();
fprintf(stderr,
"usage: %s [-m] [-v] [-z] "
"usage: %s [-h] [-m] [-v] [-z] "
#ifdef INET6
"[-L] "
#endif
@ -1500,7 +1523,7 @@ usage(void)
"\t[ anycast | -anycast ] [ deprecated | -deprecated ]\n"
"\t[ tentative | -tentative ] [ pltime n ] [ vltime n ] [ eui64 ]\n"
"\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ]\n"
" %s -a [-b] [-m] [-d] [-u] [-v] [-z] [ af ]\n"
" %s -a [-b] [-h] [-m] [-d] [-u] [-v] [-z] [ af ]\n"
" %s -l [-b] [-d] [-u] [-s]\n"
" %s -C\n"
" %s interface create\n"