diff --git a/src/platform/posix/posix_resolv_gai.c b/src/platform/posix/posix_resolv_gai.c index df7e060a6..883130456 100644 --- a/src/platform/posix/posix_resolv_gai.c +++ b/src/platform/posix/posix_resolv_gai.c @@ -1,5 +1,5 @@ // -// Copyright 2019 Staysail Systems, Inc. +// Copyright 2020 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -425,11 +425,13 @@ parse_ip(const char *addr, nng_sockaddr *sa, bool want_port) } memset(&hints, 0, sizeof(hints)); - hints.ai_flags = - AI_ADDRCONFIG | AI_NUMERICSERV | AI_NUMERICHOST | AI_PASSIVE; + hints.ai_flags = AI_NUMERICSERV | AI_NUMERICHOST | AI_PASSIVE; if (v6) { hints.ai_family = AF_INET6; } +#ifdef AI_ADDRCONFIG + hints.ai_flags |= AI_ADDRCONFIG; +#endif rv = getaddrinfo(host, port, &hints, &results); if ((rv != 0) || (results == NULL)) { diff --git a/src/platform/windows/win_resolv.c b/src/platform/windows/win_resolv.c index 67520d55f..d80b5ddf3 100644 --- a/src/platform/windows/win_resolv.c +++ b/src/platform/windows/win_resolv.c @@ -104,7 +104,6 @@ resolv_task(resolv_item *item) struct addrinfo hints; struct addrinfo *results; struct addrinfo *probe; - char port[8]; int rv; results = NULL; @@ -120,9 +119,7 @@ resolv_task(resolv_item *item) hints.ai_family = item->family; hints.ai_socktype = item->socktype; - (void) snprintf(port, sizeof(port), "%u", item->port); - - if ((rv = getaddrinfo(item->name, port, &hints, &results)) != 0) { + if ((rv = getaddrinfo(item->name, "80", &hints, &results)) != 0) { rv = resolv_errno(rv); goto done; } @@ -143,7 +140,24 @@ resolv_task(resolv_item *item) struct sockaddr_in6 *sin6; nni_sockaddr sa; - nni_win_sockaddr2nn(&sa, (void *) probe->ai_addr); + switch (probe->ai_addr->sa_family) { + case AF_INET: + rv = 0; + sin = (void *) probe->ai_addr; + sa.s_in.sa_family = NNG_AF_INET; + sa.s_in.sa_port = item->port; + sa.s_in.sa_addr = sin->sin_addr.s_addr; + nni_aio_set_sockaddr(item->aio, &sa); + break; + case AF_INET6: + rv = 0; + sin6 = (void *) probe->ai_addr; + sa.s_in6.sa_family = NNG_AF_INET6; + sa.s_in6.sa_port = item->port; + memcpy(sa.s_in6.sa_addr, sin6->sin6_addr.s6_addr, 16); + nni_aio_set_sockaddr(item->aio, &sa); + break; + } } done: @@ -315,17 +329,16 @@ parse_ip(const char *addr, nng_sockaddr *sa, bool want_port) char * buf; size_t buf_len; - if (addr == NULL) { addr = ""; } - buf_len = strlen(addr) + 1; + buf_len = strlen(addr) + 1; if ((buf = nni_alloc(buf_len)) == NULL) { return (NNG_ENOMEM); } - memcpy(buf, addr, buf_len); - host = buf; + memcpy(buf, addr, buf_len); + host = buf; if (*host == '[') { v6 = true; wrapped = true; @@ -362,7 +375,7 @@ parse_ip(const char *addr, nng_sockaddr *sa, bool want_port) goto done; } - if (!want_port && *port != 0) { + if ((!want_port) && (*port != '\0')) { rv = NNG_EADDRINVAL; goto done; } else if (*port == ':') { @@ -376,11 +389,11 @@ parse_ip(const char *addr, nng_sockaddr *sa, bool want_port) memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICSERV | AI_NUMERICHOST | AI_PASSIVE; - if (v6) { + if (v6) { hints.ai_family = AF_INET6; } - rv = getaddrinfo(addr, port, &hints, &results); + rv = getaddrinfo(host, port, &hints, &results); if ((rv != 0) || (results == NULL)) { rv = nni_win_error(rv); goto done; diff --git a/src/supplemental/tcp/tcp.c b/src/supplemental/tcp/tcp.c index dd6f28ff7..2fb7f56dd 100644 --- a/src/supplemental/tcp/tcp.c +++ b/src/supplemental/tcp/tcp.c @@ -439,7 +439,7 @@ nni_tcp_listener_alloc(nng_stream_listener **lp, const nng_url *url) h = url->u_hostname; // Wildcard special case, which means bind to INADDR_ANY. - if ((h != NULL) && ((strcmp(h, "*") == 0) || (strlen(h) == 0))) { + if ((h != NULL) && ((strcmp(h, "*") == 0) || (strcmp(h, "") == 0))) { h = NULL; } nni_tcp_resolv(h, url->u_port, af, 1, aio);