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:123
Avg. Score:4.9 ± 0.5
Reproduced:116 of 118 (98.3%)
Same Version:86 (74.1%)
Same OS:89 (76.7%)
From: tim987 at email dot com Assigned:
Status: Open Package: Network related
PHP Version: * OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tim987 at email dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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
 [2020-07-20 13:44 UTC] neufeind@php.net
Probably gethostbynamel() which already returns a list? Or gethostbyname2() to mimic what the underlying system uses?

But still not having IPv6-support in 2020 sounds wrong.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 09:01:27 2024 UTC