diff options
author | Andrey Mirtchovski <mirtchovski@gmail.com> | 2011-09-19 11:50:31 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-09-19 11:50:31 -0400 |
commit | 003bfa0e26356a61cab6bc20536ca3f233091f8b (patch) | |
tree | 9db02480c00bdd3e00551fa872998f69909a67d2 | |
parent | 46468357a2f6fd28343e988190a1b381401fd016 (diff) | |
download | go-003bfa0e26356a61cab6bc20536ca3f233091f8b.tar.gz go-003bfa0e26356a61cab6bc20536ca3f233091f8b.zip |
net: use /etc/hosts first when looking up IP addresses using native Go's dns resolver
Previously /etc/hosts would be ignored altogether, this change returns matching results
from that file without talking to a DNS server.
R=rsc
CC=golang-dev
https://golang.org/cl/5061042
-rw-r--r-- | src/pkg/net/dnsclient_unix.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/pkg/net/dnsclient_unix.go b/src/pkg/net/dnsclient_unix.go index a28eb16158..eb7db5e270 100644 --- a/src/pkg/net/dnsclient_unix.go +++ b/src/pkg/net/dnsclient_unix.go @@ -215,6 +215,18 @@ func goLookupHost(name string) (addrs []string, err os.Error) { // depending on our lookup code, so that Go and C get the same // answers. func goLookupIP(name string) (addrs []IP, err os.Error) { + // Use entries from /etc/hosts if possible. + haddrs := lookupStaticHost(name) + if len(haddrs) > 0 { + for _, haddr := range haddrs { + if ip := ParseIP(haddr); ip != nil { + addrs = append(addrs, ip) + } + } + if len(addrs) > 0 { + return + } + } onceLoadConfig.Do(loadConfig) if dnserr != nil || cfg == nil { err = dnserr |