neon 0.29 build broken on Windows

Joe Orton joe at manyfish.co.uk
Fri Sep 25 07:27:13 EDT 2009


On Sat, Sep 19, 2009 at 05:58:09PM +0200, Stefan Kueng wrote:
> neon 0.29 doesn't compile on Windows if ipv6 isn't enabled.

Hi Stefan - thanks for the report.

> There are several issues:
> config.hw.in, line 80:
> #define socklen_t                       int
> should be replaced with
> typedef int socklen_t;
> since the Win7 SDK has that typedef and with the define, the compiler  
> throws an error in the header about 'int followed by int is illegal'.

OK - if Win7 defines socklen_t could config.hw simply omit that 
altogether with a suitable

#if defined(_MSC_VER) && _MSC_VER >= XXXX

then?  If so, what'd be a suitable _MSC_VER value, do you know?

> I can work around this problem. But not around the next ones:
>
> if neither ipv6 is enabled nor USE_GETADDRINFO is defined, neon won't  
> compile due to the function inet_aton() not being available.
> If USE_GETADDRINFO is defined, neon compiles with a few warnings but  
> fails to link because inet_pton() isn't found.

Can you try the attached patch?  It should fix both the with-USE_GAI and 
without- case.

Regards, Joe

-------------- next part --------------
Index: src/ne_socket.c
===================================================================
--- src/ne_socket.c	(revision 1736)
+++ src/ne_socket.c	(working copy)
@@ -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,50 @@
     }
     
     return ne_iaddr_make(type, (unsigned char *)dst);
-#else
+#elif defined(USE_GETADDRINFO) && !defined(HAVE_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. */
+    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 mailing list