summaryrefslogtreecommitdiffstats
path: root/sbin/ifconfig/af_inet6.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/ifconfig/af_inet6.c')
-rw-r--r--sbin/ifconfig/af_inet6.c47
1 files changed, 36 insertions, 11 deletions
diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c
index 6a24125..0c8e952 100644
--- a/sbin/ifconfig/af_inet6.c
+++ b/sbin/ifconfig/af_inet6.c
@@ -65,6 +65,7 @@ static int ip6lifetime;
static int prefix(void *, int);
static char *sec2str(time_t);
static int explicit_prefix = 0;
+extern char *f_inet6, *f_addr, *f_scope;
extern void setnd6flags(const char *, int, int, const struct afswtch *);
extern void setnd6defif(const char *, int, int, const struct afswtch *);
@@ -172,9 +173,10 @@ in6_status(int s __unused, const struct ifaddrs *ifa)
struct in6_ifreq ifr6;
int s6;
u_int32_t flags6;
+ const u_int16_t *a;
struct in6_addrlifetime lifetime;
struct timespec now;
- int error;
+ int error, n_flags, i;
clock_gettime(CLOCK_MONOTONIC_FAST, &now);
@@ -206,12 +208,30 @@ in6_status(int s __unused, const struct ifaddrs *ifa)
lifetime = ifr6.ifr_ifru.ifru_lifetime;
close(s6);
- error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, addr_buf,
- sizeof(addr_buf), NULL, 0, NI_NUMERICHOST);
- if (error != 0)
- inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
- sizeof(addr_buf));
- printf("\tinet6 %s ", addr_buf);
+ if (f_addr != NULL && strcmp(f_addr, "full") == 0) {
+ a = (const u_int16_t *)&sin->sin6_addr;
+ printf("\tinet6 ");
+ for (i = 0; i < 8; i++) {
+ printf("%04hx", ntohs(*(a + i)));
+ if (i < 7)
+ printf(":");
+ }
+ } else {
+ if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0)
+ n_flags = 0;
+ else if (f_addr != NULL && strcmp(f_addr, "host") == 0)
+ n_flags = NI_NOFQDN;
+ else
+ n_flags = NI_NUMERICHOST;
+ error = getnameinfo((struct sockaddr *)sin, sin->sin6_len,
+ addr_buf, sizeof(addr_buf), NULL, 0,
+ n_flags);
+ if (error != 0 ||
+ (f_scope != NULL && strcmp(f_scope, "none") == 0))
+ inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
+ sizeof(addr_buf));
+ printf("\tinet6 %s", addr_buf);
+ }
if (ifa->ifa_flags & IFF_POINTOPOINT) {
sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr;
@@ -229,15 +249,19 @@ in6_status(int s __unused, const struct ifaddrs *ifa)
if (error != 0)
inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
sizeof(addr_buf));
- printf("--> %s ", addr_buf);
+ printf(" --> %s ", addr_buf);
}
}
sin = (struct sockaddr_in6 *)ifa->ifa_netmask;
if (sin == NULL)
sin = &null_sin;
- printf("prefixlen %d ", prefix(&sin->sin6_addr,
- sizeof(struct in6_addr)));
+ if (f_inet6 != NULL && strcmp(f_inet6, "cidr") == 0)
+ printf("/%d ", prefix(&sin->sin6_addr,
+ sizeof(struct in6_addr)));
+ else
+ printf(" prefixlen %d ", prefix(&sin->sin6_addr,
+ sizeof(struct in6_addr)));
if ((flags6 & IN6_IFF_ANYCAST) != 0)
printf("anycast ");
@@ -256,7 +280,8 @@ in6_status(int s __unused, const struct ifaddrs *ifa)
if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0)
printf("prefer_source ");
- if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id)
+ if ((f_scope == NULL || strcmp(f_scope, "none") != 0) &&
+ ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id)
printf("scopeid 0x%x ",
((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id);
OpenPOWER on IntegriCloud