aboutsummaryrefslogtreecommitdiff
path: root/src/platform/posix/posix_tcpdial.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-02-25 17:13:38 -0800
committerGarrett D'Amore <garrett@damore.org>2024-02-25 18:39:56 -0800
commit53a9740d1dcbad6be4b4c1a10a5f3fcbb97a5be9 (patch)
tree00c49f3cd56f5797ec0d3f31dab689c6573fc6e6 /src/platform/posix/posix_tcpdial.c
parent8e62028a0db24364ea218007811e58ea11d0b64f (diff)
downloadnng-53a9740d1dcbad6be4b4c1a10a5f3fcbb97a5be9.tar.gz
nng-53a9740d1dcbad6be4b4c1a10a5f3fcbb97a5be9.tar.bz2
nng-53a9740d1dcbad6be4b4c1a10a5f3fcbb97a5be9.zip
fixes #1496 Provide NNG_ENABLE_IPV6 option (disabled by default)
This also checks if the build system has the definitions for AF_INET6, which might help in some embedded IPv4 only settings. The resolver test is enhanced to include a check for IPv6 enabled in the kernel. IPv6 support is enabled by default, of course.
Diffstat (limited to 'src/platform/posix/posix_tcpdial.c')
-rw-r--r--src/platform/posix/posix_tcpdial.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/platform/posix/posix_tcpdial.c b/src/platform/posix/posix_tcpdial.c
index 0af72cfa..cf3d9368 100644
--- a/src/platform/posix/posix_tcpdial.c
+++ b/src/platform/posix/posix_tcpdial.c
@@ -1,5 +1,5 @@
//
-// Copyright 2023 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2018 Devolutions <info@devolutions.net>
//
@@ -23,6 +23,10 @@
#include "posix_tcp.h"
+#ifndef NNG_HAVE_INET6
+#undef NNG_ENABLE_IPV6
+#endif
+
// Dialer stuff.
int
nni_tcp_dialer_init(nni_tcp_dialer **dp)
@@ -93,7 +97,7 @@ static void
tcp_dialer_cancel(nni_aio *aio, void *arg, int rv)
{
nni_tcp_dialer *d = arg;
- nni_tcp_conn * c;
+ nni_tcp_conn *c;
nni_mtx_lock(&d->mtx);
if ((!nni_aio_list_active(aio)) ||
@@ -113,9 +117,9 @@ tcp_dialer_cancel(nni_aio *aio, void *arg, int rv)
static void
tcp_dialer_cb(nni_posix_pfd *pfd, unsigned ev, void *arg)
{
- nni_tcp_conn * c = arg;
+ nni_tcp_conn *c = arg;
nni_tcp_dialer *d = c->dialer;
- nni_aio * aio;
+ nni_aio *aio;
int rv;
int ka;
int nd;
@@ -171,8 +175,8 @@ tcp_dialer_cb(nni_posix_pfd *pfd, unsigned ev, void *arg)
void
nni_tcp_dial(nni_tcp_dialer *d, const nni_sockaddr *sa, nni_aio *aio)
{
- nni_tcp_conn * c;
- nni_posix_pfd * pfd = NULL;
+ nni_tcp_conn *c;
+ nni_posix_pfd *pfd = NULL;
struct sockaddr_storage ss;
size_t sslen;
int fd;
@@ -333,13 +337,15 @@ tcp_dialer_get_locaddr(void *arg, void *buf, size_t *szp, nni_type t)
static int
tcp_dialer_set_locaddr(void *arg, const void *buf, size_t sz, nni_type t)
{
- nni_tcp_dialer * d = arg;
+ nni_tcp_dialer *d = arg;
nng_sockaddr sa;
struct sockaddr_storage ss;
- struct sockaddr_in * sin;
- struct sockaddr_in6 * sin6;
+ struct sockaddr_in *sin;
size_t len;
int rv;
+#ifdef NNG_ENABLE_IPV6
+ struct sockaddr_in6 *sin6;
+#endif
if ((rv = nni_copyin_sockaddr(&sa, buf, sz, t)) != 0) {
return (rv);
@@ -356,12 +362,16 @@ tcp_dialer_set_locaddr(void *arg, const void *buf, size_t sz, nni_type t)
return (NNG_EADDRINVAL);
}
break;
+
+#ifdef NNG_ENABLE_IPV6
case AF_INET6:
sin6 = (void *) &ss;
if (sin6->sin6_port != 0) {
return (NNG_EADDRINVAL);
}
break;
+#endif // __NG_INET6
+
default:
return (NNG_EADDRINVAL);
}