From: Stig Venaas Date: Wed, 19 Sep 2001 18:08:15 +0000 (+0000) Subject: Added IPv6 support to gethostbyaddr() X-Git-Tag: PRE_SUBST_Z_MACROS~48 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=926d1506e043549fcb22fc65c8eb70a6db99270d;p=php Added IPv6 support to gethostbyaddr() @- Added IPv6 support to gethostbyaddr() @ (Patch by Matthias Wimmer and venaas) --- diff --git a/ext/standard/dns.c b/ext/standard/dns.c index c62e67487f..681d4468f0 100644 --- a/ext/standard/dns.c +++ b/ext/standard/dns.c @@ -82,7 +82,11 @@ PHP_FUNCTION(gethostbyaddr) addr = php_gethostbyaddr(Z_STRVAL_PP(arg)); if(addr == NULL) { +#if HAVE_IPV6 + php_error(E_WARNING, "Address is not a valid IPv4 or IPv6 address"); +#else php_error(E_WARNING, "Address is not in a.b.c.d form"); +#endif RETVAL_FALSE; } else { RETVAL_STRING(addr, 0); @@ -94,9 +98,21 @@ PHP_FUNCTION(gethostbyaddr) */ static char *php_gethostbyaddr(char *ip) { +#if HAVE_IPV6 + struct in6_addr addr6; +#endif struct in_addr addr; struct hostent *hp; +#if HAVE_IPV6 + if (inet_pton(AF_INET6, ip, &addr6)) { + hp = gethostbyaddr((char *) &addr6, sizeof(addr6), AF_INET6); + } else if (inet_pton(AF_INET, ip, &addr)) { + hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET); + } else { + return NULL; + } +#else addr.s_addr = inet_addr(ip); if (addr.s_addr == -1) { @@ -104,6 +120,7 @@ static char *php_gethostbyaddr(char *ip) } hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET); +#endif if (!hp) { return estrdup(ip);