summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorjoe <joe@FreeBSD.org>2001-03-04 22:25:05 +0000
committerjoe <joe@FreeBSD.org>2001-03-04 22:25:05 +0000
commit076296e962b18db5f4e4606f3a0448817a6d3c53 (patch)
tree87d3c05c787c0eccfbe2e357ef73ca23ac95a481 /usr.bin
parent6d776c50038d2b6b59af3c799f7b665b4232c011 (diff)
downloadFreeBSD-src-076296e962b18db5f4e4606f3a0448817a6d3c53.zip
FreeBSD-src-076296e962b18db5f4e4606f3a0448817a6d3c53.tar.gz
When displaying interface statistics with -i show a '-' for any
values that aren't updated for a particular network-layer address.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/netstat/if.c79
1 files changed, 64 insertions, 15 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c
index c52fbba..bc0f7d5 100644
--- a/usr.bin/netstat/if.c
+++ b/usr.bin/netstat/if.c
@@ -125,6 +125,33 @@ bdg_stats(u_long dummy, char *name) /* print bridge statistics */
}
}
+
+
+
+/*
+ * Display a formatted value, or a '-' in the same space.
+ */
+void
+show_stat(fmt, width, value, showvalue)
+ char *fmt;
+ int width;
+ u_long value;
+ short showvalue;
+{
+ char newfmt[32];
+
+ /* Construct the format string */
+ if (showvalue) {
+ sprintf(newfmt, "%%%d%s", width, fmt);
+ printf(newfmt, value);
+ } else {
+ sprintf(newfmt, "%%%ds", width);
+ printf(newfmt, "-");
+ }
+}
+
+
+
/*
* Print a description of the network interfaces.
*/
@@ -164,6 +191,8 @@ intpr(interval, ifnetaddr, pfunc)
int drops;
struct sockaddr *sa = NULL;
char name[32], tname[16];
+ short network_layer;
+ short link_layer;
if (ifnetaddr == 0) {
printf("ifnet: symbol not defined\n");
@@ -203,6 +232,9 @@ intpr(interval, ifnetaddr, pfunc)
register char *cp;
int n, m;
+ network_layer = 0;
+ link_layer = 0;
+
if (ifaddraddr == 0) {
ifnetfound = ifnetaddr;
if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) ||
@@ -276,6 +308,8 @@ intpr(interval, ifnetaddr, pfunc)
#endif
printf("%-15.15s ",
routename(sin->sin_addr.s_addr));
+
+ network_layer = 1;
break;
#ifdef INET6
case AF_INET6:
@@ -287,6 +321,8 @@ intpr(interval, ifnetaddr, pfunc)
(char *)inet_ntop(AF_INET6,
&sin6->sin6_addr,
ntop_buf, sizeof(ntop_buf)));
+
+ network_layer = 1;
break;
#endif /*INET6*/
case AF_IPX:
@@ -350,6 +386,8 @@ intpr(interval, ifnetaddr, pfunc)
m = 30 - m;
while (m-- > 0)
putchar(' ');
+
+ link_layer = 1;
break;
}
@@ -357,30 +395,41 @@ intpr(interval, ifnetaddr, pfunc)
* Fixup the statistics for interfaces that
* update stats for their network addresses
*/
- if (sa->sa_family == AF_INET ||
- sa->sa_family == AF_INET6) {
+ if (network_layer) {
opackets = ifaddr.in.ia_ifa.if_opackets;
ipackets = ifaddr.in.ia_ifa.if_ipackets;
obytes = ifaddr.in.ia_ifa.if_obytes;
ibytes = ifaddr.in.ia_ifa.if_ibytes;
- oerrors = ierrors = 0;
- collisions = timer = drops = 0;
}
ifaddraddr = (u_long)TAILQ_NEXT(&ifaddr.ifa, ifa_link);
}
- printf("%8lu %5lu ", ipackets, ierrors);
- if (bflag)
- printf("%10lu ", ibytes);
- printf("%8lu %5lu ", opackets, oerrors);
- if (bflag)
- printf("%10lu ", obytes);
- printf("%5lu", collisions);
- if (tflag)
- printf(" %3d", timer);
- if (dflag)
- printf(" %3d", drops);
+ show_stat("lu", 8, ipackets, link_layer|network_layer);
+ printf(" ");
+ show_stat("lu", 5, ierrors, link_layer);
+ printf(" ");
+ if (bflag) {
+ show_stat("lu", 10, ibytes, link_layer|network_layer);
+ printf(" ");
+ }
+ show_stat("lu", 8, opackets, link_layer|network_layer);
+ printf(" ");
+ show_stat("lu", 5, oerrors, link_layer);
+ printf(" ");
+ if (bflag) {
+ show_stat("lu", 10, obytes, link_layer|network_layer);
+ printf(" ");
+ }
+ show_stat("lu", 5, collisions, link_layer);
+ if (tflag) {
+ printf(" ");
+ show_stat("d", 3, timer, link_layer);
+ }
+ if (dflag) {
+ printf(" ");
+ show_stat("d", 3, drops, link_layer);
+ }
putchar('\n');
if (aflag && ifaddrfound) {
/*
OpenPOWER on IntegriCloud