[PATCH 2/2] server: Get socket protocol from kernel if not given.
Robin Ebert
ebertrobin2002 at gmail.com
Sun Aug 23 15:08:19 CDT 2020
The kernel selects a protocol if zero is given but the corresponding sock struct is not set accordingly. This causes problems in WS_getsockopt when trying to get socket's WSAPROTOCOL_INFOW struct.
Signed-off-by: Robin Ebert <ebertrobin2002 at gmail.com>
---
server/sock.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/server/sock.c b/server/sock.c
index 1a53ce4b..c37624b0 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
@@ -659,6 +662,7 @@ static struct object *create_socket( int family, int type, int protocol, unsigne
{
struct sock *sock;
int sockfd;
+ int proto, protolen;
sockfd = socket( family, type, protocol );
if (sockfd == -1)
@@ -676,7 +680,19 @@ 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;
+ if(!protocol)
+ {
+ /* if protocol is 0 get it from the kernel */
+ protolen = sizeof(int);
+ if(getsockopt(sockfd, SOL_SOCKET, SO_PROTOCOL, &proto, &protolen))
+ {
+ release_object( sock );
+ return NULL;
+ }
+ sock->proto = proto;
+ }
+ else
+ sock->proto = protocol;
sock->type = type;
sock->family = family;
--
2.20.1
More information about the wine-devel
mailing list