Author: ume
Date: Fri Nov 20 16:10:58 2015
New Revision: 291101
URL: https://svnweb.freebsd.org/changeset/base/291101

Log:
  MFC r290367, r290370, r290437:
  
  Change to not truncate an interface name when -W option
  is specified.
  
  MFC Requested by:     Jim Thompson <jim__at__netgate.com>

Modified:
  stable/10/usr.bin/netstat/if.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.bin/netstat/if.c
==============================================================================
--- stable/10/usr.bin/netstat/if.c      Fri Nov 20 15:13:49 2015        
(r291100)
+++ stable/10/usr.bin/netstat/if.c      Fri Nov 20 16:10:58 2015        
(r291101)
@@ -37,7 +37,7 @@ static char sccsid[] = "@(#)if.c      8.3 (Be
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/protosw.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
@@ -231,7 +231,8 @@ intpr(int interval, void (*pfunc)(char *
 {
        struct ifaddrs *ifap, *ifa;
        struct ifmaddrs *ifmap, *ifma;
-       
+       u_int ifn_len_max = 5;
+
        if (interval)
                return sidewaysintpr(interval);
 
@@ -240,11 +241,19 @@ intpr(int interval, void (*pfunc)(char *
        if (aflag && getifmaddrs(&ifmap) != 0)
                err(EX_OSERR, "getifmaddrs");
 
+       if (Wflag) {
+               for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+                       if (interface != NULL &&
+                           strcmp(ifa->ifa_name, interface) != 0)
+                               continue;
+                       if (af != AF_UNSPEC && ifa->ifa_addr->sa_family != af)
+                               continue;
+                       ifn_len_max = MAX(ifn_len_max, strlen(ifa->ifa_name));
+               }
+       }
+
        if (!pfunc) {
-               if (Wflag)
-                       printf("%-7.7s", "Name");
-               else
-                       printf("%-5.5s", "Name");
+               printf("%-*.*s", ifn_len_max, ifn_len_max, "Name");
                printf(" %5.5s %-13.13s %-17.17s %8.8s %5.5s %5.5s",
                    "Mtu", "Network", "Address", "Ipkts", "Ierrs", "Idrop");
                if (bflag)
@@ -283,10 +292,7 @@ intpr(int interval, void (*pfunc)(char *
                if (af != AF_UNSPEC && ifa->ifa_addr->sa_family != af)
                        continue;
 
-               if (Wflag)
-                       printf("%-7.7s", ifa->ifa_name);
-               else
-                       printf("%-5.5s", ifa->ifa_name);
+               printf("%-*.*s", ifn_len_max, ifn_len_max, ifa->ifa_name);
 
 #define IFA_MTU(ifa)   (((struct if_data *)(ifa)->ifa_data)->ifi_mtu)
                show_stat("lu", 6, IFA_MTU(ifa), IFA_MTU(ifa), 0);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to