#ifndef __cs361_dns_h__ #define __cs361_dns_h__ #include // Maximum buffer lengths allows #define BUFFER_LENGTH 512 // Structure of the bytes for a DNS header typedef struct { uint16_t xid; uint16_t flags; uint16_t qdcount; uint16_t ancount; uint16_t nscount; uint16_t arcount; } dns_header_t; typedef struct { dns_header_t header; unsigned char *domain; uint16_t qtype; uint16_t qclass; } dns_query_t; typedef struct { char *domain; uint16_t qtype; uint16_t qclass; uint32_t ttl; uint16_t rdlen; char *rdata; } dns_answer_t; typedef struct { dns_query_t query; dns_answer_t *answers; dns_answer_t *authorities; dns_answer_t *additionals; } dns_response_t; // Supported record types #define A 1 #define NS 2 #define CNAME 5 #define SOA 6 #define PTR 12 #define MX 15 #define AAAA 28 void print_dns_header (dns_header_t *); void print_question_section (dns_query_t *query); void print_answer_section (dns_answer_t *answer); ssize_t parse_dns_query (unsigned char *bytes, dns_query_t *query); ssize_t parse_dns_response (unsigned char *bytes, ssize_t query_len, dns_response_t *response); #endif