diff --git a/src/rdaddr.c b/src/rdaddr.c index 38bef87bd5..503886eb28 100644 --- a/src/rdaddr.c +++ b/src/rdaddr.c @@ -3,24 +3,24 @@ * * Copyright (c) 2012, Magnus Edenhill * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * + * modification, are permitted provided that the following conditions are met: + * * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. + * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * + * and/or other materials provided with the distribution. + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. @@ -45,7 +45,7 @@ const char *rd_sockaddr2str (const void *addr, int flags) { int niflags = NI_NUMERICSERV; reti = (reti + 1) % 32; - + switch (a->sinx_family) { case AF_INET: @@ -71,7 +71,7 @@ const char *rd_sockaddr2str (const void *addr, int flags) { niflags)) break; - + if (flags & RD_SOCKADDR2STR_F_PORT) { size_t len = strlen(ret[reti]); rd_snprintf(ret[reti]+len, sizeof(ret[reti])-len, @@ -79,15 +79,15 @@ const char *rd_sockaddr2str (const void *addr, int flags) { a->sinx_family == AF_INET6 ? "]" : "", portstr); } - + return ret[reti]; } - + /* Error-case */ rd_snprintf(ret[reti], sizeof(ret[reti]), "", rd_family2str(a->sinx_family)); - + return ret[reti]; } @@ -116,7 +116,7 @@ const char *rd_addrinfo_prepare (const char *nodesvc, nodelen = 0; svct = nodesvc; } - + if ((svct = strrchr(svct ? svct : nodesvc, ':')) && (*(svct-1) != ':') && *(++svct)) { /* Optional ":service" definition. */ @@ -148,10 +148,13 @@ rd_sockaddr_list_t *rd_getaddrinfo (const char *nodesvc, const char *defsvc, int flags, int family, int socktype, int protocol, const char **errstr) { - struct addrinfo hints = { .ai_family = family, - .ai_socktype = socktype, - .ai_protocol = protocol, - .ai_flags = flags }; + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); + hints.ai_family = family; + hints.ai_socktype = socktype; + hints.ai_protocol = protocol; + hints.ai_flags = flags; + struct addrinfo *ais, *ai; char *node, *svc; int r; @@ -165,7 +168,7 @@ rd_sockaddr_list_t *rd_getaddrinfo (const char *nodesvc, const char *defsvc, if (*svc) defsvc = svc; - + if ((r = getaddrinfo(node, defsvc, &hints, &ais))) { #ifdef EAI_SYSTEM if (r == EAI_SYSTEM) @@ -183,7 +186,7 @@ rd_sockaddr_list_t *rd_getaddrinfo (const char *nodesvc, const char *defsvc, } return NULL; } - + /* Count number of addresses */ for (ai = ais ; ai != NULL ; ai = ai->ai_next) cnt++;