1
#ifndef WIN32_LEAN_AND_MEAN
2
#define WIN32_LEAN_AND_MEAN
4
#undef __CRT__NO_INLINE
5
#define __CRT__NO_INLINE
10
WspiapiLegacyGetAddrInfo(const char *pszNodeName,
11
const char *pszServiceName,
12
const struct addrinfo *ptHints,
13
struct addrinfo **pptResult)
15
int err = 0, iFlags = 0, iFamily = PF_UNSPEC, iSocketType = 0, iProtocol = 0;
16
struct in_addr inAddress;
17
struct servent *svc = NULL;
19
WINBOOL isCloned = FALSE;
20
WORD tcpPort = 0, udpPort = 0, port = 0;
23
if (!pszNodeName && !pszServiceName)
27
if (ptHints->ai_addrlen != 0 || ptHints->ai_canonname != NULL
28
|| ptHints->ai_addr!=NULL || ptHints->ai_next != NULL)
30
iFlags = ptHints->ai_flags;
31
if ((iFlags & AI_CANONNAME) != 0 && !pszNodeName)
33
iFamily = ptHints->ai_family;
34
if (iFamily != PF_UNSPEC && iFamily != PF_INET)
36
iSocketType = ptHints->ai_socktype;
37
if (iSocketType != 0 && iSocketType != SOCK_STREAM && iSocketType != SOCK_DGRAM
38
&& iSocketType != SOCK_RAW)
40
iProtocol = ptHints->ai_protocol;
45
port = (WORD) strtoul (pszServiceName, &pc, 10);
48
port = tcpPort = udpPort = htons (port);
52
iSocketType = SOCK_STREAM;
57
if (iSocketType == 0 || iSocketType == SOCK_DGRAM)
59
svc = getservbyname(pszServiceName, "udp");
61
port = udpPort = svc->s_port;
63
if (iSocketType == 0 || iSocketType == SOCK_STREAM)
65
svc = getservbyname(pszServiceName, "tcp");
67
port = tcpPort = svc->s_port;
70
return (iSocketType ? EAI_SERVICE : EAI_NONAME);
73
iSocketType = (tcpPort) ? SOCK_STREAM : SOCK_DGRAM;
74
isCloned = (tcpPort && udpPort);
78
if (!pszNodeName || WspiapiParseV4Address(pszNodeName,&inAddress.s_addr))
82
inAddress.s_addr = htonl ((iFlags & AI_PASSIVE) ? INADDR_ANY : INADDR_LOOPBACK);
84
*pptResult = WspiapiNewAddrInfo(iSocketType, iProtocol, port, inAddress.s_addr);
87
if (!err && pszNodeName)
89
(*pptResult)->ai_flags |= AI_NUMERICHOST;
90
if (iFlags & AI_CANONNAME)
92
(*pptResult)->ai_canonname =
93
WspiapiStrdup (inet_ntoa (inAddress));
94
if (!(*pptResult)->ai_canonname)
99
else if (iFlags & AI_NUMERICHOST)
102
err = WspiapiLookupNode (pszNodeName, iSocketType, iProtocol, port,
103
(iFlags & AI_CANONNAME), pptResult);
104
if (!err && isCloned)
105
err = WspiapiClone(udpPort, *pptResult);
108
WspiapiLegacyFreeAddrInfo (*pptResult);