]> Cypherpunks repositories - gostls13.git/commitdiff
net: parse aliases in /etc/hosts correctly
authorAndrey Mirtchovski <mirtchovski@gmail.com>
Mon, 25 Jan 2010 22:57:04 +0000 (14:57 -0800)
committerRuss Cox <rsc@golang.org>
Mon, 25 Jan 2010 22:57:04 +0000 (14:57 -0800)
Previous behaviour only picked the first entry (official hostname) but not the aliases.

R=rsc
CC=golang-dev
https://golang.org/cl/193092

src/pkg/net/hosts.go
src/pkg/net/hosts_test.go
src/pkg/net/hosts_testdata

index 5596c9dc72a795de24748e61a9b91616d56d398c..25af7968dbb01d219d65891778e4a14df2fd8f98 100644 (file)
@@ -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()
index a05ee10e7ce64baec2e11913b9246c5cffbac8fd..d0ee2a7acbddb8cb262a7a1e38a81110b9a5763c 100644 (file)
@@ -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) {
index 7cf6fbbc79088e90090415895e5612d5a9cda3bc..b601763898b7e27ded621cc207effa4a403cecc0 100644 (file)
@@ -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