In article <[EMAIL PROTECTED]> (at Wed, 28 Nov 2007 01:28:04 -0800), "Bill 
Kelly" <[EMAIL PROTECTED]> says:

> I'm in the process of trying to debug why getaddrinfo() is
> failing to perform reverse DNS lookups on my etch-amd64
> system.  (glibc version 2.3.6.ds1-13etch2)

It is nothing to do with amd64, but the usage;
getaddrinfo() is not for reserve DNS lookups.
For that purpose, use getnameinfo() instead.

--yoshfuji

--- getaddrinfo-test.c.orig     2007-11-26 15:51:17.000000000 +0900
+++ getaddrinfo-test.c  2007-11-28 19:49:33.164757204 +0900
@@ -19,7 +19,6 @@
        const char *host = "208.77.188.166";  // www.example.com
        const char *port = NULL;
        int socktype = SOCK_STREAM;
-       int flags = AI_CANONNAME;
 
        struct addrinfo hints;
        struct addrinfo* res = NULL;
@@ -28,14 +27,28 @@
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = AF_UNSPEC;
        hints.ai_socktype = socktype;
-       hints.ai_flags = flags;
+       hints.ai_flags = 0;
 
        error = getaddrinfo(host, port, &hints, &res);
 
-       fprintf(stderr, "sock_addrinfo: error=%d res->ai_canonname='%s'\n", 
error, (res && res->ai_canonname)? res->ai_canonname : "NULL");
+       if (error) {
+               fprintf(stderr, "sock_addrinfo: error=%d: %s\n",
+                       error, gai_strerror(error));
+               return 4;
+       }
+
+       if (res) {
+               char hostbuf[NI_MAXHOST] = "???";
+
+               error = getnameinfo(res->ai_addr, res->ai_addrlen,
+                                   hostbuf, sizeof(hostbuf), NULL, 0,
+                                   0);
+
+               fprintf(stderr, "sock_nameinfo: error=%d, host=%s\n",
+                       error, hostbuf);
 
-       if (res)
                freeaddrinfo(res);
+       }
 
        return 0;
 }


--yoshfuji


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to