diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-05-03 14:28:44 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-05-03 15:14:45 -0700 |
| commit | afd555af4fba0acbf16c174dd9dece24181a1a38 (patch) | |
| tree | 9d49fec85c58ecad9a034a98e092627968494bc0 /tests/ipc.c | |
| parent | fa986e725f08e30eab68e16765b2cf71613b871c (diff) | |
| download | nng-afd555af4fba0acbf16c174dd9dece24181a1a38.tar.gz nng-afd555af4fba0acbf16c174dd9dece24181a1a38.tar.bz2 nng-afd555af4fba0acbf16c174dd9dece24181a1a38.zip | |
fixes #383 Would like peerid for IPC
We offer uid, gid, process id, and even zone id where we have them.
Docs and tests are provided.
Diffstat (limited to 'tests/ipc.c')
| -rw-r--r-- | tests/ipc.c | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/tests/ipc.c b/tests/ipc.c index 54996ee3..4c8f5e41 100644 --- a/tests/ipc.c +++ b/tests/ipc.c @@ -10,11 +10,76 @@ #include "convey.h" #include "trantest.h" +#ifdef _WIN32 +#else +#include <unistd.h> +#ifdef NNG_HAVE_GETPEERUCRED +#include <zone.h> +#endif +#endif + +#include "transport/ipc/ipc.h" // Inproc tests. +static int +check_props(nng_msg *msg) +{ + nng_pipe p; + size_t z; + nng_sockaddr la; + nng_sockaddr ra; + uint64_t id; + + p = nng_msg_get_pipe(msg); + So(nng_pipe_id(p) > 0); + So(nng_pipe_getopt_sockaddr(p, NNG_OPT_LOCADDR, &la) == 0); + So(la.s_family == NNG_AF_IPC); + // untyped + z = sizeof(nng_sockaddr); + So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0); + So(z == sizeof(ra)); + So(ra.s_family == NNG_AF_IPC); + + So(nng_pipe_getopt_size(p, NNG_OPT_REMADDR, &z) == NNG_EBADTYPE); + z = 1; + So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == NNG_EINVAL); + +#ifdef _WIN32 + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_UID, &id) == + NNG_ENOTSUP); + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_GID, &id) == + NNG_ENOTSUP); + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_ZONEID, &id) == + NNG_ENOTSUP); + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_PID, &id) == 0); + So(id == GetCurrentProcessId()); +#else + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_UID, &id) == 0); + So(id == (uint64_t) getuid()); + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_GID, &id) == 0); + So(id == (uint64_t) getgid()); + +#if defined(NNG_HAVE_SOPEERCRED) || defined(NNG_HAVE_GETPEERUCRED) + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_PID, &id) == 0); + So(id == (uint64_t) getpid()); +#else + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_PID, &id) == + NNG_ENOTSUP); +#endif + +#ifdef NNG_HAVE_GETPEERUCRED + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_ZONEID, &id) == 0); + So(id == getzoneid()); +#else + So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_ZONEID, &id) == + NNG_ENOTSUP); +#endif +#endif + return (0); +} TestMain("IPC Transport", { - trantest_test_all("ipc:///tmp/nng_ipc_test_%u"); + trantest_test_extended("ipc:///tmp/nng_ipc_test_%u", check_props); nng_fini(); }) |
