(add_hostent): search for the canonical name among all aliases

(getaddrinfo): handle AI_NUMERICHOST correctly


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@7477 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1999-12-03 06:50:21 +00:00
parent 24fd0a06e9
commit fd41a98a81

View File

@@ -223,21 +223,32 @@ add_hostent (int port, int protocol, int socktype,
{ {
char **h; char **h;
int ret; int ret;
char *canonname = NULL;
if (*flags & AI_CANONNAME) {
canonname = he->h_name;
if (strchr (he->h_name, '.') == NULL)
for (h = he->h_aliases; *h; ++h) {
if (strchr (*h, '.') != NULL) {
canonname = *h;
break;
}
}
canonname = strdup (canonname);
if (canonname == NULL)
return EAI_MEMORY;
}
for (h = he->h_addr_list; *h != NULL; ++h) { for (h = he->h_addr_list; *h != NULL; ++h) {
char *canonname = NULL;
if (*flags & AI_CANONNAME) {
canonname = strdup (he->h_name);
if (canonname == NULL)
return ENOMEM;
*flags &= ~AI_CANONNAME;
}
ret = add_one (port, protocol, socktype, ret = add_one (port, protocol, socktype,
current, func, *h, canonname); current, func, *h, canonname);
if (ret) if (ret)
return ret; return ret;
if (*flags & AI_CANONNAME) {
*flags &= ~AI_CANONNAME;
canonname = NULL;
}
} }
return 0; return 0;
} }
@@ -320,8 +331,6 @@ get_nodes (const char *nodename,
&current, const_v4, he, &flags); &current, const_v4, he, &flags);
} }
*res = first; *res = first;
if (ret == EAI_NONAME)
return get_number (nodename, hints, port, protocol, socktype, res);
return ret; return ret;
} }
@@ -369,10 +378,14 @@ getaddrinfo(const char *nodename,
return ret; return ret;
} }
if (nodename != NULL) { if (nodename != NULL) {
if (hints && hints->ai_flags & AI_NUMERICHOST) ret = get_number (nodename, hints, port, protocol, socktype, res);
ret = get_number (nodename, hints, port, protocol, socktype, res); if (ret) {
else if(hints && hints->ai_flags & AI_NUMERICHOST)
ret = get_nodes (nodename, hints, port, protocol, socktype, res); ret = EAI_NONAME;
else
ret = get_nodes (nodename, hints, port, protocol, socktype,
res);
}
} else { } else {
ret = get_null (hints, port, protocol, socktype, res); ret = get_null (hints, port, protocol, socktype, res);
} }