netstat fix
Michael Tuexen
tuexen at fh-muenster.de
Sun May 8 17:23:41 UTC 2011
Dear all,
netstat -bi currently shows on one of my systems something like:
Name Mtu Network Address Ipkts Ierrs Idrop Ibytes Opkts Oerrs Obytes Coll
ix0 9000 <Link#1> 00:1b:21:55:1e:b8 0 0 0 0 0 0 0 0
ix0 9000 10.16.0.0 10.16.0.5 0 - - 0 0 - 0 -
ix0 9000 fe80::21b:21f fe80::21b:21ff:fe 0 - - 0 2 - 152 -
...
usbus 0 <Link#18> 0 0 0 0 0 0 0 0
fwip0 1500 <Link#19> 00:30:05:b3:50:0b:40:e4:0a:02:ff:fe:00:00:00:00 0 0 0 0 0 0 0 0
fwe0* 1500 <Link#20> 02:30:05:0b:40:e4 0 0 0 0 0 0 0 0
The point here is that for one row the entry in the Address column is not limited to 17 characters
as it is in all other cases. The following patch fixes this:
Index: usr.bin/netstat/if.c
===================================================================
--- usr.bin/netstat/if.c (revision 221601)
+++ usr.bin/netstat/if.c (working copy)
@@ -394,7 +394,7 @@
n = cp - sa->sa_data + 1;
cp = sa->sa_data;
hexprint:
- while (--n >= 0)
+ while ((--n >= 0) && (m < 30))
m += printf("%02x%c", *cp++ & 0xff,
n > 0 ? ':' : ' ');
m = 32 - m;
The current code does not enforce any limit on the length of AF_LINK
addresses (and the ones which are not handled specifically with netstat).
All other addresses are truncated (see the IPv6 addresses above).
With the patch the above output is:
Name Mtu Network Address Ipkts Ierrs Idrop Ibytes Opkts Oerrs Obytes Coll
ix0 9000 <Link#1> 00:1b:21:55:1e:b8 0 0 0 0 0 0 0 0
ix0 9000 10.16.0.0 10.16.0.5 0 - - 0 0 - 0 -
ix0 9000 fe80::21b:21f fe80::21b:21ff:fe 0 - - 0 2 - 152 -
...
usbus 0 <Link#18> 0 0 0 0 0 0 0 0
fwip0 1500 <Link#19> 00:30:05:b3:50:0b: 0 0 0 0 0 0 0 0
fwe0* 1500 <Link#20> 02:30:05:0b:40:e4 0 0 0 0 0 0 0 0
Any objections against committing the patch? Or suggestions?
Best regards
Michael
More information about the freebsd-net
mailing list