{
SockAddr ret = snew(struct SockAddr_tag);
unsigned long a;
- struct hostent *h = NULL;
char realhost[8192];
int hint_family;
- int err;
/* Default to IPv4. */
hint_family = (address_family == ADDRTYPE_IPV4 ? AF_INET :
*realhost = '\0';
if ((a = p_inet_addr(host)) == (unsigned long) INADDR_NONE) {
+ struct hostent *h = NULL;
+ int err;
#ifndef NO_IPV6
/*
* Use getaddrinfo when it's available
#ifndef NO_IPV6
if (step.ai) {
+ int err = 0;
if (p_WSAAddressToStringA) {
- p_WSAAddressToStringA(step.ai->ai_addr, step.ai->ai_addrlen,
- NULL, buf, &buflen);
+ DWORD dwbuflen = buflen;
+ err = p_WSAAddressToStringA(step.ai->ai_addr, step.ai->ai_addrlen,
+ NULL, buf, &dwbuflen);
} else
- strncpy(buf, "IPv6", buflen);
+ err = -1;
+ if (err) {
+ strncpy(buf, addr->hostname, buflen);
+ if (!buf[0])
+ strncpy(buf, "<unknown>", buflen);
+ buf[buflen-1] = '\0';
+ }
} else
#endif
if (SOCKADDR_FAMILY(addr, step) == AF_INET) {