Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Dec 2015 16:04:51 +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: r291592 - head/usr.bin/netstat
Message-ID:  <201512011604.tB1G4pHa000698@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 *



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201512011604.tB1G4pHa000698>