diff options
| author | Andrey Mirtchovski <mirtchovski@gmail.com> | 2010-01-25 14:57:04 -0800 |
|---|---|---|
| committer | Andrey Mirtchovski <mirtchovski@gmail.com> | 2010-01-25 14:57:04 -0800 |
| commit | 36226b7d4da04d1ac76efef4c063f0da68ffaa54 (patch) | |
| tree | 7888d369065fa2db2b82c7a16b9bb0a1645408ea | |
| parent | ab8ce920ff9774b4ee3facac70925a83dc794264 (diff) | |
| download | golang-36226b7d4da04d1ac76efef4c063f0da68ffaa54.tar.gz | |
net: parse aliases in /etc/hosts correctly
Previous behaviour only picked the first entry (official hostname) but not the aliases.
R=rsc
CC=golang-dev
http://codereview.appspot.com/193092
Committer: Russ Cox <rsc@golang.org>
| -rw-r--r-- | src/pkg/net/hosts.go | 8 | ||||
| -rw-r--r-- | src/pkg/net/hosts_test.go | 6 | ||||
| -rw-r--r-- | src/pkg/net/hosts_testdata | 2 |
3 files changed, 13 insertions, 3 deletions
diff --git a/src/pkg/net/hosts.go b/src/pkg/net/hosts.go index 5596c9dc7..25af7968d 100644 --- a/src/pkg/net/hosts.go +++ b/src/pkg/net/hosts.go @@ -40,9 +40,11 @@ func readHosts() { if len(f) < 2 || ParseIP(f[0]) == nil { continue } - h := f[1] - old, _ := hs[h] - hs[h] = appendHost(old, f[0]) + for i := 1; i < len(f); i++ { + h := f[i] + old, _ := hs[h] + hs[h] = appendHost(old, f[0]) + } } // Update the data cache. hosts.time, _, _ = os.Time() diff --git a/src/pkg/net/hosts_test.go b/src/pkg/net/hosts_test.go index a05ee10e7..d0ee2a7ac 100644 --- a/src/pkg/net/hosts_test.go +++ b/src/pkg/net/hosts_test.go @@ -24,6 +24,12 @@ var hosttests = []hostTest{ IPv4(127, 1, 1, 1), }}, hostTest{"loki", []IP{}}, + hostTest{"ullr", []IP{ + IPv4(127, 1, 1, 2), + }}, + hostTest{"ullrhost", []IP{ + IPv4(127, 1, 1, 2), + }}, } func TestLookupStaticHost(t *testing.T) { diff --git a/src/pkg/net/hosts_testdata b/src/pkg/net/hosts_testdata index 7cf6fbbc7..b60176389 100644 --- a/src/pkg/net/hosts_testdata +++ b/src/pkg/net/hosts_testdata @@ -3,6 +3,8 @@ 127.0.0.3 odin # inline comment ::2 odin 127.1.1.1 thor +# aliases +127.1.1.2 ullr ullrhost # Bogus entries that must be ignored. 123.123.123 loki 321.321.321.321 |
