Fix a bug in route(8)
Nuno Antunes
nuno.antunes at gmail.com
Mon Sep 10 10:37:19 PDT 2007
On 9/10/07, Nuno Antunes <nuno.antunes at gmail.com> wrote:
> On 9/10/07, Matthew Dillon <dillon at apollo.backplane.com> wrote:
> > Works here. I noticed something while testing it... netstat -rn
> > (display routes) is not displaying CIDR blocks properly. Look:
> >
> > Internet:
> > Destination Gateway Flags Refs Use Netif Expire
> > 127.0.0.1 127.0.0.1 UH 0 183 lo0
> > 128.0/8 216.240.41.5 UGSc 0 0 nfe0
> >
> > That should read 128/8, not 128.0/8. It's mixing the core classes
> > with the CIDR specification.
> >
> > Would you like to have a go at fixing that, too?
>
> Yeah, I've seen that too. I think that netstat should be teached
> better regarding CIDR. I'll have a look at it during this week.
Hi,
I think this fixes netstat.
Thanks,
Nuno
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index fd87bcc..4842639 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -890,31 +890,20 @@ 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) {
+ if (mask <= IN_CLASSA_NET &&
+ (i & IN_CLASSA_HOST) == 0) {
sprintf(line, "%lu", C(i >> 24));
- break;
- }
- /* FALLTHROUGH */
- case IN_CLASSB_NET:
- if ((i & IN_CLASSB_HOST) == 0) {
+ } else if (mask <= IN_CLASSB_NET &&
+ (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) {
+ } else if (mask <= IN_CLASSC_NET &&
+ (i & IN_CLASSC_HOST) == 0) {
sprintf(line, "%lu.%lu.%lu",
C(i >> 24), C(i >> 16), C(i >> 8));
- break;
- }
- /* FALLTHROUGH */
- default:
+ } else {
sprintf(line, "%lu.%lu.%lu.%lu",
C(i >> 24), C(i >> 16), C(i >> 8), C(i));
- break;
}
}
domask(line + strlen(line), i, mask);
More information about the Submit
mailing list