ReactOS 0.4.16-dev-336-gb667d82
wspiapi.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
Include dependency graph for wspiapi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  WSPIAPI_FUNCTION
 

Macros

#define _WSPIAPI_STRCPY_S(_Dst, _Size, _Src)   strcpy((_Dst), (_Src))
 
#define _WSPIAPI_STRCAT_S(_Dst, _Size, _Src)   strcat((_Dst), (_Src))
 
#define _WSPIAPI_STRNCPY_S(_Dst, _Size, _Src, _Count)   strncpy((_Dst), (_Src), (_Count)); (_Dst)[(_Size) - 1] = 0
 
#define _WSPIAPI_SPRINTF_S_1(_Dst, _Size, _Format, _Arg1)   sprintf((_Dst), (_Format), (_Arg1))
 
#define _WSPIAPI_COUNTOF(_Array)   (sizeof(_Array) / sizeof(_Array[0]))
 
#define WspiapiMalloc(tSize)   calloc(1, (tSize))
 
#define WspiapiFree(p)   free(p)
 
#define WspiapiSwap(a, b, c)   {(c) = (a); (a) = (b); (b) = (c);}
 
#define getaddrinfo   WspiapiGetAddrInfo
 
#define getnameinfo   WspiapiGetNameInfo
 
#define freeaddrinfo   WspiapiFreeAddrInfo
 
#define WSPIAPI_INLINE   static inline
 
#define WSPIAPI_FUNCTION_ARRAY
 

Typedefs

typedef int(WINAPIWSPIAPI_PGETADDRINFO) (IN const char *nodename, IN const char *servname, IN const struct addrinfo *hints, OUT struct addrinfo **res)
 
typedef int(WINAPIWSPIAPI_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)
 
typedef void(WINAPIWSPIAPI_PFREEADDRINFO) (IN struct addrinfo *ai)
 

Functions

FORCEINLINE char *WINAPI WspiapiStrdup (IN const char *pszString)
 
FORCEINLINE BOOL WINAPI WspiapiParseV4Address (IN const char *pszAddress, OUT PDWORD pdwAddress)
 
FORCEINLINE struct addrinfo *WINAPI WspiapiNewAddrInfo (IN int iSocketType, IN int iProtocol, IN WORD wPort, IN DWORD dwAddress)
 
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)
 
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)
 
FORCEINLINE int WINAPI WspiapiClone (IN WORD wPort, IN struct addrinfo *ptResult)
 
static __inline void WINAPI WspiapiLegacyFreeAddrInfo (IN struct addrinfo *ptHead)
 
static __inline int WINAPI WspiapiLegacyGetAddrInfo (IN const char *pszNodeName, IN const char *pszServiceName, IN const struct addrinfo *ptHints, OUT struct addrinfo **pptResult)
 
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)
 
WSPIAPI_INLINE FARPROC WINAPI WspiapiLoad (IN WORD wFunction)
 
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)
 
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)
 
WSPIAPI_INLINE void WINAPI WspiapiFreeAddrInfo (IN struct addrinfo *ai)
 

Macro Definition Documentation

◆ _WSPIAPI_COUNTOF

#define _WSPIAPI_COUNTOF (   _Array)    (sizeof(_Array) / sizeof(_Array[0]))

Definition at line 32 of file wspiapi.h.

◆ _WSPIAPI_SPRINTF_S_1

#define _WSPIAPI_SPRINTF_S_1 (   _Dst,
  _Size,
  _Format,
  _Arg1 
)    sprintf((_Dst), (_Format), (_Arg1))

Definition at line 27 of file wspiapi.h.

◆ _WSPIAPI_STRCAT_S

#define _WSPIAPI_STRCAT_S (   _Dst,
  _Size,
  _Src 
)    strcat((_Dst), (_Src))

Definition at line 22 of file wspiapi.h.

◆ _WSPIAPI_STRCPY_S

#define _WSPIAPI_STRCPY_S (   _Dst,
  _Size,
  _Src 
)    strcpy((_Dst), (_Src))

Definition at line 21 of file wspiapi.h.

◆ _WSPIAPI_STRNCPY_S

#define _WSPIAPI_STRNCPY_S (   _Dst,
  _Size,
  _Src,
  _Count 
)    strncpy((_Dst), (_Src), (_Count)); (_Dst)[(_Size) - 1] = 0

Definition at line 26 of file wspiapi.h.

◆ freeaddrinfo

#define freeaddrinfo   WspiapiFreeAddrInfo

Definition at line 46 of file wspiapi.h.

◆ getaddrinfo

#define getaddrinfo   WspiapiGetAddrInfo

Definition at line 44 of file wspiapi.h.

◆ getnameinfo

#define getnameinfo   WspiapiGetNameInfo

Definition at line 45 of file wspiapi.h.

◆ WSPIAPI_FUNCTION_ARRAY

#define WSPIAPI_FUNCTION_ARRAY
Value:
{ \
{"getaddrinfo", (FARPROC) WspiapiLegacyGetAddrInfo}, \
{"getnameinfo", (FARPROC) WspiapiLegacyGetNameInfo}, \
{"freeaddrinfo", (FARPROC) WspiapiLegacyFreeAddrInfo} \
}
int(* FARPROC)()
Definition: compat.h:36
static __inline void WINAPI WspiapiLegacyFreeAddrInfo(IN struct addrinfo *ptHead)
Definition: wspiapi.h:248
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)
Definition: wspiapi.h:364
static __inline int WINAPI WspiapiLegacyGetAddrInfo(IN const char *pszNodeName, IN const char *pszServiceName, IN const struct addrinfo *ptHints, OUT struct addrinfo **pptResult)
Definition: wspiapi.h:264

Definition at line 444 of file wspiapi.h.

◆ WSPIAPI_INLINE

#define WSPIAPI_INLINE   static inline

Definition at line 51 of file wspiapi.h.

◆ WspiapiFree

#define WspiapiFree (   p)    free(p)

Definition at line 42 of file wspiapi.h.

◆ WspiapiMalloc

#define WspiapiMalloc (   tSize)    calloc(1, (tSize))

Definition at line 41 of file wspiapi.h.

◆ WspiapiSwap

#define WspiapiSwap (   a,
  b,
  c 
)    {(c) = (a); (a) = (b); (b) = (c);}

Definition at line 43 of file wspiapi.h.

Typedef Documentation

◆ WSPIAPI_PFREEADDRINFO

typedef void(WINAPI * WSPIAPI_PFREEADDRINFO) (IN struct addrinfo *ai)

Definition at line 71 of file wspiapi.h.

◆ WSPIAPI_PGETADDRINFO

typedef int(WINAPI * WSPIAPI_PGETADDRINFO) (IN const char *nodename, IN const char *servname, IN const struct addrinfo *hints, OUT struct addrinfo **res)

Definition at line 54 of file wspiapi.h.

◆ WSPIAPI_PGETNAMEINFO

typedef 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)

Definition at line 61 of file wspiapi.h.

Function Documentation

◆ WspiapiClone()

FORCEINLINE int WINAPI WspiapiClone ( IN WORD  wPort,
IN struct addrinfo ptResult 
)

Definition at line 225 of file wspiapi.h.

228{
229 struct addrinfo *ptNext = NULL;
230 struct addrinfo *ptNew = NULL;
231
232 for (ptNext = ptResult; ptNext != NULL; ) {
233 ptNew = WspiapiNewAddrInfo(SOCK_DGRAM, ptNext->ai_protocol, wPort,
234 ((struct sockaddr_in *) ptNext->ai_addr)->sin_addr.s_addr);
235 if (!ptNew) break;
236 ptNew->ai_next = ptNext->ai_next;
237 ptNext->ai_next = ptNew;
238 ptNext = ptNew->ai_next;
239 }
240 if (ptNext != NULL) return EAI_MEMORY;
241
242 return 0;
243}
#define NULL
Definition: types.h:112
struct sockaddr * ai_addr
Definition: ws2def.h:671
int ai_protocol
Definition: ws2def.h:668
struct addrinfo * ai_next
Definition: ws2def.h:672
#define SOCK_DGRAM
Definition: winsock.h:336
#define EAI_MEMORY
Definition: ws2tcpip.h:35
FORCEINLINE struct addrinfo *WINAPI WspiapiNewAddrInfo(IN int iSocketType, IN int iProtocol, IN WORD wPort, IN DWORD dwAddress)
Definition: wspiapi.h:115

Referenced by WspiapiLegacyGetAddrInfo().

◆ WspiapiFreeAddrInfo()

WSPIAPI_INLINE void WINAPI WspiapiFreeAddrInfo ( IN struct addrinfo ai)

Definition at line 556 of file wspiapi.h.

558{
559 static WSPIAPI_PFREEADDRINFO pfFreeAddrInfo = NULL;
560
561 if (!pfFreeAddrInfo) pfFreeAddrInfo = (WSPIAPI_PFREEADDRINFO) WspiapiLoad(2);
562 (*pfFreeAddrInfo)(ai);
563}
void(WINAPI * WSPIAPI_PFREEADDRINFO)(IN struct addrinfo *ai)
Definition: wspiapi.h:72
WSPIAPI_INLINE FARPROC WINAPI WspiapiLoad(IN WORD wFunction)
Definition: wspiapi.h:453

◆ WspiapiGetAddrInfo()

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 
)

Definition at line 515 of file wspiapi.h.

520{
521 int iError;
522 static WSPIAPI_PGETADDRINFO pfGetAddrInfo = NULL;
523
524 if (!pfGetAddrInfo) pfGetAddrInfo = (WSPIAPI_PGETADDRINFO) WspiapiLoad(0);
525 iError = (*pfGetAddrInfo)(nodename, servname, hints, res);
526 WSASetLastError(iError);
527
528 return iError;
529}
VOID WSAAPI WSASetLastError(IN INT iError)
Definition: dllmain.c:123
GLuint res
Definition: glext.h:9613
namespace GUID const ADDRINFOEXW * hints
Definition: sock.c:80
static const ADDRINFOW PADDRINFOW *static const WCHAR * servname
Definition: sock.c:79
int(WINAPI * WSPIAPI_PGETADDRINFO)(IN const char *nodename, IN const char *servname, IN const struct addrinfo *hints, OUT struct addrinfo **res)
Definition: wspiapi.h:55

◆ WspiapiGetNameInfo()

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 
)

Definition at line 534 of file wspiapi.h.

542{
543 int iError;
544 static WSPIAPI_PGETNAMEINFO pfGetNameInfo = NULL;
545
546 if (!pfGetNameInfo) pfGetNameInfo = (WSPIAPI_PGETNAMEINFO) WspiapiLoad(1);
547 iError = (*pfGetNameInfo)(sa, salen, host, hostlen, serv, servlen, flags);
548 WSASetLastError(iError);
549
550 return iError;
551}
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
GLbitfield flags
Definition: glext.h:7161
char * host
Definition: whois.c:55
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)
Definition: wspiapi.h:62

◆ WspiapiLegacyFreeAddrInfo()

static __inline void WINAPI WspiapiLegacyFreeAddrInfo ( IN struct addrinfo ptHead)
static

Definition at line 248 of file wspiapi.h.

250{
251 struct addrinfo *ptNext;
252
253 for (ptNext = ptHead; ptNext != NULL; ptNext = ptHead) {
254 if (ptNext->ai_canonname) WspiapiFree(ptNext->ai_canonname);
255 if (ptNext->ai_addr) WspiapiFree(ptNext->ai_addr);
256 ptHead = ptNext->ai_next;
257 WspiapiFree(ptNext);
258 }
259}
char * ai_canonname
Definition: ws2def.h:670
#define WspiapiFree(p)
Definition: wspiapi.h:42

Referenced by WspiapiLegacyGetAddrInfo().

◆ WspiapiLegacyGetAddrInfo()

static __inline int WINAPI WspiapiLegacyGetAddrInfo ( IN const char pszNodeName,
IN const char pszServiceName,
IN const struct addrinfo ptHints,
OUT struct addrinfo **  pptResult 
)
static

Definition at line 264 of file wspiapi.h.

269{
270 int iError = 0;
271 int iFlags = 0;
272 int iFamily = PF_UNSPEC;
273 int iSocketType = 0;
274 int iProtocol = 0;
275 WORD wPort = 0;
276 DWORD dwAddress = 0;
277 struct servent *ptService = NULL;
278 char *pc = NULL;
279 BOOL bClone = FALSE;
280 WORD wTcpPort = 0;
281 WORD wUdpPort = 0;
282 *pptResult = NULL;
283
284 if ((!pszNodeName) && (!pszServiceName)) return EAI_NONAME;
285 if (ptHints) {
286 if ((ptHints->ai_addrlen != 0) ||
287 (ptHints->ai_canonname != NULL) ||
288 (ptHints->ai_addr != NULL) ||
289 (ptHints->ai_next != NULL)) {
290 return EAI_FAIL;
291 }
292 iFlags = ptHints->ai_flags;
293 if ((iFlags & AI_CANONNAME) && !pszNodeName) return EAI_BADFLAGS;
294 iFamily = ptHints->ai_family;
295 if ((iFamily != PF_UNSPEC) && (iFamily != PF_INET)) return EAI_FAMILY;
296 iSocketType = ptHints->ai_socktype;
297 if ((iSocketType != 0) &&
298 (iSocketType != SOCK_STREAM) &&
299 (iSocketType != SOCK_DGRAM) &&
300 (iSocketType != SOCK_RAW))
301 return EAI_SOCKTYPE;
302 iProtocol = ptHints->ai_protocol;
303 }
304 if (pszServiceName) {
305 wPort = (WORD) strtoul(pszServiceName, &pc, 10);
306 if (*pc == '\0') {
307 wPort = wTcpPort = wUdpPort = htons(wPort);
308 if (iSocketType == 0) {
309 bClone = TRUE;
310 iSocketType = SOCK_STREAM;
311 }
312 }
313 else {
314 if ((iSocketType == 0) || (iSocketType == SOCK_DGRAM)) {
315 ptService = getservbyname(pszServiceName, "udp");
316 if (ptService) wPort = wUdpPort = ptService->s_port;
317 }
318 if ((iSocketType == 0) || (iSocketType == SOCK_STREAM)) {
319 ptService = getservbyname(pszServiceName, "tcp");
320 if (ptService) wPort = wTcpPort = ptService->s_port;
321 }
322 if (wPort == 0) return (iSocketType ? EAI_SERVICE : EAI_NONAME);
323 if (iSocketType == 0) {
324 iSocketType = (wTcpPort) ? SOCK_STREAM : SOCK_DGRAM;
325 bClone = (wTcpPort && wUdpPort);
326 }
327 }
328 }
329 if ((!pszNodeName) || (WspiapiParseV4Address(pszNodeName, &dwAddress))) {
330 if (!pszNodeName) dwAddress = htonl((iFlags & AI_PASSIVE) ? INADDR_ANY : INADDR_LOOPBACK);
331 *pptResult = WspiapiNewAddrInfo(iSocketType, iProtocol, wPort, dwAddress);
332 if (!(*pptResult)) iError = EAI_MEMORY;
333 if (!iError && pszNodeName) {
334 (*pptResult)->ai_flags |= AI_NUMERICHOST;
335 if (iFlags & AI_CANONNAME) {
336 (*pptResult)->ai_canonname = WspiapiStrdup(inet_ntoa(*((struct in_addr *) &dwAddress)));
337 if (!(*pptResult)->ai_canonname) iError = EAI_MEMORY;
338 }
339 }
340 }
341 else if (iFlags & AI_NUMERICHOST) {
342 iError = EAI_NONAME;
343 }
344 else {
345 iError = WspiapiLookupNode(pszNodeName, iSocketType,
346 iProtocol, wPort,
347 (iFlags & AI_CANONNAME),
348 pptResult);
349 }
350 if (!iError && bClone) {
351 iError = WspiapiClone(wUdpPort, *pptResult);
352 }
353 if (iError) {
354 WspiapiLegacyFreeAddrInfo(*pptResult);
355 *pptResult = NULL;
356 }
357
358 return (iError);
359}
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
CHAR FAR *WSAAPI inet_ntoa(IN IN_ADDR in)
Definition: addrconv.c:160
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define SOCK_STREAM
Definition: tcpip.h:118
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
PSERVENT WSAAPI getservbyname(IN const char FAR *name, IN const char FAR *proto)
Definition: getxbyxx.c:500
#define INADDR_ANY
Definition: inet.h:80
#define INADDR_LOOPBACK
Definition: inet.h:78
#define htons(x)
Definition: module.h:215
#define htonl(x)
Definition: module.h:214
Definition: tcpip.h:126
short s_port
Definition: winsock.h:165
#define SOCK_RAW
Definition: winsock.h:337
#define PF_INET
Definition: winsock.h:373
#define PF_UNSPEC
Definition: winsock.h:371
#define AI_NUMERICHOST
Definition: ws2def.h:295
#define AI_CANONNAME
Definition: ws2def.h:294
#define AI_PASSIVE
Definition: ws2def.h:293
#define EAI_NONAME
Definition: ws2tcpip.h:38
#define EAI_SOCKTYPE
Definition: ws2tcpip.h:40
#define EAI_FAMILY
Definition: ws2tcpip.h:34
#define EAI_BADFLAGS
Definition: ws2tcpip.h:32
#define EAI_SERVICE
Definition: ws2tcpip.h:39
#define EAI_FAIL
Definition: ws2tcpip.h:33
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)
Definition: wspiapi.h:185
FORCEINLINE char *WINAPI WspiapiStrdup(IN const char *pszString)
Definition: wspiapi.h:78
FORCEINLINE BOOL WINAPI WspiapiParseV4Address(IN const char *pszAddress, OUT PDWORD pdwAddress)
Definition: wspiapi.h:95
FORCEINLINE int WINAPI WspiapiClone(IN WORD wPort, IN struct addrinfo *ptResult)
Definition: wspiapi.h:225

◆ WspiapiLegacyGetNameInfo()

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 
)
static

Definition at line 364 of file wspiapi.h.

372{
373 struct servent *ptService;
374 WORD wPort;
375 char szBuffer[] = "65535";
376 char *pszService = szBuffer;
377 struct hostent *ptHost;
378 struct in_addr tAddress;
379 char *pszNode = NULL;
380 char *pc = NULL;
381
382 if ((!ptSocketAddress) || (tSocketLength < sizeof(struct sockaddr))) return EAI_FAIL;
383 if (ptSocketAddress->sa_family != AF_INET) return EAI_FAMILY;
384 if (tSocketLength < sizeof(struct sockaddr_in)) return EAI_FAIL;
385 if (!(pszNodeName && tNodeLength) && !(pszServiceName && tServiceLength)) {
386 return EAI_NONAME;
387 }
388 if ((iFlags & NI_NUMERICHOST) && (iFlags & NI_NAMEREQD)) {
389 return EAI_BADFLAGS;
390 }
391 if (pszServiceName && tServiceLength) {
392 wPort = ((struct sockaddr_in *) ptSocketAddress)->sin_port;
393 if (iFlags & NI_NUMERICSERV) {
394 _WSPIAPI_SPRINTF_S_1(szBuffer, _WSPIAPI_COUNTOF(szBuffer), "%u", ntohs(wPort));
395 }
396 else {
397 ptService = getservbyport(wPort, (iFlags & NI_DGRAM) ? "udp" : NULL);
398 if (ptService && ptService->s_name) {
399 pszService = ptService->s_name;
400 }
401 else {
402 _WSPIAPI_SPRINTF_S_1(szBuffer, _WSPIAPI_COUNTOF(szBuffer), "%u", ntohs(wPort));
403 }
404 }
405 if (tServiceLength > strlen(pszService))
406 _WSPIAPI_STRCPY_S(pszServiceName, tServiceLength, pszService);
407 else return EAI_FAIL;
408 }
409 if (pszNodeName && tNodeLength) {
410 tAddress = ((struct sockaddr_in *) ptSocketAddress)->sin_addr;
411 if (iFlags & NI_NUMERICHOST) {
412 pszNode = inet_ntoa(tAddress);
413 }
414 else {
415 ptHost = gethostbyaddr((char *) &tAddress, sizeof(struct in_addr), AF_INET);
416 if (ptHost && ptHost->h_name) {
417 pszNode = ptHost->h_name;
418 if ((iFlags & NI_NOFQDN) && ((pc = strchr(pszNode, '.')) != NULL)) *pc = '\0';
419 }
420 else {
421 if (iFlags & NI_NAMEREQD) {
422 switch (WSAGetLastError()) {
423 case WSAHOST_NOT_FOUND: return EAI_NONAME;
424 case WSATRY_AGAIN: return EAI_AGAIN;
425 case WSANO_RECOVERY: return EAI_FAIL;
426 default: return EAI_NONAME;
427 }
428 }
429 else pszNode = inet_ntoa(tAddress);
430 }
431 }
432 if (tNodeLength > strlen(pszNode)) _WSPIAPI_STRCPY_S(pszNodeName, tNodeLength, pszNode);
433 else return EAI_FAIL;
434 }
435
436 return 0;
437}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define AF_INET
Definition: tcpip.h:117
PSERVENT WSAAPI getservbyport(IN int port, IN const char FAR *proto)
Definition: getxbyxx.c:431
PHOSTENT WSAAPI gethostbyaddr(IN const char FAR *addr, IN int len, IN int type)
Definition: getxbyxx.c:309
#define ntohs(x)
Definition: module.h:210
char * h_name
Definition: winsock.h:134
char * s_name
Definition: winsock.h:159
#define WSATRY_AGAIN
Definition: winerror.h:2001
#define WSAHOST_NOT_FOUND
Definition: winerror.h:2000
#define WSANO_RECOVERY
Definition: winerror.h:2002
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
#define NI_NAMEREQD
Definition: ws2def.h:355
#define NI_NUMERICHOST
Definition: ws2def.h:354
#define NI_DGRAM
Definition: ws2def.h:357
#define NI_NOFQDN
Definition: ws2def.h:353
#define NI_NUMERICSERV
Definition: ws2def.h:356
#define EAI_AGAIN
Definition: ws2tcpip.h:31
#define _WSPIAPI_SPRINTF_S_1(_Dst, _Size, _Format, _Arg1)
Definition: wspiapi.h:27
#define _WSPIAPI_STRCPY_S(_Dst, _Size, _Src)
Definition: wspiapi.h:21
#define _WSPIAPI_COUNTOF(_Array)
Definition: wspiapi.h:32

◆ WspiapiLoad()

WSPIAPI_INLINE FARPROC WINAPI WspiapiLoad ( IN WORD  wFunction)

Definition at line 453 of file wspiapi.h.

455{
457
458 static BOOL bInitialized = FALSE;
459 static WSPIAPI_FUNCTION rgtGlobal[] = WSPIAPI_FUNCTION_ARRAY;
460 static const int iNumGlobal = (sizeof(rgtGlobal) / sizeof(WSPIAPI_FUNCTION));
462 FARPROC fScratch = NULL;
463 int i = 0;
464
465 if (bInitialized) return (rgtGlobal[wFunction].pfAddress);
466 for (;;) {
467 CHAR SystemDir[MAX_PATH + 1];
468 CHAR Path[MAX_PATH + 8];
469 if (GetSystemDirectoryA(SystemDir, MAX_PATH) == 0) break;
473 if (hLibrary != NULL) {
474 fScratch = GetProcAddress(hLibrary, "getaddrinfo");
475 if (fScratch == NULL) {
477 hLibrary = NULL;
478 }
479 }
480 if (hLibrary != NULL) break;
484 if (hLibrary != NULL) {
485 fScratch = GetProcAddress(hLibrary, "getaddrinfo");
486 if (fScratch == NULL) {
488 hLibrary = NULL;
489 }
490 }
491 break;
492 }
493 if (hLibrary != NULL) {
494 for (i = 0; i < iNumGlobal; i++) {
495 rgtLocal[i].pfAddress = GetProcAddress(hLibrary, rgtLocal[i].pszName);
496 if (rgtLocal[i].pfAddress == NULL) {
498 hLibrary = NULL;
499 break;
500 }
501 }
502 if (hLibrary != NULL) {
503 for (i = 0; i < iNumGlobal; i++)
504 rgtGlobal[i].pfAddress = rgtLocal[i].pfAddress;
505 }
506 }
508
509 return (rgtGlobal[wFunction].pfAddress);
510}
PRTL_UNICODE_STRING_BUFFER Path
HMODULE hLibrary
Definition: odbccp32.c:12
static BOOL bInitialized
Definition: dde.cpp:48
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2283
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
Definition: glfuncs.h:248
FARPROC pfAddress
Definition: wspiapi.h:441
#define WSPIAPI_FUNCTION_ARRAY
Definition: wspiapi.h:444
#define _WSPIAPI_STRCAT_S(_Dst, _Size, _Src)
Definition: wspiapi.h:22
char CHAR
Definition: xmlstorage.h:175

Referenced by WspiapiFreeAddrInfo(), WspiapiGetAddrInfo(), and WspiapiGetNameInfo().

◆ WspiapiLookupNode()

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 
)

Definition at line 185 of file wspiapi.h.

192{
193 int iError = 0;
194 int iAliasCount = 0;
195 char szFQDN1[NI_MAXHOST] = "";
196 char szFQDN2[NI_MAXHOST] = "";
197 char *pszName = szFQDN1;
198 char *pszAlias = szFQDN2;
199 char *pszScratch = NULL;
200
201 _WSPIAPI_STRNCPY_S(pszName, NI_MAXHOST, pszNodeName, NI_MAXHOST - 1);
202 for (;;) {
203 iError = WspiapiQueryDNS(pszNodeName, iSocketType, iProtocol, wPort, pszAlias, pptResult);
204 if (iError) break;
205 if (*pptResult) break;
206 if ((!strlen(pszAlias)) || (!strcmp(pszName, pszAlias)) || (++iAliasCount == 16)) {
207 iError = EAI_FAIL;
208 break;
209 }
210 WspiapiSwap(pszName, pszAlias, pszScratch);
211 }
212 if (!iError && bAI_CANONNAME) {
213 (*pptResult)->ai_canonname = WspiapiStrdup(pszAlias);
214 if (!(*pptResult)->ai_canonname) iError = EAI_MEMORY;
215 }
216
217 return iError;
218}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define NI_MAXHOST
Definition: ws2def.h:359
#define _WSPIAPI_STRNCPY_S(_Dst, _Size, _Src, _Count)
Definition: wspiapi.h:26
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)
Definition: wspiapi.h:146
#define WspiapiSwap(a, b, c)
Definition: wspiapi.h:43

Referenced by WspiapiLegacyGetAddrInfo().

◆ WspiapiNewAddrInfo()

FORCEINLINE struct addrinfo *WINAPI WspiapiNewAddrInfo ( IN int  iSocketType,
IN int  iProtocol,
IN WORD  wPort,
IN DWORD  dwAddress 
)

Definition at line 115 of file wspiapi.h.

120{
121 struct addrinfo *ptNew;
122 struct sockaddr_in *ptAddress;
123
124 ptNew = (struct addrinfo *) WspiapiMalloc(sizeof(struct addrinfo));
125 if (!ptNew) return NULL;
126 ptAddress = (struct sockaddr_in *) WspiapiMalloc(sizeof(struct sockaddr_in));
127 if (!ptAddress) {
128 WspiapiFree(ptNew);
129 return NULL;
130 }
131 ptAddress->sin_family = AF_INET;
132 ptAddress->sin_port = wPort;
133 ptAddress->sin_addr.s_addr = dwAddress;
134 ptNew->ai_family = PF_INET;
135 ptNew->ai_socktype = iSocketType;
136 ptNew->ai_protocol = iProtocol;
137 ptNew->ai_addrlen = sizeof(struct sockaddr_in);
138 ptNew->ai_addr = (struct sockaddr *) ptAddress;
139
140 return ptNew;
141}
size_t ai_addrlen
Definition: ws2def.h:669
int ai_socktype
Definition: ws2def.h:667
int ai_family
Definition: ws2def.h:666
struct in_addr sin_addr
Definition: winsock.h:512
short sin_family
Definition: winsock.h:510
u_short sin_port
Definition: winsock.h:511
#define WspiapiMalloc(tSize)
Definition: wspiapi.h:41

Referenced by WspiapiClone(), WspiapiLegacyGetAddrInfo(), and WspiapiQueryDNS().

◆ WspiapiParseV4Address()

FORCEINLINE BOOL WINAPI WspiapiParseV4Address ( IN const char pszAddress,
OUT PDWORD  pdwAddress 
)

Definition at line 95 of file wspiapi.h.

98{
99 DWORD dwAddress = 0;
100 const char *pcNext = NULL;
101 int iCount = 0;
102
103 for (pcNext = pszAddress; *pcNext != '\0'; pcNext++)
104 if (*pcNext == '.') iCount++;
105 if (iCount != 3) return FALSE;
106 dwAddress = inet_addr(pszAddress);
107 if (dwAddress == INADDR_NONE) return FALSE;
108 *pdwAddress = dwAddress;
109 return TRUE;
110}
ULONG WSAAPI inet_addr(IN CONST CHAR FAR *cp)
Definition: addrconv.c:71
#define INADDR_NONE
Definition: tcp.c:42

Referenced by WspiapiLegacyGetAddrInfo().

◆ WspiapiQueryDNS()

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 
)

Definition at line 146 of file wspiapi.h.

153{
154 struct addrinfo **pptNext = pptResult;
155 struct hostent *ptHost = NULL;
156 char **ppAddresses;
157
158 *pptNext = NULL;
159 pszAlias[0] = '\0';
160
161 ptHost = gethostbyname(pszNodeName);
162 if (ptHost) {
163 if ((ptHost->h_addrtype == AF_INET) && (ptHost->h_length == sizeof(struct in_addr))) {
164 for (ppAddresses = ptHost->h_addr_list; *ppAddresses != NULL; ppAddresses++) {
165 *pptNext = WspiapiNewAddrInfo(iSocketType, iProtocol, wPort, ((struct in_addr *) *ppAddresses)->s_addr);
166 if (!*pptNext) return EAI_MEMORY;
167 pptNext = &((*pptNext)->ai_next);
168 }
169 }
170 _WSPIAPI_STRNCPY_S(pszAlias, NI_MAXHOST, ptHost->h_name, NI_MAXHOST - 1);
171 return 0;
172 }
173 switch (WSAGetLastError()) {
174 case WSAHOST_NOT_FOUND: return EAI_NONAME;
175 case WSATRY_AGAIN: return EAI_AGAIN;
176 case WSANO_RECOVERY: return EAI_FAIL;
177 case WSANO_DATA: return EAI_NODATA;
178 default: return EAI_NONAME;
179 }
180}
#define s_addr
Definition: tcpip.h:133
PHOSTENT WSAAPI gethostbyname(IN const char FAR *name)
Definition: getxbyxx.c:221
short h_length
Definition: winsock.h:137
short h_addrtype
Definition: winsock.h:136
char ** h_addr_list
Definition: winsock.h:138
#define WSANO_DATA
Definition: winerror.h:2003
#define EAI_NODATA
Definition: ws2tcpip.h:36

Referenced by WspiapiLookupNode().

◆ WspiapiStrdup()

FORCEINLINE char *WINAPI WspiapiStrdup ( IN const char pszString)

Definition at line 78 of file wspiapi.h.

80{
81 char *pszMemory;
82 size_t cchMemory;
83
84 if (!pszString) return(NULL);
85 cchMemory = strlen(pszString) + 1;
86 pszMemory = (char *) WspiapiMalloc(cchMemory);
87 if (!pszMemory) return(NULL);
88 _WSPIAPI_STRCPY_S(pszMemory, cchMemory, pszString);
89 return pszMemory;
90}
_In_ DWORD _In_ DWORD _Out_writes_to_opt_ pcchString LPSTR pszString
Definition: wincrypt.h:4505

Referenced by WspiapiLegacyGetAddrInfo(), and WspiapiLookupNode().