[Joachim Breitner]
> it was reported that libnss-myhostname may report an IPv6 address
> for the local hostname that is not pingable, as it is a link scoped
> address, and it was suggested that it not do that. Do you agree and
> can you fix it?

Here is a simple patch to make sure link local addresses are no longer
returned by libnss-myhostname.

The alternative would be to return addresses with %interface appended,
but I did not investigate how to do that.

The attached and tested patch solve my problem, making the command
'ping6 $(hostname)' work again.  I choose to work on the string
representation of the address, to avoid having to add endian specific
code to look in the "raw" address.  Perhaps there is a better and
still portable way to do this?

-- 
Happy hacking
Petter Reinholdtsen
diff -ur libnss-myhostname-0.3/netlink.c libnss-myhostname-0.3-pere/netlink.c
--- libnss-myhostname-0.3/netlink.c     2013-04-27 09:32:28.000000000 +0200
+++ libnss-myhostname-0.3-pere/netlink.c        2013-04-27 09:33:39.000000000 
+0200
@@ -34,9 +34,26 @@
 #include <unistd.h>
 #include <inttypes.h>
 #include <stdlib.h>
+#include <stdbool.h>
 
 #include "ifconf.h"
 
+bool is_ipv6_link_local(unsigned short family, void *address) {
+        char str_buffer[INET6_ADDRSTRLEN];
+        if (AF_INET6 != family)
+                return false;
+
+        if (NULL == inet_ntop(AF_INET6, address, str_buffer, INET6_ADDRSTRLEN))
+                return false;
+
+        if (0 == strncmp("fe", str_buffer, 2)) {
+                char c = str_buffer[2];
+                if (c == '8' || c == '9' || c == 'a' || c == 'b')
+                        return true;
+                }
+        return false;
+}
+
 int ifconf_acquire_addresses(struct address **_list, unsigned *_n_list) {
 
         struct {
@@ -177,6 +194,9 @@
 
                         if (!address)
                                 continue;
+                        /* Skip link local ipV6 addresses */
+                        if (is_ipv6_link_local(ifaddrmsg->ifa_family, address))
+                                continue;
 
                         list = realloc(list, (n_list+1) * sizeof(struct 
address));
                         if (!list) {

Reply via email to