I want to encode DNS protocol header using C and create a UDP datagram. Lets say I have a query www.google.com.
Can anyone suggest how to go about it?
You can find the header form开发者_如何学Cat here - http://www.nersc.gov/~scottc/software/snort/dns_head.html
RFC 1035 explains the DNS packet format in full detail. Note that the format is designed to be as compact as possible, so there are a lot of bit- and byte-level optimisations that you will have to pay attention to. A proper, robust DNS encoder and decoder is not for the faint of heart.
+1 to RFC 1035. You can take a look on Wireshark: http://www.wireshark.org/ It shows packets in both - binary and decoded view + contains source code in C so you can check how decoding is implemented.
精彩评论