From f2449642b789dabe3a03dbb97a4c1888f1e88f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Gul=C3=A1csi?= Date: Wed, 11 Feb 2015 16:57:25 +0100 Subject: [PATCH] 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. --- resolver.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/resolver.go b/resolver.go index 9287428..b568833 100644 --- a/resolver.go +++ b/resolver.go @@ -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) { for _, server := range r.config.Servers { - nameserver := server + ":" + r.config.Port - ns = append(ns, nameserver) + if i := strings.IndexByte(server, '#'); i > 0 { + server = server[:i] + ":" + server[i+1:] + } else { + server = server + ":" + r.config.Port + } + ns = append(ns, server) } return }