diff --git a/net/net.go b/net/net.go index c31f512..fce86c7 100644 --- a/net/net.go +++ b/net/net.go @@ -71,6 +71,7 @@ type FilterStat struct { } var constMap = map[string]int{ + "unix": syscall.AF_UNIX, "TCP": syscall.SOCK_STREAM, "UDP": syscall.SOCK_DGRAM, "IPv4": syscall.AF_INET, @@ -178,10 +179,15 @@ func getIOCountersAll(n []IOCountersStat) ([]IOCountersStat, error) { func parseNetLine(line string) (ConnectionStat, error) { f := strings.Fields(line) - if len(f) < 9 { + if len(f) < 8 { return ConnectionStat{}, fmt.Errorf("wrong line,%s", line) } + if len(f) == 8 { + f = append(f, f[7]) + f[7] = "unix" + } + pid, err := strconv.Atoi(f[1]) if err != nil { return ConnectionStat{}, err @@ -199,9 +205,14 @@ func parseNetLine(line string) (ConnectionStat, error) { return ConnectionStat{}, fmt.Errorf("unknown type, %s", f[7]) } - laddr, raddr, err := parseNetAddr(f[8]) - if err != nil { - return ConnectionStat{}, fmt.Errorf("failed to parse netaddr, %s", f[8]) + var laddr, raddr Addr + if f[7] == "unix" { + laddr.IP = f[8] + } else { + laddr, raddr, err = parseNetAddr(f[8]) + if err != nil { + return ConnectionStat{}, fmt.Errorf("failed to parse netaddr, %s", f[8]) + } } n := ConnectionStat{ diff --git a/net/net_unix.go b/net/net_unix.go index e3ff262..4451b54 100644 --- a/net/net_unix.go +++ b/net/net_unix.go @@ -63,7 +63,7 @@ func ConnectionsPidWithContext(ctx context.Context, kind string, pid int32) ([]C case "udp6": args = append(args, "6udp") case "unix": - return ret, common.ErrNotImplementedError + args = []string{"-U"} } r, err := common.CallLsofWithContext(ctx, invoke, pid, args...)