Your structures are not like everything I learn from the RFC (yes, I wrote a lot of software to decode DNS packets).
Take a look at RFC 1035 , in particular, most of the structures you need can be displayed directly from the layouts of the fields in it.
For example, you need a header (see s4.1.1):
struct dns_header { uint16_t query_id; uint16_t flags; uint16_t qdcount; uint16_t ancount; uint16_t nscount; uint16_t arcount; };
Remember to use ntohs() to convert the wire format of these fields to the native byte order of your computer. The order of the network is large, and most machines today are not very similar.
You will need a “question” structure (see s4.1.2) and a general “resource record" structure (see s4.1.3).
Please note, however, that the wire format of both of them starts with a variable-length label label, which may also contain pointers to compression (see s4.1.4). This means that in these cases you cannot trivially map the entire block of wires to structure C.
Hope this helps ...
source share