Module Name: src Committed By: roy Date: Sat Oct 1 15:10:59 UTC 2016
Modified Files: src/sbin/ifconfig: af_inet.c af_inet6.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/sbin/ifconfig/af_inet.c cvs rdiff -u -r1.37 -r1.38 src/sbin/ifconfig/af_inet6.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/ifconfig/af_inet.c diff -u src/sbin/ifconfig/af_inet.c:1.22 src/sbin/ifconfig/af_inet.c:1.23 --- src/sbin/ifconfig/af_inet.c:1.22 Fri Sep 30 16:52:17 2016 +++ src/sbin/ifconfig/af_inet.c Sat Oct 1 15:10:58 2016 @@ -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 @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #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 */ #include <sys/param.h> @@ -64,6 +64,7 @@ static void in_status(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_or_detached(struct ifaddrs *); +static int in_prefixlen(struct sockaddr *); static void in_alias(struct ifaddrs *, prop_dictionary_t, prop_dictionary_t); static struct afswtch af = { @@ -73,10 +74,23 @@ static struct afswtch af = { .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 in_alias(struct ifaddrs *ifa, prop_dictionary_t env, prop_dictionary_t oenv) { - struct sockaddr_in sin; char hbuf[NI_MAXHOST]; const int niflag = Nflag ? 0 : NI_NUMERICHOST; char fbuf[1024]; @@ -88,6 +102,7 @@ in_alias(struct ifaddrs *ifa, prop_dicti hbuf, sizeof(hbuf), NULL, 0, niflag)) strlcpy(hbuf, "", sizeof(hbuf)); /* some message? */ printf("\tinet %s", hbuf); + printf("/%d", in_prefixlen(ifa->ifa_netmask)); if (ifa->ifa_flags & IFF_POINTOPOINT) { if (getnameinfo(ifa->ifa_dstaddr, ifa->ifa_dstaddr->sa_len, @@ -96,9 +111,6 @@ in_alias(struct ifaddrs *ifa, prop_dicti 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 (getnameinfo(ifa->ifa_broadaddr, ifa->ifa_broadaddr->sa_len, hbuf, sizeof(hbuf), NULL, 0, niflag)) Index: src/sbin/ifconfig/af_inet6.c diff -u src/sbin/ifconfig/af_inet6.c:1.37 src/sbin/ifconfig/af_inet6.c:1.38 --- src/sbin/ifconfig/af_inet6.c:1.37 Fri Sep 30 16:47:56 2016 +++ src/sbin/ifconfig/af_inet6.c Sat Oct 1 15:10:58 2016 @@ -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 @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #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 */ #include <sys/param.h> @@ -277,6 +277,9 @@ in6_alias(struct ifaddrs *ifa, prop_dict printf("\tinet6 %s", hbuf); 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) { sin6 = (struct sockaddr_in6 *)ifa->ifa_dstaddr; inet6_getscopeid(sin6, INET6_IS_ADDR_LINKLOCAL); @@ -287,10 +290,6 @@ in6_alias(struct ifaddrs *ifa, prop_dict 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); printf(" flags %s", fbuf);