From 416ef5e2bf59bb2e45066a1d5d91ac677c0f48e5 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 10 Dec 2014 03:05:47 +0000 Subject: Initial commit --- src/libs6dns/s6dns_debug_dumpdt_pre_send.c | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/libs6dns/s6dns_debug_dumpdt_pre_send.c (limited to 'src/libs6dns/s6dns_debug_dumpdt_pre_send.c') 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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) ; +} -- cgit v1.3.1