From owner-freebsd-net@FreeBSD.ORG Sun May 8 17:23:41 2011 Return-Path: Delivered-To: net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 47FB5106566B for ; Sun, 8 May 2011 17:23:41 +0000 (UTC) (envelope-from tuexen@fh-muenster.de) Received: from mail-n.franken.de (drew.ipv6.franken.de [IPv6:2001:638:a02:a001:20e:cff:fe4a:feaa]) by mx1.freebsd.org (Postfix) with ESMTP id 36C768FC0C for ; Sun, 8 May 2011 17:23:40 +0000 (UTC) Received: from [192.168.1.192] (p508FDFFE.dip.t-dialin.net [80.143.223.254]) (Authenticated sender: macmic) by mail-n.franken.de (Postfix) with ESMTP id 07FAB1C0B4611 for ; Sun, 8 May 2011 19:23:37 +0200 (CEST) From: Michael Tuexen Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Sun, 8 May 2011 19:23:37 +0200 Message-Id: <3FEFBA56-63FC-403A-960E-627FD347AA06@fh-muenster.de> To: net@freebsd.org Mime-Version: 1.0 (Apple Message framework v1084) X-Mailer: Apple Mail (2.1084) Cc: Subject: netstat fix X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 May 2011 17:23:41 -0000 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 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 0 0 0 = 0 0 0 0 0 fwip0 1500 = 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 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 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 0 0 0 = 0 0 0 0 0 fwip0 1500 00:30:05:b3:50:0b: 0 0 0 = 0 0 0 0 0 fwe0* 1500 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=