summaryrefslogtreecommitdiff
path: root/src/libs6dns/s6dns_analyze_record_strings.c
blob: 9baa42a6dcdd5af74f484efec13ee43cfd1f3828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* ISC license. */

#include <errno.h>
#include <skalibs/error.h>
#include <skalibs/stralloc.h>
#include <skalibs/skamisc.h>
#include <s6-dns/s6dns-message.h>
#include <s6-dns/s6dns-analyze.h>

int s6dns_analyze_record_strings (genwrite_t *gp, s6dns_message_rr_t const *rr, char const *packet, unsigned int packetlen, unsigned int start)
{
  stralloc sa = STRALLOC_ZERO ;
  char buf[rr->rdlength] ;
  unsigned int pos = start ;
  int r = s6dns_message_get_strings(buf, rr->rdlength, packet, packetlen, &pos) ;
  if (r < 0) return 0 ;
  if (rr->rdlength != pos - start) return (errno = EPROTO, 0) ;
  if (!string_quote(&sa, buf, r)) return 0 ;
  r = (*gp->put)(gp->target, sa.s, sa.len) >= 0 ;
  stralloc_free(&sa) ;
  return r ;
}