Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 May 2011 19:23:37 +0200
From:      Michael Tuexen <tuexen@fh-muenster.de>
To:        net@freebsd.org
Subject:   netstat fix
Message-ID:  <3FEFBA56-63FC-403A-960E-627FD347AA06@fh-muenster.de>

next in thread | raw e-mail | index | archive | help
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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- usr.bin/netstat/if.c	(revision 221601)
+++ usr.bin/netstat/if.c	(working copy)
@@ -394,7 +394,7 @@
 				n =3D cp - sa->sa_data + 1;
 				cp =3D sa->sa_data;
 			hexprint:
-				while (--n >=3D 0)
+				while ((--n >=3D 0) && (m < 30))
 					m +=3D printf("%02x%c", *cp++ & =
0xff,
 						    n > 0 ? ':' : ' ');
 				m =3D 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=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3FEFBA56-63FC-403A-960E-627FD347AA06>