]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ss: enclose IPv6 address in brackets
authorStephen Hemminger <stephen@networkplumber.org>
Fri, 4 Aug 2017 19:02:41 +0000 (12:02 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 4 Aug 2017 19:04:04 +0000 (12:04 -0700)
Based on patch by Lehner Florian <dev@der-flo.net>

Adds support for RFC2732 IPv6 address format with brackets.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
misc/ss.c

index 12763c9f426865e06eda6fff61358f9920cf03c8..f0d1c22f75cffce3411b0d7da927d3d72cb8fdf0 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1059,12 +1059,25 @@ static void inet_addr_print(const inet_prefix *a, int port, unsigned int ifindex
                        ap = format_host(AF_INET, 4, a->data);
                }
        } else {
-               ap = format_host(a->family, 16, a->data);
-               est_len = strlen(ap);
-               if (est_len <= addr_width)
-                       est_len = addr_width;
-               else
-                       est_len = addr_width + ((est_len-addr_width+3)/4)*4;
+               if (!memcmp(a->data, &in6addr_any, sizeof(in6addr_any))) {
+                       buf[0] = '*';
+                       buf[1] = 0;
+               } else {
+                       ap = format_host(a->family, 16, a->data);
+
+                       /* Numeric IPv6 addresses should be bracketed */
+                       if (strchr(ap, ':')) {
+                               snprintf(buf, sizeof(buf),
+                                        "[%s]", ap);
+                               ap = buf;
+                       }
+
+                       est_len = strlen(ap);
+                       if (est_len <= addr_width)
+                               est_len = addr_width;
+                       else
+                               est_len = addr_width + ((est_len-addr_width+3)/4)*4;
+               }
        }
 
        if (ifindex) {