Zebediah Figura : ws2_32: Pass Win32 socket types to the server.
Alexandre Julliard
julliard at winehq.org
Thu Oct 1 15:50:30 CDT 2020
Module: wine
Branch: master
Commit: abcc75cbcf57513f07ab8c008f66a19f142c5a7b
URL: https://source.winehq.org/git/wine.git/?a=commit;h=abcc75cbcf57513f07ab8c008f66a19f142c5a7b
Author: Zebediah Figura <z.figura12 at gmail.com>
Date: Wed Sep 30 10:37:50 2020 -0500
ws2_32: Pass Win32 socket types to the server.
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ws2_32/socket.c | 39 +------------------
server/sock.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 102 insertions(+), 42 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 36215cc6ef..d7802cc9cd 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -7601,41 +7601,6 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
/* convert the socket family, type and protocol */
unixaf = convert_af_w2u(af);
unixtype = convert_socktype_w2u(type);
- protocol = convert_proto_w2u(protocol);
-
- /* filter invalid parameters */
- if (protocol < 0)
- {
- /* the type could not be converted */
- if (type && unixtype < 0)
- {
- err = WSAESOCKTNOSUPPORT;
- goto done;
- }
-
- err = WSAEPROTONOSUPPORT;
- goto done;
- }
- if (unixaf < 0)
- {
- /* both family and protocol can't be invalid */
- if (protocol <= 0)
- {
- err = WSAEINVAL;
- goto done;
- }
-
- /* family could not be converted and neither socket type */
- if (unixtype < 0 && af >= 0)
- {
-
- err = WSAESOCKTNOSUPPORT;
- goto done;
- }
-
- err = WSAEAFNOSUPPORT;
- goto done;
- }
RtlInitUnicodeString(&string, afdW);
InitializeObjectAttributes(&attr, &string, (flags & WSA_FLAG_NO_HANDLE_INHERIT) ? 0 : OBJ_INHERIT, NULL, NULL);
@@ -7647,8 +7612,8 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
return INVALID_SOCKET;
}
- create_params.family = unixaf;
- create_params.type = unixtype;
+ create_params.family = af;
+ create_params.type = type;
create_params.protocol = protocol;
create_params.flags = flags & ~(WSA_FLAG_NO_HANDLE_INHERIT | WSA_FLAG_OVERLAPPED);
if ((status = NtDeviceIoControlFile(handle, NULL, NULL, NULL, &io,
diff --git a/server/sock.c b/server/sock.c
index 3bc4780f94..f0227c5906 100644
--- a/server/sock.c
+++ b/server/sock.c
@@ -30,6 +30,9 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
+#ifdef HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
#ifdef HAVE_POLL_H
# include <poll.h>
#endif
@@ -51,6 +54,29 @@
# include <linux/rtnetlink.h>
#endif
+#ifdef HAVE_NETIPX_IPX_H
+# include <netipx/ipx.h>
+#elif defined(HAVE_LINUX_IPX_H)
+# ifdef HAVE_ASM_TYPES_H
+# include <asm/types.h>
+# endif
+# ifdef HAVE_LINUX_TYPES_H
+# include <linux/types.h>
+# endif
+# include <linux/ipx.h>
+#endif
+#if defined(SOL_IPX) || defined(SO_DEFAULT_HEADERS)
+# define HAS_IPX
+#endif
+
+#ifdef HAVE_LINUX_IRDA_H
+# ifdef HAVE_LINUX_TYPES_H
+# include <linux/types.h>
+# endif
+# include <linux/irda.h>
+# define HAS_IRDA
+#endif
+
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
@@ -58,6 +84,7 @@
#include "winerror.h"
#define USE_WS_PREFIX
#include "winsock2.h"
+#include "wsipx.h"
#include "wine/afd.h"
#include "process.h"
@@ -638,12 +665,80 @@ static struct sock *create_socket(void)
return sock;
}
+static int get_unix_family( int family )
+{
+ switch (family)
+ {
+ case WS_AF_INET: return AF_INET;
+ case WS_AF_INET6: return AF_INET6;
+#ifdef HAS_IPX
+ case WS_AF_IPX: return AF_IPX;
+#endif
+#ifdef AF_IRDA
+ case WS_AF_IRDA: return AF_IRDA;
+#endif
+ case WS_AF_UNSPEC: return AF_UNSPEC;
+ default: return -1;
+ }
+}
+
+static int get_unix_type( int type )
+{
+ switch (type)
+ {
+ case WS_SOCK_DGRAM: return SOCK_DGRAM;
+ case WS_SOCK_RAW: return SOCK_RAW;
+ case WS_SOCK_STREAM: return SOCK_STREAM;
+ default: return -1;
+ }
+}
+
+static int get_unix_protocol( int protocol )
+{
+ if (protocol >= WS_NSPROTO_IPX && protocol <= WS_NSPROTO_IPX + 255)
+ return protocol;
+
+ switch (protocol)
+ {
+ case WS_IPPROTO_ICMP: return IPPROTO_ICMP;
+ case WS_IPPROTO_IGMP: return IPPROTO_IGMP;
+ case WS_IPPROTO_IP: return IPPROTO_IP;
+ case WS_IPPROTO_IPIP: return IPPROTO_IPIP;
+ case WS_IPPROTO_IPV6: return IPPROTO_IPV6;
+ case WS_IPPROTO_RAW: return IPPROTO_RAW;
+ case WS_IPPROTO_TCP: return IPPROTO_TCP;
+ case WS_IPPROTO_UDP: return IPPROTO_UDP;
+ default: return -1;
+ }
+}
+
static int init_socket( struct sock *sock, int family, int type, int protocol, unsigned int flags )
{
unsigned int options = 0;
- int sockfd;
+ int sockfd, unix_type, unix_family, unix_protocol;
+
+ unix_family = get_unix_family( family );
+ unix_type = get_unix_type( type );
+ unix_protocol = get_unix_protocol( protocol );
+
+ if (unix_protocol < 0)
+ {
+ if (type && unix_type < 0)
+ set_win32_error( WSAESOCKTNOSUPPORT );
+ else
+ set_win32_error( WSAEPROTONOSUPPORT );
+ return -1;
+ }
+ if (unix_family < 0)
+ {
+ if (family >= 0 && unix_type < 0)
+ set_win32_error( WSAESOCKTNOSUPPORT );
+ else
+ set_win32_error( WSAEAFNOSUPPORT );
+ return -1;
+ }
- sockfd = socket( family, type, protocol );
+ sockfd = socket( unix_family, unix_type, unix_protocol );
if (sockfd == -1)
{
if (errno == EINVAL) set_win32_error( WSAESOCKTNOSUPPORT );
@@ -653,9 +748,9 @@ static int init_socket( struct sock *sock, int family, int type, int protocol, u
fcntl(sockfd, F_SETFL, O_NONBLOCK); /* make socket nonblocking */
sock->state = (type != SOCK_STREAM) ? (FD_READ|FD_WRITE) : 0;
sock->flags = flags;
- sock->proto = protocol;
- sock->type = type;
- sock->family = family;
+ sock->proto = unix_protocol;
+ sock->type = unix_type;
+ sock->family = unix_family;
if (sock->fd)
{
More information about the wine-cvs
mailing list