aboutsummaryrefslogtreecommitdiff
path: root/src/rpcprotocol.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-04-07 16:22:59 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-05-13 07:23:23 +0200
commitf923c077547ceb8492e11001d571ba27145242ef (patch)
treebda88128b0f71e3644c73a3b235e7c4d0f88b37f /src/rpcprotocol.h
parentdeb3572ab160221124dfa3e9c5c4e493529f59e4 (diff)
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.
Diffstat (limited to 'src/rpcprotocol.h')
-rw-r--r--src/rpcprotocol.h24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/rpcprotocol.h b/src/rpcprotocol.h
index 8b3df19621..11bdd171d9 100644
--- a/src/rpcprotocol.h
+++ b/src/rpcprotocol.h
@@ -103,11 +103,27 @@ public:
}
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();