summaryrefslogtreecommitdiff
path: root/src/libs6dns/s6dns_message_get_caa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs6dns/s6dns_message_get_caa.c')
-rw-r--r--src/libs6dns/s6dns_message_get_caa.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libs6dns/s6dns_message_get_caa.c b/src/libs6dns/s6dns_message_get_caa.c
new file mode 100644
index 0000000..a97b8c0
--- /dev/null
+++ b/src/libs6dns/s6dns_message_get_caa.c
@@ -0,0 +1,24 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <skalibs/error.h>
+#include <s6-dns/s6dns-message.h>
+
+int s6dns_message_get_caa (s6dns_message_rr_caa_t *caa, char const *packet, unsigned int packetlen, unsigned int *pos, uint16_t rdlength)
+{
+ unsigned char taglen ;
+ if (rdlength < 4) return (errno = EPROTO, 0) ;
+ if (*pos + rdlength > packetlen) return (errno = EPROTO, 0) ;
+ caa->flags = packet[(*pos)++] ;
+ taglen = packet[(*pos)++] ;
+ if (rdlength < taglen + 3 || rdlength > taglen + 257) return (errno = EPROTO, 0) ;
+ memcpy(caa->tag, packet + *pos, taglen) ;
+ caa->tag[taglen] = 0 ;
+ *pos += taglen ;
+ memcpy(caa->value, packet + *pos, rdlength - taglen - 2) ;
+ caa->value[rdlength - taglen - 1] = 0 ;
+ *pos += rdlength - taglen - 2 ;
+ return 1 ;
+}