Date: Thu, 5 Nov 2015 11:06:47 +0000 (UTC) From: Hajimu UMEMOTO <ume@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290391 - head/usr.bin/netstat Message-ID: <201511051106.tA5B6l1o044349@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ume Date: Thu Nov 5 11:06:46 2015 New Revision: 290391 URL: https://svnweb.freebsd.org/changeset/base/290391 Log: Give enough room for addresses when -W option is specified. Modified: head/usr.bin/netstat/if.c Modified: head/usr.bin/netstat/if.c ============================================================================== --- head/usr.bin/netstat/if.c Thu Nov 5 11:04:43 2015 (r290390) +++ head/usr.bin/netstat/if.c Thu Nov 5 11:06:46 2015 (r290391) @@ -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; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201511051106.tA5B6l1o044349>