Source-Changes-HG archive

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

[src/trunk]: src/sbin/route make netname4 match the netname6 signature avoidi...



details:   https://anonhg.NetBSD.org/src/rev/51193b5f9f43
branches:  trunk
changeset: 335464:51193b5f9f43
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jan 07 22:38:32 2015 +0000

description:
make netname4 match the netname6 signature avoiding a NULL pointer.

diffstat:

 sbin/route/rtutil.c |  26 ++++++++++++++++----------
 sbin/route/rtutil.h |   2 +-
 2 files changed, 17 insertions(+), 11 deletions(-)

diffs (75 lines):

diff -r a968a1fbd102 -r 51193b5f9f43 sbin/route/rtutil.c
--- a/sbin/route/rtutil.c       Wed Jan 07 22:26:50 2015 +0000
+++ b/sbin/route/rtutil.c       Wed Jan 07 22:38:32 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtutil.c,v 1.3 2014/11/12 03:34:08 christos Exp $      */
+/*     $NetBSD: rtutil.c,v 1.4 2015/01/07 22:38:32 christos Exp $      */
 /*     $OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $        */
 
 /*
@@ -552,21 +552,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)
@@ -582,7 +588,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
@@ -693,8 +699,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 a968a1fbd102 -r 51193b5f9f43 sbin/route/rtutil.h
--- a/sbin/route/rtutil.h       Wed Jan 07 22:26:50 2015 +0000
+++ b/sbin/route/rtutil.h       Wed Jan 07 22:38:32 2015 +0000
@@ -53,7 +53,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 *);



Home | Main Index | Thread Index | Old Index