Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Feb 2007 22:57:13 +0000
From:      Bruce M Simpson <bms@incunabulum.net>
To:        net@FreeBSD.org
Subject:   [PATCH] netstat(1) should print CIDR prefixes
Message-ID:  <45CE4DC9.4050605@incunabulum.net>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------050407040501050603060107
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

This is a POLA violating 'let's move with the times' patch that gets rid 
of the special treatment of classful IPv4 network prefixes in 'netstat 
-rn' output. Comments please!

Rgards,
BMS

--------------050407040501050603060107
Content-Type: text/x-patch;
 name="route-cidr-pola.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="route-cidr-pola.diff"

Index: route.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/netstat/route.c,v
retrieving revision 1.76
diff -u -p -r1.76 route.c
--- route.c	13 May 2005 16:31:10 -0000	1.76
+++ route.c	10 Feb 2007 22:55:50 -0000
@@ -865,32 +865,7 @@ netname(u_long in, u_long mask)
 		strncpy(line, cp, sizeof(line) - 1);
 		line[sizeof(line) - 1] = '\0';
 	} else {
-		switch (dmask) {
-		case IN_CLASSA_NET:
-			if ((i & IN_CLASSA_HOST) == 0) {
-				sprintf(line, "%lu", C(i >> 24));
-				break;
-			}
-			/* FALLTHROUGH */
-		case IN_CLASSB_NET:
-			if ((i & IN_CLASSB_HOST) == 0) {
-				sprintf(line, "%lu.%lu",
-					C(i >> 24), C(i >> 16));
-				break;
-			}
-			/* FALLTHROUGH */
-		case IN_CLASSC_NET:
-			if ((i & IN_CLASSC_HOST) == 0) {
-				sprintf(line, "%lu.%lu.%lu",
-					C(i >> 24), C(i >> 16), C(i >> 8));
-				break;
-			}
-			/* FALLTHROUGH */
-		default:
-			sprintf(line, "%lu.%lu.%lu.%lu",
-				C(i >> 24), C(i >> 16), C(i >> 8), C(i));
-			break;
-		}
+		inet_ntop(AF_INET, (char *)&in, line, sizeof(line) - 1);
 	}
 	domask(line + strlen(line), i, mask);
 	return (line);

--------------050407040501050603060107--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45CE4DC9.4050605>