Date: Thu, 10 Aug 2017 22:02:13 +0200 From: raichoo <raichoo@googlemail.com> To: "Andrey V. Elsukov" <bu7cher@yandex.ru> Cc: freebsd-hackers@freebsd.org Subject: Re: `ifconfig` patch to resolve IPv6 scope names Message-ID: <CAJaUxexd2ez=DezquYCcFiUG81K4tDEVTNNFnfe6u2-MZjiYZg@mail.gmail.com> In-Reply-To: <8ebce8ed-5b3f-2b59-5b37-f6af7f3d4c2b@yandex.ru> References: <CAJaUxeyRQoQkVdb3jNim_BVbdtBp0hM1pn3AiaR_DPJZAyQapg@mail.gmail.com> <8ebce8ed-5b3f-2b59-5b37-f6af7f3d4c2b@yandex.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
Oh boy, should have read more code before posting that ^^. Thanks a lot for your feedback :) I've modified that patch to make it use the macros defined in in6.h. I'm also quite aware that this patch might be rejected since it might break script depending on `ifconfig` output. But it's a useful little learning experience anyway :) Kind regards, raichoo Here's the new iteration: diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index e93d94355e..e1d44395c9 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -167,6 +167,35 @@ setip6eui64(const char *cmd, int dummy __unused, int s, } static void +in6_addr_scope(const struct in6_addr *addr) +{ + if (IN6_IS_ADDR_LINKLOCAL(addr)) + printf("link-local "); + else if (IN6_IS_ADDR_SITELOCAL(addr)) + printf("site-local "); + else if (IN6_IS_ADDR_MULTICAST(addr)) { + printf("multicast "); + switch (__IPV6_ADDR_MC_SCOPE(addr)) { + case __IPV6_ADDR_SCOPE_NODELOCAL: + printf("node-local "); + break; + case __IPV6_ADDR_SCOPE_LINKLOCAL: + printf("link-local "); + break; + case __IPV6_ADDR_SCOPE_SITELOCAL: + printf("site-local "); + break; + case __IPV6_ADDR_SCOPE_ORGLOCAL: + printf("organization-local "); + break; + case __IPV6_ADDR_SCOPE_GLOBAL: + printf("global "); + break; + } + } +} + +static void in6_status(int s __unused, const struct ifaddrs *ifa) { struct sockaddr_in6 *sin, null_sin; @@ -272,6 +301,8 @@ in6_status(int s __unused, const struct ifaddrs *ifa) printf("scopeid 0x%x ", ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id); + in6_addr_scope(&((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_addr); + if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { printf("pltime "); if (lifetime.ia6t_preferred) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJaUxexd2ez=DezquYCcFiUG81K4tDEVTNNFnfe6u2-MZjiYZg>