summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2019-03-02 07:30:58 +0700
committerShulhan <ms@kilabit.info>2019-03-02 07:30:58 +0700
commit35066f79a4844d207057f452eaddf4f0a11c0821 (patch)
treee028687732acc7c54790be54ceb97dff06e4bbef
parentda44b655f1e46281741e47a664cd96ed560e4cb9 (diff)
downloadrescached-35066f79a4844d207057f452eaddf4f0a11c0821.tar.xz
cmd/resolver: generate unique request ID
Also, fix the name server that being requested on error.
-rw-r--r--cmd/resolver/main.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/cmd/resolver/main.go b/cmd/resolver/main.go
index 5d268ee..6af3f47 100644
--- a/cmd/resolver/main.go
+++ b/cmd/resolver/main.go
@@ -7,6 +7,7 @@ package main
import (
"fmt"
"log"
+ "math/rand"
"net"
"strings"
"time"
@@ -116,9 +117,13 @@ func lookup(opts *options, ns string, timeout time.Duration, qname []byte) *dns.
log.Fatal("! dns.NewUDPClient: ", err)
}
}
+
+ rand.Seed(time.Now().Unix())
+
cl.SetTimeout(timeout)
req := dns.NewMessage()
+ req.Header.ID = uint16(rand.Intn(65535))
req.Question.Name = qname
req.Question.Type = opts.qtype
req.Question.Class = opts.qclass
@@ -175,8 +180,8 @@ func main() {
}
var (
- res *dns.Message
- nameserver string
+ res *dns.Message
+ ns string
)
nsAddrs := parseNameServers(cr.NameServers)
@@ -192,7 +197,6 @@ func main() {
for _, qname := range queries {
for x := 0; x < cr.Attempts; x++ {
for _, addr := range nsAddrs {
- var ns string
if opts.doh {
ns = fmt.Sprintf("https://%s/dns-query", addr.IP)
} else {
@@ -211,6 +215,6 @@ func main() {
out:
if res != nil {
- println(messagePrint(nameserver, res))
+ println(messagePrint(ns, res))
}
}