[PATCH] ws2_32: Provide default protocol for SOCK_STREAM and SOCK_DGRAM

Robin Ebert ebertrobin2002 at gmail.com
Wed Jul 15 15:28:17 CDT 2020


Windows provides a default protocol in socket()
if af is AF_INET or AF_INET6
type is SOCK_STREAM or SOCK_DGRAM
and protocol is 0.

Signed-off-by: Robin Ebert <ebertrobin2002 at gmail.com>
---
 dlls/ws2_32/socket.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index d7eddde..de30ee4 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -835,6 +835,12 @@ static const int ws_poll_map[][2] =
     { WS_POLLRDBAND, POLLPRI }
 };
 
+static const int ws_default_protocol_map[][2] =
+{
+    { WS_SOCK_STREAM, WS_IPPROTO_TCP },
+    { WS_SOCK_DGRAM, WS_IPPROTO_UDP }
+};
+
 static const char magic_loopback_addr[] = {127, 12, 34, 56};
 
 #ifndef HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS
@@ -1660,6 +1666,26 @@ static int convert_poll_u2w(int events)
     return ret;
 }
 
+static int get_default_protocol(int type)
+{
+    int i, ret;
+    for(i = ret = 0; i < ARRAY_SIZE(ws_default_protocol_map); i++)
+    {
+        if (ws_default_protocol_map[i][0] == type)
+        {
+            ret = ws_default_protocol_map[i][1];
+            break;
+        }
+    }
+
+    if(!ret)
+        WARN("selecting default protocol failed: type %i\n", type);
+    else
+        TRACE("selected %i as default protocol: type %i\n", ret, type);
+
+    return ret;
+}
+
 static int set_ipx_packettype(int sock, int ptype)
 {
 #ifdef HAS_IPX
@@ -7643,6 +7669,19 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
             protocol = lpProtocolInfo->iProtocol;
     }
 
+    /*
+        Windows provides a default protocol
+        if af is AF_INET or AF_INET6,
+        type is SOCKET_STREAM or SOCKET_DGRAM
+        and protocol is 0
+    */
+    if (!protocol
+        && (af == WS_AF_INET || af == WS_AF_INET6)
+        && (type == WS_SOCK_STREAM || type == WS_SOCK_DGRAM))
+    {
+        protocol = get_default_protocol(type);
+    }
+
     if (!type && (af || protocol))
     {
         int autoproto = protocol;
-- 
2.20.1




More information about the wine-devel mailing list