Browse Source

Support IPv6 lookup in bitcoin-cli even when IPv6 only bound on localhost

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.
0.10
Wladimir J. van der Laan 11 years ago
parent
commit
f923c07754
  1. 24
      src/rpcprotocol.h

24
src/rpcprotocol.h

@ -103,11 +103,27 @@ public:
} }
bool connect(const std::string& server, const std::string& port) bool connect(const std::string& server, const std::string& port)
{ {
boost::asio::ip::tcp::resolver resolver(stream.get_io_service()); using namespace boost::asio::ip;
boost::asio::ip::tcp::resolver::query query(server.c_str(), port.c_str()); tcp::resolver resolver(stream.get_io_service());
boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); tcp::resolver::iterator endpoint_iterator;
boost::asio::ip::tcp::resolver::iterator end; #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; boost::system::error_code error = boost::asio::error::host_not_found;
tcp::resolver::iterator end;
while (error && endpoint_iterator != end) while (error && endpoint_iterator != end)
{ {
stream.lowest_layer().close(); stream.lowest_layer().close();

Loading…
Cancel
Save