From cb05e886a81631e5a632e0a1af83bc0cf6dd31b0 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Mon, 27 Oct 2014 14:13:53 +0000 Subject: [PATCH] Removed duplicate check for rDNS domain There's no need to check whether the queried address is a subdomain of in-addr.arpa, since this handler is registered with the muxer under that domain anyway. (Also, remove a magic number) --- server/server.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/server.go b/server/server.go index d6a89379..8ffd03f6 100644 --- a/server/server.go +++ b/server/server.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/miekg/dns" "net" - "strings" ) const ( @@ -12,6 +11,9 @@ const ( RDNS_DOMAIN = "in-addr.arpa." ) +// +1 to also exclude a dot +var rdnsDomainLen = len(RDNS_DOMAIN) + 1 + func checkFatal(e error) { if e != nil { Error.Fatal(e) @@ -74,8 +76,8 @@ func rdnsHandler(zone Zone, mdnsClient *MDNSClient) dns.HandlerFunc { return func(w dns.ResponseWriter, r *dns.Msg) { q := r.Question[0] Debug.Printf("Local rdns query: %+v", q) - if q.Qtype == dns.TypePTR && strings.HasSuffix(q.Name, ".in-addr.arpa.") { - if ip := net.ParseIP(q.Name[:len(q.Name)-14]); ip != nil { + if q.Qtype == dns.TypePTR { + if ip := net.ParseIP(q.Name[:len(q.Name)-rdnsDomainLen]); ip != nil { ip4 := ip.To4() revIP := []byte{ip4[3], ip4[2], ip4[1], ip4[0]} Debug.Printf("Looking for address: %+v", revIP)