summaryrefslogtreecommitdiff
path: root/src/skadns/skadns_send.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-12-10 03:05:47 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-12-10 03:05:47 +0000
commit416ef5e2bf59bb2e45066a1d5d91ac677c0f48e5 (patch)
tree1c746d673dcec7a8488c6ac51db8245411034376 /src/skadns/skadns_send.c
downloads6-dns-416ef5e2bf59bb2e45066a1d5d91ac677c0f48e5.tar.xz
Initial commit
Diffstat (limited to 'src/skadns/skadns_send.c')
-rw-r--r--src/skadns/skadns_send.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/skadns/skadns_send.c b/src/skadns/skadns_send.c
new file mode 100644
index 0000000..7ee04c7
--- /dev/null
+++ b/src/skadns/skadns_send.c
@@ -0,0 +1,41 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/uint16.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/siovec.h>
+#include <skalibs/tai.h>
+#include <skalibs/stralloc.h>
+#include <skalibs/gensetdyn.h>
+#include <skalibs/skaclient.h>
+#include <s6-dns/s6dns-domain.h>
+#include <s6-dns/skadns.h>
+
+static skadnsanswer_t const skadnsanswer_initial = { .status = EAGAIN, .data = 0, .len = 0 } ;
+
+int skadns_send (skadns_t *a, uint16 *u, s6dns_domain_t const *d, uint16 qtype, tain_t const *limit, tain_t const *deadline, tain_t *stamp)
+{
+ unsigned int i ;
+ char tmp[17] = "--Q" ;
+ char err ;
+ siovec_t v[2] = { { .s = tmp, .len = 17 }, { .s = d->s, .len = d->len } } ;
+ if (!gensetdyn_new(&a->q, &i)) return 0 ;
+ uint16_pack_big(tmp, (uint16)i) ;
+ uint16_pack_big(tmp + 3, qtype) ;
+ if (limit) tain_pack(tmp + 5, limit) ; else byte_zero(tmp + 5, 12) ;
+ if (!skaclient_sendv(&a->connection, v, 2, &skaclient_default_cb, &err, deadline, stamp))
+ {
+ register int e = errno ;
+ gensetdyn_delete(&a->q, i) ;
+ errno = e ;
+ return 0 ;
+ }
+ if (err)
+ {
+ gensetdyn_delete(&a->q, i) ;
+ return (errno = err, 0) ;
+ }
+ *GENSETDYN_P(skadnsanswer_t, &a->q, i) = skadnsanswer_initial ;
+ *u = i ;
+ return 1 ;
+}