add compile time option to disable IPv6 support

This commit is contained in:
Arvid Norberg 2009-03-31 07:45:54 +00:00
parent c85846a240
commit 1a6d2f86b9
5 changed files with 35 additions and 3 deletions

View File

@ -84,6 +84,8 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_BSD
#endif
#define TORRENT_USE_IPV6 1
// should wpath or path be used?
#if defined UNICODE && !defined BOOST_FILESYSTEM_NARROW_ONLY \
&& BOOST_VERSION >= 103400 && !defined __APPLE__

View File

@ -125,8 +125,14 @@ namespace libtorrent
size_type total_upload() const;
tcp::endpoint ip() const { return tcp::endpoint(addr, port); }
#if TORRENT_USE_IPV6
void set_ip(tcp::endpoint const& endp)
{ addr = endp.address(); port = endp.port(); }
#else
void set_ip(tcp::endpoint const& endp)
{ addr = endp.address().to_v4(); port = endp.port(); }
#endif
// this is the accumulated amount of
// uploaded and downloaded data to this
@ -141,7 +147,11 @@ namespace libtorrent
size_type prev_amount_download;
// the ip address this peer is or was connected on
#if TORRENT_USE_IPV6
address addr;
#else
address_v4 addr;
#endif
// the time when this peer was optimistically unchoked
// the last time.

View File

@ -91,6 +91,7 @@ namespace libtorrent { namespace
return address_v4(b);
}
#if TORRENT_USE_IPV6
address inaddr6_to_address(in6_addr const* ina6)
{
typedef asio::ip::address_v6::bytes_type bytes_t;
@ -98,13 +99,16 @@ namespace libtorrent { namespace
std::memcpy(&b[0], ina6, b.size());
return address_v6(b);
}
#endif
address sockaddr_to_address(sockaddr const* sin)
{
if (sin->sa_family == AF_INET)
return inaddr_to_address(&((sockaddr_in const*)sin)->sin_addr);
#if TORRENT_USE_IPV6
else if (sin->sa_family == AF_INET6)
return inaddr6_to_address(&((sockaddr_in6 const*)sin)->sin6_addr);
#endif
return address();
}
@ -192,7 +196,11 @@ namespace libtorrent { namespace
if (sa == 0
|| rti_info[RTAX_DST] == 0
|| rti_info[RTAX_NETMASK] == 0
|| (sa->sa_family != AF_INET && sa->sa_family != AF_INET6))
|| (sa->sa_family != AF_INET
#if TORRENT_USE_IPV6
&& sa->sa_family != AF_INET6
#endif
))
return false;
rt_info->gateway = sockaddr_to_address(rti_info[RTAX_GATEWAY]);
@ -209,8 +217,11 @@ namespace libtorrent { namespace
{
return (sin->sin_len == sizeof(sockaddr_in)
&& sin->sin_family == AF_INET)
#if TORRENT_USE_IPV6
|| (sin->sin_len == sizeof(sockaddr_in6)
&& sin->sin_family == AF_INET6);
&& sin->sin_family == AF_INET6)
#endif
;
}
#endif
@ -274,7 +285,10 @@ namespace libtorrent
ifreq const& item = *reinterpret_cast<ifreq*>(ifr);
if (item.ifr_addr.sa_family == AF_INET
|| item.ifr_addr.sa_family == AF_INET6)
#if TORRENT_USE_IPV6
|| item.ifr_addr.sa_family == AF_INET6
#endif
)
{
ip_interface iface;
iface.interface_address = sockaddr_to_address(&item.ifr_addr);

View File

@ -1183,7 +1183,11 @@ namespace libtorrent
policy::peer::peer(const tcp::endpoint& ip_, peer::connection_type t, int src)
: prev_amount_upload(0)
, prev_amount_download(0)
#if TORRENT_USE_IPV6
, addr(ip_.address())
#else
, addr(ip_.address().to_v4())
#endif
, last_optimistically_unchoked(min_time())
, connected(min_time())
, connection(0)

View File

@ -725,6 +725,7 @@ namespace aux {
async_accept(s.sock);
}
#if TORRENT_USE_IPV6
#ifdef TORRENT_WINDOWS
// only try to open the IPv6 port if IPv6 is installed
SOCKADDR_STORAGE storage;
@ -746,6 +747,7 @@ namespace aux {
#ifdef TORRENT_WINDOWS
}
#endif
#endif // TORRENT_USE_IPV6
}
else
{