[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

getaddrinfo() and AI_CANONNAME



Hello,

It seems that on AIX 4.3, getaddrinfo() returns unqualified name when it
is called with nodename == local host name and hints->ai_flags ==
AI_CANONNAME. /usr/lib/netdb.h refers to RFC2133 but RFC2133 does not define
what a "canonical name" means, so I wouldn't call it a bug in AIX. But
returning an unqualified name breaks krb5_sname_to_principal() when it is
called with hostname == NULL.

Would it be reasonable to call getnameinfo() on the data returned by
getaddrinfo()? getnameinfo() guarantees the returning of a FQDN.

Something like this:

diff -u -r1.1.1.1 expand_hostname.c
--- lib/krb5/expand_hostname.c	2000/09/03 19:54:10	1.1.1.1
+++ lib/krb5/expand_hostname.c	2000/10/16 20:24:20
@@ -59,6 +59,7 @@
 {
     struct addrinfo *ai, *a, hints;
     int error;
+    char tmphost[NI_MAXHOST];
 
     memset (&hints, 0, sizeof(hints));
     hints.ai_flags = AI_CANONNAME;
@@ -68,7 +69,13 @@
 	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);
+	    error = getnameinfo (ai->ai_addr, ai->ai_addrlen, tmphost,
+		sizeof(tmphost), NULL, 0, 0);
+	    if (error) {
+		freeaddrinfo (ai);
+		continue;
+	    }
+	    *new_hostname = strdup (tmphost);
 	    freeaddrinfo (ai);
 	    if (*new_hostname == NULL)
 		return ENOMEM;

Gabor

-- 
Gabor Gombas                                       Eotvos Lorand University
E-mail: gombasg@inf.elte.hu                        Hungary