diff options
author | brian <brian@cvs.openbsd.org> | 2001-08-26 09:42:05 +0000 |
---|---|---|
committer | brian <brian@cvs.openbsd.org> | 2001-08-26 09:42:05 +0000 |
commit | 6368b55e2df55e3ddc1cf9b6b703cd4ba8e11030 (patch) | |
tree | f7beae31c9277c5e28c066f85eda2f2f57ecf5fe | |
parent | c1ba8d213e9c957c72d57c56a9784ac87e49a7f1 (diff) |
Add a -q to silence zero-output lines and fix some whitespace and text nits.
Submitted by: Sam Smith <S@mSmith.net>
Ok: theo
-rw-r--r-- | usr.bin/netstat/if.c | 21 | ||||
-rw-r--r-- | usr.bin/netstat/inet.c | 16 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 9 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.1 | 14 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 3 |
5 files changed, 44 insertions, 19 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index 6173da114e9..158849b2934 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.24 2001/07/18 17:17:39 pvalchev Exp $ */ +/* $OpenBSD: if.c,v 1.25 2001/08/26 09:42:04 brian Exp $ */ /* $NetBSD: if.c,v 1.16.4.2 1996/06/07 21:46:46 thorpej Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94"; #else -static char *rcsid = "$OpenBSD: if.c,v 1.24 2001/07/18 17:17:39 pvalchev Exp $"; +static char *rcsid = "$OpenBSD: if.c,v 1.25 2001/08/26 09:42:04 brian Exp $"; #endif #endif /* not lint */ @@ -95,6 +95,7 @@ intpr(interval, ifnetaddr) struct ipx_ifaddr ipx; struct iso_ifaddr iso; } ifaddr; + u_long total; u_long ifaddraddr; struct sockaddr *sa; struct ifnet_head ifhead; /* TAILQ_HEAD */ @@ -153,6 +154,22 @@ intpr(interval, ifnetaddr) *cp = '\0'; ifaddraddr = (u_long)ifnet.if_addrlist.tqh_first; } + + if (qflag) { + total = ifnet.if_ibytes + ifnet.if_obytes + + ifnet.if_ipackets + ifnet.if_ierrors + + ifnet.if_opackets + ifnet.if_oerrors + + ifnet.if_collisions; + if (tflag) + total += ifnet.if_timer; + if (dflag) + total += ifnet.if_snd.ifq_drops; + if (total == 0) { + ifaddraddr = 0; + continue; + } + } + printf("%-7.7s %-5ld ", name, ifnet.if_mtu); if (ifaddraddr == 0) { printf("%-11.11s ", "none"); diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index 023f5b2b0b0..4ee5e5b14ed 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inet.c,v 1.52 2001/07/05 08:54:41 angelos Exp $ */ +/* $OpenBSD: inet.c,v 1.53 2001/08/26 09:42:04 brian Exp $ */ /* $NetBSD: inet.c,v 1.14 1995/10/03 21:42:37 thorpej Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94"; #else -static char *rcsid = "$OpenBSD: inet.c,v 1.52 2001/07/05 08:54:41 angelos Exp $"; +static char *rcsid = "$OpenBSD: inet.c,v 1.53 2001/08/26 09:42:04 brian Exp $"; #endif #endif /* not lint */ @@ -750,13 +750,13 @@ etherip_stats(off, name) printf(m, etheripstat.f, plural(etheripstat.f)) - p(etherip_hdrops, "\t%u packet%s shorter than header shows\n"); - p(etherip_qfull, "\t%u packet%s were dropped due to full output queue\n"); + p(etherip_hdrops, "\t%u packet%s shorter than header shows\n"); + p(etherip_qfull, "\t%u packet%s were dropped due to full output queue\n"); p(etherip_noifdrops, "\t%u packet%s were dropped because of no interface/bridge information\n"); - p(etherip_pdrops, "\t%u packet%s dropped due to policy\n"); - p(etherip_adrops, "\t%u packet%s dropped for other reasons\n"); - p(etherip_ipackets, "\t%u input ethernet-in-IP packets\n"); - p(etherip_opackets, "\t%u output ethernet-in-IP packets\n"); + p(etherip_pdrops, "\t%u packet%s dropped due to policy\n"); + p(etherip_adrops, "\t%u packet%s dropped for other reasons\n"); + p(etherip_ipackets, "\t%u input ethernet-in-IP packet%s\n"); + p(etherip_opackets, "\t%u output ethernet-in-IP packet%s\n"); p(etherip_ibytes, "\t%qu input byte%s\n"); p(etherip_obytes, "\t%qu output byte%s\n"); #undef p diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 2e7e2da34ca..96b90b7ed89 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.26 2001/07/05 08:47:44 jjbg Exp $ */ +/* $OpenBSD: main.c,v 1.27 2001/08/26 09:42:04 brian Exp $ */ /* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */ /* @@ -44,7 +44,7 @@ char copyright[] = #if 0 static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94"; #else -static char *rcsid = "$OpenBSD: main.c,v 1.26 2001/07/05 08:47:44 jjbg Exp $"; +static char *rcsid = "$OpenBSD: main.c,v 1.27 2001/08/26 09:42:04 brian Exp $"; #endif #endif /* not lint */ @@ -297,7 +297,7 @@ main(argc, argv) af = AF_UNSPEC; - while ((ch = getopt(argc, argv, "Aabdf:gI:ilM:mN:np:rstuvw:")) != -1) + while ((ch = getopt(argc, argv, "Aabdf:gI:ilM:mN:np:qrstuvw:")) != -1) switch(ch) { case 'A': Aflag = 1; @@ -371,6 +371,9 @@ main(argc, argv) } pflag = 1; break; + case 'q': + qflag = 1; + break; case 'r': rflag = 1; break; diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1 index 4a80e127392..d8f209d115a 100644 --- a/usr.bin/netstat/netstat.1 +++ b/usr.bin/netstat/netstat.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: netstat.1,v 1.25 2001/06/25 00:41:39 niklas Exp $ +.\" $OpenBSD: netstat.1,v 1.26 2001/08/26 09:42:04 brian Exp $ .\" $NetBSD: netstat.1,v 1.11 1995/10/03 21:42:43 thorpej Exp $ .\" .\" Copyright (c) 1983, 1990, 1992, 1993 @@ -47,7 +47,7 @@ .Op Fl M Ar core .Op Fl N Ar system .Nm netstat -.Op Fl bdgimnrs +.Op Fl bdgimnqrs .Op Fl f Ar address_family .Op Fl M Ar core .Op Fl N Ar system @@ -207,14 +207,18 @@ report. The program will complain if .Ar protocol is unknown or if there is no statistics routine for it. -.It Fl s -Show per-protocol statistics. -If this option is repeated, counters with a value of zero are suppressed. +.It Fl q +Only show interfaces that have seen packets (or bytes if +.Fl b +is specified) .It Fl r Show the routing tables. If the .Fl s option is also specified, show routing statistics instead. +.It Fl s +Show per-protocol statistics. +If this option is repeated, counters with a value of zero are suppressed. .It Fl v Be verbose. Avoids truncation of long addresses. diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index 879499aa7a4..f6f3572b0f9 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netstat.h,v 1.18 2001/07/05 08:47:44 jjbg Exp $ */ +/* $OpenBSD: netstat.h,v 1.19 2001/08/26 09:42:04 brian Exp $ */ /* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */ /* @@ -51,6 +51,7 @@ int lflag; /* show routing table with use and ref */ int mflag; /* show memory stats */ int nflag; /* show addresses numerically */ int pflag; /* show given protocol */ +int qflag; /* only display non-zero values for output */ int rflag; /* show routing tables (or routing stats) */ int sflag; /* show protocol statistics */ int tflag; /* show i/f watchdog timers */ |