From owner-svn-src-head@freebsd.org Tue Dec 1 16:04:52 2015 Return-Path: Delivered-To: svn-src-head@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 751EEA3D89E; Tue, 1 Dec 2015 16:04:52 +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 2493B1DA9; Tue, 1 Dec 2015 16:04:52 +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 tB1G4pBh000699; Tue, 1 Dec 2015 16:04:51 GMT (envelope-from ume@FreeBSD.org) Received: (from ume@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tB1G4pHa000698; Tue, 1 Dec 2015 16:04:51 GMT (envelope-from ume@FreeBSD.org) Message-Id: <201512011604.tB1G4pHa000698@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ume set sender to ume@FreeBSD.org using -f From: Hajimu UMEMOTO Date: Tue, 1 Dec 2015 16:04:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r291592 - 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-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Dec 2015 16:04:52 -0000 Author: ume Date: Tue Dec 1 16:04:50 2015 New Revision: 291592 URL: https://svnweb.freebsd.org/changeset/base/291592 Log: At the time a destination or a gateway of `netstat -r' protrudes its field, narrow the next field to raise readability bit. Modified: head/usr.bin/netstat/route.c Modified: head/usr.bin/netstat/route.c ============================================================================== --- head/usr.bin/netstat/route.c Tue Dec 1 15:55:20 2015 (r291591) +++ head/usr.bin/netstat/route.c Tue Dec 1 16:04:50 2015 (r291592) @@ -107,7 +107,7 @@ static const char *netname4(in_addr_t, i static const char *netname6(struct sockaddr_in6 *, struct sockaddr_in6 *); static void p_rtable_sysctl(int, int); static void p_rtentry_sysctl(const char *name, struct rt_msghdr *); -static void p_sockaddr(const char *name, struct sockaddr *, struct sockaddr *, +static int p_sockaddr(const char *name, struct sockaddr *, struct sockaddr *, int, int); static const char *fmt_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags); @@ -352,7 +352,7 @@ p_rtentry_sysctl(const char *name, struc struct sockaddr *sa, *addr[RTAX_MAX]; char buffer[128]; char prettyname[128]; - int i; + int i, protrusion; xo_open_instance(name); sa = (struct sockaddr *)(rtm + 1); @@ -362,11 +362,13 @@ p_rtentry_sysctl(const char *name, struc sa = (struct sockaddr *)((char *)sa + SA_SIZE(sa)); } - p_sockaddr("destination", addr[RTAX_DST], addr[RTAX_NETMASK], + protrusion = p_sockaddr("destination", addr[RTAX_DST], + addr[RTAX_NETMASK], rtm->rtm_flags, wid_dst); - p_sockaddr("gateway", addr[RTAX_GATEWAY], NULL, RTF_HOST, wid_gw); + protrusion = p_sockaddr("gateway", addr[RTAX_GATEWAY], NULL, RTF_HOST, + wid_gw - protrusion); snprintf(buffer, sizeof(buffer), "{[:-%d}{:flags/%%s}{]:} ", - wid_flags); + wid_flags - protrusion); p_flags(rtm->rtm_flags, buffer); if (Wflag) { xo_emit("{t:use/%*lu} ", wid_pksent, rtm->rtm_rmx.rmx_pksent); @@ -402,12 +404,13 @@ p_rtentry_sysctl(const char *name, struc xo_close_instance(name); } -static void +static int p_sockaddr(const char *name, struct sockaddr *sa, struct sockaddr *mask, int flags, int width) { const char *cp; char buf[128]; + int protrusion; cp = fmt_sockaddr(sa, mask, flags); @@ -419,12 +422,17 @@ p_sockaddr(const char *name, struct sock snprintf(buf, sizeof(buf), "{[:%d}{:%s/%%s}{]:} ", -width, name); xo_emit(buf, cp); + protrusion = strlen(cp) - width; + if (protrusion < 0) + protrusion = 0; } else { snprintf(buf, sizeof(buf), "{[:%d}{:%s/%%-.*s}{]:} ", -width, name); xo_emit(buf, width, cp); + protrusion = 0; } } + return (protrusion); } static const char *