diff --git a/include/libtorrent/enum_net.hpp b/include/libtorrent/enum_net.hpp index 431b05be0..cb34949e5 100644 --- a/include/libtorrent/enum_net.hpp +++ b/include/libtorrent/enum_net.hpp @@ -62,6 +62,9 @@ namespace libtorrent { address netmask; char name[64]; int mtu; + // an interface is preferred if its address is + // not tenative/duplicate/deprecated + bool preferred = true; }; struct ip_route diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 3690d3d2b..757c246fd 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -617,6 +617,7 @@ namespace libtorrent { { if (!valid_addr_family(unicast->Address.lpSockaddr->sa_family)) continue; + r.preferred = unicast->DadState == IpDadStatePreferred; r.interface_address = sockaddr_to_address(unicast->Address.lpSockaddr); ret.push_back(r); } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 34cd55e5e..43a9b49b6 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -310,6 +310,8 @@ namespace aux { { for (auto const& ipface : ifs) { + if (!ipface.preferred) + continue; if (ipface.interface_address.is_v4()) continue; if (ipface.interface_address.is_loopback())