gethostbyaddr, IPv6 mapped IPv4 and native IPv6 addresses
| From: | Matthias Wimmer | Date: | Tue, 18 Sep 2001 16:28:08 +0000 |
| Subject: | gethostbyaddr, IPv6 mapped IPv4 and native IPv6 addresses | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-66210@lists.php.net to get a copy of this message | ||
Hi!
I just noticed that the php function gethostbyaddr is not able to lookup
IPv6 mapped IPv4 or native IPv6 addresses.
Because I get such addresses from the apache 1.3.19 when it is patched
with the KAME IPv6 patch (that's the normal way to IPv6 enable apache
1.3) I noticed the problem.
Attached is a patch that enables php to lookup such addresses too.
Tot kijk
Matthias
--
Fon: +49-(0)70 0770 07770 http://matthias-wimmer.de/
Fax: +49-(0)89 312 88 654 jabber:mawis@charente.de
Der Euro, unser Geld - noch 105 Tage.
--- php-4.0.6/ext/standard/dns.c Tue Sep 18 18:17:58 2001 +++ php-4.0.6-patched/ext/standard/dns.c Tue Sep 18 18:17:34 2001 @@ -81,9 +81,22 @@ char *php_gethostbyaddr(char *ip) { +#if HAVE_IPV6 + struct in6_addr addr6; +#else struct in_addr addr; +#endif struct hostent *hp; +#if HAVE_IPV6 + if (!inet_pton(AF_INET6, ip, &addr6)) { +#if PHP_DEBUG + php_error(E_WARNING, "address is not a valid IPv4 or IPv6 address"); +#endif + return estrdup(ip); + } + hp = gethostbyaddr((char *) &addr6, sizeof(addr6), AF_INET6); +#else addr.s_addr = inet_addr(ip); if (addr.s_addr == -1) { #if PHP_DEBUG @@ -92,6 +105,7 @@ return estrdup(ip); } hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET); +#endif if (!hp) { #if PHP_DEBUG php_error(E_WARNING, "Unable to resolve %s\n", ip);
--- php-4.0.6/ext/standard/dns.c Tue Sep 18 18:17:58 2001 +++ php-4.0.6-patched/ext/standard/dns.c Tue Sep 18 18:17:34 2001 @@ -81,9 +81,22 @@ char *php_gethostbyaddr(char *ip) { +#if HAVE_IPV6 + struct in6_addr addr6; +#else struct in_addr addr; +#endif struct hostent *hp; +#if HAVE_IPV6 + if (!inet_pton(AF_INET6, ip, &addr6)) { +#if PHP_DEBUG + php_error(E_WARNING, "address is not a valid IPv4 or IPv6 address"); +#endif + return estrdup(ip); + } + hp = gethostbyaddr((char *) &addr6, sizeof(addr6), AF_INET6); +#else addr.s_addr = inet_addr(ip); if (addr.s_addr == -1) { #if PHP_DEBUG @@ -92,6 +105,7 @@ return estrdup(ip); } hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET); +#endif if (!hp) { #if PHP_DEBUG php_error(E_WARNING, "Unable to resolve %s\n", ip);