diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-10-02 17:32:11 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-10-03 09:47:08 -0700 |
| commit | 6fef4c1e5bf73ad76e7cdcfb65540f1308045339 (patch) | |
| tree | ca50ca2c27fb2d0a44ee9dc317cc0b673eaf9e66 /tests/tcp.c | |
| parent | 6e945e18f3f3e9b7f9ee614eac6d3bf681f768d9 (diff) | |
| download | nng-6fef4c1e5bf73ad76e7cdcfb65540f1308045339.tar.gz nng-6fef4c1e5bf73ad76e7cdcfb65540f1308045339.tar.bz2 nng-6fef4c1e5bf73ad76e7cdcfb65540f1308045339.zip | |
fixes #5 Address properties
Added TCP socket address properties on pipes.
This adds the plumbing for the various platform specifics, and
includes both v4 and v6 handling.
We've included a TCPv6 test as well.
Diffstat (limited to 'tests/tcp.c')
| -rw-r--r-- | tests/tcp.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/tests/tcp.c b/tests/tcp.c index 324c167e..92e50a8b 100644 --- a/tests/tcp.c +++ b/tests/tcp.c @@ -11,11 +11,49 @@ #include "convey.h" #include "trantest.h" -// Inproc tests. +// TCP tests. + +#ifndef _WIN32 +#include <arpa/inet.h> +#endif + +static int +check_props_v4(nng_msg *msg, nng_listener l, nng_dialer d) +{ + nng_pipe p; + size_t z; + p = nng_msg_get_pipe(msg); + So(p > 0); + + Convey("Local address property works", { + nng_sockaddr la; + 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 == (trantest_port - 1)); + So(la.s_un.s_in.sa_port != 0); + So(la.s_un.s_in.sa_addr == htonl(0x7f000001)); + }); + + Convey("Remote address property works", { + nng_sockaddr ra; + 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(nng_dialer_getopt(d, NNG_OPT_REMADDR, &ra, &z) != 0); + }); + + return (0); +} TestMain("TCP Transport", { - trantest_test_all("tcp://127.0.0.1:%u"); + trantest_test_extended("tcp://127.0.0.1:%u", check_props_v4); Convey("We cannot connect to wild cards", { nng_socket s; |
