pollita         Mon Jul  7 18:27:32 2003 EDT

  Modified files:              
    /php-src/ext/sockets        sockets.c 
  Log:
  Fix non-GNU build.  Use getaddrinfo() rather than gethostbyname2()
  
Index: php-src/ext/sockets/sockets.c
diff -u php-src/ext/sockets/sockets.c:1.143 php-src/ext/sockets/sockets.c:1.144
--- php-src/ext/sockets/sockets.c:1.143 Tue Jun 17 00:44:30 2003
+++ php-src/ext/sockets/sockets.c       Mon Jul  7 18:27:32 2003
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: sockets.c,v 1.143 2003/06/17 04:44:30 sterling Exp $ */
+/* $Id: sockets.c,v 1.144 2003/07/07 22:27:32 pollita Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -378,12 +378,16 @@
 static int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket 
*php_sock TSRMLS_DC)
 {
        struct in6_addr tmp;
-       struct hostent *host_entry;
+       struct addrinfo hints;
+       struct addrinfo *addrinfo = NULL;
 
        if (inet_pton(AF_INET6, string, &tmp)) {
                memcpy(&(sin6->sin6_addr.s6_addr), &(tmp.s6_addr), sizeof(struct 
in6_addr));
        } else {
-               if (! (host_entry = gethostbyname2(string, AF_INET6))) {
+               memset(&hints, 0, sizeof(struct addrinfo));
+               hints.ai_family = PF_INET6;
+               getaddrinfo(string, NULL, &hints, &addrinfo);
+               if (!addrinfo) {
 #ifdef PHP_WIN32
                        PHP_SOCKET_ERROR(php_sock, "Host lookup failed", 
WSAGetLastError());
 #else
@@ -391,11 +395,14 @@
 #endif
                        return 0;
                }
-               if (host_entry->h_addrtype != AF_INET6) {
+               if (addrinfo->ai_family != PF_INET6 || addrinfo->ai_addrlen != 
sizeof(struct sockaddr_in6)) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Host lookup 
failed: Non AF_INET6 domain returned on AF_INET6 socket");
+                       freeaddrinfo(addrinfo);
                        return 0;
                }
-               memcpy(&(sin6->sin6_addr.s6_addr), host_entry->h_addr_list[0], 
host_entry->h_length);
+
+               memcpy(&(sin6->sin6_addr.s6_addr), ((struct 
sockaddr_in6*)(addrinfo->ai_addr))->sin6_addr.s6_addr, sizeof(struct in6_addr));
+               freeaddrinfo(addrinfo);
        }
 
        return 1;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to