Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Aug 2017 22:18:07 +0200
From:      raichoo <raichoo@googlemail.com>
To:        freebsd-hackers@freebsd.org
Subject:   `ifconfig` patch to resolve IPv6 scope names
Message-ID:  <CAJaUxeyRQoQkVdb3jNim_BVbdtBp0hM1pn3AiaR_DPJZAyQapg@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hi,

I've made a trivial patch that resolves IPv6 scope names (according to
rfc4291).
I thought this might be handy, so one does not have to memorize what id
refers
to which scope. And it's a nice opportunity to get my feet wet I guess :)

This is my first patch and I have no idea what's the best way to contribute
to the
project (probably I didn't look hard enough or in the wrong places).

Feedback and pointers appreciated.

Kind regards,
raichoo

diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c
index e93d94355e..165b2cc90a 100644
--- a/sbin/ifconfig/af_inet6.c
+++ b/sbin/ifconfig/af_inet6.c
@@ -268,10 +268,32 @@ 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 (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) {
                printf("scopeid 0x%x ",
                    ((struct sockaddr_in6
*)(ifa->ifa_addr))->sin6_scope_id);

+               switch (((struct sockaddr_in6
*)(ifa->ifa_addr))->sin6_scope_id) {
+               case 0x1:
+                       printf("interface-local ");
+                       break;
+               case 0x2:
+                       printf("link-local ");
+                       break;
+               case 0x4:
+                       printf("admin-local ");
+                       break;
+               case 0x5:
+                       printf("site-local ");
+                       break;
+               case 0x8:
+                       printf("organization-local ");
+                       break;
+               case 0xe:
+                       printf("global ");
+                       break;
+               }
+       }
+
        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?CAJaUxeyRQoQkVdb3jNim_BVbdtBp0hM1pn3AiaR_DPJZAyQapg>