History log of /netbsd-current/usr.bin/netstat/if.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.109 28-Dec-2022 mrg

if not given an interface to monitor by default, pick the one
with the most bytes in/out the first time and keep using it.

in addition to picking the most likely intersting interface,
this actually fixes a bug where interfaces coming/going in
the middle of eg, "netstat -b -w 1", may end up showing the
data for another interface on any output line (including the
the header declaring the interface!)


Revision tags: netbsd-10-base
# 1.108 12-Dec-2022 msaitoh

Use warn() instead of warnx() and simplify.


# 1.107 19-Nov-2022 taca

netstat/if.c: Fix error message with "-w" option.

Now ifq_drops is 64bit unsigned integer.

No description in src/doc/CHANGES?


# 1.106 24-Oct-2022 msaitoh

Make ifq_drops in struct ifqueue and struct ifaltq 64 bit.


# 1.105 21-Sep-2022 msaitoh

s/u_quad_t/uint64_t/. No functional change.


# 1.104 12-Sep-2022 msaitoh

Print oqdrops correctly in continuous display mode using with kvm.


# 1.103 11-Sep-2022 msaitoh

Fix printing current output drop packet count in continuous display mode.


# 1.102 05-Sep-2022 msaitoh

G.C. No functional change.


# 1.101 05-Sep-2022 msaitoh

Print oqdrops correctly.


# 1.100 05-Sep-2022 msaitoh

Get if_data correctly when kvm is used.


# 1.99 02-Sep-2022 msaitoh

KNF. No functional change.


# 1.98 01-Sep-2022 msaitoh

KNF. No functional change.


# 1.97 18-Aug-2022 msaitoh

Use NULL instead of 0.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.96 02-Feb-2020 thorpej

Update for per-cpu interface statistics.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728
# 1.95 11-Jul-2018 msaitoh

branches: 1.95.2;
Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


Revision tags: netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.94 23-Feb-2017 ozaki-r

branches: 1.94.4; 1.94.10; 1.94.12;
Remove mkludge stuffs

For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

branches: 1.91.2;
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.108 12-Dec-2022 msaitoh

Use warn() instead of warnx() and simplify.


# 1.107 19-Nov-2022 taca

netstat/if.c: Fix error message with "-w" option.

Now ifq_drops is 64bit unsigned integer.

No description in src/doc/CHANGES?


# 1.106 24-Oct-2022 msaitoh

Make ifq_drops in struct ifqueue and struct ifaltq 64 bit.


# 1.105 21-Sep-2022 msaitoh

s/u_quad_t/uint64_t/. No functional change.


# 1.104 12-Sep-2022 msaitoh

Print oqdrops correctly in continuous display mode using with kvm.


# 1.103 11-Sep-2022 msaitoh

Fix printing current output drop packet count in continuous display mode.


# 1.102 05-Sep-2022 msaitoh

G.C. No functional change.


# 1.101 05-Sep-2022 msaitoh

Print oqdrops correctly.


# 1.100 05-Sep-2022 msaitoh

Get if_data correctly when kvm is used.


# 1.99 02-Sep-2022 msaitoh

KNF. No functional change.


# 1.98 01-Sep-2022 msaitoh

KNF. No functional change.


# 1.97 18-Aug-2022 msaitoh

Use NULL instead of 0.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.96 02-Feb-2020 thorpej

Update for per-cpu interface statistics.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728
# 1.95 11-Jul-2018 msaitoh

branches: 1.95.2;
Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


Revision tags: netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.94 23-Feb-2017 ozaki-r

branches: 1.94.4; 1.94.10; 1.94.12;
Remove mkludge stuffs

For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

branches: 1.91.2;
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.107 19-Nov-2022 taca

netstat/if.c: Fix error message with "-w" option.

Now ifq_drops is 64bit unsigned integer.

No description in src/doc/CHANGES?


# 1.106 24-Oct-2022 msaitoh

Make ifq_drops in struct ifqueue and struct ifaltq 64 bit.


# 1.105 21-Sep-2022 msaitoh

s/u_quad_t/uint64_t/. No functional change.


# 1.104 12-Sep-2022 msaitoh

Print oqdrops correctly in continuous display mode using with kvm.


# 1.103 11-Sep-2022 msaitoh

Fix printing current output drop packet count in continuous display mode.


# 1.102 05-Sep-2022 msaitoh

G.C. No functional change.


# 1.101 05-Sep-2022 msaitoh

Print oqdrops correctly.


# 1.100 05-Sep-2022 msaitoh

Get if_data correctly when kvm is used.


# 1.99 02-Sep-2022 msaitoh

KNF. No functional change.


# 1.98 01-Sep-2022 msaitoh

KNF. No functional change.


# 1.97 18-Aug-2022 msaitoh

Use NULL instead of 0.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.96 02-Feb-2020 thorpej

Update for per-cpu interface statistics.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728
# 1.95 11-Jul-2018 msaitoh

branches: 1.95.2;
Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


Revision tags: netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.94 23-Feb-2017 ozaki-r

branches: 1.94.4; 1.94.10; 1.94.12;
Remove mkludge stuffs

For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

branches: 1.91.2;
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.106 24-Oct-2022 msaitoh

Make ifq_drops in struct ifqueue and struct ifaltq 64 bit.


# 1.105 21-Sep-2022 msaitoh

s/u_quad_t/uint64_t/. No functional change.


# 1.104 12-Sep-2022 msaitoh

Print oqdrops correctly in continuous display mode using with kvm.


# 1.103 11-Sep-2022 msaitoh

Fix printing current output drop packet count in continuous display mode.


# 1.102 05-Sep-2022 msaitoh

G.C. No functional change.


# 1.101 05-Sep-2022 msaitoh

Print oqdrops correctly.


# 1.100 05-Sep-2022 msaitoh

Get if_data correctly when kvm is used.


# 1.99 02-Sep-2022 msaitoh

KNF. No functional change.


# 1.98 01-Sep-2022 msaitoh

KNF. No functional change.


# 1.97 18-Aug-2022 msaitoh

Use NULL instead of 0.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.96 02-Feb-2020 thorpej

Update for per-cpu interface statistics.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728
# 1.95 11-Jul-2018 msaitoh

branches: 1.95.2;
Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


Revision tags: netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.94 23-Feb-2017 ozaki-r

branches: 1.94.4; 1.94.10; 1.94.12;
Remove mkludge stuffs

For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

branches: 1.91.2;
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.105 21-Sep-2022 msaitoh

s/u_quad_t/uint64_t/. No functional change.


# 1.104 12-Sep-2022 msaitoh

Print oqdrops correctly in continuous display mode using with kvm.


# 1.103 11-Sep-2022 msaitoh

Fix printing current output drop packet count in continuous display mode.


# 1.102 05-Sep-2022 msaitoh

G.C. No functional change.


# 1.101 05-Sep-2022 msaitoh

Print oqdrops correctly.


# 1.100 05-Sep-2022 msaitoh

Get if_data correctly when kvm is used.


# 1.99 02-Sep-2022 msaitoh

KNF. No functional change.


# 1.98 01-Sep-2022 msaitoh

KNF. No functional change.


# 1.97 18-Aug-2022 msaitoh

Use NULL instead of 0.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.96 02-Feb-2020 thorpej

Update for per-cpu interface statistics.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728
# 1.95 11-Jul-2018 msaitoh

branches: 1.95.2;
Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


Revision tags: netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.94 23-Feb-2017 ozaki-r

branches: 1.94.4; 1.94.10; 1.94.12;
Remove mkludge stuffs

For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

branches: 1.91.2;
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.104 12-Sep-2022 msaitoh

Print oqdrops correctly in continuous display mode using with kvm.


# 1.103 11-Sep-2022 msaitoh

Fix printing current output drop packet count in continuous display mode.


# 1.102 05-Sep-2022 msaitoh

G.C. No functional change.


# 1.101 05-Sep-2022 msaitoh

Print oqdrops correctly.


# 1.100 05-Sep-2022 msaitoh

Get if_data correctly when kvm is used.


# 1.99 02-Sep-2022 msaitoh

KNF. No functional change.


# 1.98 01-Sep-2022 msaitoh

KNF. No functional change.


# 1.97 18-Aug-2022 msaitoh

Use NULL instead of 0.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.96 02-Feb-2020 thorpej

Update for per-cpu interface statistics.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728
# 1.95 11-Jul-2018 msaitoh

branches: 1.95.2;
Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


Revision tags: netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.94 23-Feb-2017 ozaki-r

branches: 1.94.4; 1.94.10; 1.94.12;
Remove mkludge stuffs

For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

branches: 1.91.2;
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.102 05-Sep-2022 msaitoh

G.C. No functional change.


# 1.101 05-Sep-2022 msaitoh

Print oqdrops correctly.


# 1.100 05-Sep-2022 msaitoh

Get if_data correctly when kvm is used.


# 1.99 02-Sep-2022 msaitoh

KNF. No functional change.


# 1.98 01-Sep-2022 msaitoh

KNF. No functional change.


# 1.97 18-Aug-2022 msaitoh

Use NULL instead of 0.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.96 02-Feb-2020 thorpej

Update for per-cpu interface statistics.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728
# 1.95 11-Jul-2018 msaitoh

Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


Revision tags: netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.94 23-Feb-2017 ozaki-r

branches: 1.94.4; 1.94.10; 1.94.12;
Remove mkludge stuffs

For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

branches: 1.91.2;
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.99 02-Sep-2022 msaitoh

KNF. No functional change.


# 1.98 01-Sep-2022 msaitoh

KNF. No functional change.


# 1.97 18-Aug-2022 msaitoh

Use NULL instead of 0.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.96 02-Feb-2020 thorpej

Update for per-cpu interface statistics.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728
# 1.95 11-Jul-2018 msaitoh

Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


Revision tags: netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.94 23-Feb-2017 ozaki-r

branches: 1.94.4; 1.94.10; 1.94.12;
Remove mkludge stuffs

For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

branches: 1.91.2;
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.98 01-Sep-2022 msaitoh

KNF. No functional change.


# 1.97 18-Aug-2022 msaitoh

Use NULL instead of 0.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.96 02-Feb-2020 thorpej

Update for per-cpu interface statistics.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728
# 1.95 11-Jul-2018 msaitoh

Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


Revision tags: netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.94 23-Feb-2017 ozaki-r

branches: 1.94.4; 1.94.10; 1.94.12;
Remove mkludge stuffs

For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

branches: 1.91.2;
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.97 18-Aug-2022 msaitoh

Use NULL instead of 0.


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base phil-wifi-20200421 phil-wifi-20200411 is-mlppp-base phil-wifi-20200406
# 1.96 02-Feb-2020 thorpej

Update for per-cpu interface statistics.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728
# 1.95 11-Jul-2018 msaitoh

Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


Revision tags: netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.94 23-Feb-2017 ozaki-r

branches: 1.94.4; 1.94.10; 1.94.12;
Remove mkludge stuffs

For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

branches: 1.91.2;
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.96 02-Feb-2020 thorpej

Update for per-cpu interface statistics.


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728
# 1.95 11-Jul-2018 msaitoh

Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


Revision tags: netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.94 23-Feb-2017 ozaki-r

branches: 1.94.4; 1.94.10; 1.94.12;
Remove mkludge stuffs

For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

branches: 1.91.2;
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 pgoyette-compat-0728
# 1.95 11-Jul-2018 msaitoh

Print iqdrops, too. This change also fixes a bug that Odrops prints
iqdrops when kvm read failed.


Revision tags: netbsd-8-0-RELEASE phil-wifi-base pgoyette-compat-0625 netbsd-8-0-RC2 pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 netbsd-8-0-RC1 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base matt-nb8-mediatek-base perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 pgoyette-localcount-20170320
# 1.94 23-Feb-2017 ozaki-r

branches: 1.94.4; 1.94.10;
Remove mkludge stuffs

For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

branches: 1.91.2;
Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.94 23-Feb-2017 ozaki-r

Remove mkludge stuffs

For unknown reasons, IPv6 multicast addresses are linked to a first
IPv6 address assigned to an interface. Due to the design, when removing
a first address having multicast addresses, we need to save them to
somewhere and later restore them once a new IPv6 address is activated.
mkludge stuffs support the operations.

This change links multicast addresses to an interface directly and
throws the kludge away.

Note that as usual some obsolete member variables remain for kvm(3)
users. And also sysctl net.inet6.multicast_kludge remains to avoid
breaking old ifmcstat.

TODO: currently ifnet has a list of in6_multi but obviously the list
should be protocol independent. Provide a common structure (if_multi
or something) to handle in6_multi and in_multi together as well as
ifaddr does for in_ifaddr and in6_ifaddr.


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.93 22-Jan-2017 mrg

re-do the previous to avoid malloc/free on the same size every iteration.

with this, or the previous, 'netstat -b 1' no longer leaks memory in
-current (or any older release using sysctl for this.)


# 1.92 22-Jan-2017 christos

sprinkle free


Revision tags: bouyer-socketcan-base
# 1.91 11-Jan-2017 ozaki-r

Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.91 11-Jan-2017 ozaki-r

Fix showing multicast addresses of !IFF_UP interfaces

netstat appends '*' to the name of an interface without IFF_UP, so
if_nametoindex which is used in mc_print fails. mc_print needs just
an interface index so pass it instead of a tweaked interface name.


Revision tags: pgoyette-localcount-20170107
# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

branches: 1.89.2;
more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied


# 1.90 24-Nov-2016 dholland

Fix "sidewaysintpr", the thing that prints interface statistics in a
loop, to use signals properly. There are two copies of this code; one
uses kvm and the other uses sysctls. One copy had been updated to use
sigset_t and sigsuspend; the other was using vintage sigpause(). Sync
up the code so both use sigpause. Also, use sig_atomic_t, and block
SIGALRM when not waiting for it to avoid a small and unlikely but real
race.

Since the non-modernized copy of the code *had* for some been
modernized to use setitimer instead of just alarm(), propagate that
change to the other copy.

These copies could share more logic than they do.


Revision tags: pgoyette-localcount-20161104 localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base
# 1.89 14-Jul-2016 christos

more XXX removal.


# 1.88 14-Jul-2016 christos

XXX: removal


# 1.87 14-Jul-2016 christos

remove __P


# 1.86 14-Jul-2016 christos

dedup


# 1.85 14-Jul-2016 christos

use sysctl to print multicast addresses


# 1.84 13-Jul-2016 christos

fix sysctl based interface printing, and annotate where we should add the
missing multicast printing code.


# 1.83 29-Feb-2016 christos

PR/50872: David Binderman: Use logical and instead of arithmetic


# 1.82 20-Sep-2015 mrg

query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.


# 1.81 07-Jan-2015 christos

adjust to the netname4 prototype.


# 1.80 06-Nov-2014 christos

use the common code from route.c


Revision tags: netbsd-7-base yamt-pagecache-base9 tls-earlyentropy-base riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 tls-maxphys-base
# 1.79 19-Oct-2013 christos

branches: 1.79.4;
use correct function and symbolic constants


# 1.78 19-Oct-2013 christos

use new scopeid functions


# 1.77 18-Oct-2013 christos

- avoid pointer gymnastics
- remove unused variables


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base agc-symver-base
# 1.76 01-Mar-2013 joerg

Retire OSI network stack. OK core@


Revision tags: yamt-pagecache-base8 yamt-pagecache-base7 yamt-pagecache-base6
# 1.75 19-Oct-2012 msaitoh

Line up total numbers again (for -b case and -X case).


Revision tags: yamt-pagecache-base5 yamt-pagecache-base4
# 1.74 20-Mar-2012 matt

branches: 1.74.2;
Use C89 function definitions


Revision tags: netbsd-6-0-6-RELEASE netbsd-6-0-5-RELEASE netbsd-6-0-4-RELEASE netbsd-6-0-3-RELEASE netbsd-6-0-2-RELEASE netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 netbsd-6-base
# 1.73 12-Feb-2012 christos

branches: 1.73.2;
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)


Revision tags: yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 1.72 16-Sep-2011 joerg

branches: 1.72.2;
Use __dead


Revision tags: cherry-xenmp-base bouyer-quota2-nbase bouyer-quota2-base
# 1.71 04-Feb-2011 martin

Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.


Revision tags: matt-mips64-premerge-20101231
# 1.70 13-Dec-2010 pooka

branches: 1.70.2;
Add netstat rump client. For now, it always sets -X, i.e. will
use only sysctl and no kvm (implementing /dev/mem for a rump kernel
would probably not be hard, but still a non-zero effort).

Note: since there is absolutely no network activity in a fresh rump
kernel, rump.netstat usually displays exactly nothing when invoked
without parameters. Arguments like -r, -bi, -p icmp etc. produce
more stuff.


# 1.69 09-Jul-2010 enami

Line up total numbers again.


# 1.68 24-Feb-2010 pooka

Add -h, which makes output of bytes counts "humanized" (e.g. -bih)

(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())


Revision tags: matt-premerge-20091211
# 1.67 27-Sep-2009 plunky

protecting sockaddr_in6 with -DINET6


# 1.66 13-Sep-2009 pgoyette

Use PRIu64 for printf'ing stuff. Fixes build breakage on part-amd64
introduced in rev 1.64 (and reverts a partial fix provided in rev 1.65)


# 1.65 13-Sep-2009 elad

Put some unsigned long long casts (as was in the original printing code).

Should fix build breakage noticed by pgoyette@ on current-users@:

http://mail-index.netbsd.org/current-users/2009/09/13/msg010554.html

(sorry, don't have an amd64 anymore!)


# 1.64 13-Sep-2009 elad

Checkin work in progress to make netstat use sysctl rather than kvm(3).

This commit mostly adds code written by Claudio Jeker for OpenBSD to
support sysctl in the interface printing parts (-i, -I, -w). The port has
been ported to NetBSD with tiny adjustments -- of course all bugs etc.
are mine.

Also add and document a -X flag to force sysctl usage. The documentation
notes this flag may be removed at any time and its presence should not be
relied on.

Some misc. comments/#ifdef changes/code snippet moves as well.

Please note that no functionality should change as the routing and
interface printing code is still not fully supported.

Mailing list reference:

http://mail-index.netbsd.org/tech-userlevel/2009/09/09/msg002604.html


Revision tags: jym-xensuspend-nbase jym-xensuspend-base
# 1.63 12-Apr-2009 lukem

Fix many WARNS=4 issues (-Wshadow -Wcast-qual -Wsign-compare).
Fix probable bug with numeric printing of anon ports when using sysctl.


Revision tags: netbsd-5-2-3-RELEASE netbsd-5-1-5-RELEASE netbsd-5-2-2-RELEASE netbsd-5-1-4-RELEASE netbsd-5-2-1-RELEASE netbsd-5-1-3-RELEASE netbsd-5-2-RELEASE netbsd-5-2-RC1 netbsd-5-1-2-RELEASE netbsd-5-1-1-RELEASE matt-nb5-mips64-premerge-20101231 matt-nb5-pq3-base netbsd-5-1-RELEASE netbsd-5-1-RC4 matt-nb5-mips64-k15 netbsd-5-1-RC3 netbsd-5-1-RC2 netbsd-5-1-RC1 netbsd-5-0-2-RELEASE matt-nb5-mips64-premerge-20091211 matt-nb5-mips64-u2-k2-k4-k7-k8-k9 matt-nb4-mips64-k7-u2a-k9b matt-nb5-mips64-u1-k1-k5 netbsd-5-0-1-RELEASE netbsd-5-0-RELEASE netbsd-5-0-RC4 netbsd-5-0-RC3 netbsd-5-0-RC2 netbsd-5-0-RC1 netbsd-5-base matt-mips64-base2 wrstuden-revivesa-base-3 wrstuden-revivesa-base-2 wrstuden-revivesa-base-1 yamt-pf42-base4 yamt-pf42-base3 hpcarm-cleanup-nbase yamt-pf42-base2 wrstuden-revivesa-base
# 1.62 23-Apr-2008 thorpej

branches: 1.62.8;
netns is no longer in the tree; completely purge it from netstat(1).


Revision tags: netbsd-4-0-1-RELEASE wrstuden-fixsa-newbase yamt-pf42-baseX yamt-pf42-base keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase matt-armv6-prevmlocking wrstuden-fixsa-base-1 netbsd-4-0-RELEASE cube-autoconf-base netbsd-4-0-RC5 netbsd-4-0-RC4 netbsd-4-0-RC3 netbsd-4-0-RC2 netbsd-4-0-RC1 matt-armv6-base matt-mips64-base hpcarm-cleanup-base wrstuden-fixsa-base netbsd-4-base
# 1.61 26-Aug-2006 matt

branches: 1.61.16;
Conditionalize XNS support. No longer enabled.


Revision tags: abandoned-netbsd-4-base chap-midi-nbase chap-midi-base
# 1.60 28-May-2006 elad

Make netstat use sysctl when dumping routing tables/stats.
Heavily based on similar code from Claudio Jeker (at OpenBSD).

While here, fix inet/inet6 sysctl stuff commited previously to
actually work, and some other nits to make netstat more sysctl
friendly.

One step closer to losing setgid kmem on this one...


# 1.59 04-Aug-2005 rpaulo

branches: 1.59.2;
Added #include <kvm.h> since netstat.h, which is included too, needs it.


Revision tags: netbsd-3-1-1-RELEASE netbsd-3-0-3-RELEASE netbsd-3-1-RELEASE netbsd-3-0-2-RELEASE netbsd-3-1-RC4 netbsd-3-1-RC3 netbsd-3-1-RC2 netbsd-3-1-RC1 netbsd-3-0-1-RELEASE netbsd-3-0-RELEASE netbsd-3-0-RC6 netbsd-3-0-RC5 netbsd-3-0-RC4 netbsd-3-0-RC3 netbsd-3-0-RC2 netbsd-3-0-RC1 netbsd-3-base
# 1.58 16-Nov-2004 itojun

NI_WITHSCOPEID was not picked up by IETF standardization process.


Revision tags: netbsd-2-0-3-RELEASE netbsd-2-1-RELEASE netbsd-2-1-RC6 netbsd-2-1-RC5 netbsd-2-1-RC4 netbsd-2-1-RC3 netbsd-2-1-RC2 netbsd-2-1-RC1 netbsd-2-0-2-RELEASE netbsd-2-0-1-RELEASE netbsd-2-base netbsd-2-0-RELEASE netbsd-2-0-RC5 netbsd-2-0-RC4 netbsd-2-0-RC3 netbsd-2-0-RC2 netbsd-2-0-RC1 netbsd-2-0-base
# 1.57 15-Nov-2003 ragge

Use itimerval() instead of alarm() for interval displaying. This increases
accuracy on interval stats also on fast machines.


# 1.56 19-Aug-2003 itojun

correct strange indentation


# 1.55 07-Aug-2003 agc

Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.


# 1.54 14-May-2003 itojun

use proper #ifdef to determine behavior (__KAME__)


# 1.53 15-Apr-2003 itojun

make char array bigger where it seems too small and may overrun.


Revision tags: fvdl_fs64_base
# 1.52 19-Jun-2002 itojun

use macro to determine link-local multicast addr


# 1.51 19-Jun-2002 itojun

identify kame scopeid hack with KAME_SCOPEID


# 1.50 08-Jun-2002 yamt

make an auto const variable static.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.49 06-Oct-2001 bjh21

Use getnameinfo() for printing link-layer addresses in netstat -i, rather
than doing it ourselves.


# 1.48 06-Apr-2001 itojun

pedant changes for strcpy/sprintf.


# 1.47 19-Feb-2001 cgd

convert to use getprogname()


# 1.46 14-Nov-2000 matt

Print out IEEE1394 addresses with : . Add a hack to limit the address
to 8 bytes.


# 1.45 11-Oct-2000 is

More format string cleanup by sommerfeld.


# 1.44 06-Jul-2000 itojun

more stats. from kame


# 1.43 03-Jul-2000 enami

Allocate one more byte for the asterisk after the name of interface.


# 1.42 03-Jul-2000 matt

Make gcc 2.96 (and maybe earlier) happier. Include <stdlib.h>,<string.>,
etc. as appropriate to get exit,srncmp,abs,abort,etc.
Add -I${.CURDIR} to a few Makefiles


# 1.41 02-Jul-2000 itojun

with -inv flag, do not truncate name of the interface (like "strip0").


Revision tags: netbsd-1-5-base minoura-xpg4dl-base
# 1.40 19-Apr-2000 enami

branches: 1.40.4;
Define members previously defined as u_long in struct iftot as u_quad_t.
Since these members are used to hold members defined now as u_quad_t
in struct if_data, u_long is quite not enough actually.
Without this, one night ttcp easily makes netstat to produce wrong output
like this:
enami@annex-2f-floor-244% netstat -ibw 1 -I tlp0
tlp0 in tlp0 out total in total out
bytes bytes bytes bytes
176333740607 176914940420 240082591 821282404
176093659136 176093659136 0 0
176093659136 176093659136 0 0


# 1.39 09-Feb-2000 itojun

use NI_WITHSCOPEID when printing multicast group with -inav.


# 1.38 05-Feb-2000 itojun

print IPv6 scopeid on -inv. with -in, scopeid is omitted due to insufficient
width.


# 1.37 25-Jan-2000 itojun

better sync with #ifdef notdef part (in -i for AF_INET).


# 1.36 25-Jan-2000 itojun

don't truncate IPv4 entries on -i (with -v). it is mainly for
"Network" column (13 digits, it will be 18 digits in maximum).


# 1.35 17-Jan-2000 itojun

print IPv6 multicast group on -ia (-iav will avoid truncation)


Revision tags: wrstuden-devbsize-19991221 wrstuden-devbsize-base
# 1.34 13-Dec-1999 itojun

per-interface statistics.
bring in and enable KAME scopeid hack.
lots of cleanups.
(sync with latest KAME)


# 1.33 19-Nov-1999 bouyer

Change printf formats for 64bit counters.


Revision tags: comdex-fall-1999-base
# 1.32 01-Jul-1999 itojun

branches: 1.32.4;
make netstat IPv6-ready.


Revision tags: netbsd-1-4-PATCH002 netbsd-1-4-PATCH001 netbsd-1-4-RELEASE netbsd-1-4-base
# 1.31 14-Mar-1999 mycroft

branches: 1.31.2;
Make the damned columns line up.


# 1.30 11-Jan-1999 mrg

#ifndef SMALL changes. saves 30k on the sparc


# 1.29 25-Aug-1998 ross

Add { and } to shut up egcs. Reformat the more questionable code.


# 1.28 12-Jul-1998 mrg

- KNF
- use err(3)
- sprintf/strcpy -> snprintf/strncpy
- change route.c:domask() to take a size_t of the buffer passed.


# 1.27 14-May-1998 kml

Partial fix for PR kern/5435 -- changed netstat to use unsigned counters
instead of signed. The rest of the fix will have to wait for 64-bit counters.


# 1.26 19-Mar-1998 kml

Add support for a '-b' option to provide byte counts in and out,
instead of just packet counts. On the byte screens, errors and
collisions are not shown, since they are more packet count related.


Revision tags: netbsd-1-3-PATCH003 netbsd-1-3-PATCH003-CANDIDATE2 netbsd-1-3-PATCH003-CANDIDATE1 netbsd-1-3-PATCH003-CANDIDATE0 netbsd-1-3-PATCH002 netbsd-1-3-PATCH001 netbsd-1-3-RELEASE netbsd-1-3-BETA netbsd-1-3-base
# 1.25 19-Oct-1997 lukem

branches: 1.25.2;
fix up .Nm usage, getopt returns -1 not EOF


Revision tags: SYN_cache_cur_base
# 1.24 22-May-1997 christos

branches: 1.24.2;
PR/3660: Dave Huang: Fix formatting misalignments in appletalk
PR/3659: Dave Huang: Fix PCB reporting in appletalk


# 1.23 07-Apr-1997 mikel

more column alignment fixes


# 1.22 07-Apr-1997 christos

PR/3451: Anders Hjalmarsson: Column alignment fixes after the netatalk addition.


# 1.21 03-Apr-1997 christos

- netatalk additions
- printf format fixes
- minor prototype cleanups


# 1.20 26-Mar-1997 thorpej

Print Ethernet and FDDI addresses in the same format as ether_ntoa().
From Matt Thomas <matt@3am-software.com>


# 1.19 07-Jun-1996 thorpej

Fix missing `)' in the sideways view of interfaces (i.e. netstat -w 1).
Bug pointed out by Chris G. Demetriou.


# 1.18 04-Jun-1996 cgd

bump MAXIF (the maximum number of interfaces for which information is kept,
for 'netstat -w <delay>') to 100, from 10. 10 was definitely not sufficient
for many hosts; 100 should be for most if not all. This code really should
dynamically allocate the information structures, based on the number of
interfaces in the kernel, account for interfaces that are added or removed,
etc., but given its current structure that would require substantial changes.


# 1.17 04-Jun-1996 cgd

if doing 'netstat -I <intf> -w <delay>', and netstat can't find an
interface of the given name, print an error message and exit.
This whole section of code needs to be re-thought, if interfaces
can be dynamically added or removed.


Revision tags: netbsd-1-2-base
# 1.16 07-May-1996 thorpej

branches: 1.16.4;
Kill a couple of unnecessary calls to strlen().


# 1.15 07-May-1996 thorpej

Update for the changes to struct ifnet. While I'm here, fix a couple
of long-standing bugs:

- Actually deal with the fact that the kernel ifnet list is
a TAILQ; it just happened to work before.

- Use kvm_openfiles() instead of kvm_open(). The code passed
arguments to kvm_open() as if it were kvm_openfiles(), but
apparently went unnoticed since the prototypes are the same.
Amusing bit: there were XXX's in the code which seemed to
apologize for a verbose libkvm, when it happened to be a
bug in netstat!


# 1.14 17-Oct-1995 jtc

Implement change done in revision 1.12 (for PR #1473 & duplicates) in a
slightly different way. This widens the Address field instead of the
Ipkts field because Address is the one that may be too big.


Revision tags: netbsd-1-1-PATCH001 netbsd-1-1-RELEASE netbsd-1-1-base
# 1.13 03-Oct-1995 thorpej

New-style RCS ids.


# 1.12 28-Sep-1995 jtc

Change formatting so that columns line up; PR #1473 + several duplicates


# 1.11 03-Jul-1995 mycroft

Remove an extra htonl().


# 1.10 12-Jun-1995 mycroft

Update to match kernel changes.


# 1.9 17-Sep-1994 mycroft

Align link address under `Address' header.


Revision tags: netbsd-1-0-PATCH06 netbsd-1-0-PATCH05 netbsd-1-0-PATCH04 netbsd-1-0-PATCH03 netbsd-1-0-PATCH02 netbsd-1-0-PATCH1 netbsd-1-0-PATCH0 netbsd-1-0-RELEASE netbsd-1-0-base
# 1.8 13-May-1994 mycroft

Clean up import.


# 1.7 01-Apr-1994 cgd

kill lots of off_t's.


# 1.6 28-Mar-1994 cgd

clean up, for off_t... ugliest 'cleaning' possible, i think...


# 1.5 03-Mar-1994 deraadt

netname() takes a struct in_addr, not an int. Breaks on sparc.
fix from Chuck Cranor <chuck@maria.wustl.edu>


# 1.4 22-Feb-1994 cgd

fix to print netstat unit number right; from Greenman


# 1.3 01-Aug-1993 mycroft

Add RCS identifiers.


Revision tags: netbsd-0-9-RELEASE netbsd-0-9-BETA netbsd-0-9-ALPHA2 netbsd-0-9-ALPHA netbsd-0-9-base
# 1.2 11-Jul-1993 paul

Included Havard Eidnes' latest changes.


Revision tags: netbsd-0-8 netbsd-alpha-1 patchkit-0-2-2
# 1.1 21-Mar-1993 cgd

branches: 1.1.1;
after 0.2.2 "stable" patches applied