When should "netstat -i" truncate output?

David Wolfskill david at catwhisker.org
Tue Aug 10 23:09:48 UTC 2010

src/usr.bin/netstat/if.c was modified back in late November 1995, to
expand the "Network" field from 11 characters to 13:

| Revision 12459 - (view) (annotate) - [select for diffs]
| Modified Wed Nov 22 22:21:04 1995 UTC (14 years, 8 months ago) by se
| File length: 11619 byte(s)
| Diff to previous 11819
| 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 ...

While I appreciate the thought & effort, it should be readily apparent
that even 13 characters is insufficient to represent even an IPv4
address in dotted quad format (in the general case), let alone a network
specification in CIDR format:

is 15 characters for the IPv4 address part itself, plus another 3 for
the mask, totalling 18.

I just checked NetBSD sources
and it appears that they (also) use "%-13.13s" as the format
specification for Network.

(OpenBSD appears to use "%-11.11s", thus limiting the output to 11

OpenSolaris, per
apparently uses "%-14s" as the format specification -- which avoids the
(potentail) truncation issue entirely.

I realize that the information in question is avaiklable in other ways,
but limiting the size of the "Network" field of netstat(1) to 13
characters yields some rather ... odd ... results -- e.g.:

d254(7.3-S)[23] netstat -nif inet
Name    Mtu Network       Address              Ipkts Ierrs    Opkts Oerrs  Coll
xl0    1500        95210     -    90017     -     -
lo0   16384              195     -      195     -     -

As evidence that the xl0 NIX is, in fact, not on a /2, I submit:

d254(7.3-S)[24] netstat -nrf inet
Routing tables

Destination        Gateway            Flags    Refs      Use  Netif Expire
default          UGS         0    61386    xl0          UH          0      195    lo0     link#1             UC          0        0    xl0        00:1a:a0:62:96:09  UHLW        2      286    xl0    431
d254(7.3-S)[25] ifconfig xl0
xl0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        ether 00:08:74:e9:c9:41
        inet netmask 0xffffff00 broadcast
        media: Ethernet autoselect (100baseTX <full-duplex>)
        status: active

I suppose the thing that's bugging me here is that "netstat -nif inet"
appears to be mis-stating the situation.  I believe it would be ideal if
it were to provide correct output, but failing that, I'm tempted to
suggest that  it might be better to be silent on the matter.

Of course, the general output of netstat(1) is fairly well entrenched in
history, and I don't advocate change for its own sake.

Anyone else think this is enough of a "problem" that it merits modifying
the code (e.g., in netstat/if.c) a bit?

David H. Wolfskill				david at catwhisker.org
Depriving a girl or boy of an opportunity for education is evil.

See http://www.catwhisker.org/~david/publickey.gpg for my public key.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20100810/a28eb5c1/attachment.pgp

More information about the freebsd-hackers mailing list