Skip to content

Commit

Permalink
hosted/gdb_if: Disable IPV6_V6ONLY socket option on listening socket
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OmniTechnoMancer authored and OmniTechnoMancer committed Mar 3, 2024
1 parent 0c0c7ff commit efe259a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/platforms/hosted/gdb_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit efe259a

Please sign in to comment.