aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs6dns/s6dns_analyze_record.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/libs6dns/s6dns_analyze_record.c
downloads6-dns-416ef5e2bf59bb2e45066a1d5d91ac677c0f48e5.tar.gz
Initial commit
Diffstat (limited to 'src/libs6dns/s6dns_analyze_record.c')
-rw-r--r--src/libs6dns/s6dns_analyze_record.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/libs6dns/s6dns_analyze_record.c b/src/libs6dns/s6dns_analyze_record.c
new file mode 100644
index 0000000..dd2e7d2
--- /dev/null
+++ b/src/libs6dns/s6dns_analyze_record.c
@@ -0,0 +1,37 @@
+/* ISC license. */
+
+#include <skalibs/uint16.h>
+#include <skalibs/uint32.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/genwrite.h>
+#include <s6-dns/s6dns-domain.h>
+#include <s6-dns/s6dns-message.h>
+#include <s6-dns/s6dns-analyze.h>
+
+static s6dns_analyze_rtypetable_t const *rtypelookup (uint16 rtype)
+{
+ register s6dns_analyze_rtypetable_t const *wut = s6dns_analyze_rtypetable ;
+ while (wut->rtype && wut->rtype != rtype) wut++ ;
+ return wut ;
+}
+
+int s6dns_analyze_record (genwrite_t *gp, s6dns_message_rr_t const *rr, char const *packet, unsigned int packetlen, unsigned int pos)
+{
+ s6dns_analyze_rtypetable_t const *wut = rtypelookup(rr->rtype) ;
+ {
+ char buf[256] ;
+ register unsigned int n = s6dns_domain_tostring(buf, 256, &rr->name) ;
+ if (!n) return 0 ;
+ if ((*gp->put)(gp->target, buf, n) < 0) return 0 ;
+ }
+ {
+ char fmt[UINT32_FMT+1] = " " ;
+ if ((*gp->put)(gp->target, fmt, 1 + uint32_fmt(fmt+1, rr->ttl)) < 0) return 0 ;
+ }
+ if ((*gp->put)(gp->target, " ", 1) < 0) return 0 ;
+ if ((*gp->put)(gp->target, wut->string, str_len(wut->string)) < 0) return 0 ;
+ if ((*gp->put)(gp->target, " ", 1) < 0) return 0 ;
+ if (!(*wut->f)(gp, rr, packet, packetlen, pos)) return 0 ;
+ if ((*gp->put)(gp->target, "\n", 1) < 0) return 0 ;
+ return 1 ;
+}