diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2014-12-10 03:05:47 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2014-12-10 03:05:47 +0000 |
commit | 416ef5e2bf59bb2e45066a1d5d91ac677c0f48e5 (patch) | |
tree | 1c746d673dcec7a8488c6ac51db8245411034376 /src/libs6dns/s6dns_resolven_parse.c | |
download | s6-dns-416ef5e2bf59bb2e45066a1d5d91ac677c0f48e5.tar.xz |
Initial commit
Diffstat (limited to 'src/libs6dns/s6dns_resolven_parse.c')
-rw-r--r-- | src/libs6dns/s6dns_resolven_parse.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/libs6dns/s6dns_resolven_parse.c b/src/libs6dns/s6dns_resolven_parse.c new file mode 100644 index 0000000..78289bc --- /dev/null +++ b/src/libs6dns/s6dns_resolven_parse.c @@ -0,0 +1,47 @@ +/* ISC license. */ + +#include <errno.h> +#include <skalibs/tai.h> +#include <skalibs/iopause.h> +#include <s6-dns/s6dns-ip46.h> +#include <s6-dns/s6dns-message.h> +#include <s6-dns/s6dns-engine.h> +#include <s6-dns/s6dns-resolve.h> + +int s6dns_resolven_parse_r (s6dns_resolve_t *list, unsigned int n, s6dns_ip46list_t const *servers, s6dns_debughook_t const *dbh, tain_t const *deadline, tain_t *stamp) +{ + s6dns_engine_t dtl[n] ; + register unsigned int i = 0 ; + for (; i < n ; i++) list[i].status = ECONNABORTED ; + for (i = 0 ; i < n ; i++) + { + dtl[i] = s6dns_engine_zero ; + if (!s6dns_engine_init_r(dtl + i, servers, list[i].options, list[i].q.s, list[i].q.len, list[i].qtype, dbh, &list[i].deadline, stamp)) + { + list[i].status = errno ; + s6dns_engine_freen(dtl, i) ; + return 0 ; + } + list[i].status = EAGAIN ; + } + + if (s6dns_resolven_loop(dtl, n, 0, deadline, stamp) < 0) goto err ; + + for (i = 0 ; i < n ; i++) + { + if (dtl[i].status) list[i].status = dtl[i].status ; + else + { + s6dns_message_header_t h ; + register int r = s6dns_message_parse(&h, s6dns_engine_packet(dtl + i), s6dns_engine_packetlen(dtl + i), list[i].parsefunc, list[i].data) ; + if (r < 0) goto err ; + list[i].status = r ? 0 : errno ; + } + } + s6dns_engine_freen(dtl, n) ; + return 1 ; + + err: + s6dns_engine_freen(dtl, n) ; + return 0 ; +} |