Skip to content

Commit

Permalink
Support IPv6 lookup in bitcoin-cli even when IPv6 only bound on local…
Browse files Browse the repository at this point in the history
…host

First query in the current way (intelligently determining which network
has a non-localhost interface). If this does not succeed, try plain
lookup.

Needed for testing.

Fixes #1827 by always allowing IPv6 to be used.
  • Loading branch information
laanwj committed May 13, 2014
1 parent deb3572 commit f923c07
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/rpcprotocol.h
Expand Up @@ -103,11 +103,27 @@ class SSLIOStreamDevice : public boost::iostreams::device<boost::iostreams::bidi
}
bool connect(const std::string& server, const std::string& port)
{
boost::asio::ip::tcp::resolver resolver(stream.get_io_service());
boost::asio::ip::tcp::resolver::query query(server.c_str(), port.c_str());
boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
boost::asio::ip::tcp::resolver::iterator end;
using namespace boost::asio::ip;
tcp::resolver resolver(stream.get_io_service());
tcp::resolver::iterator endpoint_iterator;
#if BOOST_VERSION >= 104300
try {
#endif
// The default query (flags address_configured) tries IPv6 if
// non-localhost IPv6 configured, and IPv4 if non-localhost IPv4
// configured.
tcp::resolver::query query(server.c_str(), port.c_str());
endpoint_iterator = resolver.resolve(query);
#if BOOST_VERSION >= 104300
} catch(boost::system::system_error &e)
{
// If we at first don't succeed, try blanket lookup (IPv4+IPv6 independent of configured interfaces)
tcp::resolver::query query(server.c_str(), port.c_str(), resolver_query_base::flags());
endpoint_iterator = resolver.resolve(query);
}
#endif
boost::system::error_code error = boost::asio::error::host_not_found;
tcp::resolver::iterator end;
while (error && endpoint_iterator != end)
{
stream.lowest_layer().close();
Expand Down

0 comments on commit f923c07

Please sign in to comment.