1 | /* $Id: vcc100-ws2_32-fakes.cpp 70360 2017-12-27 16:57:22Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Tricks to make the Visual C++ 2010 CRT work on NT4, W2K and XP - WS2_32.DLL.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #include <iprt/cdefs.h>
|
---|
32 | #include <iprt/types.h>
|
---|
33 | #include <iprt/asm.h>
|
---|
34 | #include <iprt/string.h>
|
---|
35 |
|
---|
36 | #ifndef RT_ARCH_X86
|
---|
37 | # error "This code is X86 only"
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | #define getaddrinfo Ignore_getaddrinfo
|
---|
41 | #define freeaddrinfo Ignore_freeaddrinfo
|
---|
42 |
|
---|
43 | #include <iprt/win/winsock2.h>
|
---|
44 | #include <iprt/win/ws2tcpip.h>
|
---|
45 |
|
---|
46 | #undef getaddrinfo
|
---|
47 | #undef freeaddrinfo
|
---|
48 |
|
---|
49 |
|
---|
50 | /** Dynamically resolves an kernel32 API. */
|
---|
51 | #define RESOLVE_ME(ApiNm) \
|
---|
52 | static bool volatile s_fInitialized = false; \
|
---|
53 | static decltype(ApiNm) *s_pfnApi = NULL; \
|
---|
54 | decltype(ApiNm) *pfnApi; \
|
---|
55 | if (s_fInitialized) \
|
---|
56 | pfnApi = s_pfnApi; \
|
---|
57 | else \
|
---|
58 | { \
|
---|
59 | pfnApi = (decltype(pfnApi))GetProcAddress(GetModuleHandleW(L"wc2_32.dll"), #ApiNm); \
|
---|
60 | s_pfnApi = pfnApi; \
|
---|
61 | s_fInitialized = true; \
|
---|
62 | } do {} while (0) \
|
---|
63 |
|
---|
64 |
|
---|
65 | extern "C"
|
---|
66 | __declspec(dllexport)
|
---|
67 | int WINAPI getaddrinfo(const char *pszNodeName, const char *pszServiceName, const struct addrinfo *pHints,
|
---|
68 | struct addrinfo **ppResults)
|
---|
69 | {
|
---|
70 | RESOLVE_ME(getaddrinfo);
|
---|
71 | if (pfnApi)
|
---|
72 | return pfnApi(pszNodeName, pszServiceName, pHints, ppResults);
|
---|
73 |
|
---|
74 | /** @todo fallback */
|
---|
75 | WSASetLastError(WSAEAFNOSUPPORT);
|
---|
76 | return WSAEAFNOSUPPORT;
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 |
|
---|
81 | extern "C"
|
---|
82 | __declspec(dllexport)
|
---|
83 | void WINAPI freeaddrinfo(struct addrinfo *pResults)
|
---|
84 | {
|
---|
85 | RESOLVE_ME(freeaddrinfo);
|
---|
86 | if (pfnApi)
|
---|
87 | pfnApi(pResults);
|
---|
88 | else
|
---|
89 | {
|
---|
90 | Assert(!pResults);
|
---|
91 | /** @todo fallback */
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 |
|
---|
97 | /* Dummy to force dragging in this object in the link, so the linker
|
---|
98 | won't accidentally use the symbols from kernel32. */
|
---|
99 | extern "C" int vcc100_ws2_32_fakes_cpp(void)
|
---|
100 | {
|
---|
101 | return 42;
|
---|
102 | }
|
---|
103 |
|
---|