';' in resolv.conf also means comment

Skip ';'-prefixed lines in /etc/resolv.conf as well.
This commit is contained in:
Anfernee Gui 2017-08-22 11:19:45 -07:00
parent 179eee87e1
commit f2d9d153ce
2 changed files with 3 additions and 1 deletions

View file

@ -38,7 +38,7 @@ func GetSystemNameServers() ([]net.IP, error) {
lines := strings.Split(string(file), "\n")
for l := range lines {
trimmed := strings.TrimSpace(lines[l])
if strings.HasPrefix(trimmed, "#") {
if len(trimmed) == 0 || trimmed[0] == '#' || trimmed[0] == ';' {
continue
}
fields := strings.Fields(trimmed)

View file

@ -40,6 +40,8 @@ func TestGetDNSServers(t *testing.T) {
defer os.Remove(file.Name())
ioutil.WriteFile(file.Name(), []byte(`
# comment
; comment
nameserver 2001:4860:4860::8844
nameserver 2001:4860:4860::8888
nameserver 8.8.8.8