summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2005-08-18 21:04:12 +0000
committerglebius <glebius@FreeBSD.org>2005-08-18 21:04:12 +0000
commitcf4f3e357511611027fdf884b61a81c71608775f (patch)
tree84ad1437e4f5e19d51438020feec36543ce4412a /usr.bin
parent805a9715f8678d8ebbe70fe705dfc123c6821126 (diff)
downloadFreeBSD-src-cf4f3e357511611027fdf884b61a81c71608775f.zip
FreeBSD-src-cf4f3e357511611027fdf884b61a81c71608775f.tar.gz
Add a new switch -h for interface stats mode, which prints all interface
statistics in human readable form. In collaboration with: vsevolod Reviewed by: cperciva
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/netstat/if.c23
-rw-r--r--usr.bin/netstat/main.c8
-rw-r--r--usr.bin/netstat/netstat.17
-rw-r--r--usr.bin/netstat/netstat.h1
4 files changed, 29 insertions, 10 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c
index 1e1e13a..b8b5a81 100644
--- a/usr.bin/netstat/if.c
+++ b/usr.bin/netstat/if.c
@@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <errno.h>
+#include <libutil.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -175,17 +176,27 @@ show_stat(const 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 {
+ if (showvalue == 0) {
+ /* Print just dash. */
sprintf(newfmt, "%%%ds", width);
printf(newfmt, "-");
+ return;
}
-}
+ if (hflag) {
+ char buf[5];
+ /* Format in human readable form. */
+ humanize_number(buf, sizeof(buf), (int64_t)value, "",
+ HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL);
+ sprintf(newfmt, "%%%ds", width);
+ printf(newfmt, buf);
+ } else {
+ /* Construct the format string. */
+ sprintf(newfmt, "%%%d%s", width, fmt);
+ printf(newfmt, value);
+ }
+}
/*
* Print a description of the network interfaces.
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index 61a0ec1..7f33f80 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -273,6 +273,7 @@ int aflag; /* show all sockets (including servers) */
int bflag; /* show i/f total bytes in/out */
int dflag; /* show i/f dropped packets */
int gflag; /* show group (multicast) routing or stats */
+int hflag; /* show counters in human readable format */
int iflag; /* show interfaces */
int Lflag; /* show size of listen queues */
int mflag; /* show memory stats */
@@ -300,7 +301,7 @@ main(int argc, char *argv[])
af = AF_UNSPEC;
- while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rSstuWw:z")) != -1)
+ while ((ch = getopt(argc, argv, "Aabdf:ghI:iLlM:mN:np:rSstuWw:z")) != -1)
switch(ch) {
case 'A':
Aflag = 1;
@@ -343,6 +344,9 @@ main(int argc, char *argv[])
case 'g':
gflag = 1;
break;
+ case 'h':
+ hflag = 1;
+ break;
case 'I': {
char *cp;
@@ -698,7 +702,7 @@ usage(void)
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
"usage: netstat [-AaLnSW] [-f protocol_family | -p protocol]\n"
" [-M core] [-N system]",
-" netstat -i | -I interface [-abdnt] [-f address_family]\n"
+" netstat -i | -I interface [-abdhnt] [-f address_family]\n"
" [-M core] [-N system]",
" netstat -w wait [-I interface] [-d] [-M core] [-N system]",
" netstat -s [-s] [-z] [-f protocol_family | -p protocol] [-M core]",
diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1
index 32edfec..62de37c 100644
--- a/usr.bin/netstat/netstat.1
+++ b/usr.bin/netstat/netstat.1
@@ -32,7 +32,7 @@
.\" @(#)netstat.1 8.8 (Berkeley) 4/18/94
.\" $FreeBSD$
.\"
-.Dd March 25, 2004
+.Dd August 19, 2005
.Dt NETSTAT 1
.Os
.Sh NAME
@@ -89,7 +89,7 @@ but show ports symbolically.
.Bk -words
.Nm
.Fl i | I Ar interface
-.Op Fl abdnt
+.Op Fl abdhnt
.Op Fl f Ar address_family
.Op Fl M Ar core
.Op Fl N Ar system
@@ -117,6 +117,9 @@ If
.Fl d
is also present, show the number of dropped packets.
If
+.Fl h
+is also present, print all counters in human readable form.
+If
.Fl t
is also present, show the contents of watchdog timers.
If
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index 3a519ac..5bc3a60 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -41,6 +41,7 @@ extern int aflag; /* show all sockets (including servers) */
extern int bflag; /* show i/f total bytes in/out */
extern int dflag; /* show i/f dropped packets */
extern int gflag; /* show group (multicast) routing or stats */
+extern int hflag; /* show counters in human readable format */
extern int iflag; /* show interfaces */
extern int Lflag; /* show size of listen queues */
extern int mflag; /* show memory stats */
OpenPOWER on IntegriCloud