diff --git a/Jamfile b/Jamfile index 9c88f3325..df5adec81 100755 --- a/Jamfile +++ b/Jamfile @@ -218,6 +218,9 @@ feature.compose absolute : TORRENT_USE_ABSOLUTE_TIME=1 ; feature.compose performance : TORRENT_USE_PERFORMANCE_TIMER=1 ; feature.compose clock : TORRENT_USE_CLOCK_GETTIME=1 ; +feature ipv6 : on off : composite propagated link-incompatible ; +feature.compose off : TORRENT_USE_IPV6=0 ; + feature need-librt : no yes : composite propagated link-incompatible ; feature pool-allocators : on off : composite propagated link-incompatible ; diff --git a/include/libtorrent/address.hpp b/include/libtorrent/address.hpp index de410eff6..cbcd1fa43 100644 --- a/include/libtorrent/address.hpp +++ b/include/libtorrent/address.hpp @@ -60,12 +60,16 @@ namespace libtorrent #if BOOST_VERSION < 103500 typedef ::asio::ip::address address; typedef ::asio::ip::address_v4 address_v4; +#if TORRENT_USE_IPV6 typedef ::asio::ip::address_v6 address_v6; +#endif #else typedef boost::asio::ip::address address; typedef boost::asio::ip::address_v4 address_v4; +#if TORRENT_USE_IPV6 typedef boost::asio::ip::address_v6 address_v6; #endif +#endif } #endif diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 64560d49f..f1388b546 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -137,7 +137,10 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_BSD #endif +#ifndef TORRENT_USE_IPV6 #define TORRENT_USE_IPV6 1 +#endif + #define TORRENT_USE_MLOCK 1 #define TORRENT_USE_READV 1 #define TORRENT_USE_WRITEV 1 diff --git a/include/libtorrent/ip_filter.hpp b/include/libtorrent/ip_filter.hpp index 25adcb9f8..175617e4b 100644 --- a/include/libtorrent/ip_filter.hpp +++ b/include/libtorrent/ip_filter.hpp @@ -276,8 +276,12 @@ public: void add_rule(address first, address last, int flags); int access(address const& addr) const; +#if TORRENT_USE_IPV6 typedef boost::tuple > , std::vector > > filter_tuple_t; +#else + typedef std::vector > filter_tuple_t; +#endif filter_tuple_t export_filter() const; diff --git a/include/libtorrent/kademlia/traversal_algorithm.hpp b/include/libtorrent/kademlia/traversal_algorithm.hpp index a10f12505..4650eaac4 100644 --- a/include/libtorrent/kademlia/traversal_algorithm.hpp +++ b/include/libtorrent/kademlia/traversal_algorithm.hpp @@ -80,12 +80,14 @@ struct traversal_algorithm : boost::noncopyable result(node_id const& id, udp::endpoint ep, unsigned char f = 0) : id(id), flags(f) { +#if TORRENT_USE_IPV6 if (ep.address().is_v6()) { flags |= ipv6_address; addr.v6 = ep.address().to_v6().to_bytes(); } else +#endif { flags &= ~ipv6_address; addr.v4 = ep.address().to_v4().to_bytes(); @@ -95,9 +97,11 @@ struct traversal_algorithm : boost::noncopyable udp::endpoint endpoint() const { +#if TORRENT_USE_IPV6 if (flags & ipv6_address) return udp::endpoint(address_v6(addr.v6), port); else +#endif return udp::endpoint(address_v4(addr.v4), port); } @@ -106,7 +110,9 @@ struct traversal_algorithm : boost::noncopyable union addr_t { address_v4::bytes_type v4; +#if TORRENT_USE_IPV6 address_v6::bytes_type v6; +#endif } addr; boost::uint16_t port; diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index c43cf475d..f15307790 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -314,7 +314,9 @@ namespace libtorrent union addr_t { address_v4::bytes_type v4; +#if TORRENT_USE_IPV6 address_v6::bytes_type v6; +#endif } addr; boost::uint16_t port; @@ -322,19 +324,23 @@ namespace libtorrent void set_peer(tcp::endpoint const& ep) { +#if TORRENT_USE_IPV6 is_v6_addr = ep.address().is_v6(); if (is_v6_addr) addr.v6 = ep.address().to_v6().to_bytes(); else +#endif addr.v4 = ep.address().to_v4().to_bytes(); port = ep.port(); } tcp::endpoint peer() const { +#if TORRENT_USE_IPV6 if (is_v6_addr) return tcp::endpoint(address_v6(addr.v6), port); else +#endif return tcp::endpoint(address_v4(addr.v4), port); } diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 60f6e9a2a..68e55b283 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -1527,6 +1527,7 @@ namespace libtorrent std::copy(myip.begin(), myip.end(), bytes.begin()); m_ses.set_external_address(address_v4(bytes)); } +#if TORRENT_USE_IPV6 else if (myip.size() == address_v6::bytes_type::static_size) { address_v6::bytes_type bytes; @@ -1537,6 +1538,7 @@ namespace libtorrent else m_ses.set_external_address(ipv6_address); } +#endif } // if we're finished and this peer is uploading only diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 90fb0312e..4de007dbc 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -298,12 +298,14 @@ namespace libtorrent ifreq netmask = item; if (ioctl(s, SIOCGIFNETMASK, &netmask) < 0) { +#if TORRENT_USE_IPV6 if (iface.interface_address.is_v6()) { // this is expected to fail (at least on MacOS X) iface.netmask = address_v6::any(); } else +#endif { ec = error_code(errno, asio::error::system_category); close(s); diff --git a/src/ip_filter.cpp b/src/ip_filter.cpp index 418bc82a0..208e4f882 100644 --- a/src/ip_filter.cpp +++ b/src/ip_filter.cpp @@ -74,8 +74,7 @@ namespace libtorrent return boost::make_tuple(m_filter4.export_filter() , m_filter6.export_filter()); #else - return boost::make_tuple(m_filter4.export_filter() - , std::vector >()); + return m_filter4.export_filter(); #endif } diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 80c5ff4d0..bef142200 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -511,11 +511,13 @@ namespace libtorrent address_v4::bytes_type bytes = addr.to_v4().to_bytes(); x.assign((char*)&bytes[0], bytes.size()); } +#if TORRENT_USE_IPV6 else { address_v6::bytes_type bytes = addr.to_v6().to_bytes(); x.assign((char*)&bytes[0], bytes.size()); } +#endif x.append((char*)&t->torrent_file().info_hash()[0], 20); sha1_hash hash = hasher(&x[0], x.size()).final(); @@ -4534,10 +4536,12 @@ namespace libtorrent // to the same protocol family as the target endpoint if (is_any(bind_interface.address())) { - if (m_remote.address().is_v4()) - bind_interface.address(address_v4::any()); - else +#if TORRENT_USE_IPV6 + if (m_remote.address().is_v6()) bind_interface.address(address_v6::any()); + else +#endif + bind_interface.address(address_v4::any()); } m_socket->bind(bind_interface, ec);