summaryrefslogtreecommitdiff
path: root/src/libs6dns/s6dns_analyze_record.c
blob: e2621f753176672ca8640527d681273d830dc0b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* ISC license. */

#include <string.h>
#include <stdint.h>
#include <skalibs/types.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_t rtype)
{
  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] ;
    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, strlen(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 ;
}