git: c7444d9cb3a9 - stable/13 - systat: clean up code assuming network classes

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

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

commit c7444d9cb3a9cf7ea855a49884e7fb74490e8f9c
Author:     Mike Karels <karels@FreeBSD.org>
AuthorDate: 2021-10-28 23:39:43 +0000
Commit:     Mike Karels <karels@FreeBSD.org>
CommitDate: 2021-12-10 16:27:44 +0000

    systat: clean up code assuming network classes
    
    Similar to netstat, clean up code that uses inet_lnaof() to check for
    binding to "host 0" (lowest host on network) as a "network" bind.
    Such things don't happen, and current networks are seldom if ever
    found in /etc/networks.
    
    (cherry picked from commit a2e7dfca86497e535039a42cfc44cfc48209abf5)
---
 usr.bin/systat/netstat.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/usr.bin/systat/netstat.c b/usr.bin/systat/netstat.c
index a334e03beb5a..a9487c4dcc9d 100644
--- a/usr.bin/systat/netstat.c
+++ b/usr.bin/systat/netstat.c
@@ -206,7 +206,7 @@ again:
 		next = &inpcb;
 		if (!aflag) {
 			if (inpcb.inp_vflag & INP_IPV4) {
-				if (inet_lnaof(inpcb.inp_laddr) == INADDR_ANY)
+				if (inpcb.inp_laddr.s_addr == INADDR_ANY)
 					continue;
 			}
 #ifdef INET6
@@ -303,8 +303,7 @@ fetchnetstat_sysctl(void)
 
 			if (!aflag) {
 				if (xip->inp_vflag & INP_IPV4) {
-					if (inet_lnaof(xip->inp_laddr) ==
-					    INADDR_ANY)
+					if (xip->inp_laddr.s_addr == INADDR_ANY)
 						continue;
 				}
 #ifdef INET6
@@ -584,7 +583,6 @@ inetname(struct sockaddr *sa)
 	char *cp = 0;
 	static char line[NI_MAXHOST];
 	struct hostent *hp;
-	struct netent *np;
 	struct in_addr in;
 
 #ifdef INET6
@@ -601,19 +599,9 @@ inetname(struct sockaddr *sa)
 
 	in = ((struct sockaddr_in *)sa)->sin_addr;
 	if (!nflag && in.s_addr != INADDR_ANY) {
-		int net = inet_netof(in);
-		int lna = inet_lnaof(in);
-
-		if (lna == INADDR_ANY) {
-			np = getnetbyaddr(net, AF_INET);
-			if (np)
-				cp = np->n_name;
-		}
-		if (cp == NULL) {
-			hp = gethostbyaddr((char *)&in, sizeof (in), AF_INET);
-			if (hp)
-				cp = hp->h_name;
-		}
+		hp = gethostbyaddr((char *)&in, sizeof (in), AF_INET);
+		if (hp)
+			cp = hp->h_name;
 	}
 	if (in.s_addr == INADDR_ANY)
 		strcpy(line, "*");