From 402fe236b2639a6c4351c5cb37bc51d0d8cfe5f1 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Sun, 22 Oct 2023 09:31:28 -0400
Subject: [PATCH] Explicitly disable IPV6_V6ONLY flag.
(It defaults to 1 for WinSock and 0 most other places.)
We try to do this no matter what, and we don't care if it fails; in case of
failure, it was either applied to a non-IPv6 socket where it would be
meaningless, or we're just going to have to live with what we got anyhow.
Reference Issue #84.
Reference Issue #58.
---
src/SDL_net.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/SDL_net.c b/src/SDL_net.c
index 41308c0..ff00995 100644
--- a/src/SDL_net.c
+++ b/src/SDL_net.c
@@ -934,6 +934,9 @@ SDLNet_Server *SDLNet_CreateServer(SDLNet_Address *addr, Uint16 port)
return NULL;
}
+ int zero = 0;
+ setsockopt(server->handle, SOL_IPV6, IPV6_V6ONLY, &zero, sizeof (zero)); // if this fails, oh well.
+
int rc = bind(server->handle, addrwithport->ai_addr, addrwithport->ai_addrlen);
freeaddrinfo(addrwithport);
@@ -1284,6 +1287,9 @@ SDLNet_DatagramSocket *SDLNet_CreateDatagramSocket(SDLNet_Address *addr, Uint16
return NULL;
}
+ int zero = 0;
+ setsockopt(sock->handle, SOL_IPV6, IPV6_V6ONLY, &zero, sizeof (zero)); // if this fails, oh well.
+
const int rc = bind(sock->handle, addrwithport->ai_addr, addrwithport->ai_addrlen);
freeaddrinfo(addrwithport);