From 85ccb0066a86a3558ae81cd357463f8dc631f94b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 14 Mar 2018 15:40:46 -0700 Subject: [PATCH] fixes #289 nng_sockaddr could just be a union fixes #290 sockaddr improvements --- docs/man/nng_inproc.adoc | 10 ++-- src/core/defs.h | 14 +++--- src/nng.h | 23 ++++++---- src/platform/posix/posix_ipc.c | 3 +- src/platform/posix/posix_resolv_gai.c | 21 ++++----- src/platform/posix/posix_sockaddr.c | 14 +++--- src/platform/posix/posix_tcp.c | 14 +++--- src/platform/windows/win_ipc.c | 2 +- src/platform/windows/win_resolv.c | 24 +++++----- src/platform/windows/win_sockaddr.c | 30 ++++++------ src/platform/windows/win_tcp.c | 14 +++--- src/transport/inproc/inproc.c | 5 +- src/transport/ipc/ipc.c | 16 +++---- src/transport/tcp/tcp.c | 8 ++-- src/transport/tls/tls.c | 16 +++---- src/transport/zerotier/zerotier.c | 44 +++++++++--------- tests/resolv.c | 66 +++++++++++++-------------- tests/tcp.c | 14 +++--- tests/tcp6.c | 26 +++++------ tests/tls.c | 14 +++--- tests/udp.c | 54 +++++++++++----------- tests/ws.c | 14 +++--- tests/wss.c | 10 ++-- tests/wssfile.c | 12 ++--- tests/zt.c | 16 +++---- 25 files changed, 241 insertions(+), 243 deletions(-) diff --git a/docs/man/nng_inproc.adoc b/docs/man/nng_inproc.adoc index c0dc270d4..5123c3a37 100644 --- a/docs/man/nng_inproc.adoc +++ b/docs/man/nng_inproc.adoc @@ -31,8 +31,7 @@ to slower transports when data must be moved within the same process. This transport tries hard to avoid copying data, and thus is very light-weight. -Registration -~~~~~~~~~~~~ +=== Registration The _inproc_ transport is generally built-in to the _nng_ core, so no extra steps to use it should be necessary. @@ -52,7 +51,8 @@ that URI. === Socket Address When using an `nng_sockaddr` structure, the actual structure is of type -`struct nng_sockaddr_inproc`. This type has the following definition: +`struct nng_sockaddr_inproc`. +This type has the following definition: [source,c] -------- @@ -62,9 +62,9 @@ When using an `nng_sockaddr` structure, the actual structure is of type typedef nng_sockaddr_inproc { // <2> uint16_t sa_family; // must be NNG_AF_INPROC - char sa_path[NNG_MAXADDRLEN]; // arbitrary "path" + char sa_name[NNG_MAXADDRLEN]; // arbitrary "name" // -} +} nng_sockaddr_inproc; -------- <1> The values of these macros may change, so applications should avoid depending upon their values and instead use them symbolically. diff --git a/src/core/defs.h b/src/core/defs.h index c449aa321..0f38b9cf3 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -31,13 +31,13 @@ // These types are common but have names shared with user space. // Internal code should use these names when possible. -typedef struct nng_msg nni_msg; -typedef struct nng_sockaddr nni_sockaddr; -typedef struct nng_event nni_event; -typedef struct nng_notify nni_notify; -typedef struct nng_url nni_url; -typedef struct nng_iov nni_iov; -typedef struct nng_aio nni_aio; +typedef nng_msg nni_msg; +typedef nng_sockaddr nni_sockaddr; +typedef nng_url nni_url; +typedef nng_iov nni_iov; +typedef nng_aio nni_aio; +typedef struct nng_event nni_event; +typedef struct nng_notify nni_notify; // These are our own names. typedef struct nni_socket nni_sock; diff --git a/src/nng.h b/src/nng.h index b7adee93c..a581d4343 100644 --- a/src/nng.h +++ b/src/nng.h @@ -619,13 +619,18 @@ enum nng_errno_enum { // sockaddr, but we have our own to cope with our unique families, etc. // The details of this structure are directly exposed to applications. // These structures can be obtained via property lookups, etc. +struct nng_sockaddr_inproc { + uint16_t sa_family; + char sa_name[NNG_MAXADDRLEN]; +}; +typedef struct nng_sockaddr_inproc nng_sockaddr_inproc; + struct nng_sockaddr_path { uint16_t sa_family; char sa_path[NNG_MAXADDRLEN]; }; typedef struct nng_sockaddr_path nng_sockaddr_path; typedef struct nng_sockaddr_path nng_sockaddr_ipc; -typedef struct nng_sockaddr_path nng_sockaddr_inproc; struct nng_sockaddr_in6 { uint16_t sa_family; @@ -654,15 +659,13 @@ typedef struct nng_sockaddr_in nng_sockaddr_udp; typedef struct nng_sockaddr_in nng_sockaddr_tcp; typedef struct nng_sockaddr_zt nng_sockaddr_zt; -typedef struct nng_sockaddr { - union { - uint16_t s_family; - nng_sockaddr_path s_path; - nng_sockaddr_inproc s_inproc; - nng_sockaddr_in6 s_in6; - nng_sockaddr_in s_in; - nng_sockaddr_zt s_zt; - } s_un; +typedef union nng_sockaddr { + uint16_t s_family; + nng_sockaddr_ipc s_ipc; + nng_sockaddr_inproc s_inproc; + nng_sockaddr_in6 s_in6; + nng_sockaddr_in s_in; + nng_sockaddr_zt s_zt; } nng_sockaddr; enum nng_sockaddr_family { diff --git a/src/platform/posix/posix_ipc.c b/src/platform/posix/posix_ipc.c index cd9da2434..f7cfc0dbf 100644 --- a/src/platform/posix/posix_ipc.c +++ b/src/platform/posix/posix_ipc.c @@ -59,8 +59,7 @@ nni_plat_ipc_ep_init(nni_plat_ipc_ep **epp, const nni_sockaddr *sa, int mode) break; case NNI_EP_MODE_LISTEN: - if ((rv = nni_plat_ipc_remove_stale( - sa->s_un.s_path.sa_path)) != 0) { + if ((rv = nni_plat_ipc_remove_stale(sa->s_ipc.sa_path)) != 0) { return (rv); } diff --git a/src/platform/posix/posix_resolv_gai.c b/src/platform/posix/posix_resolv_gai.c index f2f8a9fcd..496fb97b5 100644 --- a/src/platform/posix/posix_resolv_gai.c +++ b/src/platform/posix/posix_resolv_gai.c @@ -171,19 +171,18 @@ nni_posix_resolv_task(void *arg) switch (probe->ai_addr->sa_family) { case AF_INET: - rv = 0; - sin = (void *) probe->ai_addr; - sa->s_un.s_in.sa_family = NNG_AF_INET; - sa->s_un.s_in.sa_port = sin->sin_port; - sa->s_un.s_in.sa_addr = sin->sin_addr.s_addr; + rv = 0; + sin = (void *) probe->ai_addr; + sa->s_in.sa_family = NNG_AF_INET; + sa->s_in.sa_port = sin->sin_port; + sa->s_in.sa_addr = sin->sin_addr.s_addr; break; case AF_INET6: - rv = 0; - sin6 = (void *) probe->ai_addr; - sa->s_un.s_in6.sa_family = NNG_AF_INET6; - sa->s_un.s_in6.sa_port = sin6->sin6_port; - memcpy(sa->s_un.s_in6.sa_addr, sin6->sin6_addr.s6_addr, - 16); + rv = 0; + sin6 = (void *) probe->ai_addr; + sa->s_in6.sa_family = NNG_AF_INET6; + sa->s_in6.sa_port = sin6->sin6_port; + memcpy(sa->s_in6.sa_addr, sin6->sin6_addr.s6_addr, 16); break; } } diff --git a/src/platform/posix/posix_sockaddr.c b/src/platform/posix/posix_sockaddr.c index e9691d91d..ba088ed96 100644 --- a/src/platform/posix/posix_sockaddr.c +++ b/src/platform/posix/posix_sockaddr.c @@ -36,10 +36,10 @@ nni_posix_nn2sockaddr(void *sa, const nni_sockaddr *na) if ((sa == NULL) || (na == NULL)) { return (0); } - switch (na->s_un.s_family) { + switch (na->s_family) { case NNG_AF_INET: sin = (void *) sa; - nsin = &na->s_un.s_in; + nsin = &na->s_in; memset(sin, 0, sizeof(*sin)); sin->sin_family = PF_INET; sin->sin_port = nsin->sa_port; @@ -48,7 +48,7 @@ nni_posix_nn2sockaddr(void *sa, const nni_sockaddr *na) case NNG_AF_INET6: sin6 = (void *) sa; - nsin6 = &na->s_un.s_in6; + nsin6 = &na->s_in6; memset(sin6, 0, sizeof(*sin6)); #ifdef SIN6_LEN sin6->sin6_len = sizeof(*sin6); @@ -60,7 +60,7 @@ nni_posix_nn2sockaddr(void *sa, const nni_sockaddr *na) case NNG_AF_IPC: spath = (void *) sa; - nspath = &na->s_un.s_path; + nspath = &na->s_ipc; memset(spath, 0, sizeof(*spath)); // Make sure that the path fits! sz = sizeof(spath->sun_path); @@ -89,21 +89,21 @@ nni_posix_sockaddr2nn(nni_sockaddr *na, const void *sa) switch (((struct sockaddr *) sa)->sa_family) { case AF_INET: sin = (void *) sa; - nsin = &na->s_un.s_in; + nsin = &na->s_in; nsin->sa_family = NNG_AF_INET; nsin->sa_port = sin->sin_port; nsin->sa_addr = sin->sin_addr.s_addr; break; case AF_INET6: sin6 = (void *) sa; - nsin6 = &na->s_un.s_in6; + nsin6 = &na->s_in6; nsin6->sa_family = NNG_AF_INET6; nsin6->sa_port = sin6->sin6_port; memcpy(nsin6->sa_addr, sin6->sin6_addr.s6_addr, 16); break; case AF_UNIX: spath = (void *) sa; - nspath = &na->s_un.s_path; + nspath = &na->s_ipc; nspath->sa_family = NNG_AF_IPC; (void) snprintf(nspath->sa_path, sizeof(nspath->sa_path), "%s", spath->sun_path); diff --git a/src/platform/posix/posix_tcp.c b/src/platform/posix/posix_tcp.c index 8a6fe9d10..9caa157fb 100644 --- a/src/platform/posix/posix_tcp.c +++ b/src/platform/posix/posix_tcp.c @@ -40,11 +40,11 @@ nni_plat_tcp_ep_init(nni_plat_tcp_ep **epp, const nni_sockaddr *lsa, return (rv); } - if ((rsa != NULL) && (rsa->s_un.s_family != NNG_AF_UNSPEC)) { + if ((rsa != NULL) && (rsa->s_family != NNG_AF_UNSPEC)) { len = nni_posix_nn2sockaddr((void *) &ss, rsa); nni_posix_epdesc_set_remote(ed, &ss, len); } - if ((lsa != NULL) && (lsa->s_un.s_family != NNG_AF_UNSPEC)) { + if ((lsa != NULL) && (lsa->s_family != NNG_AF_UNSPEC)) { len = nni_posix_nn2sockaddr((void *) &ss, lsa); nni_posix_epdesc_set_local(ed, &ss, len); } @@ -130,15 +130,15 @@ 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) { + switch (sa->s_family) { case NNG_AF_INET: - ap = &sa->s_un.s_in.sa_addr; - port = sa->s_un.s_in.sa_port; + ap = &sa->s_in.sa_addr; + port = sa->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; + ap = &sa->s_in6.sa_addr; + port = sa->s_in6.sa_port; af = AF_INET6; break; default: diff --git a/src/platform/windows/win_ipc.c b/src/platform/windows/win_ipc.c index 84afbaa54..5843917c0 100644 --- a/src/platform/windows/win_ipc.c +++ b/src/platform/windows/win_ipc.c @@ -193,7 +193,7 @@ nni_plat_ipc_ep_init(nni_plat_ipc_ep **epp, const nni_sockaddr *sa, int mode) const char * path; nni_plat_ipc_ep *ep; - path = sa->s_un.s_path.sa_path; + path = sa->s_ipc.sa_path; if (nni_strnlen(path, NNG_MAXADDRLEN) >= NNG_MAXADDRLEN) { return (NNG_EINVAL); } diff --git a/src/platform/windows/win_resolv.c b/src/platform/windows/win_resolv.c index 6ee55d16c..d07b4fd54 100644 --- a/src/platform/windows/win_resolv.c +++ b/src/platform/windows/win_resolv.c @@ -1,5 +1,6 @@ // -// Copyright 2017 Garrett D'Amore +// Copyright 2018 Staysail Systems, Inc. +// Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -145,19 +146,18 @@ nni_win_resolv_task(void *arg) switch (probe->ai_addr->sa_family) { case AF_INET: - rv = 0; - sin = (void *) probe->ai_addr; - sa->s_un.s_in.sa_family = NNG_AF_INET; - sa->s_un.s_in.sa_port = sin->sin_port; - sa->s_un.s_in.sa_addr = sin->sin_addr.s_addr; + rv = 0; + sin = (void *) probe->ai_addr; + sa->s_in.sa_family = NNG_AF_INET; + sa->s_in.sa_port = sin->sin_port; + sa->s_in.sa_addr = sin->sin_addr.s_addr; break; case AF_INET6: - rv = 0; - sin6 = (void *) probe->ai_addr; - sa->s_un.s_in6.sa_family = NNG_AF_INET6; - sa->s_un.s_in6.sa_port = sin6->sin6_port; - memcpy(sa->s_un.s_in6.sa_addr, sin6->sin6_addr.s6_addr, - 16); + rv = 0; + sin6 = (void *) probe->ai_addr; + sa->s_in6.sa_family = NNG_AF_INET6; + sa->s_in6.sa_port = sin6->sin6_port; + memcpy(sa->s_in6.sa_addr, sin6->sin6_addr.s6_addr, 16); break; } } diff --git a/src/platform/windows/win_sockaddr.c b/src/platform/windows/win_sockaddr.c index f66542c68..141a1ce53 100644 --- a/src/platform/windows/win_sockaddr.c +++ b/src/platform/windows/win_sockaddr.c @@ -1,6 +1,6 @@ // -// Copyright 2017 Garrett D'Amore -// Copyright 2017 Capitar IT Group BV +// Copyright 2018 Staysail Systems, Inc. +// Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -23,21 +23,21 @@ nni_win_nn2sockaddr(SOCKADDR_STORAGE *ss, const nni_sockaddr *sa) if ((ss == NULL) || (sa == NULL)) { return (-1); } - switch (sa->s_un.s_family) { + switch (sa->s_family) { case NNG_AF_INET: sin = (void *) ss; memset(sin, 0, sizeof(*sin)); sin->sin_family = PF_INET; - sin->sin_port = sa->s_un.s_in.sa_port; - sin->sin_addr.s_addr = sa->s_un.s_in.sa_addr; + sin->sin_port = sa->s_in.sa_port; + sin->sin_addr.s_addr = sa->s_in.sa_addr; return (sizeof(*sin)); case NNG_AF_INET6: sin6 = (void *) ss; memset(sin6, 0, sizeof(*sin6)); sin6->sin6_family = PF_INET6; - sin6->sin6_port = sa->s_un.s_in6.sa_port; - memcpy(sin6->sin6_addr.s6_addr, sa->s_un.s_in6.sa_addr, 16); + sin6->sin6_port = sa->s_in6.sa_port; + memcpy(sin6->sin6_addr.s6_addr, sa->s_in6.sa_addr, 16); return (sizeof(*sin6)); } return (-1); @@ -54,17 +54,17 @@ nni_win_sockaddr2nn(nni_sockaddr *sa, const SOCKADDR_STORAGE *ss) } switch (ss->ss_family) { case PF_INET: - sin = (void *) ss; - sa->s_un.s_in.sa_family = NNG_AF_INET; - sa->s_un.s_in.sa_port = sin->sin_port; - sa->s_un.s_in.sa_addr = sin->sin_addr.s_addr; + sin = (void *) ss; + sa->s_in.sa_family = NNG_AF_INET; + sa->s_in.sa_port = sin->sin_port; + sa->s_in.sa_addr = sin->sin_addr.s_addr; return (0); case PF_INET6: - sin6 = (void *) ss; - sa->s_un.s_in6.sa_family = NNG_AF_INET6; - sa->s_un.s_in6.sa_port = sin6->sin6_port; - memcpy(sa->s_un.s_in6.sa_addr, sin6->sin6_addr.s6_addr, 16); + sin6 = (void *) ss; + sa->s_in6.sa_family = NNG_AF_INET6; + sa->s_in6.sa_port = sin6->sin6_port; + memcpy(sa->s_in6.sa_addr, sin6->sin6_addr.s6_addr, 16); return (0); } return (-1); diff --git a/src/platform/windows/win_tcp.c b/src/platform/windows/win_tcp.c index 8062eb3ea..17f7845dd 100644 --- a/src/platform/windows/win_tcp.c +++ b/src/platform/windows/win_tcp.c @@ -274,10 +274,10 @@ nni_plat_tcp_ep_init(nni_plat_tcp_ep **epp, const nni_sockaddr *lsa, ep->s = INVALID_SOCKET; - if ((rsa != NULL) && (rsa->s_un.s_family != NNG_AF_UNSPEC)) { + if ((rsa != NULL) && (rsa->s_family != NNG_AF_UNSPEC)) { ep->remlen = nni_win_nn2sockaddr(&ep->remaddr, rsa); } - if ((lsa != NULL) && (lsa->s_un.s_family != NNG_AF_UNSPEC)) { + if ((lsa != NULL) && (lsa->s_family != NNG_AF_UNSPEC)) { ep->loclen = nni_win_nn2sockaddr(&ep->locaddr, lsa); } @@ -659,15 +659,15 @@ 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) { + switch (sa->s_family) { case NNG_AF_INET: - ap = &sa->s_un.s_in.sa_addr; - port = sa->s_un.s_in.sa_port; + ap = &sa->s_in.sa_addr; + port = sa->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; + ap = &sa->s_in6.sa_addr; + port = sa->s_in6.sa_port; af = AF_INET6; break; default: diff --git a/src/transport/inproc/inproc.c b/src/transport/inproc/inproc.c index f9f438abc..375d8bdd7 100644 --- a/src/transport/inproc/inproc.c +++ b/src/transport/inproc/inproc.c @@ -183,9 +183,8 @@ nni_inproc_pipe_get_addr(void *arg, void *buf, size_t *szp) nni_sockaddr sa; memset(&sa, 0, sizeof(sa)); - sa.s_un.s_inproc.sa_family = NNG_AF_INPROC; - nni_strlcpy(sa.s_un.s_inproc.sa_path, p->addr, - sizeof(sa.s_un.s_inproc.sa_path)); + sa.s_inproc.sa_family = NNG_AF_INPROC; + nni_strlcpy(sa.s_inproc.sa_name, p->addr, sizeof(sa.s_inproc.sa_name)); return (nni_getopt_sockaddr(&sa, buf, szp)); } diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c index 41498ca3d..fa59f0feb 100644 --- a/src/transport/ipc/ipc.c +++ b/src/transport/ipc/ipc.c @@ -120,11 +120,11 @@ nni_ipc_pipe_init(nni_ipc_pipe **pipep, nni_ipc_ep *ep, void *ipp) return (rv); } - p->proto = ep->proto; - p->rcvmax = ep->rcvmax; - p->ipp = ipp; - p->sa.s_un.s_path.sa_family = NNG_AF_IPC; - p->sa = ep->sa; + p->proto = ep->proto; + p->rcvmax = ep->rcvmax; + p->ipp = ipp; + p->sa.s_ipc.sa_family = NNG_AF_IPC; + p->sa = ep->sa; *pipep = p; return (0); @@ -524,10 +524,10 @@ nni_ipc_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) } nni_mtx_init(&ep->mtx); - sz = sizeof(ep->sa.s_un.s_path.sa_path); - ep->sa.s_un.s_path.sa_family = NNG_AF_IPC; + sz = sizeof(ep->sa.s_ipc.sa_path); + ep->sa.s_ipc.sa_family = NNG_AF_IPC; - if (nni_strlcpy(ep->sa.s_un.s_path.sa_path, url->u_path, sz) >= sz) { + if (nni_strlcpy(ep->sa.s_ipc.sa_path, url->u_path, sz) >= sz) { nni_ipc_ep_fini(ep); return (NNG_EADDRINVAL); } diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index 2a23b88b5..1b4e6dc2f 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -555,16 +555,16 @@ nni_tcp_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) // XXX: arguably we could defer this part to the point we do a bind // or connect! if (mode == NNI_EP_MODE_DIAL) { - passive = 0; - lsa.s_un.s_family = NNG_AF_UNSPEC; + passive = 0; + lsa.s_family = NNG_AF_UNSPEC; nni_aio_set_input(aio, 0, &rsa); if ((host == NULL) || (serv == NULL)) { nni_aio_fini(aio); return (NNG_EADDRINVAL); } } else { - passive = 1; - rsa.s_un.s_family = NNG_AF_UNSPEC; + passive = 1; + rsa.s_family = NNG_AF_UNSPEC; nni_aio_set_input(aio, 0, &lsa); } diff --git a/src/transport/tls/tls.c b/src/transport/tls/tls.c index cf8493731..534b955d2 100644 --- a/src/transport/tls/tls.c +++ b/src/transport/tls/tls.c @@ -568,20 +568,20 @@ nni_tls_ep_init(void **epp, nni_url *url, nni_sock *sock, int mode) } if (mode == NNI_EP_MODE_DIAL) { - passive = 0; - tlsmode = NNG_TLS_MODE_CLIENT; - authmode = NNG_TLS_AUTH_MODE_REQUIRED; - lsa.s_un.s_family = NNG_AF_UNSPEC; + passive = 0; + tlsmode = NNG_TLS_MODE_CLIENT; + authmode = NNG_TLS_AUTH_MODE_REQUIRED; + lsa.s_family = NNG_AF_UNSPEC; nni_aio_set_input(aio, 0, &rsa); if ((host == NULL) || (serv == NULL)) { nni_aio_fini(aio); return (NNG_EADDRINVAL); } } else { - passive = 1; - tlsmode = NNG_TLS_MODE_SERVER; - authmode = NNG_TLS_AUTH_MODE_NONE; - rsa.s_un.s_family = NNG_AF_UNSPEC; + passive = 1; + tlsmode = NNG_TLS_MODE_SERVER; + authmode = NNG_TLS_AUTH_MODE_NONE; + rsa.s_family = NNG_AF_UNSPEC; nni_aio_set_input(aio, 0, &lsa); } diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c index 01c290dbb..2a427ca0c 100644 --- a/src/transport/zerotier/zerotier.c +++ b/src/transport/zerotier/zerotier.c @@ -345,7 +345,7 @@ zt_node_rcv4_cb(void *arg) memset(&sa, 0, sizeof(sa)); sin = (void *) &sa; - nsin = &ztn->zn_rcv4_addr.s_un.s_in; + nsin = &ztn->zn_rcv4_addr.s_in; sin->sin_family = AF_INET; sin->sin_port = nsin->sa_port; sin->sin_addr.s_addr = nsin->sa_addr; @@ -397,7 +397,7 @@ zt_node_rcv6_cb(void *arg) memset(&sa, 0, sizeof(sa)); sin6 = (void *) &sa; - nsin6 = &ztn->zn_rcv6_addr.s_un.s_in6; + nsin6 = &ztn->zn_rcv6_addr.s_in6; sin6->sin6_family = AF_INET6; sin6->sin6_port = nsin6->sa_port; memcpy(&sin6->sin6_addr, nsin6->sa_addr, 16); @@ -1326,18 +1326,18 @@ zt_wire_packet_send(ZT_Node *node, void *userptr, void *thr, int64_t socket, // the platform layer. switch (sin->sin_family) { case AF_INET: - addr.s_un.s_in.sa_family = NNG_AF_INET; - addr.s_un.s_in.sa_port = sin->sin_port; - addr.s_un.s_in.sa_addr = sin->sin_addr.s_addr; - udp = ztn->zn_udp4; - port = htons(sin->sin_port); + addr.s_in.sa_family = NNG_AF_INET; + addr.s_in.sa_port = sin->sin_port; + addr.s_in.sa_addr = sin->sin_addr.s_addr; + udp = ztn->zn_udp4; + port = htons(sin->sin_port); break; case AF_INET6: - addr.s_un.s_in6.sa_family = NNG_AF_INET6; - addr.s_un.s_in6.sa_port = sin6->sin6_port; - udp = ztn->zn_udp6; - port = htons(sin6->sin6_port); - memcpy(addr.s_un.s_in6.sa_addr, sin6->sin6_addr.s6_addr, 16); + addr.s_in6.sa_family = NNG_AF_INET6; + addr.s_in6.sa_port = sin6->sin6_port; + udp = ztn->zn_udp6; + port = htons(sin6->sin6_port); + memcpy(addr.s_in6.sa_addr, sin6->sin6_addr.s6_addr, 16); break; default: // No way to understand the address. @@ -1440,9 +1440,9 @@ zt_node_create(zt_node **ztnp, const char *path) // We want to bind to any address we can (for now). memset(&sa4, 0, sizeof(sa4)); - sa4.s_un.s_in.sa_family = NNG_AF_INET; + sa4.s_in.sa_family = NNG_AF_INET; memset(&sa6, 0, sizeof(sa6)); - sa6.s_un.s_in6.sa_family = NNG_AF_INET6; + sa6.s_in6.sa_family = NNG_AF_INET6; if ((ztn = NNI_ALLOC_STRUCT(ztn)) == NULL) { return (NNG_ENOMEM); @@ -2747,10 +2747,10 @@ zt_pipe_getopt_locaddr(void *arg, void *data, size_t *szp) nng_sockaddr sa; memset(&sa, 0, sizeof(sa)); - sa.s_un.s_zt.sa_family = NNG_AF_ZT; - sa.s_un.s_zt.sa_nwid = p->zp_nwid; - sa.s_un.s_zt.sa_nodeid = p->zp_laddr >> zt_port_shift; - sa.s_un.s_zt.sa_port = p->zp_laddr & zt_port_mask; + sa.s_zt.sa_family = NNG_AF_ZT; + sa.s_zt.sa_nwid = p->zp_nwid; + sa.s_zt.sa_nodeid = p->zp_laddr >> zt_port_shift; + sa.s_zt.sa_port = p->zp_laddr & zt_port_mask; return (nni_getopt_sockaddr(&sa, data, szp)); } @@ -2761,10 +2761,10 @@ zt_pipe_getopt_remaddr(void *arg, void *data, size_t *szp) nng_sockaddr sa; memset(&sa, 0, sizeof(sa)); - sa.s_un.s_zt.sa_family = NNG_AF_ZT; - sa.s_un.s_zt.sa_nwid = p->zp_nwid; - sa.s_un.s_zt.sa_nodeid = p->zp_raddr >> zt_port_shift; - sa.s_un.s_zt.sa_port = p->zp_raddr & zt_port_mask; + sa.s_zt.sa_family = NNG_AF_ZT; + sa.s_zt.sa_nwid = p->zp_nwid; + sa.s_zt.sa_nodeid = p->zp_raddr >> zt_port_shift; + sa.s_zt.sa_port = p->zp_raddr & zt_port_mask; return (nni_getopt_sockaddr(&sa, data, szp)); } diff --git a/tests/resolv.c b/tests/resolv.c index 9d83e6df8..dfc599c04 100644 --- a/tests/resolv.c +++ b/tests/resolv.c @@ -61,9 +61,9 @@ ip6tostr(void *addr) aio); nng_aio_wait(aio); So(nng_aio_result(aio) == 0); - So(sa.s_un.s_in6.sa_family == NNG_AF_INET6); - So(sa.s_un.s_in6.sa_port == ntohs(80)); - str = ip6tostr(&sa.s_un.s_in6.sa_addr); + So(sa.s_in6.sa_family == NNG_AF_INET6); + So(sa.s_in6.sa_port == ntohs(80)); + str = ip6tostr(&sa.s_in6.sa_addr); So(strcmp(str, "::1") == 0); nng_aio_free(aio); } @@ -83,9 +83,9 @@ TestMain("Resolver", { NNG_AF_INET, 1, aio); nng_aio_wait(aio); So(nng_aio_result(aio) == 0); - So(sa.s_un.s_in.sa_family == NNG_AF_INET); - So(sa.s_un.s_in.sa_port == ntohs(80)); - str = ip4tostr(&sa.s_un.s_in.sa_addr); + So(sa.s_in.sa_family == NNG_AF_INET); + So(sa.s_in.sa_port == ntohs(80)); + str = ip4tostr(&sa.s_in.sa_addr); So(strcmp(str, "8.8.8.8") == 0); nng_aio_free(aio); }); @@ -99,9 +99,9 @@ TestMain("Resolver", { nni_plat_udp_resolv("8.8.4.4", "69", NNG_AF_INET, 1, aio); nng_aio_wait(aio); So(nng_aio_result(aio) == 0); - So(sa.s_un.s_in.sa_family == NNG_AF_INET); - So(sa.s_un.s_in.sa_port == ntohs(69)); - str = ip4tostr(&sa.s_un.s_in.sa_addr); + So(sa.s_in.sa_family == NNG_AF_INET); + So(sa.s_in.sa_port == ntohs(69)); + str = ip4tostr(&sa.s_in.sa_addr); So(strcmp(str, "8.8.4.4") == 0); nng_aio_free(aio); }); @@ -115,9 +115,9 @@ TestMain("Resolver", { nni_plat_tcp_resolv("8.8.4.4", "80", NNG_AF_INET, 1, aio); nng_aio_wait(aio); So(nng_aio_result(aio) == 0); - So(sa.s_un.s_in.sa_family == NNG_AF_INET); - So(sa.s_un.s_in.sa_port == ntohs(80)); - str = ip4tostr(&sa.s_un.s_in.sa_addr); + So(sa.s_in.sa_family == NNG_AF_INET); + So(sa.s_in.sa_port == ntohs(80)); + str = ip4tostr(&sa.s_in.sa_addr); So(strcmp(str, "8.8.4.4") == 0); nng_aio_free(aio); }); @@ -140,9 +140,9 @@ TestMain("Resolver", { nni_plat_tcp_resolv("::1", "80", NNG_AF_INET6, 1, aio); nng_aio_wait(aio); So(nng_aio_result(aio) == 0); - So(sa.s_un.s_in6.sa_family == NNG_AF_INET6); - So(sa.s_un.s_in6.sa_port == ntohs(80)); - str = ip6tostr(&sa.s_un.s_in6.sa_addr); + So(sa.s_in6.sa_family == NNG_AF_INET6); + So(sa.s_in6.sa_port == ntohs(80)); + str = ip6tostr(&sa.s_in6.sa_addr); So(strcmp(str, "::1") == 0); nng_aio_free(aio); }); @@ -157,9 +157,9 @@ TestMain("Resolver", { nni_plat_tcp_resolv("8.8.4.4", "http", NNG_AF_INET, 1, aio); nng_aio_wait(aio); So(nng_aio_result(aio) == 0); - So(sa.s_un.s_in.sa_family == NNG_AF_INET); - So(sa.s_un.s_in.sa_port == ntohs(80)); - str = ip4tostr(&sa.s_un.s_in.sa_addr); + So(sa.s_in.sa_family == NNG_AF_INET); + So(sa.s_in.sa_port == ntohs(80)); + str = ip4tostr(&sa.s_in.sa_addr); So(strcmp(str, "8.8.4.4") == 0); nng_aio_free(aio); }); @@ -174,9 +174,9 @@ TestMain("Resolver", { nni_plat_udp_resolv("8.8.4.4", "tftp", NNG_AF_INET, 1, aio); nng_aio_wait(aio); So(nng_aio_result(aio) == 0); - So(sa.s_un.s_in.sa_family == NNG_AF_INET); - So(sa.s_un.s_in.sa_port == ntohs(69)); - str = ip4tostr(&sa.s_un.s_in.sa_addr); + So(sa.s_in.sa_family == NNG_AF_INET); + So(sa.s_in.sa_port == ntohs(69)); + str = ip4tostr(&sa.s_in.sa_addr); So(strcmp(str, "8.8.4.4") == 0); nng_aio_free(aio); }); @@ -191,10 +191,10 @@ TestMain("Resolver", { nni_plat_tcp_resolv("localhost", "80", NNG_AF_INET, 1, aio); nng_aio_wait(aio); So(nng_aio_result(aio) == 0); - So(sa.s_un.s_in.sa_family == NNG_AF_INET); - So(sa.s_un.s_in.sa_port == ntohs(80)); - So(sa.s_un.s_in.sa_addr == ntohl(0x7f000001)); - str = ip4tostr(&sa.s_un.s_in.sa_addr); + So(sa.s_in.sa_family == NNG_AF_INET); + So(sa.s_in.sa_port == ntohs(80)); + So(sa.s_in.sa_addr == ntohl(0x7f000001)); + str = ip4tostr(&sa.s_in.sa_addr); So(strcmp(str, "127.0.0.1") == 0); nng_aio_free(aio); }); @@ -209,18 +209,18 @@ TestMain("Resolver", { nni_plat_tcp_resolv("localhost", "80", NNG_AF_UNSPEC, 1, aio); nng_aio_wait(aio); So(nng_aio_result(aio) == 0); - So((sa.s_un.s_family == NNG_AF_INET) || - (sa.s_un.s_family == NNG_AF_INET6)); - switch (sa.s_un.s_family) { + So((sa.s_family == NNG_AF_INET) || + (sa.s_family == NNG_AF_INET6)); + switch (sa.s_family) { case NNG_AF_INET: - So(sa.s_un.s_in.sa_port == ntohs(80)); - So(sa.s_un.s_in.sa_addr == ntohl(0x7f000001)); - str = ip4tostr(&sa.s_un.s_in.sa_addr); + So(sa.s_in.sa_port == ntohs(80)); + So(sa.s_in.sa_addr == ntohl(0x7f000001)); + str = ip4tostr(&sa.s_in.sa_addr); So(strcmp(str, "127.0.0.1") == 0); break; case NNG_AF_INET6: - So(sa.s_un.s_in6.sa_port == ntohs(80)); - str = ip6tostr(&sa.s_un.s_in6.sa_addr); + So(sa.s_in6.sa_port == ntohs(80)); + str = ip6tostr(&sa.s_in6.sa_addr); So(strcmp(str, "::1") == 0); break; } diff --git a/tests/tcp.c b/tests/tcp.c index 42be028d6..10d777dae 100644 --- a/tests/tcp.c +++ b/tests/tcp.c @@ -33,17 +33,17 @@ check_props_v4(nng_msg *msg) z = sizeof(nng_sockaddr); So(nng_pipe_getopt(p, NNG_OPT_LOCADDR, &la, &z) == 0); So(z == sizeof(la)); - So(la.s_un.s_family == NNG_AF_INET); - So(la.s_un.s_in.sa_port == htons(trantest_port - 1)); - So(la.s_un.s_in.sa_port != 0); - So(la.s_un.s_in.sa_addr == htonl(0x7f000001)); + So(la.s_family == NNG_AF_INET); + So(la.s_in.sa_port == htons(trantest_port - 1)); + So(la.s_in.sa_port != 0); + So(la.s_in.sa_addr == htonl(0x7f000001)); z = sizeof(nng_sockaddr); So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0); So(z == sizeof(ra)); - So(ra.s_un.s_family == NNG_AF_INET); - So(ra.s_un.s_in.sa_port != 0); - So(ra.s_un.s_in.sa_addr == htonl(0x7f000001)); + So(ra.s_family == NNG_AF_INET); + So(ra.s_in.sa_port != 0); + So(ra.s_in.sa_addr == htonl(0x7f000001)); return (0); } diff --git a/tests/tcp6.c b/tests/tcp6.c index c00f00f23..07990a363 100644 --- a/tests/tcp6.c +++ b/tests/tcp6.c @@ -1,6 +1,6 @@ // -// Copyright 2017 Garrett D'Amore -// Copyright 2017 Capitar IT Group BV +// Copyright 2018 Staysail Systems, Inc. +// Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -24,10 +24,10 @@ has_v6(void) nni_plat_udp *u; int rv; - sa.s_un.s_in6.sa_family = NNG_AF_INET6; - sa.s_un.s_in6.sa_port = 0; - memset(sa.s_un.s_in6.sa_addr, 0, 16); - sa.s_un.s_in6.sa_addr[15] = 1; + sa.s_in6.sa_family = NNG_AF_INET6; + sa.s_in6.sa_port = 0; + memset(sa.s_in6.sa_addr, 0, 16); + sa.s_in6.sa_addr[15] = 1; rv = nni_plat_udp_open(&u, &sa); if (rv == 0) { @@ -52,10 +52,10 @@ check_props_v6(nng_msg *msg) So(p > 0); So(nng_pipe_getopt(p, NNG_OPT_LOCADDR, &la, &z) == 0); So(z == sizeof(la)); - So(la.s_un.s_family == NNG_AF_INET6); - // So(la.s_un.s_in.sa_port == (trantest_port - 1)); - So(la.s_un.s_in6.sa_port != 0); - So(memcmp(la.s_un.s_in6.sa_addr, loopback, 16) == 0); + So(la.s_family == NNG_AF_INET6); + // So(la.s_in.sa_port == (trantest_port - 1)); + So(la.s_in6.sa_port != 0); + So(memcmp(la.s_in6.sa_addr, loopback, 16) == 0); }); Convey("IPv6 Remote address property works", { @@ -65,9 +65,9 @@ check_props_v6(nng_msg *msg) So(p > 0); So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0); So(z == sizeof(ra)); - So(ra.s_un.s_family == NNG_AF_INET6); - So(ra.s_un.s_in6.sa_port != 0); - So(memcmp(ra.s_un.s_in6.sa_addr, loopback, 16) == 0); + So(ra.s_family == NNG_AF_INET6); + So(ra.s_in6.sa_port != 0); + So(memcmp(ra.s_in6.sa_addr, loopback, 16) == 0); }); Convey("Malformed TCPv6 addresses do not panic", { diff --git a/tests/tls.c b/tests/tls.c index f51fabefc..f46467fe0 100644 --- a/tests/tls.c +++ b/tests/tls.c @@ -118,17 +118,17 @@ check_props_v4(nng_msg *msg) z = sizeof(nng_sockaddr); So(nng_pipe_getopt(p, NNG_OPT_LOCADDR, &la, &z) == 0); So(z == sizeof(la)); - So(la.s_un.s_family == NNG_AF_INET); - So(la.s_un.s_in.sa_port == htons(trantest_port - 1)); - So(la.s_un.s_in.sa_port != 0); - So(la.s_un.s_in.sa_addr == htonl(0x7f000001)); + So(la.s_family == NNG_AF_INET); + So(la.s_in.sa_port == htons(trantest_port - 1)); + So(la.s_in.sa_port != 0); + So(la.s_in.sa_addr == htonl(0x7f000001)); z = sizeof(nng_sockaddr); So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0); So(z == sizeof(ra)); - So(ra.s_un.s_family == NNG_AF_INET); - So(ra.s_un.s_in.sa_port != 0); - So(ra.s_un.s_in.sa_addr == htonl(0x7f000001)); + So(ra.s_family == NNG_AF_INET); + So(ra.s_in.sa_port != 0); + So(ra.s_in.sa_addr == htonl(0x7f000001)); return (0); } diff --git a/tests/udp.c b/tests/udp.c index f10446b9b..b0def72a3 100644 --- a/tests/udp.c +++ b/tests/udp.c @@ -1,6 +1,6 @@ // -// Copyright 2017 Garrett D'Amore -// Copyright 2017 Capitar IT Group BV +// Copyright 2018 Staysail Systems, Inc. +// Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -39,13 +39,13 @@ TestMain("UDP support", { p1 = trantest_port++; p2 = trantest_port++; - sa1.s_un.s_in.sa_family = NNG_AF_INET; - sa1.s_un.s_in.sa_addr = loopback; - sa1.s_un.s_in.sa_port = htons(p1); + sa1.s_in.sa_family = NNG_AF_INET; + sa1.s_in.sa_addr = loopback; + sa1.s_in.sa_port = htons(p1); - sa2.s_un.s_in.sa_family = NNG_AF_INET; - sa2.s_un.s_in.sa_addr = loopback; - sa2.s_un.s_in.sa_port = htons(p2); + sa2.s_in.sa_family = NNG_AF_INET; + sa2.s_in.sa_addr = loopback; + sa2.s_in.sa_port = htons(p2); So(nni_plat_udp_open(&u1, &sa1) == 0); So(nni_plat_udp_open(&u2, &sa2) == 0); @@ -89,10 +89,9 @@ TestMain("UDP support", { So(nng_aio_count(aio2) == strlen(msg) + 1); So(strcmp(msg, rbuf) == 0); - So(from.s_un.s_in.sa_family == - sa1.s_un.s_in.sa_family); - So(from.s_un.s_in.sa_port == sa1.s_un.s_in.sa_port); - So(from.s_un.s_in.sa_addr == sa1.s_un.s_in.sa_addr); + So(from.s_in.sa_family == sa1.s_in.sa_family); + So(from.s_in.sa_port == sa1.s_in.sa_port); + So(from.s_in.sa_addr == sa1.s_in.sa_addr); // Set up some calls that will ever complete, so // we test cancellation, etc. @@ -183,10 +182,9 @@ TestMain("UDP support", { So(nng_aio_result(aio3) == 0); So(nng_aio_result(aio4) == 0); - So(from1.s_un.s_in.sa_family == - sa1.s_un.s_in.sa_family); - So(from1.s_un.s_in.sa_port == sa1.s_un.s_in.sa_port); - So(from1.s_un.s_in.sa_addr == sa1.s_un.s_in.sa_addr); + So(from1.s_in.sa_family == sa1.s_in.sa_family); + So(from1.s_in.sa_port == sa1.s_in.sa_port); + So(from1.s_in.sa_addr == sa1.s_in.sa_addr); nng_aio_free(aio1); nng_aio_free(aio2); @@ -217,11 +215,11 @@ TestMain("UDP support", { int rv; nng_iov iov; - sa.s_un.s_in6.sa_family = NNG_AF_INET6; + sa.s_in6.sa_family = NNG_AF_INET6; // address is for google.com inet_ntop(AF_INET6, "2607:f8b0:4007:804::200e", - (void *) sa.s_un.s_in6.sa_addr, 16); - sa.s_un.s_in6.sa_port = 80; + (void *) sa.s_in6.sa_addr, 16); + sa.s_in6.sa_port = 80; So(nng_aio_alloc(&aio1, NULL, NULL) == 0); iov.iov_buf = msg; iov.iov_len = strlen(msg) + 1; @@ -243,11 +241,11 @@ TestMain("UDP support", { int rv; nng_iov iov; - sa.s_un.s_in6.sa_family = NNG_AF_INET6; + sa.s_in6.sa_family = NNG_AF_INET6; // address is for google.com inet_ntop(AF_INET6, "2607:f8b0:4007:804::200e", - (void *) sa.s_un.s_in6.sa_addr, 16); - sa.s_un.s_in6.sa_port = 80; + (void *) sa.s_in6.sa_addr, 16); + sa.s_in6.sa_port = 80; So(nng_aio_alloc(&aio1, NULL, NULL) == 0); iov.iov_buf = msg; iov.iov_len = strlen(msg) + 1; @@ -269,8 +267,8 @@ TestMain("UDP support", { nng_sockaddr sa; int rv; - sa.s_un.s_path.sa_family = NNG_AF_IPC; - strcpy(sa.s_un.s_path.sa_path, "/tmp/t"); + sa.s_ipc.sa_family = NNG_AF_IPC; + strcpy(sa.s_ipc.sa_path, "/tmp/t"); So((rv = nni_plat_udp_open(&u, &sa)) != 0); // Some platforms reject IPC addresses altogether (Windows), // whereas others just say it's not supported with UDP. @@ -286,10 +284,10 @@ TestMain("UDP support", { nng_sockaddr sa; uint16_t p1; - p1 = trantest_port++; - sa.s_un.s_in.sa_family = NNG_AF_INET; - sa.s_un.s_in.sa_port = htons(p1); - sa.s_un.s_in.sa_addr = htonl(0x7f000001); + p1 = trantest_port++; + sa.s_in.sa_family = NNG_AF_INET; + sa.s_in.sa_port = htons(p1); + sa.s_in.sa_addr = htonl(0x7f000001); So(nni_plat_udp_open(&u1, &sa) == 0); So(nni_plat_udp_open(&u2, &sa) == NNG_EADDRINUSE); nni_plat_udp_close(u1); diff --git a/tests/ws.c b/tests/ws.c index 4a8bd7a71..32175e9c2 100644 --- a/tests/ws.c +++ b/tests/ws.c @@ -37,17 +37,17 @@ check_props_v4(nng_msg *msg) z = sizeof(nng_sockaddr); So(nng_pipe_getopt(p, NNG_OPT_LOCADDR, &la, &z) == 0); So(z == sizeof(la)); - So(la.s_un.s_family == NNG_AF_INET); - So(la.s_un.s_in.sa_port == htons(trantest_port - 1)); - So(la.s_un.s_in.sa_port != 0); - So(la.s_un.s_in.sa_addr == htonl(0x7f000001)); + So(la.s_family == NNG_AF_INET); + So(la.s_in.sa_port == htons(trantest_port - 1)); + So(la.s_in.sa_port != 0); + So(la.s_in.sa_addr == htonl(0x7f000001)); z = sizeof(nng_sockaddr); So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0); So(z == sizeof(ra)); - So(ra.s_un.s_family == NNG_AF_INET); - So(ra.s_un.s_in.sa_port != 0); - So(ra.s_un.s_in.sa_addr == htonl(0x7f000001)); + So(ra.s_family == NNG_AF_INET); + So(ra.s_in.sa_port != 0); + So(ra.s_in.sa_addr == htonl(0x7f000001)); // Request Header z = 0; diff --git a/tests/wss.c b/tests/wss.c index 96dc9bd9a..58df8cbf5 100644 --- a/tests/wss.c +++ b/tests/wss.c @@ -106,21 +106,21 @@ validloopback(nng_sockaddr *sa) memset(ipv6, 0, sizeof(ipv6)); ipv6[15] = 1; - switch (sa->s_un.s_family) { + switch (sa->s_family) { case NNG_AF_INET: - if (sa->s_un.s_in.sa_port == 0) { + if (sa->s_in.sa_port == 0) { return (0); } - if (sa->s_un.s_in.sa_addr != htonl(0x7f000001)) { + if (sa->s_in.sa_addr != htonl(0x7f000001)) { return (0); } return (1); case NNG_AF_INET6: - if (sa->s_un.s_in6.sa_port == 0) { + if (sa->s_in6.sa_port == 0) { return (0); } - if (memcmp(sa->s_un.s_in6.sa_addr, ipv6, sizeof(ipv6)) != 0) { + if (memcmp(sa->s_in6.sa_addr, ipv6, sizeof(ipv6)) != 0) { return (0); } return (1); diff --git a/tests/wssfile.c b/tests/wssfile.c index 8b5b01267..15f7008e4 100644 --- a/tests/wssfile.c +++ b/tests/wssfile.c @@ -11,8 +11,8 @@ #include "convey.h" #include "nng.h" #include "protocol/pair1/pair.h" -#include "transport/ws/websocket.h" #include "supplemental/tls/tls.h" +#include "transport/ws/websocket.h" #include "trantest.h" @@ -107,21 +107,21 @@ validloopback(nng_sockaddr *sa) memset(ipv6, 0, sizeof(ipv6)); ipv6[15] = 1; - switch (sa->s_un.s_family) { + switch (sa->s_family) { case NNG_AF_INET: - if (sa->s_un.s_in.sa_port == 0) { + if (sa->s_in.sa_port == 0) { return (0); } - if (sa->s_un.s_in.sa_addr != htonl(0x7f000001)) { + if (sa->s_in.sa_addr != htonl(0x7f000001)) { return (0); } return (1); case NNG_AF_INET6: - if (sa->s_un.s_in6.sa_port == 0) { + if (sa->s_in6.sa_port == 0) { return (0); } - if (memcmp(sa->s_un.s_in6.sa_addr, ipv6, sizeof(ipv6)) != 0) { + if (memcmp(sa->s_in6.sa_addr, ipv6, sizeof(ipv6)) != 0) { return (0); } return (1); diff --git a/tests/zt.c b/tests/zt.c index 1952ef1b4..3344f32bc 100644 --- a/tests/zt.c +++ b/tests/zt.c @@ -53,10 +53,10 @@ check_props(nng_msg *msg) z = sizeof(nng_sockaddr); So(nng_pipe_getopt(p, NNG_OPT_LOCADDR, &la, &z) == 0); So(z == sizeof(la)); - So(la.s_un.s_family == NNG_AF_ZT); - So(la.s_un.s_zt.sa_port == (trantest_port - 1)); - So(la.s_un.s_zt.sa_nwid == 0xa09acf02337b057bull); - So(la.s_un.s_zt.sa_nodeid != 0); + So(la.s_family == NNG_AF_ZT); + So(la.s_zt.sa_port == (trantest_port - 1)); + So(la.s_zt.sa_nwid == 0xa09acf02337b057bull); + So(la.s_zt.sa_nodeid != 0); }); Convey("Remote address property works", { @@ -66,14 +66,14 @@ check_props(nng_msg *msg) z = sizeof(nng_sockaddr); So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0); So(z == sizeof(ra)); - So(ra.s_un.s_family == NNG_AF_ZT); - So(ra.s_un.s_zt.sa_port != 0); - So(ra.s_un.s_zt.sa_nwid == 0xa09acf02337b057bull); + So(ra.s_family == NNG_AF_ZT); + So(ra.s_zt.sa_port != 0); + So(ra.s_zt.sa_nwid == 0xa09acf02337b057bull); z = sizeof(mynode); So(nng_pipe_getopt(p, NNG_OPT_ZT_NODE, &mynode, &z) == 0); So(mynode != 0); - So(ra.s_un.s_zt.sa_nodeid == mynode); + So(ra.s_zt.sa_nodeid == mynode); }); Convey("NWID property works", {