From: Guus Sliepen Date: Thu, 27 Jul 2017 08:50:23 +0000 (+0200) Subject: If binding to the configured port fails, ask the OS to provide a port. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=5da2857e6c1e017d1863d94a4703ac26011c0e1f;p=meshlink If binding to the configured port fails, ask the OS to provide a port. This will still allow MeshLink to make outgoing connections to other nodes. --- diff --git a/src/net_setup.c b/src/net_setup.c index 8cfacc3a..fb0cf8d0 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -390,8 +390,19 @@ bool setup_myself(meshlink_handle_t *mesh) { mesh->listen_sockets = 0; - if(!add_listen_address(mesh, address, NULL)) - return false; + 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); + free(mesh->myport); + mesh->myport = strdup("0"); + if(!mesh->myport) + return false; + if(!add_listen_address(mesh, address, NULL)) + return false; + } else { + return false; + } + } if(!mesh->listen_sockets) { logger(mesh, MESHLINK_ERROR, "Unable to create any listening socket!");