Modernise the output for the address to address/prefix instead

of differring outputs for INET and INET6.
The hex string of the INET netmask was particulary hard to read.
This commit is contained in:
roy 2016-10-01 15:10:58 +00:00
parent 6ca166beb3
commit 5174f725c2
2 changed files with 23 additions and 12 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: af_inet.c,v 1.22 2016/09/30 16:52:17 roy Exp $ */ /* $NetBSD: af_inet.c,v 1.23 2016/10/01 15:10:58 roy Exp $ */
/* /*
* Copyright (c) 1983, 1993 * Copyright (c) 1983, 1993
@ -31,7 +31,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: af_inet.c,v 1.22 2016/09/30 16:52:17 roy Exp $"); __RCSID("$NetBSD: af_inet.c,v 1.23 2016/10/01 15:10:58 roy Exp $");
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -64,6 +64,7 @@ static void in_status(prop_dictionary_t, prop_dictionary_t, bool);
static void in_commit_address(prop_dictionary_t, prop_dictionary_t); static void in_commit_address(prop_dictionary_t, prop_dictionary_t);
static bool in_addr_tentative(struct ifaddrs *); static bool in_addr_tentative(struct ifaddrs *);
static bool in_addr_tentative_or_detached(struct ifaddrs *); static bool in_addr_tentative_or_detached(struct ifaddrs *);
static int in_prefixlen(struct sockaddr *);
static void in_alias(struct ifaddrs *, prop_dictionary_t, prop_dictionary_t); static void in_alias(struct ifaddrs *, prop_dictionary_t, prop_dictionary_t);
static struct afswtch af = { static struct afswtch af = {
@ -73,10 +74,23 @@ static struct afswtch af = {
.af_addr_tentative_or_detached = in_addr_tentative_or_detached .af_addr_tentative_or_detached = in_addr_tentative_or_detached
}; };
static int
in_prefixlen(struct sockaddr *sa)
{
struct sockaddr_in sin;
in_addr_t mask;
int cidr;
memset(&sin, 0, sizeof(sin));
memcpy(&sin, sa, sa->sa_len);
mask = ntohl(sin.sin_addr.s_addr);
cidr = 33 - ffs(mask);
return cidr;
}
static void static void
in_alias(struct ifaddrs *ifa, prop_dictionary_t env, prop_dictionary_t oenv) in_alias(struct ifaddrs *ifa, prop_dictionary_t env, prop_dictionary_t oenv)
{ {
struct sockaddr_in sin;
char hbuf[NI_MAXHOST]; char hbuf[NI_MAXHOST];
const int niflag = Nflag ? 0 : NI_NUMERICHOST; const int niflag = Nflag ? 0 : NI_NUMERICHOST;
char fbuf[1024]; char fbuf[1024];
@ -88,6 +102,7 @@ in_alias(struct ifaddrs *ifa, prop_dictionary_t env, prop_dictionary_t oenv)
hbuf, sizeof(hbuf), NULL, 0, niflag)) hbuf, sizeof(hbuf), NULL, 0, niflag))
strlcpy(hbuf, "", sizeof(hbuf)); /* some message? */ strlcpy(hbuf, "", sizeof(hbuf)); /* some message? */
printf("\tinet %s", hbuf); printf("\tinet %s", hbuf);
printf("/%d", in_prefixlen(ifa->ifa_netmask));
if (ifa->ifa_flags & IFF_POINTOPOINT) { if (ifa->ifa_flags & IFF_POINTOPOINT) {
if (getnameinfo(ifa->ifa_dstaddr, ifa->ifa_dstaddr->sa_len, if (getnameinfo(ifa->ifa_dstaddr, ifa->ifa_dstaddr->sa_len,
@ -96,9 +111,6 @@ in_alias(struct ifaddrs *ifa, prop_dictionary_t env, prop_dictionary_t oenv)
printf(" -> %s", hbuf); printf(" -> %s", hbuf);
} }
memcpy(&sin, ifa->ifa_netmask, ifa->ifa_netmask->sa_len);
printf(" netmask 0x%x", ntohl(sin.sin_addr.s_addr));
if (ifa->ifa_flags & IFF_BROADCAST) { if (ifa->ifa_flags & IFF_BROADCAST) {
if (getnameinfo(ifa->ifa_broadaddr, ifa->ifa_broadaddr->sa_len, if (getnameinfo(ifa->ifa_broadaddr, ifa->ifa_broadaddr->sa_len,
hbuf, sizeof(hbuf), NULL, 0, niflag)) hbuf, sizeof(hbuf), NULL, 0, niflag))

View File

@ -1,4 +1,4 @@
/* $NetBSD: af_inet6.c,v 1.37 2016/09/30 16:47:56 roy Exp $ */ /* $NetBSD: af_inet6.c,v 1.38 2016/10/01 15:10:58 roy Exp $ */
/* /*
* Copyright (c) 1983, 1993 * Copyright (c) 1983, 1993
@ -31,7 +31,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: af_inet6.c,v 1.37 2016/09/30 16:47:56 roy Exp $"); __RCSID("$NetBSD: af_inet6.c,v 1.38 2016/10/01 15:10:58 roy Exp $");
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -277,6 +277,9 @@ in6_alias(struct ifaddrs *ifa, prop_dictionary_t env, prop_dictionary_t oenv)
printf("\tinet6 %s", hbuf); printf("\tinet6 %s", hbuf);
inet6_putscopeid(sin6, INET6_IS_ADDR_LINKLOCAL); inet6_putscopeid(sin6, INET6_IS_ADDR_LINKLOCAL);
sin6 = (struct sockaddr_in6 *)ifa->ifa_netmask;
printf("/%d", prefix(&sin6->sin6_addr, sizeof(struct in6_addr)));
if (ifa->ifa_flags & IFF_POINTOPOINT) { if (ifa->ifa_flags & IFF_POINTOPOINT) {
sin6 = (struct sockaddr_in6 *)ifa->ifa_dstaddr; sin6 = (struct sockaddr_in6 *)ifa->ifa_dstaddr;
inet6_getscopeid(sin6, INET6_IS_ADDR_LINKLOCAL); inet6_getscopeid(sin6, INET6_IS_ADDR_LINKLOCAL);
@ -287,10 +290,6 @@ in6_alias(struct ifaddrs *ifa, prop_dictionary_t env, prop_dictionary_t oenv)
printf(" -> %s", hbuf); printf(" -> %s", hbuf);
} }
sin6 = (struct sockaddr_in6 *)ifa->ifa_netmask;
printf(" prefixlen %d", prefix(&sin6->sin6_addr,
sizeof(struct in6_addr)));
(void)snprintb(fbuf, sizeof(fbuf), IN6_IFFBITS, ifa->ifa_addrflags); (void)snprintb(fbuf, sizeof(fbuf), IN6_IFFBITS, ifa->ifa_addrflags);
printf(" flags %s", fbuf); printf(" flags %s", fbuf);