MFC:
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 Approved by: re (kensmith)
This commit is contained in:
parent
f367659d48
commit
d4bfa24b97
@ -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,18 +176,28 @@ 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.
|
||||
*/
|
||||
|
@ -268,6 +268,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 */
|
||||
@ -295,7 +296,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;
|
||||
@ -338,6 +339,9 @@ main(int argc, char *argv[])
|
||||
case 'g':
|
||||
gflag = 1;
|
||||
break;
|
||||
case 'h':
|
||||
hflag = 1;
|
||||
break;
|
||||
case 'I': {
|
||||
char *cp;
|
||||
|
||||
@ -691,7 +695,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]",
|
||||
|
@ -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
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user