Skip to content

Commit 5c64324

Browse files
committed
[utils] allow square brackets for ipv6 addresses in bitcoin-cli
-rpcconnect can now accept ipv6 addresses with and without square brackets.
1 parent fe4faba commit 5c64324

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/bitcoin-cli.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "chainparamsbase.h"
1111
#include "clientversion.h"
1212
#include "fs.h"
13+
#include "utilstrencodings.h"
1314
#include "rpc/client.h"
1415
#include "rpc/protocol.h"
1516
#include "util.h"
@@ -191,8 +192,14 @@ static void http_error_cb(enum evhttp_request_error err, void *ctx)
191192

192193
UniValue CallRPC(const std::string& strMethod, const UniValue& params)
193194
{
194-
std::string host = GetArg("-rpcconnect", DEFAULT_RPCCONNECT);
195-
int port = GetArg("-rpcport", BaseParams().RPCPort());
195+
std::string host;
196+
// In preference order, we choose the following for the port:
197+
// 1. -rpcport
198+
// 2. port in -rpcconnect (ie following : in ipv4 or ]: in ipv6)
199+
// 3. default port for chain
200+
int port = BaseParams().RPCPort();
201+
SplitHostPort(GetArg("-rpcconnect", DEFAULT_RPCCONNECT), port, host);
202+
port = GetArg("-rpcport", port);
196203

197204
// Obtain event base
198205
raii_event_base base = obtain_event_base();

0 commit comments

Comments
 (0)