From b9d5854a99d0665cbca275790cc7ff3dc363b001 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 22 Sep 2007 17:07:55 +0000 Subject: [PATCH] IPv6 fix --- src/session_impl.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 78fd353e4..52e04a6c4 100755 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -793,15 +793,26 @@ namespace detail tcp::endpoint ep = i->sock->local_endpoint(ec); if (ec || ep.address().is_v4()) continue; - std::vector
const& ifs = enum_net_interfaces(m_io_service, ec); - for (std::vector
::const_iterator i = ifs.begin() - , end(ifs.end()); i != end; ++i) + if (ep.address().to_v6() != address_v6::any()) { - if (i->is_v4() || i->to_v6().is_link_local() || i->to_v6().is_loopback()) continue; - m_ipv6_interface = tcp::endpoint(*i, ep.port()); + // if we're listening on a specific address + // pick it + m_ipv6_interface = ep; + } + else + { + // if we're listening on any IPv6 address, enumerate them and + // pick the first non-local address + std::vector
const& ifs = enum_net_interfaces(m_io_service, ec); + for (std::vector
::const_iterator i = ifs.begin() + , end(ifs.end()); i != end; ++i) + { + if (i->is_v4() || i->to_v6().is_link_local() || i->to_v6().is_loopback()) continue; + m_ipv6_interface = tcp::endpoint(*i, ep.port()); + break; + } break; } - break; } if (!m_listen_sockets.empty())