#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; }