opnsense-src/usr.bin/netstat
Olivier Certner c63d3e582a
netstat(1): '-w': Banners to appear before a new statistics line, not after
Recurring banners except the first are printed just after the latest
interval's statistics line, giving the false impression that the latter
are omitted.  It is also better to print a new banner only if it is
going to be followed by a new line of statistics, in case netstat(1) is
interrupted or we have reached the number of iterations specified by
'-q'.

Fix this by pushing printing these banners inside the loop producing
statistics lines, after having waited for the next interval.

The first banner is printed before the loop, as we want it to be printed
immediately at launch, even if at this point we do not have statistics
to display (we have to wait for an interval to compute these, as they
are based on a difference).

While here, remove the 'goto' spaghetti by putting banner printing into
its own private function and using a proper infinite loop in
sidewaysintpr().

While here, document the why of the 21 statistics line span between two
banners.

While here, check for the number of output lines of statistics once such
a line has effectively been printed.  This allows to remove the internal
incrementation performed when reading '-w''s argument, which was a hack
to compensate the misplaced check.

While here, in the manual page, simplify the description of the '-w'
mode and mention that passing 0 to '-q' means "no count limit".

Reviewed by:    glebius
Fixes:          84c1edcbad ("Rewrite netstat/if.c to use ...")
Fixes:          bf10ffe1d3 ("Add a new option, -q howmany, ...")
MFC after:      1 week
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D56227

(cherry picked from commit 31749859525b2b79634dc7c066c3563be5b1e3fd)
2026-04-30 19:58:45 +02:00
..
bpf.c netstat(1): Complete libxo transition 2024-10-13 02:21:46 +08:00
common.c netstat(1): Complete libxo transition 2024-10-13 02:21:46 +08:00
common.h usr.bin: Remove ancient SCCS tags. 2023-11-26 22:23:30 -07:00
if.c netstat(1): '-w': Banners to appear before a new statistics line, not after 2026-04-30 19:58:45 +02:00
inet.c netstat: fix a segfault with --libxo 2026-01-20 15:31:30 -07:00
inet6.c netstat(1): Complete libxo transition 2024-10-13 02:21:46 +08:00
ipsec.c usr.bin: Automated cleanup of cdefs and other formatting 2023-11-26 22:24:01 -07:00
main.c netstat(1): '-w': Banners to appear before a new statistics line, not after 2026-04-30 19:58:45 +02:00
Makefile netstat: strip the binary of sgid 2025-04-20 13:18:44 -05:00
Makefile.depend Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
Makefile.depend.options Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
mbuf.c netstat(1): Complete libxo transition 2024-10-13 02:21:46 +08:00
mroute.c netstat: Fix whitespace in libxo output for multicast routes 2026-02-16 13:42:11 +00:00
mroute6.c netstat: Fix whitespace in libxo output for multicast routes 2026-02-16 13:42:11 +00:00
netgraph.c netstat(1): Complete libxo transition 2024-10-13 02:21:46 +08:00
netisr.c netstat(1): Complete libxo transition 2024-10-13 02:21:46 +08:00
netstat.1 netstat(1): '-w': Banners to appear before a new statistics line, not after 2026-04-30 19:58:45 +02:00
netstat.h netstat: Use bool more widely 2025-02-04 14:12:21 -05:00
nhgrp.c netstat(1): Complete libxo transition 2024-10-13 02:21:46 +08:00
nhops.c netstat(1): Complete libxo transition 2024-10-13 02:21:46 +08:00
nlist_symbols pflow: netstat statistics 2024-01-16 09:45:53 +01:00
pfkey.c usr.bin: Automated cleanup of cdefs and other formatting 2023-11-26 22:24:01 -07:00
route.c netstat: restore printing the "default" keyword, provide -nn option 2025-02-03 10:09:58 -08:00
route_netlink.c netstat(1): Fix expire column in -r flag using netlink 2026-03-26 12:42:13 +03:30
sctp.c netstat: fix typo 2026-01-21 20:53:47 +01:00
unix.c netstat(1): Complete libxo transition 2024-10-13 02:21:46 +08:00