From 5f7b734ef1a6a22a537c3ee3b29c8095fa9a803e Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Wed, 16 Aug 2017 22:10:47 +0200 Subject: [PATCH] Really bind to a free port if the configured port is not available. --- src/net_setup.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/net_setup.c b/src/net_setup.c index 45e20d00..96be9df3 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -266,6 +266,8 @@ static bool add_listen_address(meshlink_handle_t *mesh, char *address, bool bind return false; } + bool success = false; + for(struct addrinfo *aip = ai; aip; aip = aip->ai_next) { // Ignore duplicate addresses bool found = false; @@ -308,10 +310,11 @@ static bool add_listen_address(meshlink_handle_t *mesh, char *address, bool bind mesh->listen_socket[mesh->listen_sockets].bindto = bindto; memcpy(&mesh->listen_socket[mesh->listen_sockets].sa, aip->ai_addr, aip->ai_addrlen); mesh->listen_sockets++; + success = true; } freeaddrinfo(ai); - return true; + return success; } /* @@ -389,8 +392,8 @@ bool setup_myself(meshlink_handle_t *mesh) { mesh->listen_sockets = 0; if(!add_listen_address(mesh, address, NULL)) { - if(!strcmp(mesh->myport, "0")) { - logger(mesh, MESHLINK_WARNING, "Could not bind to port %s, asking OS to choose one for us", mesh->myport); + if(strcmp(mesh->myport, "0")) { + logger(mesh, MESHLINK_INFO, "Could not bind to port %s, asking OS to choose one for us", mesh->myport); free(mesh->myport); mesh->myport = strdup("0"); if(!mesh->myport) -- 2.39.2