more robust mechanism to determine external IP
This commit is contained in:
@@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/socket.hpp"
|
||||
#include "libtorrent/socket_io.hpp"
|
||||
#include "libtorrent/address.hpp"
|
||||
#include "libtorrent/hasher.hpp" // for hasher
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
@@ -92,5 +93,21 @@ namespace libtorrent
|
||||
return print_endpoint(tcp::endpoint(ep.address(), ep.port()));
|
||||
}
|
||||
|
||||
void hash_address(address const& ip, sha1_hash& h)
|
||||
{
|
||||
#if TORRENT_USE_IPV6
|
||||
if (ip.is_v6())
|
||||
{
|
||||
address_v6::bytes_type b = ip.to_v6().to_bytes();
|
||||
h = hasher((char*)&b[0], b.size()).final();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
address_v4::bytes_type b = ip.to_v4().to_bytes();
|
||||
h = hasher((char*)&b[0], b.size()).final();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user