summaryrefslogtreecommitdiff
path: root/src/libs6net/s6net_ident_client.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/libs6net/s6net_ident_client.c
downloads6-networking-e0fc82203d677a6f1e808e9a1a46176c109d89be.tar.xz
Initial commit
Diffstat (limited to 'src/libs6net/s6net_ident_client.c')
-rw-r--r--src/libs6net/s6net_ident_client.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libs6net/s6net_ident_client.c b/src/libs6net/s6net_ident_client.c
new file mode 100644
index 0000000..c6b9ac0
--- /dev/null
+++ b/src/libs6net/s6net_ident_client.c
@@ -0,0 +1,22 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/uint16.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/tai.h>
+#include <skalibs/ip46.h>
+#include <s6-networking/ident.h>
+
+int s6net_ident_client (char *s, unsigned int max, ip46_t const *remoteip, uint16 remoteport, ip46_t const *localip, uint16 localport, tain_t const *deadline, tain_t *stamp)
+{
+ char buf[S6NET_IDENT_REPLY_SIZE] ;
+ unsigned int len ;
+ register int r = s6net_ident_reply_get(buf, remoteip, remoteport, localip, localport, deadline, stamp) ;
+ if (r < 0) return errno == EPIPE ? (errno = EIO, 0) : -1 ; /* the RFC says so */
+ len = r ;
+ r = s6net_ident_reply_parse(buf, remoteport, localport) ;
+ if (r <= 0) return r ;
+ if (max + r < len + 1) return (errno = ENAMETOOLONG, -1) ;
+ byte_copy(s, len - r + 1, buf + r) ;
+ return len - r + 1 ;
+}