Currently, when IPv6 is disabled by the kernel, attempting to use the 'WebRequest' API with .NET native causes a crash. This can be recreated using the following gist: https://gist.github.com/redmcg/7d81ef833c77bee6965b5f441006f697
This patch fixes the crash by returning WSAEAFNOSUPPORT, as expected by .NET. See: https://referencesource.microsoft.com/#System/net/System/Net/Sockets/Socket....
Signed-off-by: Brendan McGrath brendan@redmandi.com --- Changes since v3: - fix broken tests (by only returning WSAEAFNOSUPPORT on assumed working protocol combinations) dlls/ws2_32/socket.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index df068fe8527..d77b6404105 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -7646,8 +7646,19 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol, /* invalid combination of valid parameters, like SOCK_STREAM + IPPROTO_UDP */ if (err == WSAEINVAL) err = WSAESOCKTNOSUPPORT; - else if (err == WSAEOPNOTSUPP) - err = WSAEPROTONOSUPPORT; + else if (err == WSAEOPNOTSUPP) { + if (unixtype == SOCK_STREAM && protocol == IPPROTO_TCP && + (unixaf == AF_INET || unixaf == AF_INET6)) + err = WSAEAFNOSUPPORT; + else if (unixtype == SOCK_DGRAM && protocol == IPPROTO_IP && + (unixaf == AF_INET || unixaf == AF_INET6)) + err = WSAEAFNOSUPPORT; + else if (unixtype == SOCK_DGRAM && protocol == IPPROTO_IPV6 && + unixaf == AF_INET6) + err = WSAEAFNOSUPPORT; + else + err = WSAEPROTONOSUPPORT; + } }
done: