diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 58508b6a354f..559b20917b8e 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -1,4 +1,4 @@ -/* $NetBSD: route.c,v 1.46 2000/01/15 01:39:54 hubertf Exp $ */ +/* $NetBSD: route.c,v 1.47 2000/01/17 17:54:56 itojun Exp $ */ /* * Copyright (c) 1983, 1988, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94"; #else -__RCSID("$NetBSD: route.c,v 1.46 2000/01/15 01:39:54 hubertf Exp $"); +__RCSID("$NetBSD: route.c,v 1.47 2000/01/17 17:54:56 itojun Exp $"); #endif #endif /* not lint */ @@ -804,7 +804,7 @@ netname6(sa6, mask) struct in6_addr *mask; { static char line[NI_MAXHOST]; - u_char *p; + u_char *p, *q; u_char *lim; int masklen, final = 0, illegal = 0; #ifdef KAME_SCOPEID @@ -813,13 +813,18 @@ netname6(sa6, mask) int flag = 0; #endif int error; + struct sockaddr_in6 sin6; + sin6 = *sa6; if (mask) { masklen = 0; lim = (u_char *)mask + 16; - for (p = (u_char *)mask; p < lim; p++) { + for (p = (u_char *)mask, q = (u_char *)&sin6.sin6_addr; + p < lim; + p++, q++) { if (final && *p) { illegal++; + *q = 0; continue; } @@ -863,19 +868,24 @@ netname6(sa6, mask) illegal++; break; } + + if (!illegal) + *q &= *p; + else + *q = 0; } } else masklen = 128; - if (masklen == 0 && IN6_IS_ADDR_UNSPECIFIED(&sa6->sin6_addr)) + if (masklen == 0 && IN6_IS_ADDR_UNSPECIFIED(&sin6.sin6_addr)) return("default"); if (illegal) fprintf(stderr, "illegal prefixlen\n"); if (nflag) flag |= NI_NUMERICHOST; - error = getnameinfo((struct sockaddr *)sa6, sa6->sin6_len, + error = getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, line, sizeof(line), NULL, 0, flag); if (error) strcpy(line, "invalid");