diff options
author | ume <ume@FreeBSD.org> | 2015-11-20 16:10:58 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2015-11-20 16:10:58 +0000 |
commit | 9aec66905fd79577d0e13907c4aff0a92b0e8b27 (patch) | |
tree | 641149a8309f3317be791aaa4184866b6036e530 /usr.bin | |
parent | ca485ab416cec921aef2fb10e48a12ee41e5eaad (diff) | |
download | FreeBSD-src-9aec66905fd79577d0e13907c4aff0a92b0e8b27.zip FreeBSD-src-9aec66905fd79577d0e13907c4aff0a92b0e8b27.tar.gz |
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>
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/netstat/if.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index 0bb2581..4b802d4 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -37,7 +37,7 @@ static char sccsid[] = "@(#)if.c 8.3 (Berkeley) 4/28/95"; #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 *), int af) { 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 *), int af) 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 *), int af) 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); |