|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 07:00:01 2025 UTC | 
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); } /* }}} */