accept port 0 in listen_interfaces

This commit is contained in:
Alden Torres 2016-09-20 11:11:24 -04:00
parent db14df5d0d
commit 089d6c3144
3 changed files with 7 additions and 2 deletions

View File

@ -1652,7 +1652,8 @@ namespace aux {
}
if (ec == error_code(error::address_in_use)
&& !(flags & listen_no_system_port))
&& !(flags & listen_no_system_port)
&& bind_ep.port() != 0)
{
// instead of giving up, try let the OS pick a port
bind_ep.port(0);

View File

@ -279,7 +279,7 @@ namespace libtorrent
else
{
iface.port = std::atoi(port.c_str());
if (iface.port <= 0 || iface.port > 65535) iface.port = -1;
if (iface.port < 0 || iface.port > 65535) iface.port = -1;
}
// skip spaces

View File

@ -342,6 +342,10 @@ TORRENT_TEST(parse_list)
test_parse_interface("nic :", {}, "");
test_parse_interface("nic ", {}, "");
test_parse_interface("nic s", {}, "");
// parse interface with port 0
test_parse_interface("127.0.0.1:0"
, {{"127.0.0.1", 0, false}}, "127.0.0.1:0");
}
TORRENT_TEST(tokenize)