Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/netstat mask addresses properly on netstat -inv.



details:   https://anonhg.NetBSD.org/src/rev/091f8017df2d
branches:  trunk
changeset: 480683:091f8017df2d
user:      itojun <itojun%NetBSD.org@localhost>
date:      Mon Jan 17 17:54:56 2000 +0000

description:
mask addresses properly on netstat -inv.
From: Matt Thomas <matt%3am-software.com@localhost>

diffstat:

 usr.bin/netstat/route.c |  22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

diffs (74 lines):

diff -r ec540baf6e0d -r 091f8017df2d usr.bin/netstat/route.c
--- a/usr.bin/netstat/route.c   Mon Jan 17 17:47:03 2000 +0000
+++ b/usr.bin/netstat/route.c   Mon Jan 17 17:54:56 2000 +0000
@@ -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 @@
        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 @@
        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 @@
                                 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");



Home | Main Index | Thread Index | Old Index