cvs: php4 /ext/standard dns.c
| From: | Stig Venaas | Date: | Wed, 19 Sep 2001 18:08:15 +0000 |
| Subject: | cvs: php4 /ext/standard dns.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-7485@lists.php.net to get a copy of this message | ||
venaas Wed Sep 19 14:08:15 2001 EDT
Modified files:
/php4/ext/standard dns.c
Log:
Added IPv6 support to gethostbyaddr()
@- Added IPv6 support to gethostbyaddr()
@ (Patch by Matthias Wimmer <matthias@charente.de> and venaas)
Index: php4/ext/standard/dns.c
diff -u php4/ext/standard/dns.c:1.34 php4/ext/standard/dns.c:1.35
--- php4/ext/standard/dns.c:1.34 Sun Sep 9 09:29:17 2001
+++ php4/ext/standard/dns.c Wed Sep 19 14:08:15 2001
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dns.c,v 1.34 2001/09/09 13:29:17 derick Exp $ */
+/* $Id: dns.c,v 1.35 2001/09/19 18:08:15 venaas Exp $ */
/* {{{ includes
*/
@@ -82,7 +82,11 @@
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 @@
*/
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 @@
}
hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
+#endif
if (!hp) {
return estrdup(ip);