1
0
mirror of https://github.com/golang/go synced 2024-11-22 07:14:40 -07:00

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
https://golang.org/cl/193092
This commit is contained in:
Andrey Mirtchovski 2010-01-25 14:57:04 -08:00 committed by Russ Cox
parent 6d8829e931
commit 3fc41d5e65
3 changed files with 13 additions and 3 deletions

View File

@ -40,10 +40,12 @@ func readHosts() {
if len(f) < 2 || ParseIP(f[0]) == nil { if len(f) < 2 || ParseIP(f[0]) == nil {
continue continue
} }
h := f[1] for i := 1; i < len(f); i++ {
h := f[i]
old, _ := hs[h] old, _ := hs[h]
hs[h] = appendHost(old, f[0]) hs[h] = appendHost(old, f[0])
} }
}
// Update the data cache. // Update the data cache.
hosts.time, _, _ = os.Time() hosts.time, _, _ = os.Time()
hosts.path = hp hosts.path = hp

View File

@ -24,6 +24,12 @@ var hosttests = []hostTest{
IPv4(127, 1, 1, 1), IPv4(127, 1, 1, 1),
}}, }},
hostTest{"loki", []IP{}}, hostTest{"loki", []IP{}},
hostTest{"ullr", []IP{
IPv4(127, 1, 1, 2),
}},
hostTest{"ullrhost", []IP{
IPv4(127, 1, 1, 2),
}},
} }
func TestLookupStaticHost(t *testing.T) { func TestLookupStaticHost(t *testing.T) {

View File

@ -3,6 +3,8 @@
127.0.0.3 odin # inline comment 127.0.0.3 odin # inline comment
::2 odin ::2 odin
127.1.1.1 thor 127.1.1.1 thor
# aliases
127.1.1.2 ullr ullrhost
# Bogus entries that must be ignored. # Bogus entries that must be ignored.
123.123.123 loki 123.123.123 loki
321.321.321.321 321.321.321.321