netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrei Vagin <avagin@openvz.org>
To: stephen@networkplumber.org
Cc: netdev@vger.kernel.org, Andrei Vagin <avagin@virtuozzo.com>
Subject: [PATCH] ss: replace all zero characters in a unix name to '@'
Date: Sat,  1 Apr 2017 04:31:57 +0300	[thread overview]
Message-ID: <1491010317-27083-1-git-send-email-avagin@openvz.org> (raw)

From: Andrei Vagin <avagin@virtuozzo.com>

A name of an abstract socket can contain zero characters.
Now we replace only the first character. If a name contains more
than one zero character, the ss tool shows only a part of the name:
u_str  UNCONN    0    0     @                            1931097   * 0

the output with this patch:
u_str  UNCONN    0    0     @@zdtm-./sk-unix-unconn-23/@ 1931097   * 0

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 misc/ss.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/misc/ss.c b/misc/ss.c
index 5cda728..a3200a1 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -2726,10 +2726,24 @@ static int unix_show_sock(const struct sockaddr_nl *addr, struct nlmsghdr *nlh,
 	if (tb[UNIX_DIAG_NAME]) {
 		int len = RTA_PAYLOAD(tb[UNIX_DIAG_NAME]);
 
+		if (len > sizeof(name) - 1)
+			len = sizeof(name) - 1;
+
 		memcpy(name, RTA_DATA(tb[UNIX_DIAG_NAME]), len);
 		name[len] = '\0';
-		if (name[0] == '\0')
+		if (name[0] == '\0') {
+			char *n;
+
 			name[0] = '@';
+
+			n = name + 1;
+			while (n && n < name + len) {
+				n = memchr(n, 0, name + len - n);
+				if (n == NULL)
+					break;
+				*n = '@';
+			}
+		}
 		stat.name = &name[0];
 		memcpy(stat.local.data, &stat.name, sizeof(stat.name));
 	}
-- 
2.7.4

             reply	other threads:[~2017-04-01  1:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-01  1:31 Andrei Vagin [this message]
2017-04-04 21:44 ` [PATCH] ss: replace all zero characters in a unix name to '@' Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1491010317-27083-1-git-send-email-avagin@openvz.org \
    --to=avagin@openvz.org \
    --cc=avagin@virtuozzo.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).