diff --git a/src/kademlia/node_id.cpp b/src/kademlia/node_id.cpp index e867a5d7c..9b85a2824 100644 --- a/src/kademlia/node_id.cpp +++ b/src/kademlia/node_id.cpp @@ -98,14 +98,16 @@ struct static_ { static_() { std::srand(std::time(0)); } } static__; 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(); } 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(); } } diff --git a/src/kademlia/rpc_manager.cpp b/src/kademlia/rpc_manager.cpp index bd91dcb2b..fee63dcc4 100644 --- a/src/kademlia/rpc_manager.cpp +++ b/src/kademlia/rpc_manager.cpp @@ -348,6 +348,7 @@ bool rpc_manager::incoming(msg const& m, node_id* id) memcpy(&b[0], ext_ip->string_ptr(), 4); m_ses.set_external_address(address_v4(b)); } +#if TORRENT_USE_IPV6 else if (ext_ip && ext_ip->string_length() == 16) { // 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); m_ses.set_external_address(address_v6(b)); } +#endif #ifdef TORRENT_DHT_VERBOSE_LOGGING TORRENT_LOG(rpc) << "[" << o->m_algorithm.get() << "] Reply with transaction id: " diff --git a/src/socket_io.cpp b/src/socket_io.cpp index 7b609b779..bcb6cb7eb 100644 --- a/src/socket_io.cpp +++ b/src/socket_io.cpp @@ -49,14 +49,16 @@ namespace libtorrent 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()); } 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()); } }