From 6fef4c1e5bf73ad76e7cdcfb65540f1308045339 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 2 Oct 2017 17:32:11 -0700 Subject: 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. --- src/transport/tcp/tcp.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src/transport') diff --git a/src/transport/tcp/tcp.c b/src/transport/tcp/tcp.c index 413d8fa5..37bd49c7 100644 --- a/src/transport/tcp/tcp.c +++ b/src/transport/tcp/tcp.c @@ -406,6 +406,32 @@ nni_tcp_pipe_peer(void *arg) return (p->peer); } +static int +nni_tcp_pipe_getopt_locaddr(void *arg, void *v, size_t *szp) +{ + nni_tcp_pipe *p = arg; + int rv; + nng_sockaddr sa; + + if ((rv = nni_plat_tcp_pipe_sockname(p->tpp, &sa)) == 0) { + rv = nni_getopt_sockaddr(&sa, v, szp); + } + return (rv); +} + +static int +nni_tcp_pipe_getopt_remaddr(void *arg, void *v, size_t *szp) +{ + nni_tcp_pipe *p = arg; + int rv; + nng_sockaddr sa; + + if ((rv = nni_plat_tcp_pipe_peername(p->tpp, &sa)) == 0) { + rv = nni_getopt_sockaddr(&sa, v, szp); + } + return (rv); +} + static int nni_tcp_parse_pair(char *pair, char **hostp, char **servp) { @@ -785,10 +811,8 @@ nni_tcp_ep_getopt_linger(void *arg, void *v, size_t *szp) } static nni_tran_pipe_option nni_tcp_pipe_options[] = { -#if 0 - { NNG_OPT_LOCADDR, nni_tcp_pipe_get_locaddr }, - { NNG_OPT_REMADDR, nni_tcp_pipe_get_remaddr }, -#endif + { NNG_OPT_LOCADDR, nni_tcp_pipe_getopt_locaddr }, + { NNG_OPT_REMADDR, nni_tcp_pipe_getopt_remaddr }, // terminate list { NULL, NULL } }; -- cgit v1.2.3-70-g09d2