From f29a7dd518f2119a5d26dfb96887b8303efcad8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hampus=20Sj=C3=B6berg?= Date: Mon, 5 Sep 2016 23:56:50 +0200 Subject: [PATCH] Qt: Ask user to use standard port on startup if specified port is in use If the port (specified by -port or GUI setting) is already in use when starting the GUI client, and it's not the standard port, ask the user if they want to listen via the standard network port instead. Github-Pull: #7107 Rebased-From: 1f37c87d8f2fbb7113c38674d1cc65933a222ccb --- src/net.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/net.cpp b/src/net.cpp index e1206745a4..489cbead47 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -3224,7 +3224,29 @@ bool CConnman::InitBinds(const Options& options) inaddr_any.s_addr = htonl(INADDR_ANY); const CService ipv4_any{inaddr_any, GetListenPort()}; // 0.0.0.0 if (!Bind(ipv4_any, BF_REPORT_ERROR, NetPermissionFlags::None)) { - return false; + int defaultPort = Params().GetDefaultPort(); + // If listening failed and another port than the standard port was specified, + // ask if the user wants to connect via the standard port for the network instead + if (GetListenPort() != defaultPort) { + bool fRet = uiInterface.ThreadSafeQuestion( + strprintf(_("Do you want to use the standard network port for %s (port %s) instead?"), PACKAGE_NAME, defaultPort), + strprintf(_("Listen on port %s failed.").translated, GetListenPort()), + "", CClientUIInterface::MSG_INFORMATION | CClientUIInterface::MODAL | CClientUIInterface::BTN_OK | CClientUIInterface::BTN_ABORT); + + if (fRet) { + // FIXME: Unbind IPv6 on the other port + + gArgs.ForceSetArg("-port", defaultPort); + // Attempt to use standard port + struct in6_addr inaddr6_any = IN6ADDR_ANY_INIT; + Bind(CService(inaddr6_any, defaultPort), BF_NONE, NetPermissionFlags::None); + struct in_addr inaddr_any; + inaddr_any.s_addr = INADDR_ANY; + if (!Bind(CService(inaddr_any, defaultPort), BF_REPORT_ERROR, NetPermissionFlags::None)) { + return false; + } + } + } } } return true;