diff options
Diffstat (limited to 'sbin/ifconfig/af_inet6.c')
-rw-r--r-- | sbin/ifconfig/af_inet6.c | 47 |
1 files changed, 17 insertions, 30 deletions
diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index 0c8e952..3ddf303 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -65,13 +65,13 @@ 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 char *f_inet6, *f_addr; extern void setnd6flags(const char *, int, int, const struct afswtch *); extern void setnd6defif(const char *, int, int, const struct afswtch *); extern void nd6_status(int); -static char addr_buf[MAXHOSTNAMELEN *2 + 1]; /*for getnameinfo()*/ +static char addr_buf[NI_MAXHOST]; /*for getnameinfo()*/ static void setifprefixlen(const char *addr, int dummy __unused, int s, @@ -173,10 +173,9 @@ 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, n_flags, i; + int error, n_flags; clock_gettime(CLOCK_MONOTONIC_FAST, &now); @@ -208,30 +207,19 @@ in6_status(int s __unused, const struct ifaddrs *ifa) lifetime = ifr6.ifr_ifru.ifru_lifetime; close(s6); - 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 (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) + 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; @@ -280,8 +268,7 @@ in6_status(int s __unused, const struct ifaddrs *ifa) if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0) printf("prefer_source "); - if ((f_scope == NULL || strcmp(f_scope, "none") != 0) && - ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) + if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) printf("scopeid 0x%x ", ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id); |