[PATCH] server: Derive protocol in create_socket if not given

Robin Ebert ebertrobin2002 at gmail.com
Sat Jul 18 16:33:18 CDT 2020


The protocol entry of a sock structure should not be 0 if either SOCK_STREAM or SOCK_DGRAM are used
because this leads to an invalid behaviour of
ws2_32's WS_getsockopt(..., SOL_SOCKET, SO_PROTOCOL_INFOW, ..., ...)

Signed-off-by: Robin Ebert <ebertrobin2002 at gmail.com>
---
 server/sock.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/server/sock.c b/server/sock.c
index 1a53ce4..3e7e14a 100644
--- a/server/sock.c
+++ b/server/sock.c
@@ -38,6 +38,9 @@
 #ifdef HAVE_SYS_SOCKET_H
 # include <sys/socket.h>
 #endif
+#ifdef HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
@@ -676,7 +679,12 @@ static struct object *create_socket( int family, int type, int protocol, unsigne
     init_sock( sock );
     sock->state  = (type != SOCK_STREAM) ? (FD_READ|FD_WRITE) : 0;
     sock->flags  = flags;
-    sock->proto  = protocol;
+    sock->proto  = protocol ? protocol
+        /* if protocol is 0 try to derive it */
+        /* FIXME: maybe get the protocol through the kernel? */
+        : type == SOCK_STREAM ? IPPROTO_TCP
+        : type == SOCK_DGRAM ? IPPROTO_UDP
+        : 0;
     sock->type   = type;
     sock->family = family;
 
-- 
2.20.1




More information about the wine-devel mailing list