X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fipaddr%2Fng_ipaddr.c;h=0367a1f75848b4d9766425d7e6021b3e8f8bf9a9;hb=8fd0e29d463c934756dce7a562f09ea831b5d968;hp=3b0595d79719b92b13edfd0f4a5422311f1ff550;hpb=d9c26f3aeb35e979b72f7b0ac4220dbd07d7bc15;p=ngircd.git diff --git a/src/ipaddr/ng_ipaddr.c b/src/ipaddr/ng_ipaddr.c index 3b0595d7..0367a1f7 100644 --- a/src/ipaddr/ng_ipaddr.c +++ b/src/ipaddr/ng_ipaddr.c @@ -24,18 +24,19 @@ ng_ipaddr_init(ng_ipaddr_t *addr, const char *ip_str, UINT16 port) int ret; char portstr[64]; struct addrinfo *res0; - struct addrinfo hints = { -#ifndef WANT_IPV6 /* only accept v4 addresses */ - .ai_family = AF_INET, -#endif - .ai_flags = AI_NUMERICHOST - }; + struct addrinfo hints; + + assert(ip_str); - if (ip_str == NULL) - hints.ai_flags |= AI_PASSIVE; + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = AI_NUMERICHOST; + + /* some getaddrinfo implementations require that ai_socktype is set. */ + hints.ai_socktype = SOCK_STREAM; /* silly, but ngircd stores UINT16 in server config, not string */ snprintf(portstr, sizeof(portstr), "%u", (unsigned int) port); + ret = getaddrinfo(ip_str, portstr, &hints, &res0); assert(ret == 0); if (ret != 0) @@ -49,8 +50,7 @@ ng_ipaddr_init(ng_ipaddr_t *addr, const char *ip_str, UINT16 port) freeaddrinfo(res0); return ret == 0; #else /* HAVE_GETADDRINFO */ - if (ip_str == NULL) - ip_str = "0.0.0.0"; + assert(ip_str); addr->sin4.sin_family = AF_INET; # ifdef HAVE_INET_ATON if (inet_aton(ip_str, &addr->sin4.sin_addr) == 0) @@ -151,7 +151,8 @@ ng_ipaddr_tostr_r(const ng_ipaddr_t *addr, char *str) if (*str == ':') { char tmp[NG_INET_ADDRSTRLEN] = "0"; ret = getnameinfo(sa, ng_ipaddr_salen(addr), - tmp+1, sizeof(tmp) -1, NULL, 0, NI_NUMERICHOST); + tmp + 1, (socklen_t)sizeof(tmp) - 1, + NULL, 0, NI_NUMERICHOST); if (ret == 0) strlcpy(str, tmp, NG_INET_ADDRSTRLEN); }