rrda

REST API allowing to perform DNS queries over HTTP
Log | Files | Refs | README | LICENSE

commit 18c4fa4f4ddad235a91505e1c7c854f676b16be7
parent 2bd46e785603e8df9c8328f1e444d2d91f52b05e
Author: Frederic Cambus <fred@statdns.com>
Date:   Fri,  5 Feb 2016 17:04:32 +0100

Use error code returned by dns.Exchange() to detect truncated DNS messages (Fixes #11)

Diffstat:
Mrrda.go | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/rrda.go b/rrda.go @@ -107,12 +107,9 @@ func resolve(w http.ResponseWriter, r *http.Request, server string, domain strin c := new(dns.Client) Redo: - if in, _, err := c.Exchange(m, server); err == nil { // Second return value is RTT, not used for now - if in.MsgHdr.Truncated { - c.Net = "tcp" - goto Redo - } + in, _, err := c.Exchange(m, server) // Second return value is RTT, not used for now + if err == nil { switch in.MsgHdr.Rcode { case dns.RcodeServerFailure: error(w, 500, 502, "The name server encountered an internal failure while processing this request (SERVFAIL)") @@ -123,6 +120,9 @@ Redo: default: jsonify(w, r, in.Question, in.Answer, in.Ns, in.Extra) } + } else if err == dns.ErrTruncated { + c.Net = "tcp" + goto Redo } else { error(w, 500, 501, "DNS server could not be reached") }