fix build with IPv6 disabled

This commit is contained in:
Arvid Norberg 2010-12-18 18:46:20 +00:00
parent 20d4279177
commit de3a5784be
3 changed files with 12 additions and 6 deletions

View File

@ -98,14 +98,16 @@ struct static_ { static_() { std::srand(std::time(0)); } } static__;
void hash_address(address const& ip, sha1_hash& h) void hash_address(address const& ip, sha1_hash& h)
{ {
if (ip.is_v4()) #if TORRENT_USE_IPV6
if (ip.is_v6())
{ {
address_v4::bytes_type b = ip.to_v4().to_bytes(); address_v6::bytes_type b = ip.to_v6().to_bytes();
h = hasher((char*)&b[0], b.size()).final(); h = hasher((char*)&b[0], b.size()).final();
} }
else else
#endif
{ {
address_v6::bytes_type b = ip.to_v6().to_bytes(); address_v4::bytes_type b = ip.to_v4().to_bytes();
h = hasher((char*)&b[0], b.size()).final(); h = hasher((char*)&b[0], b.size()).final();
} }
} }

View File

@ -348,6 +348,7 @@ bool rpc_manager::incoming(msg const& m, node_id* id)
memcpy(&b[0], ext_ip->string_ptr(), 4); memcpy(&b[0], ext_ip->string_ptr(), 4);
m_ses.set_external_address(address_v4(b)); m_ses.set_external_address(address_v4(b));
} }
#if TORRENT_USE_IPV6
else if (ext_ip && ext_ip->string_length() == 16) else if (ext_ip && ext_ip->string_length() == 16)
{ {
// this node claims we use the wrong node-ID! // this node claims we use the wrong node-ID!
@ -355,6 +356,7 @@ bool rpc_manager::incoming(msg const& m, node_id* id)
memcpy(&b[0], ext_ip->string_ptr(), 16); memcpy(&b[0], ext_ip->string_ptr(), 16);
m_ses.set_external_address(address_v6(b)); m_ses.set_external_address(address_v6(b));
} }
#endif
#ifdef TORRENT_DHT_VERBOSE_LOGGING #ifdef TORRENT_DHT_VERBOSE_LOGGING
TORRENT_LOG(rpc) << "[" << o->m_algorithm.get() << "] Reply with transaction id: " TORRENT_LOG(rpc) << "[" << o->m_algorithm.get() << "] Reply with transaction id: "

View File

@ -49,14 +49,16 @@ namespace libtorrent
std::string address_to_bytes(address const& a) std::string address_to_bytes(address const& a)
{ {
if (a.is_v4()) #if TORRENT_USE_IPV6
if (a.is_v6())
{ {
address_v4::bytes_type b = a.to_v4().to_bytes(); address_v6::bytes_type b = a.to_v6().to_bytes();
return std::string((char*)&b[0], b.size()); return std::string((char*)&b[0], b.size());
} }
else else
#endif
{ {
address_v6::bytes_type b = a.to_v6().to_bytes(); address_v4::bytes_type b = a.to_v4().to_bytes();
return std::string((char*)&b[0], b.size()); return std::string((char*)&b[0], b.size());
} }
} }