When should "netstat -i" truncate output?
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
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) netstat -nif inet
Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll
xl0 1500 192.168.7.0/2 192.168.7.254 95210 - 90017 - -
lo0 16384 127.0.0.0/8 127.0.0.1 195 - 195 - -
As evidence that the xl0 NIX is, in fact, not on a /2, I submit:
d254(7.3-S) netstat -nrf inet
Destination Gateway Flags Refs Use Netif Expire
default 192.168.7.1 UGS 0 61386 xl0
127.0.0.1 127.0.0.1 UH 0 195 lo0
192.168.7.0/24 link#1 UC 0 0 xl0
192.168.7.1 00:1a:a0:62:96:09 UHLW 2 286 xl0 431
d254(7.3-S) ifconfig xl0
xl0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
inet 192.168.7.254 netmask 0xffffff00 broadcast 192.168.7.255
media: Ethernet autoselect (100baseTX <full-duplex>)
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
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