You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by am...@apache.org on 2006/10/20 17:04:21 UTC

svn commit: r466137 - in /xerces/c/trunk: configure.ac src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp

Author: amassari
Date: Fri Oct 20 08:04:20 2006
New Revision: 466137

URL: http://svn.apache.org/viewvc?view=rev&rev=466137
Log:
Enable IPv6 addresses by using getaddrinfo when available [based on a patch by Ramanjaneyulu Malisetti]

Modified:
    xerces/c/trunk/configure.ac
    xerces/c/trunk/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp

Modified: xerces/c/trunk/configure.ac
URL: http://svn.apache.org/viewvc/xerces/c/trunk/configure.ac?view=diff&rev=466137&r1=466136&r2=466137
==============================================================================
--- xerces/c/trunk/configure.ac (original)
+++ xerces/c/trunk/configure.ac Fri Oct 20 08:04:20 2006
@@ -104,13 +104,15 @@
 #AC_FUNC_MEMCMP
 #AC_FUNC_STRCOLL
 #AC_FUNC_STRTOD
-AC_CHECK_FUNCS([clock_gettime ftime getcwd gethostbyaddr gethostbyname gettimeofday localeconv \
-				mblen memmove memset nl_langinfo pathconf realpath setlocale socket \
-				strcasecmp strncasecmp stricmp strnicmp strchr strdup \
-				strrchr strstr strtol strtoul \
-				towupper towlower \
-				mbrlen wcsrtombs mbsrtowcs \
-				])
+AC_CHECK_FUNCS([getcwd pathconf realpath \
+		getaddrinfo gethostbyaddr gethostbyname socket \
+		clock_gettime ftime gettimeofday \
+		memmove memset nl_langinfo setlocale localeconv \
+		strcasecmp strncasecmp stricmp strnicmp strchr strdup \
+		strrchr strstr strtol strtoul \
+		towupper towlower \
+		mblen mbrlen wcsrtombs mbsrtowcs \
+		])
 				
 AC_SUBST([SHREXT], [$shrext_cmds])
 

Modified: xerces/c/trunk/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp?view=diff&rev=466137&r1=466136&r2=466137
==============================================================================
--- xerces/c/trunk/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp Fri Oct 20 08:04:20 2006
@@ -18,18 +18,32 @@
  * $Id$
  */
 
+#if HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#if !defined(XML_BEOS)
-  #include <netinet/in.h>
-  #include <arpa/inet.h>
+#if HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+#if HAVE_SYS_TYPES_H
+#  include <sys/types.h>
+#endif
+#if HAVE_SYS_SOCKET_H 
+#  include <sys/socket.h>
+#endif
+#if HAVE_NETINET_IN_H 
+#  include <netinet/in.h>
+#endif
+#if HAVE_ARPA_INET_H
+#  include <arpa/inet.h>
+#endif
+#if HAVE_NETDB_H 
+#  include <netdb.h>
 #endif
-#include <netdb.h>
 #include <errno.h>
 
 #include <xercesc/util/XMLNetAccessor.hpp>
@@ -247,6 +261,42 @@
     //
     // Set up a socket.
     //
+#if HAVE_GETADDRINFO
+    struct addrinfo hints, *res, *ai;
+
+    memset(&hints, 0, sizeof(struct addrinfo));
+    hints.ai_family = PF_UNSPEC;
+    hints.ai_socktype = SOCK_STREAM;
+    int n = getaddrinfo(hostNameAsCharStar,portAsASCII,&hints, &res);
+    if(n<0)
+    {
+        hints.ai_flags = AI_NUMERICHOST;
+        n = getaddrinfo(hostNameAsCharStar,portAsASCII,&hints, &res);
+        if(n<0)
+            ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_TargetResolution, hostName, fMemoryManager);
+    }
+    int s;
+    for (ai = res; ai != NULL; ai = ai->ai_next) {
+        // Open a socket with the correct address family for this address.
+        s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+        if (s < 0)
+            continue;
+        if (connect(s, ai->ai_addr, ai->ai_addrlen) < 0)
+        {
+            freeaddrinfo(res);
+            ThrowXMLwithMemMgr1(NetAccessorException,
+                     XMLExcepts::NetAcc_ConnSocket, urlSource.getURLText(), fMemoryManager);
+        }
+        break;
+    }
+    freeaddrinfo(res);
+    if (s < 0)
+    {
+        ThrowXMLwithMemMgr1(NetAccessorException,
+                 XMLExcepts::NetAcc_CreateSocket, urlSource.getURLText(), fMemoryManager);
+    }
+    SocketJanitor janSock(&s);
+#else
     struct hostent*     hostEntPtr = 0;
     struct sockaddr_in  sa;
 
@@ -282,6 +332,7 @@
         ThrowXMLwithMemMgr1(NetAccessorException,
                  XMLExcepts::NetAcc_ConnSocket, urlSource.getURLText(), fMemoryManager);
     }
+#endif
 
     // The port is open and ready to go.
     // Build up the http GET command to send to the server.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org