diff --git a/os/Xtrans.c b/os/Xtrans.c index 2b739a0dd..9c9c851b7 100644 --- a/os/Xtrans.c +++ b/os/Xtrans.c @@ -46,6 +46,7 @@ from The Open Group. * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #include #include @@ -54,6 +55,8 @@ from The Open Group. #include #endif +#include "os/ossock.h" + /* * The transport table contains a definition for every transport (protocol) * family. All operations that can be made on the transport go through this @@ -401,13 +404,7 @@ _XSERVTransOpen (int type, const char *address) prmsg (2,"Open(%d,%s)\n", type, address); -#if defined(WIN32) && defined(TCPCONN) - if (_XSERVTransWSAStartup()) - { - prmsg (1,"Open: WSAStartup failed\n"); - return NULL; - } -#endif + ossock_init(); /* Parse the Address */ diff --git a/os/Xtrans.h b/os/Xtrans.h index 3dc45a6ae..696078d48 100644 --- a/os/Xtrans.h +++ b/os/Xtrans.h @@ -297,8 +297,4 @@ int _XSERVTransGetHostname ( int /* maxlen */ ); -#if defined(WIN32) && defined(TCPCONN) -int _XSERVTransWSAStartup(void); -#endif - #endif /* _XTRANS_H_ */ diff --git a/os/Xtransutil.c b/os/Xtransutil.c index 8d7849f60..de11c01dd 100644 --- a/os/Xtransutil.c +++ b/os/Xtransutil.c @@ -219,19 +219,6 @@ int _XSERVTransConvertAddress(int *familyp, int *addrlenp, Xtransaddr **addrp) return 0; } -#if defined(WIN32) && defined(TCPCONN) -int _XSERVTransWSAStartup (void) -{ - static WSADATA wsadata; - - prmsg (2,"WSAStartup()\n"); - - if (!wsadata.wVersion && WSAStartup(MAKEWORD(2,2), &wsadata)) - return 1; - return 0; -} -#endif - #include #include #include diff --git a/os/meson.build b/os/meson.build index 20a411c2b..ff135b965 100644 --- a/os/meson.build +++ b/os/meson.build @@ -13,6 +13,7 @@ srcs_os = [ 'mitauth.c', 'osinit.c', 'ospoll.c', + 'ossock.c', 'serverlock.c', 'string.c', 'utils.c', diff --git a/os/ossock.c b/os/ossock.c new file mode 100644 index 000000000..3100b6312 --- /dev/null +++ b/os/ossock.c @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: MIT OR X11 + * + * Copyright © 2024 Enrico Weigelt, metux IT consult + */ +#include + +#ifdef WIN32 +#include +#endif + +#include "os/ossock.h" + +void ossock_init(void) +{ +#ifdef WIN32 + static WSADATA wsadata; + if (!wsadata.wVersion) + WSAStartup(0x0202, &wsadata); +#endif +} diff --git a/os/ossock.h b/os/ossock.h new file mode 100644 index 000000000..c62575693 --- /dev/null +++ b/os/ossock.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: MIT OR X11 + * + * Copyright © 2024 Enrico Weigelt, metux IT consult + */ +#ifndef _XSERVER_OS_OSSOCK_H_ +#define _XSERVER_OS_OSSOCK_H_ + +/* + * os specific initialization of the socket layer + */ +void ossock_init(void); + +#endif /* _XSERVER_OS_OSSOCK_H_ */ diff --git a/os/xdmcp.c b/os/xdmcp.c index a4cb3e2dc..8a3ea4e7a 100644 --- a/os/xdmcp.c +++ b/os/xdmcp.c @@ -37,6 +37,7 @@ #include "dix/dix_priv.h" #include "os/auth.h" +#include "os/ossock.h" #include "misc.h" #include "osdep.h" @@ -1412,9 +1413,7 @@ get_addr_by_name(const char *argtype, #ifdef XTHREADS_NEEDS_BYNAMEPARAMS _Xgethostbynameparams hparams; #endif -#if defined(WIN32) && defined(TCPCONN) - _XSERVTransWSAStartup(); -#endif + ossock_init(); if (!(hep = _XGethostbyname(namestr, hparams))) { FatalError("Xserver: %s unknown host: %s\n", argtype, namestr); }