Hi,

The following small diff does the following:
 - allows the default to only show all non-listneing scokets, which matches
   the manpage and what netstat(1) does, sans the aflag (-a).
 - allows one to use 'a' to toggle the above (include listening or not).
 - implement [r]eset to reset all toggles to default (all/tcp/udp).
 - document a/n/r/t/u toggles.

comments/feedback/ok?

Cheers,
Okan

Index: netstat.c
===================================================================
RCS file: /home/okan/openbsd/cvs/src/usr.bin/systat/netstat.c,v
retrieving revision 1.34
diff -u -p -r1.34 netstat.c
--- netstat.c   2 Mar 2011 06:48:17 -0000       1.34
+++ netstat.c   27 Jan 2012 19:45:53 -0000
@@ -276,15 +276,17 @@ again:
 
                if (!aflag) {
                        if (!(inpcb.inp_flags & INP_IPV6) &&
-                           inet_lnaof(inpcb.inp_laddr) == INADDR_ANY)
+                           inet_lnaof(inpcb.inp_faddr) == INADDR_ANY)
                                continue;
                        if ((inpcb.inp_flags & INP_IPV6) &&
-                           IN6_IS_ADDR_UNSPECIFIED(&inpcb.inp_laddr6))
+                           IN6_IS_ADDR_UNSPECIFIED(&inpcb.inp_faddr6))
                                continue;
                }
                KREAD(inpcb.inp_socket, &sockb, sizeof (sockb));
                if (istcp) {
                        KREAD(inpcb.inp_ppcb, &tcpcb, sizeof (tcpcb));
+                       if (!aflag && tcpcb.t_state <= TCPS_LISTEN)
+                               continue;
                        enter(&inpcb, &sockb, tcpcb.t_state, "tcp");
                } else
                        enter(&inpcb, &sockb, 0, "udp");
@@ -438,8 +440,18 @@ int
 ns_keyboard_callback(int ch)
 {
        switch (ch) {
+       case 'a':
+               aflag = !aflag;
+               gotsig_alarm = 1;
+               break;
        case 'n':
                nflag = !nflag;
+               gotsig_alarm = 1;
+               break;
+       case 'r':
+               aflag = 0;
+               nflag = 1;
+               protos = TCP|UDP;
                gotsig_alarm = 1;
                break;
        case 't':
Index: systat.1
===================================================================
RCS file: /home/okan/openbsd/cvs/src/usr.bin/systat/systat.1,v
retrieving revision 1.92
diff -u -p -r1.92 systat.1
--- systat.1    29 Apr 2011 05:48:04 -0000      1.92
+++ systat.1    27 Jan 2012 15:13:55 -0000
@@ -295,49 +295,26 @@ Display mbuf usage information from kern
 and mbuf cluster pool statistics of each network interface.
 .It Ic netstat
 Display network connections.
-By default, network servers awaiting requests are not displayed.
 Each address
-is displayed in the format
-.Dq host:port ,
-with each shown symbolically, when possible.
-.\"It is possible to have addresses displayed numerically,
-.\"limit the display to a set of ports, hosts, and/or protocols
-.\"(the minimum unambiguous prefix may be supplied):
-.\".Bl -tag -width Ar
-.\".It Cm all
-.\"Toggle the displaying of server processes awaiting requests (this
-.\"is the equivalent of the
-.\".Fl a
-.\"flag to
-.\".Xr netstat 1 ) .
-.\".It Cm display Op Ar items
-.\"Display information about the connections associated with the
-.\"specified hosts or ports.
-.\"As for
-.\".Ar ignore ,
-.\".Ar items
-.\"may be names or numbers.
-.\".It Cm ignore Op Ar items
-.\"Do not display information about connections associated with
-.\"the specified hosts or ports.
-.\"Hosts and ports may be specified
-.\"by name
-.\".Pf ( Dq vangogh ,
-.\".Dq ftp ) ,
-.\"or numerically.
-.\"Host addresses
-.\"use the Internet dot notation
-.\".Pq Dq 128.32.0.9 .
-.\"Multiple items
-.\"may be specified with a single command by separating them with
-.\"spaces.
-.\".It Cm names
-.\"Display network addresses symbolically.
-.\".It Cm numbers
-.\"Display network addresses numerically.
-.\".It Cm reset
-.\"Reset the port, host, and protocol matching mechanisms to the default
-.\"(any protocol, port, or host).
+is displayed numerically in the format
+.Dq host:port .
+By default, network servers awaiting requests are not displayed.
+It is also possible to have addresses displayed symbolically,
+when possible, and limit the display to a set of protocols
+(the minimum unambiguous prefix may be supplied):
+.Bl -tag -width Ar
+.It Cm all
+Toggle the displaying of server processes awaiting requests (this
+is the equivalent of the
+.Fl a
+flag to
+.Xr netstat 1 ) .
+.It Cm names
+Display network addresses symbolically.
+.It Cm numbers
+Display network addresses numerically.
+.It Cm reset
+Reset matching mechanisms to the default.
 .\".It Cm show Oo
 .\".Ar protocols \*(Ba ports \*(Ba hosts
 .\".Oc
@@ -348,9 +325,9 @@ with each shown symbolically, when possi
 .\"If an argument is supplied to
 .\".Cm show ,
 .\"then only the requested information will be displayed.
-.\".It Cm tcp \*(Ba udp \*(Ba all
-.\"Display only network connections using the indicated protocol.
-.\".El
+.It Cm tcp \*(Ba udp
+Display only network connections using the indicated protocol.
+.El
 .It Ic nfsclient
 Display statistics about NFS client activity.
 Output resembles

Reply via email to