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

#include <string.h>
#include <errno.h>
#include <skalibs/error.h>
#include "s6dns-message-internal.h"

int s6dns_message_get_string_internal (char *s, size_t max, char const *packet, unsigned int packetlen, unsigned int *pos)
{
  unsigned char len = ((unsigned char const *)packet)[*pos] ;
  if (*pos + len + 1 > packetlen) return (errno = EPROTO, -1) ;
  if (len > max) return (errno = ENAMETOOLONG, -1) ;
  memcpy(s, packet + *pos + 1, len) ;
  *pos += len + 1 ;
  return len ;
}