netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] ss: Fixed broken output for Netlink 'Peer Address:Port' column
@ 2014-10-18 17:46 Vadim Kochan
  0 siblings, 0 replies; only message in thread
From: Vadim Kochan @ 2014-10-18 17:46 UTC (permalink / raw)
  To: netdev; +Cc: Vadim Kochan

When output the netlink sockets:

    ss -A netlink state close

the layout is a little broken with a shifted 'Peer Address:Port'
stars and empty new lines. Fixed by making the port field to be
wider for 'Local Address:Port' column.

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
---
 misc/ss.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index 2420b51..0f89588 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -88,6 +88,8 @@ int state_width;
 int addrp_width;
 int addr_width;
 int serv_width;
+int paddr_width;
+int pserv_width;
 int screen_width;
 
 static const char *TCP_PROTO = "tcp";
@@ -3020,10 +3022,10 @@ static void netlink_show_one(struct filter *f,
 
 	if (state == NETLINK_CONNECTED) {
 		printf("%*d:%-*d",
-		       addr_width, dst_group, serv_width, dst_pid);
+		       paddr_width, dst_group, pserv_width, dst_pid);
 	} else {
 		printf("%*s*%-*s",
-		       addr_width, "", serv_width, "");
+		       paddr_width, "", pserv_width, "");
 	}
 
 	char *pid_context = NULL;
@@ -3769,9 +3771,22 @@ int main(int argc, char *argv[])
 		printf("%-*s ", state_width, "State");
 	printf("%-6s %-6s ", "Recv-Q", "Send-Q");
 
+	paddr_width = addr_width;
+	pserv_width = serv_width;
+
+	/* Netlink service column can be resolved as process name/pid thus it
+	 * can be much wider than address column which is just a
+	 * protocol name/id.
+	 */
+	if (current_filter.dbs & (1<<NETLINK_DB)) {
+		serv_width = addr_width - 10;
+		paddr_width = 13;
+		pserv_width = 13;
+	}
+
 	printf("%*s:%-*s %*s:%-*s\n",
 	       addr_width, "Local Address", serv_width, "Port",
-	       addr_width, "Peer Address", serv_width, "Port");
+	       paddr_width, "Peer Address", pserv_width, "Port");
 
 	fflush(stdout);
 
-- 
2.1.0

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2014-10-18 17:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-18 17:46 [PATCH iproute2] ss: Fixed broken output for Netlink 'Peer Address:Port' column Vadim Kochan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).