s4-ipv6: fix iface_list_best_ip() for IPv6
authorAndrew Tridgell <tridge@samba.org>
Mon, 6 Jun 2011 05:18:12 +0000 (15:18 +1000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 7 Jun 2011 02:55:37 +0000 (12:55 +1000)
return an interface with the same address family as the target

source4/lib/socket/interface.c

index 96cee2fbe6135fe4a8cf24ef09a6ad06f5fdcadb..1bf1e4f62b369725a6383fdc7b52a43b46f2c720 100644 (file)
@@ -371,6 +371,23 @@ const char *iface_list_first_v4(struct interface *ifaces)
        return NULL;
 }
 
+/**
+  return the first IPv6 interface address we have registered
+  **/
+static const char *iface_list_first_v6(struct interface *ifaces)
+{
+       struct interface *i;
+
+#ifdef HAVE_IPV6
+       for (i=ifaces; i; i=i->next) {
+               if (i->ip.ss_family == AF_INET6) {
+                       return i->ip_s;
+               }
+       }
+#endif
+       return NULL;
+}
+
 /**
    check if an interface is IPv4
   **/
@@ -435,7 +452,12 @@ const char *iface_list_best_ip(struct interface *ifaces, const char *dest)
        if (iface) {
                return iface->ip_s;
        }
-       return iface_list_n_ip(ifaces, 0);
+#ifdef HAVE_IPV6
+       if (ss.ss_family == AF_INET6) {
+               return iface_list_first_v6(ifaces);
+       }
+#endif
+       return iface_list_first_v4(ifaces);
 }
 
 /**