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

#include <errno.h>
#include <skalibs/error.h>
#include <skalibs/genalloc.h>
#include <s6-dns/s6dns-domain.h>
#include <s6-dns/s6dns-message.h>

int s6dns_message_parse_answer_domain (s6dns_message_rr_t const *rr, char const *packet, unsigned int packetlen, unsigned int pos, unsigned int section, void *stuff)
{
  s6dns_dpag_t *data = stuff ;
  if ((section == 2) && (rr->rtype == data->rtype))
  {
    s6dns_domain_t d ;
    register unsigned int start = pos ;
    if (!s6dns_message_get_domain(&d, packet, packetlen, &pos)) return 0 ;
    if (rr->rdlength != pos - start) return (errno = EPROTO, 0) ;
    if (!genalloc_append(s6dns_domain_t, &data->ds, &d)) return -1 ;
  }
  return 1 ;
}