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

Re: getaddrinfo() and AI_CANONNAME



Hello,

The patch I just sent is bogus. This one should be better (I hope):

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 22:00:37
@@ -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,11 @@
 	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)
+		continue;
+	    *new_hostname = strdup (tmphost);
 	    freeaddrinfo (ai);
 	    if (*new_hostname == NULL)
 		return ENOMEM;
@@ -119,6 +124,7 @@
     struct addrinfo *ai, *a, hints;
     int error;
     krb5_error_code ret = 0;
+    char tmphost[NI_MAXHOST];
 
     memset (&hints, 0, sizeof(hints));
     hints.ai_flags = AI_CANONNAME;
@@ -130,7 +136,11 @@
 
     for (a = ai; a != NULL; a = a->ai_next) {
 	if (a->ai_canonname != NULL) {
-	    ret = copy_hostname (context, a->ai_canonname, new_hostname);
+	    error = getnameinfo (ai->ai_addr, ai->ai_addrlen, tmphost,
+		sizeof(tmphost), NULL, 0, 0);
+	    if (error)
+		continue;
+	    ret = copy_hostname (context, tmphost, new_hostname);
 	    if (ret) {
 		freeaddrinfo (ai);
 		return ret;
@@ -144,5 +154,6 @@
 	    free (*new_hostname);
 	}
     }
+    freeaddrinfo (ai);
     return vanilla_hostname (context, orig_hostname, new_hostname, realms);
 }

Gabor

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