`ifconfig` patch to resolve IPv6 scope names
raichoo
raichoo at googlemail.com
Thu Aug 10 20:02:17 UTC 2017
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) {
More information about the freebsd-hackers
mailing list