• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef WIN32_LEAN_AND_MEAN
2 #define WIN32_LEAN_AND_MEAN
3 #endif
4 #undef  __CRT__NO_INLINE
5 #define __CRT__NO_INLINE
6 #include <winsock2.h>
7 #include <wspiapi.h>
8 
9 int WINAPI
WspiapiQueryDNS(const char * pszNodeName,int iSocketType,int iProtocol,WORD wPort,char pszAlias[NI_MAXHOST],struct addrinfo ** pptResult)10 WspiapiQueryDNS(const char *pszNodeName,
11 		int iSocketType, int iProtocol,
12 		WORD wPort, char pszAlias[NI_MAXHOST],
13 		struct addrinfo **pptResult)
14 {
15   struct addrinfo **paddrinfo = pptResult;
16   struct hostent *phost = NULL;
17   char **h;
18 
19   *paddrinfo = NULL;
20   pszAlias[0] = 0;
21   phost = gethostbyname (pszNodeName);
22   if (phost)
23     {
24       if (phost->h_addrtype == AF_INET && phost->h_length == sizeof(struct in_addr))
25 	  {
26 	    for (h = phost->h_addr_list; *h != NULL; h++)
27 	      {
28 		*paddrinfo = WspiapiNewAddrInfo (iSocketType, iProtocol, wPort,
29 						 ((struct in_addr *) *h)->s_addr);
30 		if (!*paddrinfo)
31 		  return EAI_MEMORY;
32 		paddrinfo = &((*paddrinfo)->ai_next);
33 	      }
34 	  }
35 	strncpy (pszAlias, phost->h_name, NI_MAXHOST - 1);
36 	pszAlias[NI_MAXHOST - 1] = 0;
37 	return 0;
38     }
39   switch(WSAGetLastError())
40     {
41     case WSAHOST_NOT_FOUND: break;
42     case WSATRY_AGAIN: return EAI_AGAIN;
43     case WSANO_RECOVERY: return EAI_FAIL;
44     case WSANO_DATA: return EAI_NODATA;
45     default: break;
46     }
47   return EAI_NONAME;
48 }
49