Allow non-standard namserver ports

For example Consul uses port 8600.
With this patch, I can add
  nameserver 127.0.0.1#8600
to my godns-specific resolv.conf.
This commit is contained in:
Tamás Gulácsi 2015-02-11 16:57:25 +01:00
parent b24fe9ac4a
commit f2449642b7
1 changed files with 8 additions and 2 deletions

View File

@ -49,10 +49,16 @@ func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error
} }
// Namservers return the array of nameservers, with port number appended.
// '#' in the name is treated as port separator, as with dnsmasq.
func (r *Resolver) Nameservers() (ns []string) { func (r *Resolver) Nameservers() (ns []string) {
for _, server := range r.config.Servers { for _, server := range r.config.Servers {
nameserver := server + ":" + r.config.Port if i := strings.IndexByte(server, '#'); i > 0 {
ns = append(ns, nameserver) server = server[:i] + ":" + server[i+1:]
} else {
server = server + ":" + r.config.Port
}
ns = append(ns, server)
} }
return return
} }