From b9185518d3e203b1cbe444b7e410ee102c6acbad Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 8 Nov 2022 22:13:42 +0100 Subject: [PATCH] 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. --- src/meshlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); -- 2.39.5