This should not normally be needed in the field. It is, however, a good opportunity to better understand the DNS protocol and to get experience of sending binary UDP packets.
We begin with a function to print a name from a DNS message.
If a length has its two highest bits set (that is,
0xc0), then it and the next byte should be interpreted as a pointer instead.
We must also be aware at all times that the DNS response from the DNS server could be ill-formed or corrupted. We must try to write our program in such a way that it won't crash if it receives a bad message. This is easier said than done.