diff options
author | Renato Botelho <renato@netgate.com> | 2016-06-02 18:34:21 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2016-06-02 18:34:21 -0300 |
commit | 4775a2bdcd046cf79426a4cdd0dbc8f52a414ca8 (patch) | |
tree | f7ba4164f8a1690df639984ef7588d4ed6ed80cd /sbin/ifconfig/af_inet6.c | |
parent | 58cc1dd9a16eac0125c6fce83aa28f26d7e13989 (diff) | |
parent | ada12d916d2fc4a725e9c2f0ec61f027ce65471a (diff) | |
download | FreeBSD-src-4775a2bdcd046cf79426a4cdd0dbc8f52a414ca8.zip FreeBSD-src-4775a2bdcd046cf79426a4cdd0dbc8f52a414ca8.tar.gz |
Merge remote-tracking branch 'origin/master' into devel-11
Diffstat (limited to 'sbin/ifconfig/af_inet6.c')
-rw-r--r-- | sbin/ifconfig/af_inet6.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index 6a24125..3ddf303 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -65,12 +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; 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, @@ -174,7 +175,7 @@ in6_status(int s __unused, const struct ifaddrs *ifa) u_int32_t flags6; struct in6_addrlifetime lifetime; struct timespec now; - int error; + int error, n_flags; clock_gettime(CLOCK_MONOTONIC_FAST, &now); @@ -206,12 +207,19 @@ 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 (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); + printf("\tinet6 %s", addr_buf); if (ifa->ifa_flags & IFF_POINTOPOINT) { sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr; @@ -229,15 +237,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 "); |