Fix PR comments made by shirou

This commit is contained in:
Marco Pfatschbacher 2017-11-09 13:14:12 +01:00
parent 6e7aca41d7
commit df6462b50e
1 changed files with 8 additions and 5 deletions

View File

@ -97,7 +97,7 @@ func ParseNetstat(output string, mode string,
} }
func IOCounters(pernic bool) ([]IOCountersStat, error) { func IOCounters(pernic bool) ([]IOCountersStat, error) {
netstat, err := exec.LookPath("/usr/bin/netstat") netstat, err := exec.LookPath("netstat")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -204,10 +204,13 @@ func parseNetstatAddr(local string, remote string, family uint32) (laddr Addr, r
host := matches[1] host := matches[1]
port := matches[2] port := matches[2]
if host == "*" { if host == "*" {
if family == syscall.AF_INET { switch family {
case syscall.AF_INET:
host = "0.0.0.0" host = "0.0.0.0"
} else { case syscall.AF_INET6:
host = "::" host = "::"
default:
return Addr{}, fmt.Errorf("unknown family, %d", family)
} }
} }
lport, err := strconv.Atoi(port) lport, err := strconv.Atoi(port)
@ -241,7 +244,7 @@ func Connections(kind string) ([]ConnectionStat, error) {
case "all": case "all":
fallthrough fallthrough
case "inet": case "inet":
// nothing to add
case "inet4": case "inet4":
args = append(args, "-finet") args = append(args, "-finet")
case "inet6": case "inet6":
@ -262,7 +265,7 @@ func Connections(kind string) ([]ConnectionStat, error) {
return ret, common.ErrNotImplementedError return ret, common.ErrNotImplementedError
} }
netstat, err := exec.LookPath("/usr/bin/netstat") netstat, err := exec.LookPath("netstat")
if err != nil { if err != nil {
return nil, err return nil, err
} }