From owner-svn-src-all@freebsd.org Wed Nov 4 14:57:48 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 37564A26478; Wed, 4 Nov 2015 14:57:48 +0000 (UTC) (envelope-from ume@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D306C1BDB; Wed, 4 Nov 2015 14:57:47 +0000 (UTC) (envelope-from ume@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tA4EvkbO048271; Wed, 4 Nov 2015 14:57:46 GMT (envelope-from ume@FreeBSD.org) Received: (from ume@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tA4EvkBs048270; Wed, 4 Nov 2015 14:57:46 GMT (envelope-from ume@FreeBSD.org) Message-Id: <201511041457.tA4EvkBs048270@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ume set sender to ume@FreeBSD.org using -f From: Hajimu UMEMOTO Date: Wed, 4 Nov 2015 14:57:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r290367 - head/usr.bin/netstat X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Nov 2015 14:57:48 -0000 Author: ume Date: Wed Nov 4 14:57:46 2015 New Revision: 290367 URL: https://svnweb.freebsd.org/changeset/base/290367 Log: Change to not truncate an interface name 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 Wed Nov 4 14:47:10 2015 (r290366) +++ head/usr.bin/netstat/if.c Wed Nov 4 14:57:46 2015 (r290367) @@ -271,7 +271,9 @@ intpr(void (*pfunc)(char *), int af) { struct ifaddrs *ifap, *ifa; struct ifmaddrs *ifmap, *ifma; - + u_int ifn_len_max = 5, ifn_len; + char ifn_hdr_fmt[14], ifn_bdy_fmt[41]; + if (interval) return sidewaysintpr(); @@ -280,12 +282,28 @@ intpr(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 = strlen(ifa->ifa_name); + if ((ifa->ifa_flags & IFF_UP) == 0) + ++ifn_len; + ifn_len_max = MAX(ifn_len_max, ifn_len); + } + } + snprintf(ifn_hdr_fmt, sizeof(ifn_hdr_fmt), "{T:/%%-%d.%ds}", + ifn_len_max, ifn_len_max); + snprintf(ifn_bdy_fmt, sizeof(ifn_bdy_fmt), + "{etk:name/%%s}{e:flags/0x%%x}{d:/%%-%d.%ds}", ifn_len_max, + ifn_len_max); + xo_open_list("interface"); if (!pfunc) { - if (Wflag) - xo_emit("{T:/%-7.7s}", "Name"); - else - xo_emit("{T:/%-5.5s}", "Name"); + xo_emit(ifn_hdr_fmt, "Name"); xo_emit(" {T:/%5.5s} {T:/%-13.13s} {T:/%-17.17s} {T:/%8.8s} " "{T:/%5.5s} {T:/%5.5s}", "Mtu", "Network", "Address", "Ipkts", "Ierrs", "Idrop"); @@ -336,12 +354,7 @@ intpr(void (*pfunc)(char *), int af) } else xname = name; - if (Wflag) - xo_emit("{etk:name/%s}{e:flags/0x%x}{d:/%-7.7s}", - name, ifa->ifa_flags, xname); - else - xo_emit("{etk:name/%s}{e:flags/0x%x}{d:/%-5.5s}", - name, ifa->ifa_flags, xname); + xo_emit(ifn_bdy_fmt, name, ifa->ifa_flags, xname); #define IFA_MTU(ifa) (((struct if_data *)(ifa)->ifa_data)->ifi_mtu) show_stat("lu", 6, "mtu", IFA_MTU(ifa), IFA_MTU(ifa), 0);