From: Zebediah Figura Subject: [PATCH v3 3/5] server: Introduce IOCTL_AFD_CREATE. Message-Id: <20200919221338.1880691-3-z.figura12@gmail.com> Date: Sat, 19 Sep 2020 17:13:36 -0500 In-Reply-To: <20200919221338.1880691-1-z.figura12@gmail.com> References: <20200919221338.1880691-1-z.figura12@gmail.com> Signed-off-by: Zebediah Figura --- v3: Avoid collision with other publicly defined ioctls. include/wine/afd.h | 34 ++++++++++++++++++++++++++++++++++ server/sock.c | 19 ++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 include/wine/afd.h diff --git a/include/wine/afd.h b/include/wine/afd.h new file mode 100644 index 00000000000..41caaa7b4f3 --- /dev/null +++ b/include/wine/afd.h @@ -0,0 +1,34 @@ +/* + * Socket driver ioctls + * + * Copyright 2020 Zebediah Figura for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __WINE_WINE_AFD_H +#define __WINE_WINE_AFD_H + +#include + +#define IOCTL_AFD_CREATE CTL_CODE(FILE_DEVICE_NETWORK, 200, METHOD_BUFFERED, FILE_WRITE_ACCESS) + +struct afd_create_params +{ + int family, type, protocol; + unsigned int flags; +}; + +#endif diff --git a/server/sock.c b/server/sock.c index 0448519df2a..2b6e02907ee 100644 --- a/server/sock.c +++ b/server/sock.c @@ -58,6 +58,7 @@ #include "winerror.h" #define USE_WS_PREFIX #include "winsock2.h" +#include "wine/afd.h" #include "process.h" #include "file.h" @@ -133,6 +134,7 @@ static int sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ); static void sock_queue_async( struct fd *fd, struct async *async, int type, int count ); static void sock_reselect_async( struct fd *fd, struct async_queue *queue ); +static int init_socket( struct sock *sock, int family, int type, int protocol, unsigned int flags ); static int sock_get_ntstatus( int err ); static unsigned int sock_get_error( int err ); @@ -542,10 +544,23 @@ static int sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) assert( sock->obj.ops == &sock_ops ); - if (get_unix_fd( fd ) == -1) return 0; + if (get_unix_fd( fd ) == -1 && code != IOCTL_AFD_CREATE) return 0; switch(code) { + case IOCTL_AFD_CREATE: + { + const struct afd_create_params *params = get_req_data(); + + if (get_req_data_size() != sizeof(*params)) + { + set_error( STATUS_INVALID_PARAMETER ); + return 0; + } + init_socket( sock, params->family, params->type, params->protocol, params->flags ); + return 0; + } + case WS_SIO_ADDRESS_LIST_CHANGE: if ((sock->state & FD_WINE_NONBLOCKING) && async_is_blocking( async )) { @@ -680,6 +695,8 @@ static int init_socket( struct sock *sock, int family, int type, int protocol, u sock->type = type; sock->family = family; + if (sock->fd) release_object( sock->fd ); + if (!(sock->fd = create_anonymous_fd( &sock_fd_ops, sockfd, &sock->obj, (flags & WSA_FLAG_OVERLAPPED) ? 0 : FILE_SYNCHRONOUS_IO_NONALERT ))) { -- 2.28.0