From 5da2857e6c1e017d1863d94a4703ac26011c0e1f Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 27 Jul 2017 10:50:23 +0200 Subject: [PATCH] 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. --- src/net_setup.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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!"); -- 2.39.2