aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs6dns/s6dns_message_header_unpack.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs6dns/s6dns_message_header_unpack.c')
-rw-r--r--src/libs6dns/s6dns_message_header_unpack.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libs6dns/s6dns_message_header_unpack.c b/src/libs6dns/s6dns_message_header_unpack.c
new file mode 100644
index 0000000..ae2b35c
--- /dev/null
+++ b/src/libs6dns/s6dns_message_header_unpack.c
@@ -0,0 +1,18 @@
+/* ISC license. */
+
+#include <skalibs/uint16.h>
+#include <s6-dns/s6dns-message.h>
+
+void s6dns_message_header_unpack (char const *s, s6dns_message_header_t *h)
+{
+ uint16_unpack_big(s, &h->id) ;
+ h->qr = s[2] & 0x8000U ? 1 : 0 ;
+ h->opcode = (s[2] >> 3) & 15 ;
+ h->aa = s[2] & 4 ? 1 : 0 ;
+ h->tc = s[2] & 2 ? 1 : 0 ;
+ h->rd = s[2] & 1 ;
+ h->ra = s[3] & 0x8000U ? 1 : 0 ;
+ h->z = (s[3] >> 4) & 7 ;
+ h->rcode = s[3] & 15 ;
+ s6dns_message_counts_unpack(s+4, &h->counts) ;
+}