git: 9206c7996198 - main - usr.bin/netstat: -n should not print symbolic names

From: Allan Jude <allanjude_at_FreeBSD.org>
Date: Tue, 26 Nov 2024 14:57:05 UTC
The branch main has been updated by allanjude:

URL: https://cgit.FreeBSD.org/src/commit/?id=9206c79961986c2114a9a2cfccf009ac010ad259

commit 9206c79961986c2114a9a2cfccf009ac010ad259
Author:     Allan Jude <allanjude@FreeBSD.org>
AuthorDate: 2024-11-26 14:54:04 +0000
Commit:     Allan Jude <allanjude@FreeBSD.org>
CommitDate: 2024-11-26 14:56:21 +0000

    usr.bin/netstat: -n should not print symbolic names
    
    In numeric mode, the default route is printed as "default" rather
    than 0.0.0.0/0 or ::/0
    
    From the man page:
    "-n: Show network addresses and ports as numbers.
    Normally netstat attempts to resolve addresses and ports, and display
    them symbolically.  If the -n option is specified, the address is
    printed numerically, according to the address family.
    For more information regarding the Internet IPv4 ``dot format'', refer
    to inet(3).  Unspecified, or `wildcard'', addresses and ports appear
    as `*''."
    
    Reported By:    rgrimes
    Reviewed by:    emaste, ngie, eadler, seanc
    Relnotes:       yes
    Sponsored by:   Klara, Inc.
    Differential Revision:  https://reviews.freebsd.org/D10320
---
 usr.bin/netstat/route.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index 74797e2addb8..c54b1e61aa11 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -578,7 +578,7 @@ netname4(in_addr_t in, in_addr_t mask)
 	struct netent *np = 0;
 	in_addr_t i;
 
-	if (in == INADDR_ANY && mask == 0) {
+	if (!numeric_addr && in == INADDR_ANY && mask == 0) {
 		strlcpy(line, "default", sizeof(line));
 		return (line);
 	}
@@ -673,7 +673,8 @@ netname6(struct sockaddr_in6 *sa6, struct sockaddr_in6 *mask)
 	else
 		masklen = 128;
 
-	if (masklen == 0 && IN6_IS_ADDR_UNSPECIFIED(&sa6->sin6_addr))
+	if (!numeric_addr && masklen == 0 &&
+	    IN6_IS_ADDR_UNSPECIFIED(&sa6->sin6_addr))
 		return("default");
 
 	getnameinfo((struct sockaddr *)sa6, sa6->sin6_len, nline, sizeof(nline),