Q1 - Is it possible to capture DNS request/responses with the library?
Q2 - If yes, once I have the packet does anyone have any sample code that shows how I could extract the fields from the DNS response? In particular the IP address that DNS resolved for the given DNS name provided in particular.
Yes, it's possible.
Sample code would be a bit on the long side, though...
In essence, you need to:
then handle the rest of the packet according to the very thorough description given in RFC 1035.
In practise that means:
QR == 1
)RCODE == 0
and ANCOUNT > 0
To further complicate matters you have to handle DNS labels (series of <count><data...>
fields) and potentially handle compressed labels too!
This sounds nasty, but none of it is actually that hard. I have C++ code that does all this and it's not that long, but I can't release it.