- Set last error inside getaddrinfo to properly mask some non-fatal errors generated by adns

svn path=/trunk/; revision=57107
This commit is contained in:
Cameron Gutman 2012-08-19 07:32:47 +00:00
parent ebb8b4350e
commit 0813b21bc8

View file

@ -1598,14 +1598,24 @@ getaddrinfo(const char FAR * nodename,
DNS_STATUS dns_status; DNS_STATUS dns_status;
PDNS_RECORD dp, currdns; PDNS_RECORD dp, currdns;
struct sockaddr_in *sin; struct sockaddr_in *sin;
INT error;
if (res == NULL) if (res == NULL)
return WSAEINVAL; {
error = WSAEINVAL;
goto End;
}
if (nodename == NULL && servname == NULL) if (nodename == NULL && servname == NULL)
return WSAHOST_NOT_FOUND; {
error = WSAHOST_NOT_FOUND;
goto End;
}
if (!WSAINITIALIZED) if (!WSAINITIALIZED)
return WSANOTINITIALISED; {
error = WSANOTINITIALISED;
goto End;
}
if (servname) if (servname)
{ {
@ -1619,14 +1629,20 @@ getaddrinfo(const char FAR * nodename,
{ {
pent = getprotobynumber(hints->ai_protocol); pent = getprotobynumber(hints->ai_protocol);
if (pent == NULL) if (pent == NULL)
return WSAEINVAL; {
error = WSAEINVAL;
goto End;
}
proto = pent->p_name; proto = pent->p_name;
} }
else else
proto = NULL; proto = NULL;
se = getservbyname(servname, proto); se = getservbyname(servname, proto);
if (se == NULL) if (se == NULL)
return WSATYPE_NOT_FOUND; {
error = WSATYPE_NOT_FOUND;
goto End;
}
port = se->s_port; port = se->s_port;
} }
else else
@ -1639,7 +1655,10 @@ getaddrinfo(const char FAR * nodename,
{ {
/* Is it an IPv6 address? */ /* Is it an IPv6 address? */
if (strstr(nodename, ":")) if (strstr(nodename, ":"))
return WSAHOST_NOT_FOUND; {
error = WSAHOST_NOT_FOUND;
goto End;
}
/* Is it an IPv4 address? */ /* Is it an IPv4 address? */
addr = inet_addr(nodename); addr = inet_addr(nodename);
@ -1729,16 +1748,24 @@ getaddrinfo(const char FAR * nodename,
} }
if (ret == NULL) if (ret == NULL)
return WSAHOST_NOT_FOUND; {
error = WSAHOST_NOT_FOUND;
goto End;
}
if (hints && hints->ai_family != PF_UNSPEC && hints->ai_family != PF_INET) if (hints && hints->ai_family != PF_UNSPEC && hints->ai_family != PF_INET)
{ {
freeaddrinfo(ret); freeaddrinfo(ret);
return WSAEAFNOSUPPORT; error = WSAEAFNOSUPPORT;
goto End;
} }
*res = ret; *res = ret;
return 0; error = 0;
End:
WSASetLastError(error);
return error;
} }
/* EOF */ /* EOF */