SOCK: Properly implement getaddrinfo when the host OS doesn't have it.

As reported in #767
This commit is contained in:
Mark Pizzolato 2019-11-14 13:14:14 -08:00
parent 3c9efd7fdb
commit bdc677b748

View file

@ -284,41 +284,34 @@ if (hostname) {
(0 == strcmp("255.255.255.255", hostname))) { (0 == strcmp("255.255.255.255", hostname))) {
fixed[0] = &ipaddr; fixed[0] = &ipaddr;
fixed[1] = NULL; fixed[1] = NULL;
if ((hints->ai_flags & AI_CANONNAME) && !(hints->ai_flags & AI_NUMERICHOST)) {
he = gethostbyaddr((char *)&ipaddr, 4, AF_INET);
if (NULL != he)
cname = he->h_name;
else
cname = hostname;
}
ips = fixed;
} }
else { else {
if ((0xffffffff != (ipaddr.s_addr = inet_addr(hostname))) || if (hints->ai_flags & AI_NUMERICHOST)
(0 == strcmp("255.255.255.255", hostname))) { return EAI_NONAME;
fixed[0] = &ipaddr; he = gethostbyname(hostname);
fixed[1] = NULL; if (he) {
if ((hints->ai_flags & AI_CANONNAME) && !(hints->ai_flags & AI_NUMERICHOST)) { ips = (struct in_addr **)he->h_addr_list;
he = gethostbyaddr((char *)&ipaddr, 4, AF_INET); if (hints->ai_flags & AI_CANONNAME)
if (NULL != he) cname = he->h_name;
cname = he->h_name;
else
cname = hostname;
}
ips = fixed;
} }
else { else {
if (hints->ai_flags & AI_NUMERICHOST) switch (h_errno)
return EAI_NONAME; {
he = gethostbyname(hostname); case HOST_NOT_FOUND:
if (he) { case NO_DATA:
ips = (struct in_addr **)he->h_addr_list; return EAI_NONAME;
if (hints->ai_flags & AI_CANONNAME) case TRY_AGAIN:
cname = he->h_name; return EAI_AGAIN;
} default:
else { return EAI_FAIL;
switch (h_errno)
{
case HOST_NOT_FOUND:
case NO_DATA:
return EAI_NONAME;
case TRY_AGAIN:
return EAI_AGAIN;
default:
return EAI_FAIL;
}
} }
} }
} }