From nobody@FreeBSD.org  Tue Oct 25 09:07:05 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id DB505106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 25 Oct 2011 09:07:05 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id CB9058FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 25 Oct 2011 09:07:05 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p9P975HU074117
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 25 Oct 2011 09:07:05 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p9P974mr074116;
	Tue, 25 Oct 2011 09:07:04 GMT
	(envelope-from nobody)
Message-Id: <201110250907.p9P974mr074116@red.freebsd.org>
Date: Tue, 25 Oct 2011 09:07:04 GMT
From: Dennis Yusupoff <dyr@smartspb.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Interface auto-width in "netstat -rn"
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         161986
>Category:       bin
>Synopsis:       [patch] netstat(1): Interface auto-width in "netstat -rn"
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 25 09:10:01 UTC 2011
>Closed-Date:    
>Last-Modified:  Thu Feb 23 11:00:23 UTC 2012
>Originator:     Dennis Yusupoff
>Release:        7,8 and 9
>Organization:
SmartTelecom
>Environment:
No matter :)
>Description:
Currently there are two version of "netstat -rn" - "wide" and "usual". Wide is turning on by option "-W" and show additional information about routes (only for IPv4 family, as I understand route.c) - MTU and the full interface name(limited, however, by 8 symbols). In "usual" mode Netif limited by 6 symbols, which definitly isn't enough for VLAN interfaces:

===
netstat  -rn| head -n6
Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            217.119.16.33      UGS         0 2147187618    em0
10.1.0.0/16        10.78.77.9         UG1         0        0 vlan30
===


===
netstat  -Wrn| head -n6
Routing tables

Internet:
Destination        Gateway            Flags    Refs        Use    Mtu    Netif Expire
default            217.119.16.33      UGS         0 2147115775   1500      em0
10.1.0.0/16        10.78.77.9         UG1         0          0   1500 vlan3050
===

I think, that truncating Netif is absolutely incorrect and easily confusing most FreeBSD users. 

So I propose:
1. Limit wid_if by getting width of longest netif name (i.e. automatically, on-the-fly)
2.1 Show full netif by default or:
2.2 Add special "truncated" symbol at the end of Netif, for example ">", like that:
===
Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            217.119.16.33      UGS         0 2147187618    em0
10.1.0.0/16        10.78.77.9         UG1         0        0 vlan30>
===


>How-To-Repeat:

>Fix:
Don't know C as should, but it looks like it might be easily patch route.c

>Release-Note:
>Audit-Trail:

From: =?koi8-r?B?8MXS28nOIPfMwcTJzcnS?= <pershin87@yandex.ru>
To: bug-followup@freebsd.org,dyr@smartspb.net
Cc:  
Subject: Re: bin/161986: netstat(1): Interface auto-width in &quot;netstat -rn&quot;
Date: Wed, 09 Nov 2011 06:56:32 +0400

 I wrote small patch.
 Tested patch on 8.2-RELEASE-p3
 
 --- route.c     2010-12-21 23:09:25.000000000 +0600
 +++ route_n.c   2011-11-04 23:01:33.000000000 +0600
 @@ -264,13 +264,11 @@
  #ifndef INET6
  #define        WID_DST_DEFAULT(af)     18      /* width of destination column */
  #define        WID_GW_DEFAULT(af)      18      /* width of gateway column */
 -#define        WID_IF_DEFAULT(af)      (Wflag ? 8 : 6) /* width of netif column */
  #else
  #define        WID_DST_DEFAULT(af) \
         ((af) == AF_INET6 ? (numeric_addr ? 33: 18) : 18)
  #define        WID_GW_DEFAULT(af) \
         ((af) == AF_INET6 ? (numeric_addr ? 29 : 18) : 18)
 -#define        WID_IF_DEFAULT(af)      ((af) == AF_INET6 ? 8 : (Wflag ? 8 : 6))
  #endif /*INET6*/
 
  static int wid_dst;
 @@ -291,11 +289,10 @@
         wid_refs = 6;
         wid_use = 8;
         wid_mtu = 6;
 -       wid_if = WID_IF_DEFAULT(ef);
 +       wid_if = 8;
         wid_expire = 6;
 
 -       if (Wflag)
 -               size_cols_tree(rn);
 +       size_cols_tree(rn);
  }
 
  static void
 @@ -781,7 +778,7 @@
                         if (rt->rt_rmx.rmx_mtu != 0)
                                 printf("%*lu ", wid_mtu, rt->rt_rmx.rmx_mtu);
                         else
 -                               printf("%*s ", wid_mtu, "");
 +                               printf("%*s ", wid_mtu, "");
                 }
         }
         if (rt->rt_ifp) {

From: Dennis Yusupoff <dyr@smartspb.net>
To: bug-followup@FreeBSD.org, pershin87@yandex.ru
Cc:  
Subject: Re: bin/161986: [patch] netstat(1): Interface auto-width in &quot;netstat
 -rn&quot;
Date: Fri, 18 Nov 2011 14:21:32 +0400

 This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
 --------------enig5D86B41D394D8570270AFE3F
 Content-Type: text/plain; charset=UTF-8
 Content-Transfer-Encoding: quoted-printable
 
 Thank you for your patch, it works excellent, what I really wanted to
 see al this years! :)
 
 Example after patch:
 =3D=3D=3D
  netstat -rn
 Routing tables
 
 Internet:
 Destination        Gateway            Flags    Refs      Use    Netif Exp=
 ire
 default            10.78.77.35        UGS         0     2538      em0
 1.1.1.0/30         link#7             U           0        0 em0.3050
 1.1.1.1            link#7             UHS         0        0      lo0
 127.0.0.1          link#6             UH          0        1      lo0
 =3D=3D=3D
 It's even works with renamed interfaces also:
 =3D=3D=3D
 # ifconfig em0.3050 name eth0.tag.3050
 # netstat -rn|grep eth0
 1.1.1.0/30         link#7             U           0        0 eth0.tag.305=
 0
 #
 =3D=3D=3D
 Brilliant!
 
 And, there is also same problem with interface counters view (netstat
 -i). Moreover, it doesn't viewed correctly even in wide mode!
 See:
 =3D=3D=3D
 root@exBastinda:/usr/src/usr.bin/netstat (387) netstat -inW|grep em0
 em0      1500 <Link#3>      00:30:48:64:e9:4a   133090     0     0  =20
 18862     0     0
 em0      1500 10.78.77.0/24 10.78.77.22          23468     -     -  =20
 16827     -     -
 em0.305  1500 <Link#7>      00:30:48:64:e9:4a        0     0   =20
 0        2     0     0
 em0.305  1500 1.1.1.0/30    1.1.1.1                  0     -   =20
 -        0     -     -
 root@exBastinda:/usr/src/usr.bin/netstat (388) netstat -in|grep em0
 em0    1500 <Link#3>      00:30:48:64:e9:4a   133117     0     0  =20
 18889     0     0
 em0    1500 10.78.77.0/24 10.78.77.22          23495     -     -  =20
 16854     -     -
 em0.3  1500 <Link#7>      00:30:48:64:e9:4a        0     0     0      =20
 2     0     0
 em0.3  1500 1.1.1.0/30    1.1.1.1                  0     -     -      =20
 0     -     -
 =3D=3D=3D
 
 So would you be so kind to fix this behavior also?
 
 --=20
 With best regards,
 Dennis Yusupoff,
 network engineer of
 Smart-Telecom ISP
 Russia, Saint-Petersburg=20

 
 
 --------------enig5D86B41D394D8570270AFE3F
 Content-Type: application/pgp-signature; name="signature.asc"
 Content-Description: OpenPGP digital signature
 Content-Disposition: attachment; filename="signature.asc"
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.10 (MingW32)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
 iQEcBAEBAgAGBQJOxjGsAAoJEBUTaqBS2NB4PfwH/A6qP6RC6VhekbFSYZ0+LPx1
 HcePtxzawbZH0Yguw4qs4zuy/pbzIs7YyfRWsj36JkpRCUBn6hN7mYt9whNQ0Ai/
 H2orGTa/EPTx+3yBmufZ06rKr42oU2UhsIKH+PIjADpIIL80q7ZOtysLu0d5HWY/
 qvDAfq6PqJLqvrmBe/8sjhklGFLNPSnQUxk+F/1VOel6V91utYZa6XzkWkTk25NO
 KtjTUWIZMk6BSLqXfJCx+1UVqncvdxlQw6Iw14nroNgsxsNG2oP1lIn4F1ELFNkJ
 piRy8Ojn+MP+XMdkjmBjah/Uz1kuI0YMLSA+Nk54f+CqGiJs4VkQoCa+Iq8jUiA=
 =YavP
 -----END PGP SIGNATURE-----
 
 --------------enig5D86B41D394D8570270AFE3F--

From: Pershin Vladimir <pershin87@yandex.ru>
To: bug-followup@freebsd.org,dyr@smartspb.net
Cc:  
Subject: Re: bin/161986: [patch] netstat(1): Interface auto-width in 
Date: Thu, 23 Feb 2012 14:53:06 +0400

 I wrote small patch.
 By default the width equal 10, if you use -W then width equal 16.
 
 --- if_old.c	2010-12-21 23:09:25.000000000 +0600
 +++ if.c	2012-02-23 16:47:58.000000000 +0600
 @@ -223,9 +223,9 @@
  
  	if (!pfunc) {
  		if (Wflag)
 -			printf("%-7.7s", "Name");
 +			printf("%-16.16s", "Name");
  		else
 -			printf("%-5.5s", "Name");
 +			printf("%-10.10s", "Name");
  		printf(" %5.5s %-13.13s %-17.17s %8.8s %5.5s %5.5s",
  		    "Mtu", "Network", "Address", "Ipkts", "Ierrs", "Idrop");
  		if (bflag)
 @@ -293,9 +293,9 @@
  
  		if (ifaddraddr == 0) {
  			if (Wflag)
 -				printf("%-7.7s", name);
 +				printf("%-16.16s", name);
  			else
 -				printf("%-5.5s", name);
 +				printf("%-10.10s", name);
  			printf(" %5lu ", ifnet.if_mtu);
  			printf("%-13.13s ", "none");
  			printf("%-17.17s ", "none");
 @@ -315,9 +315,9 @@
  				continue;
  			}
  			if (Wflag)
 -				printf("%-7.7s", name);
 +				printf("%-16.16s", name);
  			else
 -				printf("%-5.5s", name);
 +				printf("%-10.10s", name);
  			printf(" %5lu ", ifnet.if_mtu);
  			switch (sa->sa_family) {
  			case AF_UNSPEC:
>Unformatted:
