diff options
author | Russ Cox <rsc@golang.org> | 2009-11-10 17:09:33 -0800 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-11-10 17:09:33 -0800 |
commit | 484f46daea9a44afd9fc0ea90b2172dfa524d9bb (patch) | |
tree | 66b8d217271b0bc429f02168fc3f4292fbf510db | |
parent | c8bb81fddc956c5aafbf54ca81c8f7e34257e24b (diff) | |
download | go-484f46daea9a44afd9fc0ea90b2172dfa524d9bb.tar.gz go-484f46daea9a44afd9fc0ea90b2172dfa524d9bb.zip |
net: fix dns bug reported on irc.
if suffixes don't work, check for name directly.
also fixes short names like bit.ly when ndots>1.
tested by tossing domain and search lines from /etc/resolv.conf
Fixes #2.
R=agl, agl1
CC=golang-dev
https://golang.org/cl/152048
-rw-r--r-- | src/pkg/net/dnsclient.go | 11 | ||||
-rw-r--r-- | src/pkg/net/net_test.go | 2 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/pkg/net/dnsclient.go b/src/pkg/net/dnsclient.go index bea31c3ceb..064e1017bf 100644 --- a/src/pkg/net/dnsclient.go +++ b/src/pkg/net/dnsclient.go @@ -268,5 +268,16 @@ func LookupHost(name string) (cname string, addrs []string, err os.Error) { return; } } + + // Last ditch effort: try unsuffixed. + rname := name; + if !rooted { + rname += "." + } + addrs, err = tryOneName(cfg, rname); + if err == nil { + cname = rname; + return; + } return; } diff --git a/src/pkg/net/net_test.go b/src/pkg/net/net_test.go index 532a62b985..c06a05b3ef 100644 --- a/src/pkg/net/net_test.go +++ b/src/pkg/net/net_test.go @@ -35,7 +35,7 @@ var dialErrorTests = []DialErrorTest{ }, DialErrorTest{ "tcp", "", "no-such-name:80", - `dial tcp no-such-name:80: lookup no-such-name\..*\.( on .*)?: no (.*)`, + `dial tcp no-such-name:80: lookup no-such-name\.(.*\.)?( on .*)?: no (.*)`, }, DialErrorTest{ "tcp", "", "mh/astro/r70:http", |