ret->error = winsock_error_string(err); } else { memcpy (&a, h->h_addr, sizeof(a)); *canonicalname = h->h_name;
ret->error = (err == WSAENETDOWN ? "Network is down" : err == WSAHOST_NOT_FOUND ? "Host does not exist" : err == WSATRY_AGAIN ? "Host not found" : #ifdef IPV6 fGetAddrInfo ? "getaddrinfo: unknown error" : #endif "gethostbyname: unknown error"); #ifdef DEBUG { LPVOID lpMsgBuf; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf,	0,	NULL); debug(("Error %ld: %s (h=%lx)\n", err, lpMsgBuf, h));  LocalFree(lpMsgBuf); } #endif
SockAddr sk_namelookup(char *host, char **canonicalname) {    SockAddr ret = smalloc(sizeof(struct SockAddr_tag));    unsigned long a;    struct hostent *h;    ret->error = NULL;    if ( (a = inet_addr(host)) == (unsigned long) INADDR_NONE) {	if ( (h = gethostbyname(host)) == NULL) {	    DWORD err = WSAGetLastError();	    ret->error = winsock_error_string(err);	} else {	    memcpy (&a, h->h_addr, sizeof(a));	    *canonicalname = h->h_name;	}    } else {	*canonicalname = host;    }    ret->address = ntohl(a);    return ret;}