First round of netstat(1) cleanup.

Removed the ambiguity in -s, -f, -p and -i flags handling.
Basically, there are four displays (except others):

1.  PCB display.
2.  Protocol statistics display. (-s)
3.  Interface statistics display. (-i)
4.  Per-interface protocol statistics display. (-i -s)

All of the above except 3) can be limited to a particular
protocol family (-f) or a single protocol (-p).

Some examples:

1.  netstat -f inet    -- show PCBs of all INET protocols
2.  netstat -p udp     -- show PCB of UDP protocol only (NEW!)
3.  netstat -s         -- show protocol statistics for all families
4.  netstat -s -f inet -- show INET protocols statistics
5.  netstat -s -p icmp -- show ICMP protocol statistics

This is a work in progress.  Manpage has been fixed slightly,
but is still incomplete.
This commit is contained in:
ru 2001-06-15 18:25:38 +00:00
parent b24972e849
commit 67653866aa
4 changed files with 56 additions and 69 deletions

View File

@ -202,7 +202,7 @@ intpr(int interval, u_long ifnetaddr, void (*pfunc)(char *))
if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet))
return;
if ((!sflag || iflag) && !pflag) {
if (!pfunc) {
printf("%-5.5s %-5.5s %-13.13s %-15.15s %8.8s %5.5s",
"Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs");
if (bflag)

View File

@ -315,7 +315,7 @@ int Lflag; /* show size of listen queues */
int mflag; /* show memory stats */
int numeric_addr; /* show addresses numerically */
int numeric_port; /* show ports numerically */
int pflag; /* show given protocol */
static int pflag; /* show given protocol */
int rflag; /* show routing tables (or routing stats) */
int sflag; /* show protocol statistics */
int tflag; /* show i/f watchdog timers */
@ -338,7 +338,7 @@ main(argc, argv)
af = AF_UNSPEC;
while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rsStuWw:")) != -1)
while ((ch = getopt(argc, argv, "Aabdf:gI:iLlM:mN:np:rSstuWw:")) != -1)
switch(ch) {
case 'A':
Aflag = 1;
@ -491,25 +491,6 @@ main(argc, argv)
mbpr(0, 0, 0, 0);
exit(0);
}
if (pflag) {
if (iflag && tp->pr_istats) {
kread(0, 0, 0);
intpr(interval, nl[N_IFNET].n_value, tp->pr_istats);
exit(0);
}
if (!tp->pr_stats) {
printf("%s: no stats routine\n", tp->pr_name);
exit(0);
}
if (tp->pr_usesysctl) {
(*tp->pr_stats)(tp->pr_usesysctl, tp->pr_name, af);
} else {
kread(0, 0, 0);
(*tp->pr_stats)(nl[tp->pr_sindex].n_value,
tp->pr_name, af);
}
exit(0);
}
#if 0
/*
* Keep file descriptors open to avoid overhead
@ -524,10 +505,7 @@ main(argc, argv)
* used for the queries, which is slower.
*/
#endif
if (iflag) {
if (sflag && af != AF_UNSPEC)
goto protostat;
if (iflag && !sflag) {
kread(0, 0, 0);
intpr(interval, nl[N_IFNET].n_value, NULL);
exit(0);
@ -562,8 +540,11 @@ main(argc, argv)
exit(0);
}
protostat:
kread(0, 0, 0);
if (tp) {
printproto(tp, tp->pr_name);
exit(0);
}
if (af == AF_INET || af == AF_UNSPEC)
for (tp = protox; tp->pr_name; tp++)
printproto(tp, tp->pr_name);
@ -621,15 +602,29 @@ printproto(tp, name)
if (tp->pr_istats)
intpr(interval, nl[N_IFNET].n_value,
tp->pr_istats);
else if (pflag)
printf("%s: no per-interface stats routine\n",
tp->pr_name);
return;
}
else {
pr = tp->pr_stats;
if (!pr) {
if (pflag)
printf("%s: no stats routine\n",
tp->pr_name);
return;
}
off = tp->pr_usesysctl ? tp->pr_usesysctl
: nl[tp->pr_sindex].n_value;
}
} else {
pr = tp->pr_cblocks;
if (!pr) {
if (pflag)
printf("%s: no PCB routine\n", tp->pr_name);
return;
}
off = tp->pr_usesysctl ? tp->pr_usesysctl
: nl[tp->pr_index].n_value;
}

View File

@ -32,7 +32,7 @@
.\" @(#)netstat.1 8.8 (Berkeley) 4/18/94
.\" $FreeBSD$
.\"
.Dd April 18, 1994
.Dd June 15, 2001
.Dt NETSTAT 1
.Os
.Sh NAME
@ -41,33 +41,30 @@
.Sh SYNOPSIS
.Nm
.Op Fl AaLlnW
.Op Fl f Ar address_family | Fl p Ar protocol
.Op Fl M Ar core
.Op Fl N Ar system
.Nm
.Op Fl gilnrsS
.Op Fl f Ar address_family
.Op Fl M Ar core
.Op Fl N Ar system
.Nm
.Op Fl bdgilnrsS
.Op Fl f Ar address_family
.Op Fl M Ar core
.Op Fl N Ar system
.Nm
.Op Fl bdn
.Op Fl I Ar interface
.Op Fl M Ar core
.Op Fl N Ar system
.Fl i | I Ar interface
.Op Fl w Ar wait
.Nm
.Op Fl p Ar protocol
.Op Fl abdgt
.Op Fl M Ar core
.Op Fl N Ar system
.Nm
.Op Fl p Ar protocol
.Op Fl i
.Op Fl I Ar Interface
.Fl s Op Fl s
.Op Fl f Ar address_family | Fl p Ar protocol
.Op Fl M Ar core
.Op Fl N Ar system
.Nm
.Op Fl s
.Op Fl f Ar address_family
.Op Fl i
.Op Fl I Ar Interface
.Fl i | I Ar interface Fl s
.Op Fl f Ar address_family | Fl p Ar protocol
.Op Fl M Ar core
.Op Fl N Ar system
.Nm
.Fl m
.Op Fl M Ar core
@ -89,9 +86,13 @@ interval specified,
.Nm
will continuously display the information regarding packet
traffic on the configured network interfaces.
The fourth form displays statistics about the named protocol.
The fifth and sixth forms display per interface statistics for
The fourth form displays statistics for
the specified protocol or address familily.
The fifth form displays per-interface statistics for
the specified protocol or address family.
The sixth form displays
.Xr mbuf 9
statistics.
.Pp
The options have the following meaning:
.Bl -tag -width flag
@ -112,8 +113,8 @@ parent route); normally these routes are
not shown.
.It Fl b
With the interface display (option
.Fl i
, as described below),
.Fl i ,
as described below),
show the number of bytes in and out.
.It Fl d
With either interface display (option
@ -165,18 +166,14 @@ used with a
.Ar wait
interval as described below.
If the
.Fl f Ar address_family
option (with the
.Fl s
option) or the
.Fl p Ar protocol
option is present, show per-interface statistics on the
option is present, show per-interface protocol statistics on the
.Ar interface
for the specified
.Ar address_family
or
.Ar protocol ,
respectively.
or for all protocol families.
.It Fl i
Show the state of interfaces which have been auto-configured
(interfaces statically configured into a system, but not
@ -188,17 +185,13 @@ for each Ethernet interface and for each IP interface address.
Multicast addresses are shown on separate lines following the interface
address with which they are associated.
If the
.Fl f Ar address_family
option (with the
.Fl s
option) or the
.Fl p Ar protocol
option is present, show per-interface statistics on all interfaces
for the specified
.Ar address_family
or
.Ar protocol ,
respectively.
or for all protocol families.
.It Fl L
Show the size of the various listen queues.
The first count shows the
@ -223,10 +216,6 @@ Show network addresses and ports as numbers (normally
interprets addresses and ports and attempts to display them
symbolically).
This option may be used with any of the display formats.
.It Fl S
Show network addresses as numbers (as with
.Fl n )
but show ports symbolically).
.It Fl p Ar protocol
Show statistics about
.Ar protocol ,
@ -241,9 +230,6 @@ 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 r
Show the routing tables.
Use with
@ -259,6 +245,13 @@ is also present,
assumes more columns are there and the maximum transmission unit
.Pq Dq mtu
are also displayed.
.It Fl S
Show network addresses as numbers (as with
.Fl n )
but show ports symbolically).
.It Fl s
Show per-protocol statistics.
If this option is repeated, counters with a value of zero are suppressed.
.It Fl W
In certain displays, avoid truncating addresses even if this causes
some fields to overflow.

View File

@ -47,7 +47,6 @@ extern int Lflag; /* show size of listen queues */
extern int mflag; /* show memory stats */
extern int numeric_addr; /* show addresses numerically */
extern int numeric_port; /* show ports numerically */
extern int pflag; /* show given protocol */
extern int rflag; /* show routing tables (or routing stats) */
extern int sflag; /* show protocol statistics */
extern int tflag; /* show i/f watchdog timers */