commit: r1740 - in neon/branches/0.29.x: . src

joe at manyfish.co.uk joe at manyfish.co.uk
Sat Sep 26 15:58:08 EDT 2009


Author: joe
Date: Sat Sep 26 12:58:08 2009
New Revision: 1740

Modified:
   neon/branches/0.29.x/config.hw.in
   neon/branches/0.29.x/src/ne_socket.c

Log:
Merge r1738, r1739 from trunk:

* src/ne_socket.c (ne_iaddr_parse): Fix Win32 build for both
  USE_GETADDRINFO and !USE_GETADDRINFO cases.

* config.hw.in: Fix socklen_t with recent SDKs, thanks to Stefan Kung.

Reviewed by: jorton


Modified: neon/branches/0.29.x/config.hw.in
==============================================================================
--- neon/branches/0.29.x/config.hw.in	(original)
+++ neon/branches/0.29.x/config.hw.in	Sat Sep 26 12:58:08 2009
@@ -77,7 +77,7 @@
 #define in_addr_t                       unsigned int
 #endif
 
-#define socklen_t                       int
+typedef int socklen_t;
 
 #include <io.h>
 #define read _read

Modified: neon/branches/0.29.x/src/ne_socket.c
==============================================================================
--- neon/branches/0.29.x/src/ne_socket.c	(original)
+++ neon/branches/0.29.x/src/ne_socket.c	Sat Sep 26 12:58:08 2009
@@ -1069,7 +1069,7 @@
 
 ne_inet_addr *ne_iaddr_parse(const char *addr, ne_iaddr_type type)
 {
-#if defined(USE_GETADDRINFO)
+#if defined(USE_GETADDRINFO) && defined(HAVE_INET_PTON)
     char dst[sizeof(struct in6_addr)];
     int af = type == ne_iaddr_ipv6 ? AF_INET6 : AF_INET;
 
@@ -1078,19 +1078,52 @@
     }
     
     return ne_iaddr_make(type, (unsigned char *)dst);
-#else
+#elif defined(USE_GETADDRINFO) && !defined(HAVE_INET_PTON)
+    /* For Windows, which lacks inet_pton(). */
+    struct addrinfo *ai, *rv, hints;
+
+    memset(&hints, 0, sizeof hints);
+    hints.ai_socktype = SOCK_STREAM;
+    hints.ai_flags = AI_NUMERICHOST;
+    hints.ai_family = type == ne_iaddr_ipv6 ? AF_INET6 : AF_INET;
+    
+    if (getaddrinfo(addr, NULL, &hints, &ai)) {
+        return NULL;
+    }
+    
+    /* Copy the returned addrinfo, since it needs to be ne_free()-able
+     * later; must only call freeaddrinfo() on ai. */
+    rv = ne_calloc(sizeof *rv);
+    memcpy(rv, ai, sizeof *rv);
+    rv->ai_next = NULL;
+    rv->ai_canonname = NULL;
+    rv->ai_addr = ne_calloc(ai->ai_addrlen);
+    memcpy(rv->ai_addr, ai->ai_addr, ai->ai_addrlen);
+    freeaddrinfo(ai);
+    
+    return rv;    
+#else /* !USE_GETADDRINFO */
     struct in_addr a;
     
     if (type == ne_iaddr_ipv6) {
         return NULL;
     }
 
+#ifdef WIN32
+    /* inet_addr() is broken because INADDR_NONE is a valid
+     * broadcast address, so only use it on Windows. */
+    a.s_addr = inet_addr(addr);
+    if (a.s_addr == INADDR_NONE) {
+        return NULL;
+    }
+#else /* !WIN32 */
     if (inet_aton(addr, &a) == 0) {
         return NULL;
     }
+#endif
     
     return ne_iaddr_make(ne_iaddr_ipv4, (unsigned char *)&a.s_addr);
-#endif
+#endif /* !USE_GETADDRINFO */
 }
 
 int ne_iaddr_reverse(const ne_inet_addr *ia, char *buf, size_t bufsiz)



More information about the neon-commits mailing list