History log of /freebsd-current/usr.bin/netstat/if.c
Revision Date Author Comments
# 5dea523b 06-Dec-2023 Kristof Provost <kp@FreeBSD.org>

pflow: netstat statistics

Expose pflow counters via netstat.

Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D43107


# 5e3934b1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# bdcbfde3 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 372e3d56 26-Jul-2023 Mike Karels <karels@FreeBSD.org>

netstat -i: compute most field widths dynamically

The network and address fields were sometimes truncated for netstat -i
without -W, and often much too wide for netstat -i with the -W option.
Fields such as normal packet counts often overflowed. As a result,
columns didn't line up, and large white spaces made it harder to
follow a line across the display. Change the code to compute the
required field sizes for network, address, and various packet counts.
Hoist the code to format network and address into a subroutine that
can be called twice, once to measure the required field widths,
and once to emit the values. Use separate field widths for input
and output packets, byte counts, and error and drop counters.
These are left at defaults (the preceding values) with the -h
option, in which case the fields have a limited total width.
An extra space is included between the Network and Address, which
otherwise seemed too close.

Change the mention of -W with -i in the man page to say that most
field widths are computed dynamically in this case.

MFC after: 1 week
Reviewed by: sjg, glebius
Differential Revision: https://reviews.freebsd.org/D41160


# 4bf98559 29-May-2023 Kajetan Staszkiewicz <vegeta@tuxpowered.net>

pf: make contents of struct pfsync_state configurable

Make struct pfsync_state contents configurable by sending out new
versions of the structure in separate subheader actions. Both old and
new version of struct pfsync_state can be understood, so replication of
states from a system running an older kernel is possible. The version
being sent out is configured using ifconfig pfsync0 … version XXXX. The
version is an user-friendly string - 1301 stands for FreeBSD 13.1 (I
have checked synchronization against a host running 13.1), 1400 stands
for 14.0.

A host running an older kernel will just ignore the messages and count
them as "packets discarded for bad action".

Reviewed by: kp
Sponsored by: InnoGames GmbH
Differential Revision: https://reviews.freebsd.org/D39392


# cd9e5d43 07-Feb-2023 Kajetan Staszkiewicz <vegeta@tuxpowered.net>

netstat: fix pfsync stats spelling

Reviewed by: mjg


# 231092bb 02-Jul-2022 Mike Karels <karels@FreeBSD.org>

netstat -i: do not truncate interface names

The field for interface names for netstat -i was 5 characters by
default, which is no longer sufficient with names like "vlan1234"
and "vtnet0". netstat -iW computed the necessary field width, but
also enlarged the address field by a lot (especially with IPv6 enabled).
Make netstat -i compute the field width for interface names with or
without -W. Note that the existing default output does not fit in
80 columns in any case. Update the man page accordingly, documenting
the remaining effect of -W with -i. Also add -W to the list of
General Options, as there are numerous pointers to this.

Reported by: Chris Ross
Reviewed by: melifaro, rgrimes, cy
Differential Revision: https://reviews.freebsd.org/D35703
MFC after: 1 week


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <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.


# fbbd9655 28-Feb-2017 Warner Losh <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


# f193c8ce 05-Jan-2017 Xin LI <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


# b1a302a5 19-Nov-2015 Hajimu UMEMOTO <ume@FreeBSD.org>

Avoid core dump when output style is html.


# d48d68fa 16-Nov-2015 Hajimu UMEMOTO <ume@FreeBSD.org>

JSON doesn't permit a hexadecimal notation of an integer.


# b670e89a 06-Nov-2015 Hajimu UMEMOTO <ume@FreeBSD.org>

Do not truncate addresses when printing in encoded format.


# fb3ab86f 06-Nov-2015 Hajimu UMEMOTO <ume@FreeBSD.org>

- Fix alignment for padding link address.
- Trim whitespace of link address.


# f9b3502c 06-Nov-2015 Enji Cooper <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


# cca052c6 05-Nov-2015 Hajimu UMEMOTO <ume@FreeBSD.org>

Give enough room for addresses when -W option is specified.


# 011ae9c9 05-Nov-2015 Hajimu UMEMOTO <ume@FreeBSD.org>

Fix alignment of `Drop' header.


# 3e687cd8 04-Nov-2015 Hajimu UMEMOTO <ume@FreeBSD.org>

Fix alignment of AF_LINK address.


# 86a59895 04-Nov-2015 Hajimu UMEMOTO <ume@FreeBSD.org>

Simplify r290367 using asterisk for a field width
and precision.


# 38f16ca6 04-Nov-2015 Hajimu UMEMOTO <ume@FreeBSD.org>

Unify AF_INET case and AF_INET6 case.


# bd4fceca 04-Nov-2015 Hajimu UMEMOTO <ume@FreeBSD.org>

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


# 8e2d18a7 04-Nov-2015 Hajimu UMEMOTO <ume@FreeBSD.org>

Restore an interface name field to left align.


# 9eddb899 10-Sep-2015 Mark Johnston <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


# a261e361 02-Sep-2015 Hiroki Sato <hrs@FreeBSD.org>

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

PR: 183598


# 10d5269f 01-Sep-2015 Hiroki Sato <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
netname().

- 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


# e42e1fcc 06-May-2015 Gleb Smirnoff <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.


# 56d5e096 06-Apr-2015 Gleb Smirnoff <glebius@FreeBSD.org>

Stop including if_var.h from userland.

Sponsored by: Nginx, Inc.


# 315ca438 03-Mar-2015 Marcel Moolenaar <marcel@FreeBSD.org>

Fix typo in dropped-packets attribute (missing s).

Pointed-out by: allanjude (excellent catch!)


# 65f28331 25-Feb-2015 Marcel Moolenaar <marcel@FreeBSD.org>

Fix "netstat -hdw 1" output.

Reported by: np@


# ade9ccfe 21-Feb-2015 Marcel Moolenaar <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.


# 55fb7d68 18-Mar-2014 Gleb Smirnoff <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.


# 45c203fc 14-Mar-2014 Gleb Smirnoff <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.


# 2c284d93 13-Mar-2014 Gleb Smirnoff <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.


# b245f96c 12-Mar-2014 Gleb Smirnoff <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.


# 526b18aa 29-Dec-2013 Gleb Smirnoff <glebius@FreeBSD.org>

Claim copyright since I've almost rewritten this file in r256512.


# fc47e028 19-Dec-2013 Alexander V. Chernikov <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
kern/167204.
Some non-working code (ng_socket.ko symbol addresses calculation) removed.
Some global variables eliminated.

PR: kern/167204
MFC after: 4 weeks


# 3e4d5cd3 29-Oct-2013 Gleb Smirnoff <glebius@FreeBSD.org>

Make userland tools honor WITHOUT_PF build option.

Tested by: dt71@gmx.com


# 84c1edcb 15-Oct-2013 Gleb Smirnoff <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
debugger.

Sponsored by: Netflix
Sponsored by: Nginx, Inc.


# d6d3f01e 08-Sep-2012 Gleb Smirnoff <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>


# 0b6654ea 04-Apr-2012 Gleb Smirnoff <glebius@FreeBSD.org>

Print pfsync action statistics.


# 58dbc1a0 04-Apr-2012 Gleb Smirnoff <glebius@FreeBSD.org>

In pfsync stats print last couple of lines in a plural form optionally.


# 16410af7 04-Apr-2012 Gleb Smirnoff <glebius@FreeBSD.org>

With pf 4.5 import the name of pfsync stats sysctl has changed, thus
'netstat -sp pfsync' got broken. Fix this.


# b4f7ea19 09-Jan-2012 Eitan Adler <eadler@FreeBSD.org>

Fix warning when compiling with gcc46:
error: variable 'ifnetfound' set but not used

Approved by: dim
MFC after: 3 days


# b3608ae1 03-Jan-2012 Ed Schouten <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.


# 62372898 12-Jul-2011 Michael Tuexen <tuexen@FreeBSD.org>

Truncate link addresses like it is done for any
other address type.

MFC after: 4 weeks


# cd05232a 20-Jan-2011 Hajimu UMEMOTO <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>


# da52b4ca 11-Dec-2010 Joel Dahl <joel@FreeBSD.org>

Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

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

Discussed with: imp, rwatson


# 3c578b2a 18-Nov-2010 Ryan Stone <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


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 5eb2aa45 14-Jul-2010 Ed Maste <emaste@FreeBSD.org>

Remove more extraneous ;s.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 0985bbea 09-Feb-2010 Xin LI <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)


# bf10ffe1 10-Jan-2010 Xin LI <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


# 2df34815 19-Dec-2009 Attilio Rao <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


# 821df508 12-Dec-2009 Xin LI <delphij@FreeBSD.org>

Revert most part of 200420 as requested, as more review and polish is
needed.


# 6f2d3221 11-Dec-2009 Xin LI <delphij@FreeBSD.org>

Remove unneeded header includes from usr.bin/ except contributed code.

Tested with: make universe


# aaae58c4 01-Dec-2009 Bjoern A. Zeeb <bz@FreeBSD.org>

Unbreak user space after if_timer/if_watchdog removal in r199975.

Tested by: glebius


# d72dc9a7 25-Nov-2009 Attilio Rao <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


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 65475bc8 02-Jan-2008 David E. O'Brien <obrien@FreeBSD.org>

style(9)
+ kread is not a boolean, so check it as such
+ fix $FreeBSD$ Ids
+ denote copyrights with /*-
+ misc whitespace changes.


# feda1a43 16-Jul-2007 John Baldwin <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
changes:
- 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
live).
- 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)


# b6c86f4b 26-Feb-2007 Bruce Evans <bde@FreeBSD.org>

Fixed some style bugs (whitespace lossage for removal of __P(()), and
lots of naming and typing errors involving `interval').


# 93547b07 26-Feb-2007 Bruce Evans <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
conversion.


# 1f575ce8 08-Nov-2006 Bruce Evans <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.


# 7b95a1eb 28-Jul-2006 Yaroslav Tykhiy <ytykhiy@gmail.com>

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


# b5f67491 09-Nov-2005 Ruslan Ermilov <ru@FreeBSD.org>

Align output.


# b6de9e91 27-Sep-2005 Max Laier <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)


# 7c23a867 27-Sep-2005 Gleb Smirnoff <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.


# c6358a5e 20-Aug-2005 Ruslan Ermilov <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.)


# c2dfd19f 18-Aug-2005 Gleb Smirnoff <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


# 2e37c5a3 14-Jul-2005 Max Laier <mlaier@FreeBSD.org>

Print newly exported pfsync statistics with netstat(8).

Requested by: glebius
MFC after: 1 week


# 6cc6f122 26-Jul-2004 Philippe 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
prototypes.


# e1655201 12-Apr-2004 Ruslan Ermilov <ru@FreeBSD.org>

Show link-level multicast packet counters with the -a option.


# bce2e7c8 12-Apr-2004 Ruslan Ermilov <ru@FreeBSD.org>

Fixed alignment of multicast addresses when printing that got
broken in previous revision.


# 25d295e1 28-Nov-2003 Bruce M Simpson <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)


# 9bf40ede 31-Oct-2003 Brooks Davis <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)


# ab54ea99 05-Mar-2003 Peter Wemm <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.


# ec3b72e9 10-Feb-2003 Robert Drehmel <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.


# a01e3379 05-Sep-2002 David Malone <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).


# e65dd7bc 27-Apr-2002 Mark Murray <markm@FreeBSD.org>

fix warnings; change variable/argument names that mask global names.


# 6f9cdfce 18-Oct-2001 Matthew N. Dodd <mdodd@FreeBSD.org>

Print statistics for AF_IPX.
Note that the IPX code doesn't update these correctly yet, but should.


# acb60e59 09-Oct-2001 Ruslan Ermilov <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.


# dd1f8b9b 08-Oct-2001 Matthew N. Dodd <mdodd@FreeBSD.org>

Minor output formatting for 'netstat -i':
- Right align Mtu
- Print AF_INET family with correct field width.


# d44ddba9 11-Sep-2001 Ruslan Ermilov <ru@FreeBSD.org>

Implement the ``-f address_family'' filter for -i.

Prodded by: Igor Podlesny <poige@morning.ru>


# f964d60d 15-Jun-2001 Assar Westerlund <assar@FreeBSD.org>

remove warnings
remove superfluous declarations
make things more consistent


# 5e051718 15-Jun-2001 Assar Westerlund <assar@FreeBSD.org>

remove K&R support


# e9370a2e 15-Jun-2001 Assar Westerlund <assar@FreeBSD.org>

revert removal of warning and K&R support

Requested by: bde


# cf5e44f8 15-Jun-2001 Ruslan Ermilov <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.


# af7a0a2d 14-Jun-2001 Assar Westerlund <assar@FreeBSD.org>

remove most of the warnings


# b9d92bf5 26-Apr-2001 Bill 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.


# 0b23654b 30-Mar-2001 Poul-Henning Kamp <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>


# 445f17bb 04-Mar-2001 Josef Karthauser <joe@FreeBSD.org>

When displaying interface statistics with -i show a '-' for any
values that aren't updated for a particular network-layer address.


# 6817526d 06-Feb-2001 Poul-Henning Kamp <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


# 4d51ef63 30-Dec-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Use macro API to <sys/queue.h>

Submitted by: "Jason" <jsmethers@pdq.net>
Reviewed by: phk


# 591c194a 30-Oct-2000 Guido van Rooij <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).


# 5da9f8fa 19-Oct-2000 Josef Karthauser <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
stats.


# 3cfac2c5 27-Jul-2000 John Polstra <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
"if.c".

Submitted by: Maxime Henrion <mhenrion@cybercable.fr>


# e54ca68c 03-Jan-2000 Jordan K. Hubbard <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>


# cfa1ca9d 07-Dec-1999 Yoshinobu Inoue <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


# 890bc2a5 09-Nov-1999 Doug Rabson <dfr@FreeBSD.org>

Fix the output of 'netstat -I de0 1' for the alpha. Fix a bunch of
warnings while I'm here.


# f41f949d 23-Oct-1999 Matthew Dillon <dillon@FreeBSD.org>

Cleanup missing includes, stale includes, and a few printf format
inconsistancies.


# a97a9922 21-Oct-1999 Julian Elischer <julian@FreeBSD.org>

Cleanup towards -Wall


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 0024d1db 26-Apr-1999 Luigi Rizzo <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.


# 9baac9f2 20-Apr-1999 Bill Fumerola <billf@FreeBSD.org>

IPX address formatting nit.

PR: bin/11179
Submitted by: Dan Nelson <dnelson@emsphone.com>


# 22694eba 06-Jul-1998 Bruce Evans <bde@FreeBSD.org>

Fixed printf format errors.


# c115df18 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <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.


# 75fb8770 13-Jan-1997 Garrett Wollman <wollman@FreeBSD.org>

Print out the interface's multicast addresses using the new
structures.


# 87669425 03-Jan-1997 Garrett Wollman <wollman@FreeBSD.org>

Update to match changes in <net/if.h> and <netinet/ip_mroute.h>.


# 15244cd5 13-Dec-1996 Garrett Wollman <wollman@FreeBSD.org>

Learn to follow the new interface address lists.


# 0e27dc05 11-Dec-1996 Garrett Wollman <wollman@FreeBSD.org>

Understand queue-ized ifnet structures.


# 628d2ac1 10-Dec-1996 Garrett 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.


# f6719675 01-Dec-1996 Bill 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


# a8d37845 31-Aug-1996 Julian Elischer <julian@FreeBSD.org>

fix printing of netranges in the i and r displays for netatalk


# 3a67d2bc 22-Jul-1996 Julian Elischer <julian@FreeBSD.org>

Submitted by: archie@whistle.com

appletalk cleanups


# 6ffcfd6c 08-Jul-1996 Julian Elischer <julian@FreeBSD.org>

appletalk cleanups

e.g.
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 [*.*]*

etc..


# 7d56c0ee 02-Jun-1996 Alexander Langer <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.


# 0b87c915 29-Feb-1996 David Greenman <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).


# cbc17e71 13-Feb-1996 Garrett Wollman <wollman@FreeBSD.org>

XNS sort-of-support is no more.


# 0761cb29 06-Feb-1996 Garrett 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).


# 05ddff6e 14-Jan-1996 Peter Wemm <peter@FreeBSD.org>

Merge in Lite-2 changes.


# 6889b16a 14-Jan-1996 Peter Wemm <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
form)

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.


# 09a67ffa 22-Nov-1995 Stefan Eßer <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 ...


# cc6a66f2 26-Oct-1995 Julian Elischer <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
supervisor@alb.asctmd.com


# 1b72e71c 23-Sep-1995 David Greenman <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.


# 3aa80b1d 29-Jul-1995 David Greenman <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.


# e1e293a5 11-Oct-1994 David Greenman <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).


# 541f2562 04-Aug-1994 David Greenman <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.


# 9b50d902 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Usr.bin Sources