mirror of
https://github.com/golang/go
synced 2024-11-22 00:34:40 -07:00
net: try /etc/hosts before loading DNS config.
On Mac X 10.6 /etc/resolv.conf is changed dynamically, and may not exist at all when all network connections are turned off, thus any lookup, even for "localhost" would fail with "error reading DNS config: open /etc/resolv.conf: no such file or directory". This change avoids the error by trying to lookup addresses in /etc/hosts before loading DNS config. R=golang-dev, rsc1, rsc CC=golang-dev https://golang.org/cl/4431054
This commit is contained in:
parent
338b7abdfc
commit
a260de44e9
@ -313,16 +313,16 @@ func lookup(name string, qtype uint16) (cname string, addrs []dnsRR, err os.Erro
|
|||||||
// depending on our lookup code, so that Go and C get the same
|
// depending on our lookup code, so that Go and C get the same
|
||||||
// answers.
|
// answers.
|
||||||
func goLookupHost(name string) (addrs []string, err os.Error) {
|
func goLookupHost(name string) (addrs []string, err os.Error) {
|
||||||
onceLoadConfig.Do(loadConfig)
|
|
||||||
if dnserr != nil || cfg == nil {
|
|
||||||
err = dnserr
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Use entries from /etc/hosts if they match.
|
// Use entries from /etc/hosts if they match.
|
||||||
addrs = lookupStaticHost(name)
|
addrs = lookupStaticHost(name)
|
||||||
if len(addrs) > 0 {
|
if len(addrs) > 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
onceLoadConfig.Do(loadConfig)
|
||||||
|
if dnserr != nil || cfg == nil {
|
||||||
|
err = dnserr
|
||||||
|
return
|
||||||
|
}
|
||||||
ips, err := goLookupIP(name)
|
ips, err := goLookupIP(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user