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

#include <errno.h>
#include <skalibs/error.h>
#include <skalibs/uint16.h>
#include <skalibs/uint32.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 ;
}