netstat: produce numeric-ip output for non-resolved names
authorMark Marshall <mark.marshall@omicronenergy.com>
Mon, 19 Mar 2018 09:45:40 +0000 (10:45 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 27 Mar 2018 21:28:53 +0000 (23:28 +0200)
If we don't ask for numerical output, and the symbolic look-up failed
we used to get "(null)", but the numeric output would be better.

function                                             old     new   delta
ip_port_str                                          109     121     +12

Signed-off-by: Mark Marshall <mark.marshall@omicronenergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/netstat.c

index 33281e333f8325227713303b306270f7e824592a..f6bcd44ba1656dbfbc961f568a842b80d28472a9 100644 (file)
@@ -397,8 +397,11 @@ static char *ip_port_str(struct sockaddr *addr, int port, const char *proto, int
        /* Code which used "*" for INADDR_ANY is removed: it's ambiguous
         * in IPv6, while "0.0.0.0" is not. */
 
-       host = numeric ? xmalloc_sockaddr2dotted_noport(addr)
-                      : xmalloc_sockaddr2host_noport(addr);
+       host = NULL;
+       if (!numeric)
+               host = xmalloc_sockaddr2host_noport(addr);
+       if (!host)
+               host = xmalloc_sockaddr2dotted_noport(addr);
 
        host_port = xasprintf("%s:%s", host, get_sname(htons(port), proto, numeric));
        free(host);