(krb5_expand_hostname): handle ai_canonname being set in any of the

addresses returnedby getaddrinfo.  glibc apparently returns the
reverse lookup of every address in ai_canonname.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@7761 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
2000-01-08 08:07:18 +00:00
parent 54c51830a0
commit f23bd0709b

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999 Kungliga Tekniska H<>gskolan
* Copyright (c) 1999 - 2000 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -46,12 +46,17 @@ copy_hostname(krb5_context context,
return 0;
}
/*
* Try to make `orig_hostname' into a more canonical one in the newly
* allocated space returned in `new_hostname'.
*/
krb5_error_code
krb5_expand_hostname (krb5_context context,
const char *orig_hostname,
char **new_hostname)
{
struct addrinfo *ai, hints;
struct addrinfo *ai, *a, hints;
int error;
memset (&hints, 0, sizeof(hints));
@@ -60,13 +65,16 @@ krb5_expand_hostname (krb5_context context,
error = getaddrinfo (orig_hostname, NULL, &hints, &ai);
if (error)
return copy_hostname (context, orig_hostname, new_hostname);
if (ai->ai_canonname == NULL) {
freeaddrinfo (ai);
return copy_hostname (context, orig_hostname, new_hostname);
for (a = ai; a != NULL; a = a->ai_next) {
if (a->ai_canonname != NULL) {
*new_hostname = strdup (a->ai_canonname);
freeaddrinfo (ai);
if (*new_hostname == NULL)
return ENOMEM;
else
return 0;
}
}
*new_hostname = strdup(ai->ai_canonname);
freeaddrinfo (ai);
if (*new_hostname == NULL)
return ENOMEM;
return 0;
return copy_hostname (context, orig_hostname, new_hostname);
}