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-getservbyname.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/conn-tools/s6-getservbyname.c (limited to 'src/conn-tools/s6-getservbyname.c') diff --git a/src/conn-tools/s6-getservbyname.c b/src/conn-tools/s6-getservbyname.c new file mode 100644 index 0000000..0888df5 --- /dev/null +++ b/src/conn-tools/s6-getservbyname.c @@ -0,0 +1,28 @@ +/* ISC license. */ + +#include +#include +#include +#include + +#define USAGE "s6-getservbyname service proto" + +int main (int argc, char const *const *argv) +{ + char fmt[UINT16_FMT] ; + uint16 port ; + PROG = "s6-getservbyname" ; + if (argc < 3) strerr_dieusage(100, USAGE) ; + if (!uint160_scan(argv[1], &port)) + { + struct servent *se = getservbyname(argv[1], argv[2]) ; + uint16 tmpport ; + if (!se) return 1 ; + tmpport = (uint16)se->s_port ; + uint16_unpack_big((char const *)&tmpport, &port) ; + } + if ((buffer_put(buffer_1small, fmt, uint16_fmt(fmt, port)) < 0) + || (buffer_putflush(buffer_1small, "\n", 1) < 1)) + strerr_diefu1sys(111, "write to stdout") ; + return 0 ; +} -- cgit v1.3.1