From efe259ab4e5b68f7397a89125f9b11bca3fe7c86 Mon Sep 17 00:00:00 2001 From: OmniTechnoMancer Date: Sat, 2 Mar 2024 16:54:07 +0000 Subject: [PATCH] hosted/gdb_if: Disable IPV6_V6ONLY socket option on listening socket When IPV6_V6ONLY is not set then an IPv6 listening socket for TCP or UDP will accept connections for both IPv4 and IPv6 allowing a single socket to be used for both. On linux the default value of this socket option is set by the net.ipv6.bindv6only sysctl value, on Windows this socket option is enabled by default and must be disabled to allow dual stack listening. In order to ensure that the listening socket can accept connections for both IPv6 and IPv4 if possible add code to disable this socket option when binding to an IPv6 address, if the set fails then a warning is given that IPv6 only listening will occur. --- src/platforms/hosted/gdb_if.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/platforms/hosted/gdb_if.c b/src/platforms/hosted/gdb_if.c index 9a4d7d5e0ce..09bf16a4b1b 100644 --- a/src/platforms/hosted/gdb_if.c +++ b/src/platforms/hosted/gdb_if.c @@ -252,6 +252,12 @@ int gdb_if_init(void) !socket_set_int_opt(gdb_if_serv, IPPROTO_TCP, TCP_NODELAY, 1)) continue; + if (addr.ss_family == AF_INET6) { + DEBUG_INFO("Setting V6ONLY to off for dual stack listening.\n"); + if (!socket_set_int_opt(gdb_if_serv, IPPROTO_IPV6, IPV6_V6ONLY, 0)) + DEBUG_WARN("Listening on IPv6 only.\n"); + } + if (bind(gdb_if_serv, (sockaddr_s *)&addr, family_to_size(addr.ss_family)) == -1) { handle_error(gdb_if_serv, "binding socket"); continue;