From: Guus Sliepen Date: Tue, 8 Nov 2022 21:13:42 +0000 (+0100) Subject: Never automatically try to bind to ports >= 32768. X-Git-Url: http://git.meshlink.io/?p=meshlink;a=commitdiff_plain Never automatically try to bind to ports >= 32768. RFC 6335 says operating systems should use ports 49152-65535 for ephemeral ports. However, Linux and several other operating systems use 32768-65535 by default. Make sure we don't bind in that range, as a single outgoing TCP connection that uses the same port for the local end as MeshLink wants to use for the listening port can cause problems. --- diff --git a/src/meshlink.c b/src/meshlink.c index f425b4b2..a1a2ec40 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -651,7 +651,7 @@ static bool try_bind(meshlink_handle_t *mesh, int port) { int check_port(meshlink_handle_t *mesh) { for(int i = 0; i < 1000; i++) { - int port = 0x1000 + prng(mesh, 0x8000); + int port = 0x1000 + prng(mesh, 0x7000); if(try_bind(mesh, port)) { free(mesh->myport);