naccyde / rpms / iproute

Forked from rpms/iproute 7 months ago
Clone

Blame SOURCES/0070-ss-enclose-IPv6-address-in-brackets.patch

36cfb7
From 765baea7751f7140571dfb0285b1fca974b3450b Mon Sep 17 00:00:00 2001
36cfb7
From: Andrea Claudi <aclaudi@redhat.com>
36cfb7
Date: Mon, 29 Apr 2019 18:03:01 +0200
36cfb7
Subject: [PATCH] ss: enclose IPv6 address in brackets
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1588122
36cfb7
Upstream Status: iproute2.git commit aba9c23a6e1cb
36cfb7
36cfb7
commit aba9c23a6e1cb134840c998df14888dca469a485
36cfb7
Author: Stephen Hemminger <stephen@networkplumber.org>
36cfb7
Date:   Fri Aug 4 12:02:41 2017 -0700
36cfb7
36cfb7
    ss: enclose IPv6 address in brackets
36cfb7
36cfb7
    Based on patch by Lehner Florian <dev@der-flo.net>
36cfb7
36cfb7
    Adds support for RFC2732 IPv6 address format with brackets.
36cfb7
36cfb7
    Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
36cfb7
---
36cfb7
 misc/ss.c | 25 +++++++++++++++++++------
36cfb7
 1 file changed, 19 insertions(+), 6 deletions(-)
36cfb7
36cfb7
diff --git a/misc/ss.c b/misc/ss.c
36cfb7
index c0cb33e96d9ec..86defc71fabc4 100644
36cfb7
--- a/misc/ss.c
36cfb7
+++ b/misc/ss.c
36cfb7
@@ -1093,12 +1093,25 @@ static void inet_addr_print(const inet_prefix *a, int port, unsigned int ifindex
36cfb7
 			ap = format_host(AF_INET, 4, a->data);
36cfb7
 		}
36cfb7
 	} else {
36cfb7
-		ap = format_host(a->family, 16, a->data);
36cfb7
-		est_len = strlen(ap);
36cfb7
-		if (est_len <= addr_width)
36cfb7
-			est_len = addr_width;
36cfb7
-		else
36cfb7
-			est_len = addr_width + ((est_len-addr_width+3)/4)*4;
36cfb7
+		if (!memcmp(a->data, &in6addr_any, sizeof(in6addr_any))) {
36cfb7
+			buf[0] = '*';
36cfb7
+			buf[1] = 0;
36cfb7
+		} else {
36cfb7
+			ap = format_host(a->family, 16, a->data);
36cfb7
+
36cfb7
+			/* Numeric IPv6 addresses should be bracketed */
36cfb7
+			if (strchr(ap, ':')) {
36cfb7
+				snprintf(buf, sizeof(buf),
36cfb7
+					 "[%s]", ap);
36cfb7
+				ap = buf;
36cfb7
+			}
36cfb7
+
36cfb7
+			est_len = strlen(ap);
36cfb7
+			if (est_len <= addr_width)
36cfb7
+				est_len = addr_width;
36cfb7
+			else
36cfb7
+				est_len = addr_width + ((est_len-addr_width+3)/4)*4;
36cfb7
+		}
36cfb7
 	}
36cfb7
 
36cfb7
 	if (ifindex) {
36cfb7
-- 
e138d9
2.21.0
36cfb7