From 41ee1916cce90e45bc6f9a2f482d7d3d94fefd86 Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 8 Jan 2015 11:47:11 +0000 Subject: [PATCH] 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. --- sbin/route/rtutil.c | 26 ++++++++++++++++---------- sbin/route/rtutil.h | 2 +- usr.bin/netstat/if.c | 23 ++++++----------------- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/sbin/route/rtutil.c b/sbin/route/rtutil.c index dca2e4ab0349..8d0841b50a0b 100644 --- a/sbin/route/rtutil.c +++ b/sbin/route/rtutil.c @@ -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 @@ routename6(const struct sockaddr_in6 *sin6, int flags) * 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 @@ netname4(in_addr_t in, in_addr_t mask, int flags) 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 @@ netname(const struct sockaddr *sa, const struct sockaddr *mask, int flags) 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 --git a/sbin/route/rtutil.h b/sbin/route/rtutil.h index 016e4fcc7536..4f1e2498cd0b 100644 --- a/sbin/route/rtutil.h +++ b/sbin/route/rtutil.h @@ -52,7 +52,7 @@ char *routename6(const struct sockaddr_in6 *, int); 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 --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index 9d627b3f1218..fd81b3cb1879 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -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 @@ print_addr(struct sockaddr *sa, struct sockaddr **rtinfo, struct if_data *ifd, 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 @@ print_addr(struct sockaddr *sa, struct sockaddr **rtinfo, struct if_data *ifd, 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