X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fipaddr%2Fng_ipaddr.h;h=8f7376001872bbcd3e4d3ef0f45c4981f9c5017c;hb=6685ae063f4e7dd75346cf50cff84c8c109e2d6b;hp=6490a0747a9ac0f62ff4608c8d7cbaea9e8023a5;hpb=4ed2cb1a0248130f476ff9afd4fd4ed887fee376;p=ngircd-alex.git diff --git a/src/ipaddr/ng_ipaddr.h b/src/ipaddr/ng_ipaddr.h index 6490a074..8f737600 100644 --- a/src/ipaddr/ng_ipaddr.h +++ b/src/ipaddr/ng_ipaddr.h @@ -1,6 +1,4 @@ /* - * Functions for AF_ agnostic ipv4/ipv6 handling. - * * (c) 2008 Florian Westphal , public domain. */ @@ -8,6 +6,12 @@ #define NG_IPADDR_HDR #include "portab.h" +/** + * @file + * Functions for AF_ agnostic ipv4/ipv6 handling (header). + */ + +#include #include #include @@ -43,6 +47,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 @@ -55,13 +60,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); } @@ -71,11 +77,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); } @@ -102,12 +111,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; } @@ -115,4 +130,3 @@ ng_ipaddr_tostr_r(const ng_ipaddr_t *addr, char *d) #endif /* -eof- */ -