Edit report at https://bugs.php.net/bug.php?id=49493&edit=1
ID: 49493 Comment by: landy2005 at gmail dot com Reported by: tim987 at email dot com Summary: Add IPv6 support in gethostbyname() Status: Open Type: Feature/Change Request Package: Network related Operating System: * PHP Version: * Block user comment: N Private report: N New Comment: any progress on this? Previous Comments: ------------------------------------------------------------------------ [2009-12-23 04:21:47] 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); } /* }}} */ ------------------------------------------------------------------------ [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 https://bugs.php.net/bug.php?id=49493&edit=1