summaryrefslogtreecommitdiff
path: root/src/conn-tools/s6-getservbyname.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-12-15 23:08:59 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-12-15 23:08:59 +0000
commite0fc82203d677a6f1e808e9a1a46176c109d89be (patch)
treee9609209b755e3f7a8480aea86601ffe9d4ca540 /src/conn-tools/s6-getservbyname.c
downloads6-networking-e0fc82203d677a6f1e808e9a1a46176c109d89be.tar.xz
Initial commit
Diffstat (limited to 'src/conn-tools/s6-getservbyname.c')
-rw-r--r--src/conn-tools/s6-getservbyname.c28
1 files changed, 28 insertions, 0 deletions
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 <netdb.h>
+#include <skalibs/uint16.h>
+#include <skalibs/buffer.h>
+#include <skalibs/strerr2.h>
+
+#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 ;
+}