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_debug_dumpdt_pre_send.c | |
| download | s6-dns-416ef5e2bf59bb2e45066a1d5d91ac677c0f48e5.tar.gz | |
Initial commit
Diffstat (limited to 'src/libs6dns/s6dns_debug_dumpdt_pre_send.c')
| -rw-r--r-- | src/libs6dns/s6dns_debug_dumpdt_pre_send.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/libs6dns/s6dns_debug_dumpdt_pre_send.c b/src/libs6dns/s6dns_debug_dumpdt_pre_send.c new file mode 100644 index 0000000..df8131d --- /dev/null +++ b/src/libs6dns/s6dns_debug_dumpdt_pre_send.c @@ -0,0 +1,59 @@ +/* ISC license */ + +#include <errno.h> +#include <skalibs/uint16.h> +#include <skalibs/fmtscan.h> +#include <skalibs/tai.h> +#include <skalibs/djbtime.h> +#include <skalibs/genwrite.h> +#include <skalibs/ip46.h> +#include <s6-dns/s6dns-constants.h> +#include <s6-dns/s6dns-ip46.h> +#include <s6-dns/s6dns-engine.h> +#include <s6-dns/s6dns-analyze.h> +#include <s6-dns/s6dns-debug.h> + +#ifdef SKALIBS_IPV6_ENABLED +# define s6dns_ipfmt(buf, ip, is6) ((is6) ? ip6_fmt(buf, ip) : ip4_fmt(buf, ip)) +#else +# define s6dns_ipfmt(buf, ip, is6) ip4_fmt(buf, ip) +#endif + +int s6dns_debug_dumpdt_pre_send (s6dns_engine_t const *dt, void *data) +{ + genwrite_t *gp = data ; + char buf[LOCALTMN_FMT] ; + unsigned int len ; + if ((*gp->put)(gp->target, "Preparing to send via ", 22) < 22) return 0 ; + if ((*gp->put)(gp->target, dt->flagtcp ? "TCP" : "UDP", 3) < 3) return 0 ; + if ((*gp->put)(gp->target, " to ", 4) < 4) return 0 ; + len = dt->sa.s[4] & 1 ; + if ((*gp->put)(gp->target, len ? "cache" : "server", len ? 5 : 6) < (len ? 5 : 6)) return 0 ; + if ((*gp->put)(gp->target, " ", 1) < 1) return 0 ; + len = s6dns_ipfmt(buf, s6dns_ip46list_ip(&dt->servers, dt->curserver), s6dns_ip46list_is6(&dt->servers, dt->curserver)) ; + if ((*gp->put)(gp->target, buf, len) < (int)len) return 0 ; + if ((*gp->put)(gp->target, " with deadline ", 15) < 15) return 0 ; + { + localtmn_t l ; + if (!localtmn_from_tain(&l, &dt->localdeadline, 0)) + { + if (errno != EOVERFLOW) return 0 ; + byte_copy(buf, 10, "\"infinite\"") ; len = 10 ; + } + else len = localtmn_fmt(buf, &l) ; + } + if ((*gp->put)(gp->target, buf, len) < (int)len) return 0 ; + if ((*gp->put)(gp->target, ", ", 2) < 2) return 0 ; + if (dt->flagstrict && (*gp->put)(gp->target, "strict, ", 8) < 8) return 0 ; + if ((*gp->put)(gp->target, "query id ", 9) < 9) return 0 ; + { + uint16 id ; + uint16_unpack_big(dt->sa.s + 2, &id) ; + len = uint16_fmt(buf, id) ; + } + if ((*gp->put)(gp->target, buf, len) < (int)len) return 0 ; + if ((*gp->put)(gp->target, ":\n", 2) < 2) return 0 ; + if (!s6dns_analyze_packet(gp, dt->sa.s + 2, dt->querylen - 2, 1)) return 0 ; + if ((*gp->put)(gp->target, "\n", 1) < 1) return 0 ; + return (*gp->flush)(gp->target) ; +} |
