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

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

int s6dns_message_parse_getrr (s6dns_message_rr_t_ref rr, char const *packet, unsigned int packetlen, unsigned int *pos)
{
  if (!s6dns_message_get_domain(&rr->name, packet, packetlen, pos)) return 0 ;
  if (*pos + 10 > packetlen) return (errno = EPROTO, 0) ;
  uint16_unpack_big(packet + *pos, &rr->rtype) ; *pos += 2 ;
  uint16_unpack_big(packet + *pos, &rr->rclass) ; *pos += 2 ;
  uint32_unpack_big(packet + *pos, &rr->ttl) ; *pos += 4 ;
  uint16_unpack_big(packet + *pos, &rr->rdlength) ; *pos += 2 ;
  if (*pos + rr->rdlength > packetlen) return (errno = EPROTO, 0) ;
  return 1 ;
}