]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ipaddr/ng_ipaddr.h
Test suite/platformtest.sh: Detect when tests have been skipped
[ngircd-alex.git] / src / ipaddr / ng_ipaddr.h
index 1e198b0e7ce41d49e0d18f8f0189e8a9dc1390c3..f8409de99288e7f6b666e1f18c0a63c10b4ec8ad 100644 (file)
@@ -1,13 +1,22 @@
 /*
- * Functions for AF_ agnostic ipv4/ipv6 handling.
- *
  * (c) 2008 Florian Westphal <fw@strlen.de>, public domain.
  */
 
 #ifndef NG_IPADDR_HDR
 #define NG_IPADDR_HDR
+
 #include "portab.h"
 
+/**
+ * @file
+ * Functions for AF_ agnostic ipv4/ipv6 handling (header).
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
 #ifdef HAVE_ARPA_INET_H
 # include <arpa/inet.h>
 #else
@@ -40,6 +49,7 @@ typedef struct NG_IP_ADDR_DONTUSE ng_ipaddr_t;
 static inline int
 ng_ipaddr_af(const ng_ipaddr_t *a)
 {
+       assert(a != NULL);
 #ifdef WANT_IPV6
        return a->sa.sa_family;
 #else
@@ -52,13 +62,14 @@ ng_ipaddr_af(const ng_ipaddr_t *a)
 static inline socklen_t
 ng_ipaddr_salen(const ng_ipaddr_t *a)
 {
+       assert(a != NULL);
 #ifdef WANT_IPV6
        assert(a->sa.sa_family == AF_INET || a->sa.sa_family == AF_INET6);
        if (a->sa.sa_family == AF_INET6)
-               return sizeof(a->sin6);
+               return (socklen_t)sizeof(a->sin6);
 #endif
        assert(a->sin4.sin_family == AF_INET);
-       return sizeof(a->sin4);
+       return (socklen_t)sizeof(a->sin4);
 }
 
 
@@ -68,11 +79,14 @@ ng_ipaddr_getport(const ng_ipaddr_t *a)
 #ifdef WANT_IPV6
        int af = a->sa.sa_family;
 
+       assert(a != NULL);
        assert(af == AF_INET || af == AF_INET6);
 
        if (af == AF_INET6)
                return ntohs(a->sin6.sin6_port);
 #endif /* WANT_IPV6 */
+
+       assert(a != NULL);
        assert(a->sin4.sin_family == AF_INET);
        return ntohs(a->sin4.sin_port);
 }
@@ -81,7 +95,6 @@ ng_ipaddr_getport(const ng_ipaddr_t *a)
  * init a ng_ipaddr_t object.
  * @param addr: pointer to ng_ipaddr_t to initialize.
  * @param ip_str: ip address in dotted-decimal (ipv4) or hexadecimal (ipv6) notation
- *                if ip_str is NULL it is treated as 0.0.0.0/[::]
  * @param port: transport layer port number to use.
  */
 GLOBAL bool ng_ipaddr_init PARAMS((ng_ipaddr_t *addr, const char *ip_str, UINT16 port));
@@ -100,12 +113,18 @@ GLOBAL const char *ng_ipaddr_tostr PARAMS((const ng_ipaddr_t *addr));
 /* convert struct sockaddr to string. dest must be NG_INET_ADDRSTRLEN bytes long */
 GLOBAL bool ng_ipaddr_tostr_r PARAMS((const ng_ipaddr_t *addr, char *dest));
 #else
-static inline const char *
-ng_ipaddr_tostr(const ng_ipaddr_t *addr) { return inet_ntoa(addr->sin4.sin_addr); }
+static inline const char*
+ng_ipaddr_tostr(const ng_ipaddr_t *addr)
+{
+       assert(addr != NULL);
+       return inet_ntoa(addr->sin4.sin_addr);
+}
 
 static inline bool
 ng_ipaddr_tostr_r(const ng_ipaddr_t *addr, char *d)
 {
+       assert(addr != NULL);
+       assert(d != NULL);
        strlcpy(d, inet_ntoa(addr->sin4.sin_addr), NG_INET_ADDRSTRLEN);
        return true;
 }