Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/ifconfig Modernise the output for the address to addres...
details: https://anonhg.NetBSD.org/src/rev/7c4b59a0ecf8
branches: trunk
changeset: 818174:7c4b59a0ecf8
user: roy <roy%NetBSD.org@localhost>
date: Sat Oct 01 15:10:58 2016 +0000
description:
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.
diffstat:
sbin/ifconfig/af_inet.c | 24 ++++++++++++++++++------
sbin/ifconfig/af_inet6.c | 11 +++++------
2 files changed, 23 insertions(+), 12 deletions(-)
diffs (108 lines):
diff -r 77d006734003 -r 7c4b59a0ecf8 sbin/ifconfig/af_inet.c
--- a/sbin/ifconfig/af_inet.c Sat Oct 01 13:57:44 2016 +0000
+++ b/sbin/ifconfig/af_inet.c Sat Oct 01 15:10:58 2016 +0000
@@ -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_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 @@
.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 @@
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 @@
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))
diff -r 77d006734003 -r 7c4b59a0ecf8 sbin/ifconfig/af_inet6.c
--- a/sbin/ifconfig/af_inet6.c Sat Oct 01 13:57:44 2016 +0000
+++ b/sbin/ifconfig/af_inet6.c Sat Oct 01 15:10:58 2016 +0000
@@ -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 @@
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 @@
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);
Home |
Main Index |
Thread Index |
Old Index