Skip to content

Commit

Permalink
windows fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Jul 28, 2020
1 parent b3483e1 commit 3cfe9cf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
8 changes: 5 additions & 3 deletions src/platform/posix/posix_resolv_gai.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2019 Staysail Systems, Inc. <[email protected]>
// Copyright 2020 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand Down Expand Up @@ -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)) {
Expand Down
37 changes: 25 additions & 12 deletions src/platform/windows/win_resolv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 == ':') {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/supplemental/tcp/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3cfe9cf

Please sign in to comment.