diff options
author | ume <ume@FreeBSD.org> | 2015-11-05 11:06:46 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2015-11-05 11:06:46 +0000 |
commit | 9614edb1e1641235b9e6a493e7b56a5c07bc0165 (patch) | |
tree | e83c53ba99b94aec8451623d969399f50a0f77b6 | |
parent | e165e91db74d24cac3c6f21533292e0bb43d73c8 (diff) | |
download | FreeBSD-src-9614edb1e1641235b9e6a493e7b56a5c07bc0165.zip FreeBSD-src-9614edb1e1641235b9e6a493e7b56a5c07bc0165.tar.gz |
Give enough room for addresses when -W option is specified.
-rw-r--r-- | usr.bin/netstat/if.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index 8aed896..534b40e 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -272,6 +272,7 @@ intpr(void (*pfunc)(char *), int af) struct ifaddrs *ifap, *ifa; struct ifmaddrs *ifmap, *ifma; u_int ifn_len_max = 5, ifn_len; + u_int has_ipv6 = 0, net_len = 13, addr_len = 17; if (interval) return sidewaysintpr(); @@ -292,15 +293,23 @@ intpr(void (*pfunc)(char *), int af) if ((ifa->ifa_flags & IFF_UP) == 0) ++ifn_len; ifn_len_max = MAX(ifn_len_max, ifn_len); + if (ifa->ifa_addr->sa_family == AF_INET6) + has_ipv6 = 1; } + if (has_ipv6) { + net_len = 24; + addr_len = 39; + } else + net_len = 18; } xo_open_list("interface"); if (!pfunc) { xo_emit("{T:/%-*.*s}", ifn_len_max, ifn_len_max, "Name"); - xo_emit(" {T:/%5.5s} {T:/%-13.13s} {T:/%-17.17s} {T:/%8.8s} " + xo_emit(" {T:/%5.5s} {T:/%-*.*s} {T:/%-*.*s} {T:/%8.8s} " "{T:/%5.5s} {T:/%5.5s}", - "Mtu", "Network", "Address", "Ipkts", "Ierrs", "Idrop"); + "Mtu", net_len, net_len, "Network", addr_len, addr_len, + "Address", "Ipkts", "Ierrs", "Idrop"); if (bflag) xo_emit(" {T:/%10.10s}","Ibytes"); xo_emit(" {T:/%8.8s} {T:/%5.5s}", "Opkts", "Oerrs"); @@ -357,22 +366,26 @@ intpr(void (*pfunc)(char *), int af) switch (ifa->ifa_addr->sa_family) { case AF_UNSPEC: - xo_emit("{:network/%-13.13s} ", "none"); - xo_emit("{:address/%-15.15s} ", "none"); + xo_emit("{:network/%-*.*s} ", net_len, net_len, + "none"); + xo_emit("{:address/%-*.*s} ", addr_len, addr_len, + "none"); break; case AF_INET: #ifdef INET6 case AF_INET6: #endif /* INET6 */ if (Wflag) { - xo_emit("{t:network/%-13s} ", + xo_emit("{t:network/%-*s} ", net_len, netname(ifa->ifa_addr, ifa->ifa_netmask)); - xo_emit("{t:address/%-17s} ", + xo_emit("{t:address/%-*s} ", addr_len, routename(ifa->ifa_addr, numeric_addr)); } else { - xo_emit("{t:network/%-13.13s} ", + xo_emit("{t:network/%-*.*s} ", + net_len, net_len, netname(ifa->ifa_addr, ifa->ifa_netmask)); - xo_emit("{t:address/%-17.17s} ", + xo_emit("{t:address/%-*.*s} ", + addr_len, addr_len, routename(ifa->ifa_addr, numeric_addr)); } @@ -385,14 +398,15 @@ intpr(void (*pfunc)(char *), int af) sdl = (struct sockaddr_dl *)ifa->ifa_addr; sprintf(linknum, "<Link#%d>", sdl->sdl_index); - xo_emit("{t:network/%-13.13s} ", linknum); + xo_emit("{t:network/%-*.*s} ", net_len, net_len, + linknum); if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) xo_emit("{P: }"); else - xo_emit("{:address/%-17.17s} ", - routename(ifa->ifa_addr, 1)); + xo_emit("{:address/%-*.*s} ", addr_len, + addr_len, routename(ifa->ifa_addr, 1)); link = true; break; } |