Skip to content

Commit

Permalink
ss: Fixed broken output for Netlink 'Peer Address:Port' column
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vkochan authored and Stephen Hemminger committed Nov 29, 2014
1 parent 45a4770 commit 2dc8548
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions misc/ss.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -3031,10 +3033,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;
Expand Down Expand Up @@ -3777,9 +3779,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);

Expand Down

0 comments on commit 2dc8548

Please sign in to comment.