So I am following this guide DNS Resolver in C to mimic DNS query in C , by following it I am able to fetch A records successfully
But when I change the query type to 2 , that is NS record query , I do not get the complete answer
header.qdcount=htons(1);
header.ancount=htons(3); //number of NS records I want
dns_question_t question;
question.dnstype=htons(2);//query type is 2 , that is NS record
question.dnsclass = htons(1);//class Internet
When I completely dump the response buffer from DNS server , I get someting like this
4▒▒.cloudflare.com▒
qns3▒
▒
qns4▒
▒
qns5▒
▒
qns6▒
▒
qns7▒
How am I suppose to parse the answer part of the buffer ?
Here is the structure I am using for “ANSWER” section
typedef struct {
uint16_t compression;
uint16_t type;
uint16_t class;
uint32_t ttl;
uint16_t length;
char name[];
} __attribute__((packed)) dns_record_ns_t;
From reading RFC 1035 I got to know that it could be due to name compression , but when I check the
first two bits of compression , they both are not set , because if compressed , then they should be set bits.
for (int i = 0; i < ntohs (response_header->ancount); i++)
{
uint16_t x = ntohs(records[i].compression);
printf ("%" PRId16 "n",((x>>1)&1));
printf ("%" PRId16 "n",((x>>2)&1));
}