Source-Changes-HG archive

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

[src/netbsd-7]: src Pull up following revision(s) (requested by prlw1 in tick...



details:   https://anonhg.NetBSD.org/src/rev/c7e6de273701
branches:  netbsd-7
changeset: 798803:c7e6de273701
user:      martin <martin%NetBSD.org@localhost>
date:      Thu Jan 08 11:47:11 2015 +0000

description:
Pull up following revision(s) (requested by prlw1 in ticket #395):
        sbin/route/rtutil.c: revision 1.4
        sbin/route/rtutil.h: revision 1.3
        usr.bin/netstat/if.c: revision 1.81
make netname4 match the netname6 signature avoiding a NULL pointer.
adjust to the netname4 prototype.

diffstat:

 sbin/route/rtutil.c  |  26 ++++++++++++++++----------
 sbin/route/rtutil.h  |   2 +-
 usr.bin/netstat/if.c |  23 ++++++-----------------
 3 files changed, 23 insertions(+), 28 deletions(-)

diffs (130 lines):

diff -r 9bae8a7841e7 -r c7e6de273701 sbin/route/rtutil.c
--- a/sbin/route/rtutil.c       Thu Jan 08 11:39:37 2015 +0000
+++ b/sbin/route/rtutil.c       Thu Jan 08 11:47:11 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtutil.c,v 1.4.2.2 2015/01/08 11:01:01 martin Exp $    */
+/*     $NetBSD: rtutil.c,v 1.4.2.3 2015/01/08 11:47:11 martin Exp $    */
 /*     $OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $        */
 
 /*
@@ -548,21 +548,27 @@
  * The address is assumed to be that of a net or subnet, not a host.
  */
 char *
-netname4(in_addr_t in, in_addr_t mask, int flags)
+netname4(const struct sockaddr_in* sa4, const struct sockaddr_in *mask, int flags)
 {
        const char *cp = NULL;
        struct netent *np = NULL;
        int mbits;
+       in_addr_t in = sa4->sin_addr.s_addr;
+
+       if (mask) {
+               in_addr_t m = mask->sin_addr.s_addr ;
+               m = ntohl(m);
+               mbits = m ? 33 - ffs(m) : 0;
+       } else
+               mbits = 0;
 
        in = ntohl(in);
-       mask = ntohl(mask);
-       if (!(flags & RT_NFLAG) && in != INADDR_ANY) {
+       if (in == INADDR_ANY && !mbits)
+               cp = "default";
+       else if (!(flags & RT_NFLAG) && in != INADDR_ANY) {
                if ((np = getnetbyaddr(in, AF_INET)) != NULL)
                        cp = np->n_name;
        }
-       mbits = mask ? 33 - ffs(mask) : 0;
-       if (in == INADDR_ANY && !mbits)
-                       cp = "default";
        if (cp)
                strlcpy(line, cp, sizeof(line));
 #define C(x)   ((x) & 0xff)
@@ -578,7 +584,7 @@
                snprintf(line, sizeof(line), "%u.%u.%u.%u/%d", C(in >> 24),
                    C(in >> 16), C(in >> 8), C(in), mbits);
 #undef C
-       return (line);
+       return line;
 }
 
 #ifdef INET6
@@ -689,8 +695,8 @@
        switch (sa->sa_family) {
 
        case AF_INET:
-               return netname4(((const struct sockaddr_in *)sa)->sin_addr.s_addr,
-                   ((const struct sockaddr_in *)mask)->sin_addr.s_addr, flags);
+               return netname4((const struct sockaddr_in *)sa,
+                   (const struct sockaddr_in *)mask, flags);
 #ifdef INET6
        case AF_INET6:
                return netname6((const struct sockaddr_in6 *)sa,
diff -r 9bae8a7841e7 -r c7e6de273701 sbin/route/rtutil.h
--- a/sbin/route/rtutil.h       Thu Jan 08 11:39:37 2015 +0000
+++ b/sbin/route/rtutil.h       Thu Jan 08 11:47:11 2015 +0000
@@ -52,7 +52,7 @@
 char *netname6(const struct sockaddr_in6 *, const struct sockaddr_in6 *, int);
 #endif
 char *netname(const struct sockaddr *, const struct sockaddr *, int);
-char *netname4(in_addr_t, in_addr_t, int);
+char *netname4(const struct sockaddr_in *, const struct sockaddr_in *, int);
 
 char *mpls_ntoa(const struct sockaddr *);
 char *any_ntoa(const struct sockaddr *);
diff -r 9bae8a7841e7 -r c7e6de273701 usr.bin/netstat/if.c
--- a/usr.bin/netstat/if.c      Thu Jan 08 11:39:37 2015 +0000
+++ b/usr.bin/netstat/if.c      Thu Jan 08 11:47:11 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.79.4.1 2015/01/08 11:01:01 martin Exp $       */
+/*     $NetBSD: if.c,v 1.79.4.2 2015/01/08 11:47:11 martin Exp $       */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.79.4.1 2015/01/08 11:01:01 martin Exp $");
+__RCSID("$NetBSD: if.c,v 1.79.4.2 2015/01/08 11:47:11 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -337,7 +337,7 @@
        const int niflag = NI_NUMERICHOST;
        struct sockaddr_in6 *sin6, *netmask6;
 #endif
-       in_addr_t netmask;
+       struct sockaddr_in netmask;
        struct sockaddr_in *sin;
        char *cp;
        int n, m;
@@ -349,24 +349,13 @@
                break;
        case AF_INET:
                sin = (struct sockaddr_in *)sa;
-#ifdef notdef
-               /*
-                * can't use inet_makeaddr because kernel
-                * keeps nets unshifted.
-                */
-               in = inet_makeaddr(ifaddr.in.ia_subnet,
-                       INADDR_ANY);
-               cp = netname4(in.s_addr,
-                       ifaddr.in.ia_subnetmask, nflag);
-#else
                if (use_sysctl) {
-                       netmask = ((struct sockaddr_in *)rtinfo[RTAX_NETMASK])->sin_addr.s_addr;
+                       netmask = *((struct sockaddr_in *)rtinfo[RTAX_NETMASK]);
                } else {
                        struct in_ifaddr *ifaddr_in = (void *)rtinfo;
-                       netmask = ifaddr_in->ia_subnetmask;
+                       netmask.sin_addr.s_addr = ifaddr_in->ia_subnetmask;
                }
-               cp = netname4(sin->sin_addr.s_addr, netmask, nflag);
-#endif
+               cp = netname4(sin, &netmask, nflag);
                if (vflag)
                        n = strlen(cp) < 13 ? 13 : strlen(cp);
                else



Home | Main Index | Thread Index | Old Index