From 2278df1493e064c197913e49b5d1935942d83448 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 6 May 2025 16:57:32 -0700 Subject: initial import --- test/test-parse_dns_udp.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/test-parse_dns_udp.c (limited to 'test/test-parse_dns_udp.c') diff --git a/test/test-parse_dns_udp.c b/test/test-parse_dns_udp.c new file mode 100644 index 0000000..7fec577 --- /dev/null +++ b/test/test-parse_dns_udp.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include "../include/dns.h" + +#define ASSERT(x) do { \ + if (!(x)) { \ + fprintf(stderr, "FAIL: %s:%d: %s\n", __FILE__, __LINE__, #x); \ + return EXIT_FAILURE; \ + } \ +} while (0) + +int main(void) { + // Simple DNS query for "example.com" A record + // Manually constructed: + // - Header: 12 bytes + // - Question: example.com (as labels) + QTYPE A + QCLASS IN + uint8_t pkt[] = { + 0x12, 0x34, // Transaction ID + 0x01, 0x00, // Flags: standard query + 0x00, 0x01, // QDCOUNT: 1 + 0x00, 0x00, // ANCOUNT + 0x00, 0x00, // NSCOUNT + 0x00, 0x00, // ARCOUNT + 0x07, 'e','x','a','m','p','l','e', + 0x03, 'c','o','m', + 0x00, // null terminator + 0x00, 0x01, // QTYPE A + 0x00, 0x01 // QCLASS IN + }; + + struct dns_question qs[MAX_DNS_QUESTIONS]; + size_t count = parse_dns_udp(pkt, sizeof(pkt), qs, MAX_DNS_QUESTIONS); + + ASSERT(count == 1); + ASSERT(strcmp(qs[0].name, "example.com") == 0); + ASSERT(qs[0].qtype == 1); + + printf("PASS: parse_dns_udp\n"); + return EXIT_SUCCESS; +} -- cgit v1.2.3