diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-03-04 17:04:11 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-03-04 19:42:17 -0800 |
| commit | 23a38d766780f4749945d84316b4e0a71e707b15 (patch) | |
| tree | 336cf1bfc7c7e32999653a4c4014232d2b735a3e /src/platform/windows | |
| parent | 0094f83a9e3b54d6cbfc1ea1885036366b87b991 (diff) | |
| download | nng-23a38d766780f4749945d84316b4e0a71e707b15.tar.gz nng-23a38d766780f4749945d84316b4e0a71e707b15.tar.bz2 nng-23a38d766780f4749945d84316b4e0a71e707b15.zip | |
fixes #262 NNG_OPT_URL should be resolved
This causes TCP, TLS, and ZT endpoints to resolve any
wildcards, and even IP addresses, when reporting the listen
URL. The dialer URL is reported unresolved. Test cases
for this are added as well, and nngcat actually reports this
if --verbose is supplied.
Diffstat (limited to 'src/platform/windows')
| -rw-r--r-- | src/platform/windows/win_tcp.c | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/src/platform/windows/win_tcp.c b/src/platform/windows/win_tcp.c index 20f324b3..da661588 100644 --- a/src/platform/windows/win_tcp.c +++ b/src/platform/windows/win_tcp.c @@ -355,7 +355,7 @@ nni_plat_tcp_ep_fini(nni_plat_tcp_ep *ep) } static int -nni_win_tcp_listen(nni_plat_tcp_ep *ep) +nni_win_tcp_listen(nni_plat_tcp_ep *ep, nni_sockaddr *bsa) { int rv; BOOL yes; @@ -392,6 +392,17 @@ nni_win_tcp_listen(nni_plat_tcp_ep *ep) goto fail; } + if (bsa != NULL) { + SOCKADDR_STORAGE bound; + int len = sizeof(bound); + rv = getsockname(s, (SOCKADDR *) &bound, &len); + if (rv != 0) { + rv = nni_win_error(GetLastError()); + goto fail; + } + nni_win_sockaddr2nn(bsa, &bound); + } + if (listen(s, SOMAXCONN) != 0) { rv = nni_win_error(GetLastError()); goto fail; @@ -410,12 +421,12 @@ fail: } int -nni_plat_tcp_ep_listen(nni_plat_tcp_ep *ep) +nni_plat_tcp_ep_listen(nni_plat_tcp_ep *ep, nng_sockaddr *bsa) { int rv; nni_mtx_lock(&ep->acc_ev.mtx); - rv = nni_win_tcp_listen(ep); + rv = nni_win_tcp_listen(ep, bsa); nni_mtx_unlock(&ep->acc_ev.mtx); return (rv); } @@ -643,6 +654,47 @@ nni_plat_tcp_ep_connect(nni_plat_tcp_ep *ep, nni_aio *aio) } int +nni_plat_tcp_ntop(const nni_sockaddr *sa, char *ipstr, char *portstr) +{ + const void *ap; + uint16_t port; + int af; + switch (sa->s_un.s_family) { + case NNG_AF_INET: + ap = &sa->s_un.s_in.sa_addr; + port = sa->s_un.s_in.sa_port; + af = AF_INET; + break; + case NNG_AF_INET6: + ap = &sa->s_un.s_in6.sa_addr; + port = sa->s_un.s_in6.sa_port; + af = AF_INET6; + break; + default: + return (NNG_EINVAL); + } + if (ipstr != NULL) { + if (af == AF_INET6) { + size_t l; + ipstr[0] = '['; + InetNtopA(af, ap, ipstr + 1, INET6_ADDRSTRLEN); + l = strlen(ipstr); + ipstr[l++] = ']'; + ipstr[l++] = '\0'; + } else { + InetNtopA(af, ap, ipstr, INET6_ADDRSTRLEN); + } + } + if (portstr != NULL) { +#ifdef NNG_LITTLE_ENDIAN + port = ((port >> 8) & 0xff) | ((port & 0xff) << 8); +#endif + snprintf(portstr, 6, "%u", port); + } + return (0); +} + +int nni_win_tcp_sysinit(void) { WSADATA data; |
