bringing in code from miekg/dns, modified it to handle responses, and simplified