From fd41a98a8110065ef495c3c23a1ffbd2015562b9 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Fri, 3 Dec 1999 06:50:21 +0000 Subject: [PATCH] (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 --- lib/roken/getaddrinfo.c | 43 +++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/lib/roken/getaddrinfo.c b/lib/roken/getaddrinfo.c index 7dbff5776..b233947fd 100644 --- a/lib/roken/getaddrinfo.c +++ b/lib/roken/getaddrinfo.c @@ -223,21 +223,32 @@ add_hostent (int port, int protocol, int socktype, { char **h; 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) { - 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, current, func, *h, canonname); if (ret) return ret; + if (*flags & AI_CANONNAME) { + *flags &= ~AI_CANONNAME; + canonname = NULL; + } } return 0; } @@ -320,8 +331,6 @@ get_nodes (const char *nodename, ¤t, const_v4, he, &flags); } *res = first; - if (ret == EAI_NONAME) - return get_number (nodename, hints, port, protocol, socktype, res); return ret; } @@ -369,10 +378,14 @@ getaddrinfo(const char *nodename, return ret; } if (nodename != NULL) { - if (hints && hints->ai_flags & AI_NUMERICHOST) - ret = get_number (nodename, hints, port, protocol, socktype, res); - else - ret = get_nodes (nodename, hints, port, protocol, socktype, res); + ret = get_number (nodename, hints, port, protocol, socktype, res); + if (ret) { + if(hints && hints->ai_flags & AI_NUMERICHOST) + ret = EAI_NONAME; + else + ret = get_nodes (nodename, hints, port, protocol, socktype, + res); + } } else { ret = get_null (hints, port, protocol, socktype, res); }