From e0fc82203d677a6f1e808e9a1a46176c109d89be Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 15 Dec 2014 23:08:59 +0000 Subject: Initial commit --- src/conn-tools/s6-ident-client.c | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/conn-tools/s6-ident-client.c (limited to 'src/conn-tools/s6-ident-client.c') diff --git a/src/conn-tools/s6-ident-client.c b/src/conn-tools/s6-ident-client.c new file mode 100644 index 0000000..e475870 --- /dev/null +++ b/src/conn-tools/s6-ident-client.c @@ -0,0 +1,71 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define USAGE "s6-ident-client [ -t timeout ] ra rp la lp" +#define dieusage() strerr_dieusage(100, USAGE) + +int main (int argc, char const *const *argv) +{ + tain_t deadline ; + ip46_t ra, la ; + uint16 rp, lp ; + PROG = "s6-ident-client" ; + { + unsigned int t = 0 ; + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + register int opt = subgetopt_r(argc, argv, "t:", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + if (t) tain_from_millisecs(&deadline, t) ; else deadline = tain_infinite_relative ; + } + if (argc < 4) dieusage() ; + + if (!ip46_scan(argv[0], &ra)) + strerr_dief2x(100, "invalid IP address: ", argv[0]) ; + if (!uint160_scan(argv[1], &rp)) + strerr_dief2x(100, "invalid port number: ", argv[1]) ; + if (!ip46_scan(argv[2], &la)) + strerr_dief2x(100, "invalid IP address: ", argv[2]) ; + if (!uint160_scan(argv[3], &lp)) + strerr_dief2x(100, "invalid port number: ", argv[3]) ; + if (ip46_is6(&ra) != ip46_is6(&la)) + strerr_dief1x(100, "address family mismatch") ; + + tain_now_g() ; + tain_add_g(&deadline, &deadline) ; + + { + char buf[BUFFER_OUTSIZE_SMALL] ; + register int r = s6net_ident_client_g(buf, BUFFER_OUTSIZE_SMALL, &ra, rp, &la, lp, &deadline) ; + if (r < 0) strerr_diefu1sys(errno == ETIMEDOUT ? 99 : 111, "s6net_ident_client") ; + else if (!r) + { + strerr_warnw2x("ident server replied: ", s6net_ident_error_str(errno)) ; + return 1 ; + } + buffer_putnoflush(buffer_1small, buf, r-1) ; + } + buffer_putnoflush(buffer_1small, "\n", 1) ; + if (!buffer_timed_flush_g(buffer_1small, &deadline)) + strerr_diefu1sys(111, "write to stdout") ; + return 0 ; +} -- cgit v1.2.3