7#if (NTDDI_VERSION >= NTDDI_WIN2K)
14#if defined(__GOT_SECURE_LIB__) && __GOT_SECURE_LIB__ >= 200402L
16#define _WSPIAPI_STRCPY_S strcpy_s
17#define _WSPIAPI_STRCAT_S strcat_s
21#define _WSPIAPI_STRCPY_S(_Dst, _Size, _Src) strcpy((_Dst), (_Src))
22#define _WSPIAPI_STRCAT_S(_Dst, _Size, _Src) strcat((_Dst), (_Src))
26#define _WSPIAPI_STRNCPY_S(_Dst, _Size, _Src, _Count) strncpy((_Dst), (_Src), (_Count)); (_Dst)[(_Size) - 1] = 0
27#define _WSPIAPI_SPRINTF_S_1(_Dst, _Size, _Format, _Arg1) sprintf((_Dst), (_Format), (_Arg1))
29#if !defined(_WSPIAPI_COUNTOF)
31#if !defined(__cplusplus)
32#define _WSPIAPI_COUNTOF(_Array) (sizeof(_Array) / sizeof(_Array[0]))
34template <
typename __CountofType,
size_t _N>
35char (&__wspiapi_countof_helper(__CountofType (&_Array)[
_N]))[
_N];
36#define _WSPIAPI_COUNTOF(_Array) sizeof(__wspiapi_countof_helper(_Array))
41#define WspiapiMalloc(tSize) calloc(1, (tSize))
42#define WspiapiFree(p) free(p)
43#define WspiapiSwap(a, b, c) {(c) = (a); (a) = (b); (b) = (c);}
44#define getaddrinfo WspiapiGetAddrInfo
45#define getnameinfo WspiapiGetNameInfo
46#define freeaddrinfo WspiapiFreeAddrInfo
49#define WSPIAPI_INLINE __inline
51#define WSPIAPI_INLINE static inline
56 IN const char *nodename,
87 if (!pszMemory)
return(
NULL);
96 IN const char *pszAddress,
100 const char *pcNext =
NULL;
103 for (pcNext = pszAddress; *pcNext !=
'\0'; pcNext++)
104 if (*pcNext ==
'.') iCount++;
105 if (iCount != 3)
return FALSE;
108 *pdwAddress = dwAddress;
125 if (!ptNew)
return NULL;
133 ptAddress->
sin_addr.s_addr = dwAddress;
147 IN const char *pszNodeName,
154 struct addrinfo **pptNext = pptResult;
164 for (ppAddresses = ptHost->
h_addr_list; *ppAddresses !=
NULL; ppAddresses++) {
167 pptNext = &((*pptNext)->ai_next);
186 IN const char *pszNodeName,
197 char *pszName = szFQDN1;
198 char *pszAlias = szFQDN2;
199 char *pszScratch =
NULL;
203 iError =
WspiapiQueryDNS(pszNodeName, iSocketType, iProtocol, wPort, pszAlias, pptResult);
205 if (*pptResult)
break;
206 if ((!
strlen(pszAlias)) || (!
strcmp(pszName, pszAlias)) || (++iAliasCount == 16)) {
212 if (!iError && bAI_CANONNAME) {
214 if (!(*pptResult)->ai_canonname) iError =
EAI_MEMORY;
232 for (ptNext = ptResult; ptNext !=
NULL; ) {
253 for (ptNext = ptHead; ptNext !=
NULL; ptNext = ptHead) {
265 IN const char *pszNodeName,
266 IN const char *pszServiceName,
284 if ((!pszNodeName) && (!pszServiceName))
return EAI_NONAME;
286 if ((ptHints->ai_addrlen != 0) ||
287 (ptHints->ai_canonname !=
NULL) ||
288 (ptHints->ai_addr !=
NULL) ||
289 (ptHints->ai_next !=
NULL)) {
292 iFlags = ptHints->ai_flags;
294 iFamily = ptHints->ai_family;
296 iSocketType = ptHints->ai_socktype;
297 if ((iSocketType != 0) &&
302 iProtocol = ptHints->ai_protocol;
304 if (pszServiceName) {
307 wPort = wTcpPort = wUdpPort =
htons(wPort);
308 if (iSocketType == 0) {
314 if ((iSocketType == 0) || (iSocketType ==
SOCK_DGRAM)) {
316 if (ptService) wPort = wUdpPort = ptService->
s_port;
318 if ((iSocketType == 0) || (iSocketType ==
SOCK_STREAM)) {
320 if (ptService) wPort = wTcpPort = ptService->
s_port;
323 if (iSocketType == 0) {
325 bClone = (wTcpPort && wUdpPort);
333 if (!iError && pszNodeName) {
337 if (!(*pptResult)->ai_canonname) iError =
EAI_MEMORY;
350 if (!iError && bClone) {
367 OUT char *pszNodeName,
368 IN size_t tNodeLength,
369 OUT char *pszServiceName,
370 IN size_t tServiceLength,
375 char szBuffer[] =
"65535";
376 char *pszService = szBuffer;
379 char *pszNode =
NULL;
382 if ((!ptSocketAddress) || (tSocketLength <
sizeof(
struct sockaddr)))
return EAI_FAIL;
385 if (!(pszNodeName && tNodeLength) && !(pszServiceName && tServiceLength)) {
391 if (pszServiceName && tServiceLength) {
392 wPort = ((
struct sockaddr_in *) ptSocketAddress)->sin_port;
398 if (ptService && ptService->
s_name) {
399 pszService = ptService->
s_name;
405 if (tServiceLength >
strlen(pszService))
409 if (pszNodeName && tNodeLength) {
410 tAddress = ((
struct sockaddr_in *) ptSocketAddress)->sin_addr;
416 if (ptHost && ptHost->
h_name) {
444#define WSPIAPI_FUNCTION_ARRAY { \
445 {"getaddrinfo", (FARPROC) WspiapiLegacyGetAddrInfo}, \
446 {"getnameinfo", (FARPROC) WspiapiLegacyGetNameInfo}, \
447 {"freeaddrinfo", (FARPROC) WspiapiLegacyFreeAddrInfo} \
460 static const int iNumGlobal = (
sizeof(rgtGlobal) /
sizeof(
WSPIAPI_FUNCTION));
465 if (
bInitialized)
return (rgtGlobal[wFunction].pfAddress);
475 if (fScratch ==
NULL) {
486 if (fScratch ==
NULL) {
494 for (
i = 0;
i < iNumGlobal;
i++) {
496 if (rgtLocal[
i].pfAddress ==
NULL) {
503 for (
i = 0;
i < iNumGlobal;
i++)
504 rgtGlobal[
i].pfAddress = rgtLocal[
i].pfAddress;
509 return (rgtGlobal[wFunction].pfAddress);
547 iError = (*pfGetNameInfo)(
sa, salen,
host, hostlen, serv, servlen,
flags);
562 (*pfFreeAddrInfo)(ai);
PRTL_UNICODE_STRING_BUFFER Path
int strcmp(const char *String1, const char *String2)
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
ACPI_SIZE strlen(const char *String)
char * strchr(const char *String, int ch)
CHAR FAR *WSAAPI inet_ntoa(IN IN_ADDR in)
ULONG WSAAPI inet_addr(IN CONST CHAR FAR *cp)
static struct sockaddr_in sa
#define GetProcAddress(x, y)
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
VOID WSAAPI WSASetLastError(IN INT iError)
PSERVENT WSAAPI getservbyport(IN int port, IN const char FAR *proto)
PHOSTENT WSAAPI gethostbyname(IN const char FAR *name)
PSERVENT WSAAPI getservbyname(IN const char FAR *name, IN const char FAR *proto)
PHOSTENT WSAAPI gethostbyaddr(IN const char FAR *addr, IN int len, IN int type)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
namespace GUID const ADDRINFOEXW * hints
static const ADDRINFOW PADDRINFOW *static const WCHAR * servname
PULONG MinorVersion OPTIONAL
struct sockaddr * ai_addr
struct addrinfo * ai_next
_In_ DWORD _In_ DWORD _Out_writes_to_opt_ pcchString LPSTR pszString
#define WSAHOST_NOT_FOUND
int PASCAL FAR WSAGetLastError(void)
FORCEINLINE int WINAPI WspiapiLookupNode(IN const char *pszNodeName, IN int iSocketType, IN int iProtocol, IN WORD wPort, IN BOOL bAI_CANONNAME, OUT struct addrinfo **pptResult)
static __inline void WINAPI WspiapiLegacyFreeAddrInfo(IN struct addrinfo *ptHead)
static __inline int WINAPI WspiapiLegacyGetNameInfo(IN const struct sockaddr *ptSocketAddress, IN socklen_t tSocketLength, OUT char *pszNodeName, IN size_t tNodeLength, OUT char *pszServiceName, IN size_t tServiceLength, IN int iFlags)
int(WINAPI * WSPIAPI_PGETNAMEINFO)(IN const struct sockaddr *sa, IN socklen_t salen, OUT char *host, IN size_t hostlen, OUT char *serv, IN size_t servlen, IN int flags)
#define _WSPIAPI_SPRINTF_S_1(_Dst, _Size, _Format, _Arg1)
static __inline int WINAPI WspiapiLegacyGetAddrInfo(IN const char *pszNodeName, IN const char *pszServiceName, IN const struct addrinfo *ptHints, OUT struct addrinfo **pptResult)
WSPIAPI_INLINE int WINAPI WspiapiGetAddrInfo(IN const char *nodename OPTIONAL, IN const char *servname OPTIONAL, IN const struct addrinfo *hints OPTIONAL, OUT struct addrinfo **res)
#define WSPIAPI_FUNCTION_ARRAY
FORCEINLINE struct addrinfo *WINAPI WspiapiNewAddrInfo(IN int iSocketType, IN int iProtocol, IN WORD wPort, IN DWORD dwAddress)
WSPIAPI_INLINE void WINAPI WspiapiFreeAddrInfo(IN struct addrinfo *ai)
FORCEINLINE char *WINAPI WspiapiStrdup(IN const char *pszString)
#define WspiapiMalloc(tSize)
WSPIAPI_INLINE int WINAPI WspiapiGetNameInfo(IN const struct sockaddr *sa, IN socklen_t salen, OUT char *host, IN size_t hostlen, OUT char *serv, IN size_t servlen, IN int flags)
void(WINAPI * WSPIAPI_PFREEADDRINFO)(IN struct addrinfo *ai)
int(WINAPI * WSPIAPI_PGETADDRINFO)(IN const char *nodename, IN const char *servname, IN const struct addrinfo *hints, OUT struct addrinfo **res)
FORCEINLINE BOOL WINAPI WspiapiParseV4Address(IN const char *pszAddress, OUT PDWORD pdwAddress)
#define _WSPIAPI_STRNCPY_S(_Dst, _Size, _Src, _Count)
FORCEINLINE int WINAPI WspiapiQueryDNS(IN const char *pszNodeName, IN int iSocketType, IN int iProtocol, IN WORD wPort, OUT char pszAlias[NI_MAXHOST], OUT struct addrinfo **pptResult)
WSPIAPI_INLINE FARPROC WINAPI WspiapiLoad(IN WORD wFunction)
#define _WSPIAPI_STRCPY_S(_Dst, _Size, _Src)
#define WspiapiSwap(a, b, c)
FORCEINLINE int WINAPI WspiapiClone(IN WORD wPort, IN struct addrinfo *ptResult)
#define _WSPIAPI_COUNTOF(_Array)
#define _WSPIAPI_STRCAT_S(_Dst, _Size, _Src)