]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ipaddr/ng_ipaddr.c
Test suite/platformtest.sh: Detect when tests have been skipped
[ngircd-alex.git] / src / ipaddr / ng_ipaddr.c
index 4f1d4ca40492562858e87357c107c320b85c48b2..37f75b6de919f64d7ddbdfb9ac24a5b3d0e51a75 100644 (file)
@@ -1,11 +1,14 @@
 /*
- * Functions for AF_ agnostic ipv4/ipv6 handling.
- *
  * (c) 2008 Florian Westphal <fw@strlen.de>, public domain.
  */
 
 #include "portab.h"
 
+/**
+ * @file
+ * Functions for AF_ agnostic ipv4/ipv6 handling.
+ */
+
 #include <assert.h>
 #include <stdio.h>
 #include <string.h>
@@ -20,7 +23,7 @@
 GLOBAL bool
 ng_ipaddr_init(ng_ipaddr_t *addr, const char *ip_str, UINT16 port)
 {
-#ifdef HAVE_GETADDRINFO
+#ifdef HAVE_WORKING_GETADDRINFO
        int ret;
        char portstr[64];
        struct addrinfo *res0;
@@ -29,7 +32,12 @@ ng_ipaddr_init(ng_ipaddr_t *addr, const char *ip_str, UINT16 port)
        assert(ip_str);
 
        memset(&hints, 0, sizeof(hints));
+#ifdef AI_NUMERICHOST
        hints.ai_flags = AI_NUMERICHOST;
+#endif
+#ifndef WANT_IPV6      /* do not convert ipv6 addresses */
+       hints.ai_family = AF_INET;
+#endif
 
        /* some getaddrinfo implementations require that ai_socktype is set. */
        hints.ai_socktype = SOCK_STREAM;
@@ -38,12 +46,11 @@ ng_ipaddr_init(ng_ipaddr_t *addr, const char *ip_str, UINT16 port)
        snprintf(portstr, sizeof(portstr), "%u", (unsigned int) port);
 
        ret = getaddrinfo(ip_str, portstr, &hints, &res0);
-       assert(ret == 0);
        if (ret != 0)
                return false;
 
-       assert(sizeof(*addr) >= res0->ai_addrlen);
-       if (sizeof(*addr) >= res0->ai_addrlen)
+       assert(sizeof(*addr) >= (size_t)res0->ai_addrlen);
+       if (sizeof(*addr) >= (size_t)res0->ai_addrlen)
                memcpy(addr, res0->ai_addr, res0->ai_addrlen);
        else
                ret = -1;