From 4a6c468f9fdf16eb4b6b7b09a0f5fc07fabb0e50 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sat, 17 Apr 2021 16:28:25 -0700 Subject: [PATCH] server: warn when falling back to random TCP port --- src/serverconn.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/serverconn.cpp b/src/serverconn.cpp index fc4fb91..fb28ee2 100644 --- a/src/serverconn.cpp +++ b/src/serverconn.cpp @@ -343,6 +343,7 @@ ServIface::ServIface(const std::string& addr, unsigned short port, server::Serve ,sock(AF_INET, SOCK_STREAM, 0) { server->acceptor_loop.assertInLoop(); + auto orig_port = bind_addr.port(); // try to bind to requested port, then fallback to a random port while(true) { @@ -360,6 +361,10 @@ ServIface::ServIface(const std::string& addr, unsigned short port, server::Serve name = bind_addr.tostring(); + if(bind_addr.port() != orig_port) { + log_warn_printf(connsetup, "Server unable to bind port %u, falling back to %s\n", orig_port, name.c_str()); + } + // added in libevent 2.1.1 #ifndef LEV_OPT_DISABLED # define LEV_OPT_DISABLED 0