From 6a6d4d8884788c1e860bda886d168301623e1ea3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 6 Jun 2011 15:18:12 +1000 Subject: s4-ipv6: fix iface_list_best_ip() for IPv6 return an interface with the same address family as the target --- source4/lib/socket/interface.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'source4/lib') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 96cee2fbe6..1bf1e4f62b 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -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); } /** -- cgit