aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-18 18:56:16 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-18 18:56:16 -0800
commite6cded3832c9e92c922d49d824b446ce33fbf120 (patch)
treef1ee4ab169c4e69c69699b2ce5c37bf368fc51e5
parent8049d822b3d8ea8bd11793369004c638d833964e (diff)
downloadnng-e6cded3832c9e92c922d49d824b446ce33fbf120.tar.gz
nng-e6cded3832c9e92c922d49d824b446ce33fbf120.tar.bz2
nng-e6cded3832c9e92c922d49d824b446ce33fbf120.zip
Address segfault in TCP, and fix wild card handling.
-rw-r--r--src/platform/posix/posix_net.c6
-rw-r--r--src/platform/windows/win_net.c4
-rw-r--r--src/transport/tcp/tcp.c3
-rw-r--r--tests/tcp.c26
4 files changed, 34 insertions, 5 deletions
diff --git a/src/platform/posix/posix_net.c b/src/platform/posix/posix_net.c
index b89e7c49..eb85669f 100644
--- a/src/platform/posix/posix_net.c
+++ b/src/platform/posix/posix_net.c
@@ -46,7 +46,7 @@ nni_plat_to_sockaddr(struct sockaddr_storage *ss, const nni_sockaddr *sa)
case NNG_AF_INET6:
sin6 = (void *) ss;
- memset(&sin6, 0, sizeof (sin6));
+ memset(sin6, 0, sizeof (*sin6));
#ifdef SIN6_LEN
sin6->sin6_len = sizeof (*sin6);
#endif
@@ -92,7 +92,7 @@ nni_plat_lookup_host(const char *host, nni_sockaddr *addr, int flags)
struct addrinfo *ai;
memset(&hint, 0, sizeof (hint));
- hint.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
+ hint.ai_flags = AI_PASSIVE | AI_ADDRCONFIG | AI_NUMERICSERV;
hint.ai_family = PF_UNSPEC;
hint.ai_socktype = SOCK_STREAM;
hint.ai_protocol = IPPROTO_TCP;
@@ -100,7 +100,7 @@ nni_plat_lookup_host(const char *host, nni_sockaddr *addr, int flags)
hint.ai_family = PF_INET;
}
- if (getaddrinfo(host, NULL, &hint, &ai) != 0) {
+ if (getaddrinfo(host, "1", &hint, &ai) != 0) {
return (NNG_EADDRINVAL);
}
diff --git a/src/platform/windows/win_net.c b/src/platform/windows/win_net.c
index 36390053..bc237d0f 100644
--- a/src/platform/windows/win_net.c
+++ b/src/platform/windows/win_net.c
@@ -163,7 +163,7 @@ nni_plat_lookup_host(const char *host, nni_sockaddr *addr, int flags)
ADDRINFO *ai;
memset(&hint, 0, sizeof (hint));
- hint.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
+ hint.ai_flags = AI_PASSIVE | AI_ADDRCONFIG | AI_NUMERICSERV;
hint.ai_family = PF_UNSPEC;
hint.ai_socktype = SOCK_STREAM;
hint.ai_protocol = IPPROTO_TCP;
@@ -171,7 +171,7 @@ nni_plat_lookup_host(const char *host, nni_sockaddr *addr, int flags)
hint.ai_family = PF_INET;
}
- if (getaddrinfo(host, NULL, &hint, &ai) != 0) {
+ if (getaddrinfo(host, "1", &hint, &ai) != 0) {
return (NNG_EADDRINVAL);
}
diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c
index 09a2b385..d18fd289 100644
--- a/src/transport/tcp/tcp.c
+++ b/src/transport/tcp/tcp.c
@@ -343,6 +343,9 @@ nni_tcp_ep_connect(void *arg, void **pipep)
if ((rv = nni_parseaddr(rempart, &host, &port)) != 0) {
return (rv);
}
+ if (host == NULL) {
+ return (NNG_EADDRINVAL);
+ }
if ((rv = nni_plat_lookup_host(host, &remaddr, flag)) != 0) {
return (rv);
}
diff --git a/tests/tcp.c b/tests/tcp.c
index 02b75795..ea97454e 100644
--- a/tests/tcp.c
+++ b/tests/tcp.c
@@ -16,5 +16,31 @@
TestMain("TCP Transport", {
nni_init();
trantest_test_all("tcp://127.0.0.1:4450");
+
+
+ Convey("We cannot connect to wild cards", {
+ nng_socket *s;
+
+ So(nng_open(&s, NNG_PROTO_PAIR) == 0);
+ Reset({
+ nng_close(s);
+ })
+ So(nng_dial(s, "tcp://*:5555", NULL, NNG_FLAG_SYNCH) == NNG_EADDRINVAL);
+ })
+
+ Convey("We can bind to wild card", {
+ nng_socket *s1;
+ nng_socket *s2;
+ So(nng_open(&s1, NNG_PROTO_PAIR) == 0);
+ So(nng_open(&s2, NNG_PROTO_PAIR) == 0);
+ Reset({
+ nng_close(s2);
+ nng_close(s1);
+ })
+ So(nng_listen(s1, "tcp://*:5599", NULL, NNG_FLAG_SYNCH) == 0);
+ So(nng_dial(s2, "tcp://127.0.0.1:5599", NULL, NNG_FLAG_SYNCH) == 0);
+ })
nni_fini();
+
+
})