From 3cdbda928e418fbc984616f462f490e1c4d32182 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 7 Aug 2007 07:17:13 +0000 Subject: [PATCH] fixes #104 --- src/torrent.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/torrent.cpp b/src/torrent.cpp index 1b23ca8f5..509753814 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1658,17 +1658,26 @@ namespace libtorrent }; #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES + namespace + { + unsigned long swap_bytes(unsigned long a) + { + return (a >> 24) | ((a & 0xff0000) >> 8) | ((a & 0xff00) << 8) | (a << 24); + } + } + void torrent::resolve_peer_country(boost::intrusive_ptr const& p) const { if (m_resolving_country || p->has_country() || p->is_connecting() || p->is_queued() - || p->in_handshake()) return; + || p->in_handshake() + || p->remote().address().is_v6()) return; m_resolving_country = true; - tcp::resolver::query q(boost::lexical_cast(p->remote().address()) - + ".zz.countries.nerd.dk", "0"); + asio::ip::address_v4 reversed(swap_bytes(p->remote().address().to_v4().to_ulong())); + tcp::resolver::query q(reversed.to_string() + ".zz.countries.nerd.dk", "0"); m_host_resolver.async_resolve(q, m_ses.m_strand.wrap( bind(&torrent::on_country_lookup, shared_from_this(), _1, _2, p))); }