]> granicus.if.org Git - php/commitdiff
Added IPv6 support to gethostbyaddr()
authorStig Venaas <venaas@php.net>
Wed, 19 Sep 2001 18:08:15 +0000 (18:08 +0000)
committerStig Venaas <venaas@php.net>
Wed, 19 Sep 2001 18:08:15 +0000 (18:08 +0000)
@- Added IPv6 support to gethostbyaddr()
@  (Patch by Matthias Wimmer <matthias@charente.de> and venaas)

ext/standard/dns.c

index c62e67487f86283c84dcfa6d6744b1f68debcd43..681d4468f0608a2508011bb0596be82816a2b76d 100644 (file)
@@ -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);