aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs6dns/s6dns_message_parse_question_nodecode.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-12-02 10:23:03 +0000
committerLaurent Bercot <ska@appnovation.com>2023-12-02 10:23:03 +0000
commit2d78c35314f0310561cabefea8564123ccbb2622 (patch)
tree450ad222f89f6a0a92efd5492973701cf3ac3beb /src/libs6dns/s6dns_message_parse_question_nodecode.c
parentc3fa4bca2f0d71b296b990593a33584a8fe396e1 (diff)
downloads6-dns-2d78c35314f0310561cabefea8564123ccbb2622.tar.gz
Add nodecode functions for get_domain and parse_question
Also make sure get_domain always returns lowercase. Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libs6dns/s6dns_message_parse_question_nodecode.c')
-rw-r--r--src/libs6dns/s6dns_message_parse_question_nodecode.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libs6dns/s6dns_message_parse_question_nodecode.c b/src/libs6dns/s6dns_message_parse_question_nodecode.c
new file mode 100644
index 0000000..f6cc4a7
--- /dev/null
+++ b/src/libs6dns/s6dns_message_parse_question_nodecode.c
@@ -0,0 +1,28 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <errno.h>
+
+#include <skalibs/posixishard.h>
+#include <skalibs/uint16.h>
+
+#include <s6-dns/s6dns-constants.h>
+#include <s6-dns/s6dns-domain.h>
+#include <s6-dns/s6dns-message.h>
+
+int s6dns_message_parse_question_nodecode (s6dns_message_counts_t *counts, s6dns_domain_t *name, uint16_t *qtypep, char const *packet, unsigned int packetlen, unsigned int *pos)
+{
+ s6dns_domain_t d ;
+ uint16_t qtype ;
+ uint16_t qclass ;
+ if (!counts->qd) return (errno = EINVAL, 0) ;
+ if (!s6dns_message_get_domain_nodecode(&d, packet, packetlen, pos)) return 0 ;
+ if (*pos + 4 > packetlen) return (errno = EPROTO, 0) ;
+ uint16_unpack_big(packet + *pos, &qtype) ; *pos += 2 ;
+ uint16_unpack_big(packet + *pos, &qclass) ; *pos += 2 ;
+ if (qclass != S6DNS_C_IN) return (errno = ENOTSUP, 0) ;
+ counts->qd-- ;
+ *name = d ;
+ *qtypep = qtype ;
+ return 1 ;
+}