History log of /freebsd-head/usr.bin/netstat/if.c
Revision Date Author Comments
872b698bd4a1bfc0bf008c09228e6fd238809c75 20-Nov-2017 pfg <pfg@FreeBSD.org> General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
7e6cabd06e6caa6a02eeb86308dc0cb3f27e10da 28-Feb-2017 imp <imp@FreeBSD.org> Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96
1b12c4f0adbb7641116ff77a2a7eb4fb00abf1bc 05-Jan-2017 delphij <delphij@FreeBSD.org> Use strlcpy and snprintf in netstat(1).

Expand inet6name() line buffer to NI_MAXHOST and use strlcpy/snprintf
in various places.

Reported by: Anton Yuzhaninov <citrin citrin ru>
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D8916
00d578928eca75be320b36d37543a7e2a4f9fbdb 27-May-2016 grehan <grehan@FreeBSD.org> Create branch for bhyve graphics import.
513e9b690f5bb0abdec4b77b4ab0de8385608740 07-Jan-2016 markj <markj@FreeBSD.org> MFC r287649:
Use a common subroutine to fetch and zero protocol stats instead of
duplicating roughly similar code for each protocol.
9aec66905fd79577d0e13907c4aff0a92b0e8b27 20-Nov-2015 ume <ume@FreeBSD.org> MFC r290367, r290370, r290437:

Change to not truncate an interface name when -W option
is specified.

MFC Requested by: Jim Thompson <jim__at__netgate.com>
4abd0209099ccb065b3524684fc1980b04060b7a 20-Nov-2015 ume <ume@FreeBSD.org> Avoid core dump when output style is html.
16f234bfccac9b4f00a3b2576b63dd068bae1e07 17-Nov-2015 ume <ume@FreeBSD.org> JSON doesn't permit a hexadecimal notation of an integer.
69eae64be28712d61cd4229c47f3c0b7c5318786 06-Nov-2015 ume <ume@FreeBSD.org> Do not truncate addresses when printing in encoded format.
da474a11ae38947c9477277315e71a990bda7c3f 06-Nov-2015 ume <ume@FreeBSD.org> - Fix alignment for padding link address.
- Trim whitespace of link address.
f256f350a9f1d7dcfc8f1b807f4593d9214e0013 06-Nov-2015 ngie <ngie@FreeBSD.org> Fix compiling netstat after r290367 by substituting sys/types.h for
sys/param.h, as sys/param.h defines the MAX(..) macro

Reported by: O. Hartmann <ohartman@zedat.fu-berlin.de>
Pointyhat to: ume
9614edb1e1641235b9e6a493e7b56a5c07bc0165 05-Nov-2015 ume <ume@FreeBSD.org> Give enough room for addresses when -W option is specified.
e165e91db74d24cac3c6f21533292e0bb43d73c8 05-Nov-2015 ume <ume@FreeBSD.org> Fix alignment of `Drop' header.
6b8c1fe2431e303e1161442700dee3d9f958d47d 04-Nov-2015 ume <ume@FreeBSD.org> Fix alignment of AF_LINK address.
bad3c35c8dd3e3bba0ca4848d8bfc41f745413ca 04-Nov-2015 ume <ume@FreeBSD.org> Simplify r290367 using asterisk for a field width
and precision.
14dab036a27856908c468f4d93bae22a3ca304a4 04-Nov-2015 ume <ume@FreeBSD.org> Unify AF_INET case and AF_INET6 case.
363ca1b6f12cba99d2d63ee8d5e22e0376164e02 04-Nov-2015 ume <ume@FreeBSD.org> Change to not truncate an interface name when -W option
is specified.
b4086eb5b8194473cbf0d5bdbc3c4effd3c166c4 04-Nov-2015 ume <ume@FreeBSD.org> Restore an interface name field to left align.
65d9a559eb7b19c7541531c4e8891e6d45b00ff2 11-Sep-2015 markj <markj@FreeBSD.org> Use a common subroutine to fetch and zero protocol stats instead of
duplicating roughly similar code for each protocol.

MFC after: 2 weeks
c02639b79471c7dcfd8094a16aff3ef9975fd6f8 09-Sep-2015 hrs <hrs@FreeBSD.org> MFC r287406:

Divide statistics in the number of packets with 1000 instead of 1024
in human-readable form.

PR: 183598
2d45fb7584109113be7fd7da0121791625264acc 02-Sep-2015 hrs <hrs@FreeBSD.org> Divide statistics in the number of packets with 1000 instead of 1024
in human-readable form.

PR: 183598
df2a89db2bc25e73b139f02c6fbe0095a4168253 01-Sep-2015 hrs <hrs@FreeBSD.org> - Add -W flag support for network column in intpr() (-i flag) and
routepr() (-r flag). It is too narrow to show an IPv6 prefix
in most cases.

- Accept "local" as a synonym of "unix" in protocol family name.

- Show a prefix length in CIDR notation when name resolution failed in

- Make routename() and netname() AF-independent and remove
unnecessary typecasting from struct sockaddr.

- Use getnameinfo(3) to format L2 addr in intpr().

- Fix a bug which showed "Address" when -A flag is specfied in pr_rthdr().

- Replace cryptic GETSA() macro with SA_SIZE().

- Fix declarations shadowing local variables with the same names.

- Add more static, remove unused header files and variables.

MFC after: 1 week
f9e194c4522d1ea9c0d6fc67545673fcc09afeb7 06-May-2015 glebius <glebius@FreeBSD.org> Printing interface names:

o Restore historical behaviour of appending '*' if interface is down,
and we have enough space to print it (usually we don't). [1]
o Do not truncate interface names when printing in encoded format.
o Report interface flags into encoded format.

PR: 199873 [1]
Sponsored by: Nginx, Inc.
78d51c7b15fc92383c6c68b46966248bdaf2bf1a 06-Apr-2015 glebius <glebius@FreeBSD.org> Stop including if_var.h from userland.

Sponsored by: Nginx, Inc.
7a87033ac98b808df19eb3ff0da8a9b49cfadf67 04-Mar-2015 marcel <marcel@FreeBSD.org> Fix typo in dropped-packets attribute (missing s).

Pointed-out by: allanjude (excellent catch!)
03eeeb2651118370f5b3b824c5d9bd36b37ef233 25-Feb-2015 marcel <marcel@FreeBSD.org> Fix "netstat -hdw 1" output.

Reported by: np@
0ea1b83e3703e39c50804c558e396324cec66c74 21-Feb-2015 marcel <marcel@FreeBSD.org> Convert netstat to use libxo.

Obtained from: Phil Shafer <phil@juniper.net>
Ported to -current by: alfred@ (mostly), Kim Shrier
Formatting: marcel@
Sponsored by: Juniper Networks, Inc.
1e3b3008927ebb2708c3f6a87ba9f302ad3c0c66 03-Apr-2014 glebius <glebius@FreeBSD.org> o Provide a compatibility shim for netstat(1) to obtain output queue
drops via NET_RT_IFLISTL sysctl. The sysctl handler appends oqdrops
at the end of struct if_msghdrl, and netstat(1) sees that as an
additional field of struct if_data. This allows us to fetch the data
keeping ABI and API compatibility.
This is direct commit to stable/10.

o Merge r263331 from head, to restore printing of queue drops.

Sponsored by: Nginx, Inc.
Sponsored by: Netflix
78bde6490528c198cd485385ecb997b6031f1bdb 19-Mar-2014 glebius <glebius@FreeBSD.org> Merge r259562,r259566,r259638,r259645,r260124 by melifaro:

Switch netstat -rn to use standard API for retrieving list
of routes instead of peeking inside in-kernel radix via kget.
1bb14616e9ab64d01f1ab514361a82e686a0e293 19-Mar-2014 glebius <glebius@FreeBSD.org> Now, after r263102 we have ifi_oqdrops in if_data, restore printing of
output queue drops in netstat(1).

No driver, neither kernel fills this field in if_data, yet.

Sponsored by: Netflix
Sponsored by: Nginx, Inc.
80e85e32a582ff3a03a87cb98dd996b7929f824b 14-Mar-2014 glebius <glebius@FreeBSD.org> Remove AppleTalk support.

AppleTalk was a network transport protocol for Apple Macintosh devices
in 80s and then 90s. Starting with Mac OS X in 2000 the AppleTalk was
a legacy protocol and primary networking protocol is TCP/IP. The last
Mac OS X release to support AppleTalk happened in 2009. The same year
routing equipment vendors (namely Cisco) end their support.

Thus, AppleTalk won't be supported in FreeBSD 11.0-RELEASE.
d494babace1c51efd0d2c4582515a1e1ae5fa9d2 14-Mar-2014 glebius <glebius@FreeBSD.org> Remove IPX support.

IPX was a network transport protocol in Novell's NetWare network operating
system from late 80s and then 90s. The NetWare itself switched to TCP/IP
as default transport in 1998. Later, in this century the Novell Open
Enterprise Server became successor of Novell NetWare. The last release
that claimed to still support IPX was OES 2 in 2007. Routing equipment
vendors (e.g. Cisco) discontinued support for IPX in 2011.

Thus, IPX won't be supported in FreeBSD 11.0-RELEASE.
b38edcd355dfe9c2ac4080b8837687b0dba7dd41 13-Mar-2014 glebius <glebius@FreeBSD.org> Since 32-bit if_baudrate isn't enough to describe a baud rate of a 10 Gbit
interface, in the r241616 a crutch was provided. It didn't work well, and
finally we decided that it is time to break ABI and simply make if_baudrate
a 64-bit value. Meanwhile, the entire struct if_data was reviewed.

o Remove the if_baudrate_pf crutch.

o Make all fields of struct if_data fixed machine independent size. The
notion of data (packet counters, etc) are by no means MD. And it is a
bug that on amd64 we've got a 64-bit counters, while on i386 32-bit,
which at modern speeds overflow within a second.

This also removes quite a lot of COMPAT_FREEBSD32 code.

o Give 16 bit for the ifi_datalen field. This field was provided to
make future changes to if_data less ABI breaking. Unfortunately the
8 bit size of it had effectively limited sizeof if_data to 256 bytes.

o Give 32 bits to ifi_mtu and ifi_metric.
o Give 64 bits to the rest of fields, since they are counters.

__FreeBSD_version bumped.

Discussed with: emax
Sponsored by: Netflix
Sponsored by: Nginx, Inc.
f937dcf2bd0584087acec5d8dc92dd5dba177113 12-Mar-2014 glebius <glebius@FreeBSD.org> Bulk sync of pf changes from head, in attempt to fixup broken build I
made in r263029.

Merge r257186,257215,257349,259736,261797.

These changesets split pfvar.h into several smaller headers and make
userland utilities to include only some of them.
eb1a5f8de9f7ea602c373a710f531abbf81141c4 21-Feb-2014 gjb <gjb@FreeBSD.org> Move ^/user/gjb/hacking/release-embedded up one directory, and remove
^/user/gjb/hacking since this is likely to be merged to head/ soon.

Sponsored by: The FreeBSD Foundation
c3a529c9ca25ce9bf60844fd55d7668812f638e4 27-Jan-2014 glebius <glebius@FreeBSD.org> Merged /head:r256510,256512,257376,257469,260052:

Make 'netstat -i' use getifaddrs(3) instead of kvm(3).
a79cb7b61f19d57c813e122eb30b5f0868741de1 29-Dec-2013 glebius <glebius@FreeBSD.org> Claim copyright since I've almost rewritten this file in r256512.
6b01bbf146ab195243a8e7d43bb11f8835c76af8 27-Dec-2013 gjb <gjb@FreeBSD.org> Copy head@r259933 -> user/gjb/hacking/release-embedded for initial
inclusion of (at least) arm builds with the release.

Sponsored by: The FreeBSD Foundation
8bd5f6c17c9114783f5e62ffeb7b2dac564d3a30 20-Dec-2013 melifaro <melifaro@FreeBSD.org> Use more fine-grained kvm(3) symbol lookup: routing code retrieves only
necessary symbols needed per subsystem. Main kvm(3) init is now delayed
as much as possbile. This finally fixes performance issues reported in
Some non-working code (ng_socket.ko symbol addresses calculation) removed.
Some global variables eliminated.

PR: kern/167204
MFC after: 4 weeks
b0bc7b1d54670db8d6c891ef9a5c1cda849a2fac 29-Oct-2013 glebius <glebius@FreeBSD.org> Make userland tools honor WITHOUT_PF build option.

Tested by: dt71@gmx.com
4abf8ebc710cee8231b65b3b909809fd612465bb 15-Oct-2013 glebius <glebius@FreeBSD.org> Rewrite netstat/if.c to use getifaddrs(3) and getifmaddrs(3) instead of
libkvm digging in kernel memory. This is possible since r231506 made
getifaddrs(3) to supply if_data for each ifaddr.

The pros of this change is that now netstat(1) doesn't know about kernel
struct ifnet and struct ifaddr. And these structs are about to change
significantly in head soon. New netstat binary will work well with 10.0
and any future kernel.

The cons is that now it isn't possible to obtain interface statistics
from a vmcore.

Functions intpr() and sidewaysintpr() were rewritten from scratch.

The output of netstat(1) has underwent the following changes:

1) The MTU is not printed for protocol addresses, since it has no notion.
Dash is printed instead. If there would be a strong desire to return
previous output, it is doable.
2) Output interface queue drops are not printed. Currently this data isn't
available to userland via any API. We plan to drop 'struct ifqueue' from
'struct ifnet' very soon, so old kvm(3) access to queue drops is soon
to be broken, too. The plan is that drivers would handle their queues
theirselves and a new field in if_data would be updated in case of drops.
3) In-kernel reference count for multicast addresses isn't printed. I doubt
that anyone used it. Anyway, netstat(1) is sysadmin tool, not kernel

Sponsored by: Netflix
Sponsored by: Nginx, Inc.
5190d38ee392f405f48ee4edd4912dbe48d19953 08-Sep-2012 glebius <glebius@FreeBSD.org> Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:

o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.

New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.

Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:

r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.

I'd like to thank people who participated in early testing:

Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
a729154742743bcfc10aa0b4ad6bd2950a549442 06-Apr-2012 attilio <attilio@FreeBSD.org> MFC
9c9bd90f632e127fc233408c11d58e8f1686f05f 04-Apr-2012 glebius <glebius@FreeBSD.org> With pf 4.5 import the name of pfsync stats sysctl has changed, thus
'netstat -sp pfsync' got broken. Fix this.
988368040652cc2c1de4ae3b058ed129dd6a671e 10-Jan-2012 eadler <eadler@FreeBSD.org> Fix warning when compiling with gcc46:
error: variable 'ifnetfound' set but not used

Approved by: dim
MFC after: 3 days
e7e5b53bf16ab3b35646f0580b36fa7d7afa9678 03-Jan-2012 ed <ed@FreeBSD.org> Replace index() and rindex() calls with strchr() and strrchr().

The index() and rindex() functions were marked LEGACY in the 2001
revision of POSIX and were subsequently removed from the 2008 revision.
The strchr() and strrchr() functions are part of the C standard.

This makes the source code a lot more consistent, as most of these C
files also call into other str*() routines. In fact, about a dozen
already perform strchr() calls.
ab8d20947c9e5b5e7ec0aa95ccf8f2a23f0cbaec 12-Jul-2011 tuexen <tuexen@FreeBSD.org> Truncate link addresses like it is done for any
other address type.

MFC after: 4 weeks
95417d69062ea9181cd7b53a2910a7ec94edc83b 20-Jan-2011 ume <ume@FreeBSD.org> - Hide the internal scope address representation of the KAME IPv6
stack from the output of `netstat -ani'.
- The node-local multicast address in the output of `netstat -rn'
should be handled as well.

Spotted by: Bernd Walter <ticso__at__cicely7.cicely.de>
29af67e52c02dc751039a3117bc88ae6192e891e 11-Dec-2010 joel <joel@FreeBSD.org> Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with: imp, rwatson
562d278523a62b2568bd70c090839f79db28f06c 18-Nov-2010 rstone <rstone@FreeBSD.org> When netstat was run with -i/-I and -w1 to produce running counters, the idrop
field printed an absolute value rather than the delta from the last value

Approved by: emaste (mentor)
MFC after: 1 week
09f9c897d33c41618ada06fbbcf1a9b3812dee53 19-Oct-2010 jamie <jamie@FreeBSD.org> A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.
fc51f07699c12d18c3f565bd7da9ff7eeda0ecde 15-Jul-2010 emaste <emaste@FreeBSD.org> Remove more extraneous ;s.
f1216d1f0ade038907195fc114b7e630623b402c 19-Mar-2010 delphij <delphij@FreeBSD.org> Create a custom branch where I will be able to do the merge.
56c6dfba43330adcd014d353900bc76289b651d9 10-Feb-2010 delphij <delphij@FreeBSD.org> MFC r202060:

Add a new option, -q howmany, which when used in conjuction with -w,
exits netstat after _howmany_ outputs.

Requested by: thomasa
Reviewed by: freebsd-net (bms, old version in early 2007)
689b6abf98d8f9ae31541c526ff14fc4fda4b89a 11-Jan-2010 delphij <delphij@FreeBSD.org> Add a new option, -q howmany, which when used in conjuction with -w,
exits netstat after _howmany_ outputs.

Requested by: thomasa
Reviewed by: freebsd-net (bms, old version in early 2007)
MFC after: 1 month
97dd2a321957e1693bfb166be4be99bd39ae7e29 19-Dec-2009 attilio <attilio@FreeBSD.org> MFC r199803:
Add the possibility to show informations about dropped packets on the
input path when showing interfaces informations.

Sponsored by: Sandvine Incorporated
0842b7d53ffede64468e775f5c79965e3d9e48ae 13-Dec-2009 delphij <delphij@FreeBSD.org> Revert most part of 200420 as requested, as more review and polish is
b963db4652a0bf1718825e8e1a9bc93e87b7a80f 11-Dec-2009 delphij <delphij@FreeBSD.org> Remove unneeded header includes from usr.bin/ except contributed code.

Tested with: make universe
3595d5cfed7d9eaa4ef3c6d382c4564a6df138f2 01-Dec-2009 bz <bz@FreeBSD.org> Unbreak user space after if_timer/if_watchdog removal in r199975.

Tested by: glebius
c984dc56360945b3348330530b2cec41b26e99e5 25-Nov-2009 attilio <attilio@FreeBSD.org> Add the possibility to show informations about dropped packets on the
input path when showing informations about the interfaces.

Obtained from: Sandvine Incorporated
Reviewed by: emaste
Sponsored by: Sandvine Incorporated
MFC: 2 weeks
19b6af98ec71398e77874582eb84ec5310c7156f 22-Nov-2008 dfr <dfr@FreeBSD.org> Clone Kip's Xen on stable/6 tree so that I can work on improving FreeBSD/amd64
performance in Xen's HVM mode.
cf5320822f93810742e3d4a1ac8202db8482e633 19-Oct-2008 lulf <lulf@FreeBSD.org> - Import the HEAD csup code which is the basis for the cvsmode work.
4e4c1baf05facc6b498b90fd6adbd3a8e2c1444a 16-Mar-2008 obrien <obrien@FreeBSD.org> MFC: style(9)
74070565806ee33326b76dcdd5e1e0a86cd4e6ed 02-Jan-2008 obrien <obrien@FreeBSD.org> style(9)
+ kread is not a boolean, so check it as such
+ fix $FreeBSD$ Ids
+ denote copyrights with /*-
+ misc whitespace changes.
44ff2749c081059ba6487d842a736b022cce05bb 23-Jul-2007 jhb <jhb@FreeBSD.org> MFC: Restore netstat -M functionality for most statistics on core dumps.
One change in this patch relative to the changes in HEAD is that the
mroute statistics will still fallback to using libkvm on live kernels
if the sysctl fails.
27187e7f6bd04a94e9ada0ca994e7c828abb4514 16-Jul-2007 jhb <jhb@FreeBSD.org> Restore netstat -M functionality for most statistics on core dumps. In
general, when support was added to netstat for fetching data using sysctl,
no provision was left for fetching equivalent data from a core dump, and
in fact, netstat would _always_ fetch data from the live kernel using
sysctl even when -M was specified resulting in the user believing they
were getting data from coredumps when they actually weren't. Some specific
- Add a global 'live' variable that is true if netstat is running against
the live kernel and false if -M has been specified.
- Stop abusing the sysctl flag in the protocol tables to hold the protocol
number. Instead, the protocol is now its own field in the tables, and
it is passed as a separate parameter to the PCB and stat routines rather
than overloading the KVM offset parameter.
- Don't run PCB or stats functions who don't have a namelist offset if we
are being run against a crash dump (!live).
- For the inet and unix PCB routines, we generate the same buffer from KVM
that the sysctl usually generates complete with the header and trailer.
- Don't run bpf stats for !live (before it would just silently always run
- kread() no longer trashes memory when opening the buffer if there is an
error on open and the passed in buffer is smaller than _POSIX2_LINE_MAX.
- The multicast routing code doesn't fallback to kvm on live kernels if
the sysctl fails. Keeping this made the code rather hairy, and netstat
is already tied to the kernel ABI anyway (even when using sysctl's since
things like xinpcb contain an inpcb) so any kernels this is run against
that have the multicast routing stuff should have the sysctls.
- Don't try to dig around in the kernel linker in the netgraph PCB routine
for core dumps.

Other notes:
- sctp's PCB routine only works on live kernels, it looked rather
complicated to generate all the same stuff via KVM. Someone can always
add it later if desired though.
- Fix the ipsec removal bug where N_xxx for IPSEC stats weren't renumbered.
- Use sysctlbyname() everywhere rather than hardcoded mib values.

MFC after: 1 week
Approved by: re (rwatson)
2c1a6137955d58c467aca41a4d796ee6b0fb959d 14-Jun-2007 bde <bde@FreeBSD.org> MFC: all except 1.63:

1.59-1.62: already merged
1.63: removal of bridge(45) not merged
1.64: already merged
1.65: use uintmax_t
1.66: repair formatting to 79 columns
1.67: increase accuracy of timeouts and thus of per-interval counts
1.68: style fixes

Requested by: kuriyama (1.66)

1.66 changes the whitespace in output. Hopefully nothing depends on the
exact misformatting that it fixes.
a94865a5ece16616f8b180b20917c4761c44304b 27-Feb-2007 bde <bde@FreeBSD.org> Fixed some style bugs (whitespace lossage for removal of __P(()), and
lots of naming and typing errors involving `interval').
3ee0d09a443f80fc57dc791114562e66b6856c71 27-Feb-2007 bde <bde@FreeBSD.org> Use a periodic itimer instead of repeated calls to alarm() in
sidewaysintpr(). This increases the accuracy of the per-interval
counts when they are interpreted as rates. Repeated calls to alarm(n)
give an average interval that is about 2 ticks larger than n and has
a large variance. Periodic itimers normally get the average almost
right but have similarly large variance (due to scheduling delays).

Statistics utilities should use clock_gettime() to determine the
actual interval, but it is still useful to maximize the accuracy of
the interval, especially for cases like netstat -w where counts are
displayed so the program cannot hide the inaccuracy in a rate
4df7030ad9c69297e92f40c19afc512a2c7da06e 08-Nov-2006 bde <bde@FreeBSD.org> Don't always print a space character in show_stat(), since a space
shouldn't be printed after the last column. This restores the
formatting to 79 columns.
e1db503689ae54aa3513f73b6e1aa4212ded2641 28-Jul-2006 yar <yar@FreeBSD.org> Achieve WARNS=2 by using uintmax_t to pass around 64-bit quantities,
including to printf(). Using uintmax_t is also robust to further
extensions in both the C language and the bitwidth of kernel counters.

Tested on: i386 amd64 ia64
583f9a601af4d5e2e3e43e4d285e417d9812e61f 16-Nov-2005 ru <ru@FreeBSD.org> MFC: 1.64: Align output.
d86b86314820730112b76b436b1405a1b7a5b76d 09-Nov-2005 ru <ru@FreeBSD.org> Align output.
7b38b603f582e20f00162b3c9bdd7c6d67b093da 09-Nov-2005 glebius <glebius@FreeBSD.org> MFC 1.61 by ru:
Bail if interface is misspelled instead of falling out into the
"all interfaces" mode. (Only works with -w, but still better
than nothing.)
ebe24453ed6134b981c9d7a7f7887b13a52bb647 29-Sep-2005 glebius <glebius@FreeBSD.org> MFC 1.62:
- Print space character in show_stat(). Remove a lot of priuntf(" ").
- Utilize show_stat() in sidewaysintpr() loop. This makes periodic
statistics to honor -h flag.

Approved by: re (kensmith)
a42af632d87879621ea936244e0eb8a934e9054c 27-Sep-2005 mlaier <mlaier@FreeBSD.org> Remove bridge(4) from the tree. if_bridge(4) is a full functional
replacement and has additional features which make it superior.

Discussed on: -arch
Reviewed by: thompsa
X-MFC-after: never (RELENG_6 as transition period)
00692854b3e507a9895b6ecd784bcb0ef9180566 27-Sep-2005 glebius <glebius@FreeBSD.org> - Print space character in show_stat(). Remove a lot of priuntf(" ").
- Utilize show_stat() in sidewaysintpr() loop. This makes periodic
statistics to honor -h flag.
c569eb998b369eb62cdf46006ed3ff4dcc23b32b 20-Aug-2005 ru <ru@FreeBSD.org> Bail if interface is misspelled instead of falling out into the
"all interfaces" mode. (Only works with -w, but still better
than nothing.)
d4bfa24b972d70f5fe0c7571484b9b57568cf229 19-Aug-2005 glebius <glebius@FreeBSD.org> MFC:
Add a new switch -h for interface stats mode, which prints all interface
statistics in human readable form.

In collaboration with: vsevolod
Reviewed by: cperciva

Approved by: re (kensmith)
cf4f3e357511611027fdf884b61a81c71608775f 18-Aug-2005 glebius <glebius@FreeBSD.org> Add a new switch -h for interface stats mode, which prints all interface
statistics in human readable form.

In collaboration with: vsevolod
Reviewed by: cperciva
6b5cea57ef66a5fc8ebeca58f433178c83f8d72d 23-Jul-2005 mlaier <mlaier@FreeBSD.org> MFC: -sp pfsync

Print newly exported pfsync statistics with netstat(8).

Requested by: glebius

Approved by: re (kensmith)
c224d596cf8de5c957244e362536d42d21579fa4 14-Jul-2005 mlaier <mlaier@FreeBSD.org> Print newly exported pfsync statistics with netstat(8).

Requested by: glebius
MFC after: 1 week
cd48a1d32b7e37d716e9ca0da9ba773994c976b3 26-Jul-2004 charnier <charnier@FreeBSD.org> Add __FBSDID. Replace local variable sin by sockin to not conflict with sin(3).
Use warnx() instead of warn() when error message is not of any interest. Add
4998d56908acfa474baafa8e5238f77cc0c6b0bf 12-Apr-2004 ru <ru@FreeBSD.org> Show link-level multicast packet counters with the -a option.
4db6a5ba580465ff6f49acb7b7d1e384272efb01 12-Apr-2004 ru <ru@FreeBSD.org> Fixed alignment of multicast addresses when printing that got
broken in previous revision.
a36a8ab06d69627279afdd6cb31c3c2e69f77c5a 28-Nov-2003 bms <bms@FreeBSD.org> Fix some minor nits in netstat whereby large interface names would be
truncated. In environments where many tunnel or vlan interfaces are created,
interface names have high numbers which overflow the field width.

PRs: bin/52349, bin/35838
Submitted by: Mike Tancsa, Scot W. Hetzel
Approved by: re (rwatson)
f1e94c6f29b079e4ad9d9305ef3e90a719bcbbda 31-Oct-2003 brooks <brooks@FreeBSD.org> Replace the if_name and if_unit members of struct ifnet with new members
if_xname, if_dname, and if_dunit. if_xname is the name of the interface
and if_dname/unit are the driver name and instance.

This change paves the way for interface renaming and enhanced pseudo
device creation and configuration symantics.

Approved By: re (in principle)
Reviewed By: njl, imp
Tested On: i386, amd64, sparc64
Obtained From: NetBSD (if_xname)
6467f119a1ad62ff9f05c304ee003b4e44b53f66 05-Mar-2003 peter <peter@FreeBSD.org> Kill #ifdef NS and some leftover #ifdef ISO code. Re-pack the nlist[]
array, it isn't likely to find any ARPAnet IMP drivers in FreeBSD.
1932d78f6cce8e4990f0cfb18def3e391327a72e 10-Feb-2003 robert <robert@FreeBSD.org> - Determine the size of buffers with sizeof() instead of using
plain magic numbers - one of them was apparently wrong but unharmful.
- Remove empty line.
cb4604919fc3c4fef1de7daff27468d6c5fbd56d 05-Sep-2002 dwmalone <dwmalone@FreeBSD.org> Warns cleanups for netstat:
1) Include arpa/inet.h for ntohs.
2) Constness fixes.
3) Fix shadowing except for "sin" which shouldn't be in scope.
4) Remove register keyword.
5) Add missing initialsers to user defined structs.
5) Make prototype of netname6 globally visable.
6) Use right macros for printing syncache stats (even though entrie isn't
a word).
0f588b93731c0d826bbc0590f928f38702d4bd77 28-Apr-2002 markm <markm@FreeBSD.org> fix warnings; change variable/argument names that mask global names.
cc2750c4a1cda635c2e61ed70326526ab0f0b69b 19-Oct-2001 mdodd <mdodd@FreeBSD.org> Print statistics for AF_IPX.
Note that the IPX code doesn't update these correctly yet, but should.
08ebd59071666c947a81c9e1f7733756f6714d51 09-Oct-2001 ru <ru@FreeBSD.org> The previous change also disaligned lines with AF_IPX and AF_NS
addresses. Unshrink "Network" width to the previous value, and
make sure everything is aligned again.
40ada64ef51dce61469fb22f3381bf251cf0971d 09-Oct-2001 mdodd <mdodd@FreeBSD.org> Minor output formatting for 'netstat -i':
- Right align Mtu
- Print AF_INET family with correct field width.
a955db2e6b8ec6194b1bf6f2fb937500c05aea10 11-Sep-2001 ru <ru@FreeBSD.org> Implement the ``-f address_family'' filter for -i.

Prodded by: Igor Podlesny <poige@morning.ru>
f5fc9b53400a054604623dad4c679865150873d4 15-Jun-2001 assar <assar@FreeBSD.org> remove warnings
remove superfluous declarations
make things more consistent
ee746c97f9f42b279e24583560b4f0eaef1e081b 15-Jun-2001 assar <assar@FreeBSD.org> remove K&R support
6c0b683445bcb0c4262928ed96c5600046fd89c4 15-Jun-2001 assar <assar@FreeBSD.org> revert removal of warning and K&R support

Requested by: bde
67653866aa83c06cbc92828ae2988bbeea1e776d 15-Jun-2001 ru <ru@FreeBSD.org> First round of netstat(1) cleanup.

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

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

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

Some examples:

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

This is a work in progress. Manpage has been fixed slightly,
but is still incomplete.
9e34fe7efd02802c8741141cf670713ba1ade2e5 15-Jun-2001 assar <assar@FreeBSD.org> remove most of the warnings
2947d98f456fae1bdd98b4465a8bb3c7e5a0e83d 26-Apr-2001 fenner <fenner@FreeBSD.org> Add missing break when printing IPv6 multicast addresses.
Use the sockaddr_dl sdl_type, not ifnet.if_type, to decide what type
a multicast sockaddr_dl is.
117d0220172695939c81f5daccce72d9c953e804 30-Mar-2001 phk <phk@FreeBSD.org> Don't core dump when given "-i -a". Problem caused by a mistaken
dereference of a kernel-pointer in userland.

PR: 26168
Submitted by: Peter Pentchev <roam@orbitel.bg>
076296e962b18db5f4e4606f3a0448817a6d3c53 04-Mar-2001 joe <joe@FreeBSD.org> When displaying interface statistics with -i show a '-' for any
values that aren't updated for a particular network-layer address.
d214ae21714540c7d954bd861ed084fb157abeb9 06-Feb-2001 phk <phk@FreeBSD.org> Convert if_multiaddrs from LIST to TAILQ so that it can be traversed
backwards in the three drivers which want to do that.

Reviewed by: mikeh
4ea1588b37cbd62c1c2af3dfbd4c731cde0ea954 30-Dec-2000 phk <phk@FreeBSD.org> Use macro API to <sys/queue.h>

Submitted by: "Jason" <jsmethers@pdq.net>
Reviewed by: phk
4c8593424da973794cbb6b416c87a0314c30339e 30-Oct-2000 guido <guido@FreeBSD.org> Now that the amount of (pseudo) interfaces is growing with IPv6,
get rid of stupid upperbound on the amount of interfaces (was 8).
c6d8349444659c4a281b31a709377e8c71a90ad9 19-Oct-2000 joe <joe@FreeBSD.org> Augment the 'ifaddr' structure with a 'struct if_data' to keep
statistics on a per network address basis.

Teach the IPv4 and IPv6 input/output routines to log packets/bytes
against the network address connected to the flow.

Teach netstat to display the per-address stats for IP protocols
when 'netstat -i' is evoked, instead of displaying the per-interface
725292b291f28a3adbd479f0209979006fcdde33 28-Jul-2000 jdp <jdp@FreeBSD.org> Fix bug: "netstat -si" prints interface information, but the header
line is missing. This apparently was broken in revision 1.31 of

Submitted by: Maxime Henrion <mhenrion@cybercable.fr>
b42951578188c5aab5c9f8cbcde4a743f8092cdc 02-Apr-2000 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'ALSA'.
47cb278dcf5993d02be1380cffbe647d3bcc5923 03-Jan-2000 jkh <jkh@FreeBSD.org> Print mac addresses in standard byte:byte format rather than
byte.byte. This makes it consistent with our other utilities
like arp(8) and ifconfig(8).

Submitted by: Paul Vixie <paul@vix.com>
70f0bdf6818a73c858bc47a23afc1e9d7c56d716 07-Dec-1999 shin <shin@FreeBSD.org> udp IPv6 support, IPv6/IPv4 tunneling support in kernel,
packet divert at kernel for IPv6/IPv4 translater daemon

This includes queue related patch submitted by jburkhol@home.com.

Submitted by: queue related patch from jburkhol@home.com
Reviewed by: freebsd-arch, cvs-committers
Obtained from: KAME project
6ab56498cae52faa92736d5163587be3ffb0ded6 09-Nov-1999 dfr <dfr@FreeBSD.org> Fix the output of 'netstat -I de0 1' for the alpha. Fix a bunch of
warnings while I'm here.
405fc1165a74f692670f70b4749507b6a98f08ec 23-Oct-1999 dillon <dillon@FreeBSD.org> Cleanup missing includes, stale includes, and a few printf format
698af92f8613624eb9b69ed626a553ef9ed11bc3 21-Oct-1999 julian <julian@FreeBSD.org> Cleanup towards -Wall
3b842d34e82312a8004a7ecd65ccdb837ef72ac1 28-Aug-1999 peter <peter@FreeBSD.org> $Id$ -> $FreeBSD$
564d182065fdf8f65991755b00f96cb3a2bcf24b 26-Apr-1999 luigi <luigi@FreeBSD.org> Add support for printing bridging statistics with ``-p bdg '' .
If someone has a better flag to use I'll be glad to change it.
0232b8dbc35ec6cccef686f5f8e9d9624dd742d9 20-Apr-1999 billf <billf@FreeBSD.org> IPX address formatting nit.

PR: bin/11179
Submitted by: Dan Nelson <dnelson@emsphone.com>
0609531ab6b945c4918206f095bc1f6640408654 06-Jul-1998 bde <bde@FreeBSD.org> Fixed printf format errors.
0506343883d62f6649f7bbaf1a436133cef6261d 11-Jan-1998 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'jb'.
7c6e96080c4fb49bf912942804477d202a53396c 10-Jan-1998 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'JB'.
f390c26dd9214a3602049fa55835b2d367ef60df 22-Feb-1997 peter <peter@FreeBSD.org> Revert $FreeBSD$ to $Id$
808a36ef658c1810327b5d329469bcf5dad24b28 14-Jan-1997 jkh <jkh@FreeBSD.org> Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.
ae33ce68ad9b80c80470a8bcfdd1e4790246bb82 13-Jan-1997 wollman <wollman@FreeBSD.org> Print out the interface's multicast addresses using the new
e9eee4f4075fde5691b87c6d72f173e550b0fb4c 03-Jan-1997 wollman <wollman@FreeBSD.org> Update to match changes in <net/if.h> and <netinet/ip_mroute.h>.
2c02b8c04afd723238ec165f2994d91dff5f8c96 13-Dec-1996 wollman <wollman@FreeBSD.org> Learn to follow the new interface address lists.
2bf6d9001a4c006c71e7a38300aa0543ac6a4a12 11-Dec-1996 wollman <wollman@FreeBSD.org> Understand queue-ized ifnet structures.
d3ecee07b35f58cb9d8e5e3c25e923af0c1c5056 10-Dec-1996 wollman <wollman@FreeBSD.org> Fix up programs which expect <net/if.h> to include <sys/time.h> to instead
do it themselves. (Some of these programs actually depended on this
beyond compiling the definition of struct ifinfo!) Also fix up some
other #include messes while we're at it.
a9efebe64e5d894efc31d901780a1a683983e0e4 02-Dec-1996 fenner <fenner@FreeBSD.org> Display multicast addresses if the "a" flag is used in combination
with "-i". This was already in the man page but was not implemented.

Obtained from: Multicast release 3.5
31eae602d6dbb4e278484b412f5bdb5aa019c54d 31-Aug-1996 julian <julian@FreeBSD.org> fix printing of netranges in the i and r displays for netatalk
7805978130bff3d12577cd0f7ab22e16fcf455ed 23-Jul-1996 julian <julian@FreeBSD.org> Submitted by: archie@whistle.com

appletalk cleanups
0c208df31d99f808dbe41d524b1681b1e3acc70e 09-Jul-1996 julian <julian@FreeBSD.org> appletalk cleanups

Active ATALK connections
Proto Recv-Q Send-Q Local Address Foreign Address (state)
ddp 0 0 [69.230]130 [*.*]*
ddp 0 0 [69.230]128 [*.*]*
ddp 0 0 [69.230]1 [*.*]*

5c1e86ebb424294fcfae39ae7ff1efcf8808086d 02-Jun-1996 alex <alex@FreeBSD.org> Code cleanup: remove unused variables, use correct *printf format
specifiers (some unsigned values were printed as signed, some longs
were printed as ints), and place parentheses around assignments in
if statements.
be0c3a28c5728348ec0ae9fd6224ebc3c9b98471 29-Feb-1996 dg <dg@FreeBSD.org> Make the -w option actually useful to people. Instead of it creating a
messy 130 column collage, output the system totals -or- info for a
specific interface if -I is given. Also wait for <interval> before
outputting the first sample so that it represents meaningful data (as
opposed to the total since the system was booted - most busy systems
wrap around many times during their operation, so these numbers are
only misleading).
379b9b388fc8788659993af038bb322bfbcea8b2 13-Feb-1996 wollman <wollman@FreeBSD.org> XNS sort-of-support is no more.
61d8d8e40b45efc45d9bbdf14fe96e565ceb074f 06-Feb-1996 wollman <wollman@FreeBSD.org> Remove support for OSI networking in user-land (#ifdef OSI aor CCITT)
in preparation for its removal from the kernel source tree. NB: because
a function was deleted, libc is now at version 3.0 (was 2.2 previously).
e0dc99202602929138dfd9fb9d465d21b685919c 14-Jan-1996 peter <peter@FreeBSD.org> Merge in Lite-2 changes.
5476eae499a3e1c3530620c0ebc3a69ffb2f25ba 14-Jan-1996 peter <peter@FreeBSD.org> Import netstat from 4.4Lite-2 - this version eliminates some of the
severely bogus mask guessing in the netname code, and also reports the
mask length of the route (like linux's netstat, but in a much more compact

The current code is doing bogus things like shifting c-class subnets by
4 bits and looking them up, causing a DNS lookup of 0x0C0CBxxx which
takes an eternity to fail.
262d14803690c3c8f394da8917b4a04d8f187c70 22-Nov-1995 se <se@FreeBSD.org> Increase width of Network column from 11 to 13 for the AF_INET case.
This seems to have been missed, when the recent IPX changes went in ...
86f1bc4514fdcfd255f37f3218fe234bdc3664fc 05-Nov-1995 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'LINUX'.
90ae06d6ac1d2da3758389a70a20c91f3e9fd1dc 26-Oct-1995 julian <julian@FreeBSD.org> Reviewed by: julian and jhay@mikom.csir.co.za
Submitted by: Mike Mitchell, supervisor@alb.asctmd.com

This is a bulk mport of Mike's IPX/SPX protocol stacks and all the
related gunf that goes with it..
it is not guaranteed to work 100% correctly at this time
but as we had several people trying to work on it
I figured it would be better to get it checked in so
they could all get teh same thing to work on..

Mikes been using it for a year or so
but on 2.0

more changes and stuff will be merged in from other developers now that this is in.

Mike Mitchell, Network Engineer
AMTECH Systems Corporation, Technology and Manufacturing
8600 Jefferson Street, Albuquerque, New Mexico 87113 (505) 856-8000
17596c2d332ec25a4ca1df70171b5b512a0420fb 23-Sep-1995 dg <dg@FreeBSD.org> Fixed netstat to not bogusly mangle the argv[] command args by rewriting
the way it stores and handles "interface". The previous behavior resulted
in strange output from 'w' and 'ps' when an interface specification was
given to netstat.
d07d67048ecfd869ae329f73245a968f13f85372 29-Jul-1995 dg <dg@FreeBSD.org> Output statistics as unsigned in the -w section.
Look at error return of kread() and stop on error.
Fix warning in kread() to not output "kvm_read:" twice.
Killed PCB cache misses stat as we no longer have it.
2e14d9ebc3d3592c67bdf625af9ebe0dfc386653 14-Mar-1995 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'MATT_THOMAS'.
ec62e724b8eecbb45b5b63e1fa140326e65d35c3 12-Oct-1994 dg <dg@FreeBSD.org> Added '-b' option to display the number of in and out bytes on a given
interface (used with -i and -I flag).
34cd81d75f398ee455e61969b118639dacbfd7a6 23-Sep-1994 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'MACKERRAS'.
e16baf7a5fe7ac1453381d0017ed1dcdeefbc995 07-Aug-1994 cvs2svn <cvs2svn@FreeBSD.org> This commit was manufactured by cvs2svn to create branch 'SUNRPC'.
d2ff996240e57a6d1e6eaa5510c6a27f562b49e1 05-Aug-1994 dg <dg@FreeBSD.org> Changed output formatting to 0 pad hex bytes if necessary. This makes
the output consistent with traditional representations of ethernet
addresses. I still don't like the spacing in netstat -i, however.
f9ab90d9d6d02989a075d0f0074496d5b1045e4b 27-May-1994 rgrimes <rgrimes@FreeBSD.org> BSD 4.4 Lite Usr.bin Sources