OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris | 5 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris |
6 | 6 |
7 // Read system DNS config from /etc/resolv.conf | 7 // Read system DNS config from /etc/resolv.conf |
8 | 8 |
9 package net | 9 package net |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 f := getFields(line) | 35 f := getFields(line) |
36 if len(f) < 1 { | 36 if len(f) < 1 { |
37 continue | 37 continue |
38 } | 38 } |
39 switch f[0] { | 39 switch f[0] { |
40 case "nameserver": // add one name server | 40 case "nameserver": // add one name server |
41 if len(f) > 1 && len(conf.servers) < 3 { // small, but t
he standard limit | 41 if len(f) > 1 && len(conf.servers) < 3 { // small, but t
he standard limit |
42 // One more check: make sure server name is | 42 // One more check: make sure server name is |
43 // just an IP address. Otherwise we need DNS | 43 // just an IP address. Otherwise we need DNS |
44 // to look it up. | 44 // to look it up. |
45 » » » » if ParseIP(f[1]) != nil { | 45 » » » » if parseIPv4(f[1]) != nil { |
| 46 » » » » » conf.servers = append(conf.servers, f[1]
) |
| 47 » » » » } else if ip, _ := parseIPv6(f[1], true); ip !=
nil { |
46 conf.servers = append(conf.servers, f[1]
) | 48 conf.servers = append(conf.servers, f[1]
) |
47 } | 49 } |
48 } | 50 } |
49 | 51 |
50 case "domain": // set search path to just this domain | 52 case "domain": // set search path to just this domain |
51 if len(f) > 1 { | 53 if len(f) > 1 { |
52 conf.search = []string{f[1]} | 54 conf.search = []string{f[1]} |
53 } | 55 } |
54 | 56 |
55 case "search": // set search path to given servers | 57 case "search": // set search path to given servers |
(...skipping 29 matching lines...) Expand all Loading... |
85 } | 87 } |
86 } | 88 } |
87 } | 89 } |
88 } | 90 } |
89 return conf, nil | 91 return conf, nil |
90 } | 92 } |
91 | 93 |
92 func hasPrefix(s, prefix string) bool { | 94 func hasPrefix(s, prefix string) bool { |
93 return len(s) >= len(prefix) && s[:len(prefix)] == prefix | 95 return len(s) >= len(prefix) && s[:len(prefix)] == prefix |
94 } | 96 } |
OLD | NEW |