ID:               49493
 Comment by:       vnegrier at optilian dot com
 Reported By:      tim987 at email dot com
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: Windows/Linux
 PHP Version:      5.3.0
 New Comment:

Here is a patch (applies to 5.3.1 ext/standard/dns.c) 

If ipv6 is enabled, it will try first and fallback to ipv4 resolution
if no record is found.

--- dns.c.orig  2009-12-23 05:13:19.000000000 +0100
+++ dns.c       2009-12-23 05:17:14.000000000 +0100
@@ -251,16 +251,27 @@
 {
        struct hostent *hp;
        struct in_addr in;
+       char* txt_addr;
+#if HAVE_IPV6
+       char txt_addr6[128];

-       hp = gethostbyname(name);
+       hp = gethostbyname2(name, AF_INET6);

        if (!hp || !*(hp->h_addr_list)) {
-               return estrdup(name);
+#endif
+               hp = gethostbyname(name);
+               if (!hp || !*(hp->h_addr_list)) {
+                       return estrdup(name);
+               }
+               memcpy(&in.s_addr, *(hp->h_addr_list),
sizeof(in.s_addr));
+               txt_addr = inet_ntoa(in);
+#if HAVE_IPV6
+       } else {
+               inet_ntop(AF_INET6, *(hp->h_addr_list), txt_addr6,
sizeof(txt_addr6));
+               txt_addr = txt_addr6;
        }
-
-       memcpy(&in.s_addr, *(hp->h_addr_list), sizeof(in.s_addr));
-
-       return estrdup(inet_ntoa(in));
+#endif
+       return estrdup(txt_addr);
 }
 /* }}} */


Previous Comments:
------------------------------------------------------------------------

[2009-09-08 03:42:15] tim987 at email dot com

Description:
------------
The php function gethostbyname currently only returns IPv4 addresses as
stated here:

http://us2.php.net/manual/en/function.gethostbyname.php

My feature request is, it should be able to return IPv6 addresses too.





------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49493&edit=1

Reply via email to