improved local IP guessing slightly

This commit is contained in:
Arvid Norberg 2007-05-16 18:58:31 +00:00
parent 3bfaaf1129
commit 674e1f96b1
3 changed files with 10 additions and 1 deletions

View File

@ -84,6 +84,9 @@ void lsd::rebind(address const& listen_interface)
udp::resolver::iterator i = r.resolve(udp::resolver::query(asio::ip::host_name(), "0"));
for (;i != udp::resolver_iterator(); ++i)
{
// ignore the loopback
if (i->endpoint().address() == address_v4((127 << 24) + 1)) continue;
// ignore non-IPv4 addresses
if (i->endpoint().address().is_v4()) break;
}

View File

@ -74,6 +74,9 @@ void natpmp::rebind(address const& listen_interface) try
udp::resolver::iterator i = r.resolve(udp::resolver::query(asio::ip::host_name(), "0"));
for (;i != udp::resolver_iterator(); ++i)
{
// ignore the loopback
if (i->endpoint().address() == address_v4((127 << 24) + 1)) continue;
// ignore non-IPv4 addresses
if (i->endpoint().address().is_v4()) break;
}

View File

@ -95,13 +95,16 @@ void upnp::rebind(address const& listen_interface) try
udp::resolver::iterator i = r.resolve(udp::resolver::query(asio::ip::host_name(), "0"));
for (;i != udp::resolver_iterator(); ++i)
{
// ignore the loopback
if (i->endpoint().address() == address_v4((127 << 24) + 1)) continue;
// ignore non-IPv4 addresses
if (i->endpoint().address().is_v4()) break;
}
if (i == udp::resolver_iterator())
{
throw std::runtime_error("local host name did not resolve to an "
"IPv4 address. disabling NAT-PMP");
"IPv4 address. disabling UPnP");
}
m_local_ip = i->endpoint().address().to_v4();