Skip to content

Commit

Permalink
Trivial fixes in core/pkg/net
Browse files Browse the repository at this point in the history
- Simplify util method IsIPV6
- Skip ';'-prefixed lines in /etc/resolv.conf as comment
  • Loading branch information
Anfernee Gui committed Aug 22, 2017
1 parent a392f29 commit 99227da
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion core/pkg/net/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions core/pkg/net/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions core/pkg/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ limitations under the License.

package net

import (
_net "net"
"strings"
)
import _net "net"

// IsIPV6 checks if the input contains a valid IPV6 address
func IsIPV6(ip _net.IP) bool {
if dp := strings.Index(ip.String(), ":"); dp != -1 {
return true
}
return false
return ip.To4() == nil
}

0 comments on commit 99227da

Please sign in to comment.