fixed building with no IPv6 support

This commit is contained in:
Arvid Norberg 2009-11-27 18:46:29 +00:00
parent 9fd7a58370
commit ddceb1487d
10 changed files with 38 additions and 5 deletions

View File

@ -218,6 +218,9 @@ feature.compose <timer>absolute : <define>TORRENT_USE_ABSOLUTE_TIME=1 ;
feature.compose <timer>performance : <define>TORRENT_USE_PERFORMANCE_TIMER=1 ;
feature.compose <timer>clock : <define>TORRENT_USE_CLOCK_GETTIME=1 ;
feature ipv6 : on off : composite propagated link-incompatible ;
feature.compose <ipv6>off : <define>TORRENT_USE_IPV6=0 ;
feature need-librt : no yes : composite propagated link-incompatible ;
feature pool-allocators : on off : composite propagated link-incompatible ;

View File

@ -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

View File

@ -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

View File

@ -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<ip_range<address_v4> >
, std::vector<ip_range<address_v6> > > filter_tuple_t;
#else
typedef std::vector<ip_range<address_v4> > filter_tuple_t;
#endif
filter_tuple_t export_filter() const;

View File

@ -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;

View File

@ -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);
}

View File

@ -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

View File

@ -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);

View File

@ -74,8 +74,7 @@ namespace libtorrent
return boost::make_tuple(m_filter4.export_filter<address_v4>()
, m_filter6.export_filter<address_v6>());
#else
return boost::make_tuple(m_filter4.export_filter<address_v4>()
, std::vector<ip_range<address_v6> >());
return m_filter4.export_filter<address_v4>();
#endif
}

View File

@ -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);