git: 2cd55edbb288 - stable/13 - netstat: reduce use of historical Internet classes

From: Mike Karels <karels_at_FreeBSD.org>
Date: Fri, 10 Dec 2021 16:29:15 UTC
The branch stable/13 has been updated by karels:

URL: https://cgit.FreeBSD.org/src/commit/?id=2cd55edbb2887c0ceeb10cdbe776a99059fa85fa

commit 2cd55edbb2887c0ceeb10cdbe776a99059fa85fa
Author:     Mike Karels <karels@FreeBSD.org>
AuthorDate: 2021-10-27 03:39:10 +0000
Commit:     Mike Karels <karels@FreeBSD.org>
CommitDate: 2021-12-10 16:27:02 +0000

    netstat: reduce use of historical Internet classes
    
    When attempting to characterize bound addresses, netstat was checking
    for host 0 on a (historical) net using inet_lnaof().  Such addresses
    are not normally bound, as they would not work, with the exception
    of the unspecified address, INADDR_ANY.  Check for that explicitly.
    Similarly, don't check bound addresses for a match to a network name.
    
    (cherry picked from commit bd27c71c4573e14916ccd27e545a69606f0a8192)
---
 usr.bin/netstat/inet.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c
index 49478c4a9247..b46f5c92e808 100644
--- a/usr.bin/netstat/inet.c
+++ b/usr.bin/netstat/inet.c
@@ -296,14 +296,14 @@ protopr(u_long off, const char *name, int af1, int proto)
 		    (
 		     (istcp && tp->t_state == TCPS_LISTEN)
 		     || (af1 == AF_INET &&
-		      inet_lnaof(inp->inp_laddr) == INADDR_ANY)
+		      inp->inp_laddr.s_addr == INADDR_ANY)
 #ifdef INET6
 		     || (af1 == AF_INET6 &&
 			 IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
 #endif /* INET6 */
 		     || (af1 == AF_UNSPEC &&
 			 (((inp->inp_vflag & INP_IPV4) != 0 &&
-			   inet_lnaof(inp->inp_laddr) == INADDR_ANY)
+			   inp->inp_laddr.s_addr == INADDR_ANY)
 #ifdef INET6
 			  || ((inp->inp_vflag & INP_IPV6) != 0 &&
 			      IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr))
@@ -1471,24 +1471,13 @@ inetname(struct in_addr *inp)
 	char *cp;
 	static char line[MAXHOSTNAMELEN];
 	struct hostent *hp;
-	struct netent *np;
 
 	cp = 0;
 	if (!numeric_addr && inp->s_addr != INADDR_ANY) {
-		int net = inet_netof(*inp);
-		int lna = inet_lnaof(*inp);
-
-		if (lna == INADDR_ANY) {
-			np = getnetbyaddr(net, AF_INET);
-			if (np)
-				cp = np->n_name;
-		}
-		if (cp == NULL) {
-			hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET);
-			if (hp) {
-				cp = hp->h_name;
-				trimdomain(cp, strlen(cp));
-			}
+		hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET);
+		if (hp) {
+			cp = hp->h_name;
+			trimdomain(cp, strlen(cp));
 		}
 	}
 	if (inp->s_addr == INADDR_ANY)