]> Cypherpunks repositories - gostls13.git/commitdiff
net: use /etc/hosts first when looking up IP addresses using native Go's dns resolver
authorAndrey Mirtchovski <mirtchovski@gmail.com>
Mon, 19 Sep 2011 15:50:31 +0000 (11:50 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 19 Sep 2011 15:50:31 +0000 (11:50 -0400)
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

src/pkg/net/dnsclient_unix.go

index a28eb16158477e27389887511d7022d589c8a5b2..eb7db5e27073b90ed221ff149485828fc00f4cdc 100644 (file)
@@ -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