php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #49493 Add IPv6 support in gethostbyname()
Submitted: 2009-09-08 03:42 UTC Modified: 2010-12-29 13:11 UTC
Votes:112
Avg. Score:4.9 ± 0.4
Reproduced:108 of 110 (98.2%)
Same Version:85 (78.7%)
Same OS:87 (80.6%)
From: tim987 at email dot com Assigned:
Status: Open Package: Network related
PHP Version: * OS: *
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-09-08 03:42 UTC] 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.




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-23 04:21 UTC] vnegrier at optilian dot com
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);
 }
 /* }}} */
 [2010-12-29 13:11 UTC] jani@php.net
-Summary: gethostbyname IPv6 +Summary: Add IPv6 support in gethostbyname() -Package: Feature/Change Request +Package: Network related -Operating System: Windows/Linux +Operating System: * -PHP Version: 5.3.0 +PHP Version: *
 [2013-03-08 20:52 UTC] landy2005 at gmail dot com
any progress on this?
 [2013-09-09 07:09 UTC] mikhey at zloy dot org
Please, Add IPv6 support in gethostbyname
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 14:02:33 2014 UTC