diff --git a/common/lsof/lsof.go b/common/lsof/lsof.go new file mode 100644 index 0000000..42c06fb --- /dev/null +++ b/common/lsof/lsof.go @@ -0,0 +1,10 @@ +package lsof + +import ( + "errors" +) + +var ( + ErrNotFound = errors.New("not found") + ErrNotImplemented = errors.New("not implemented") +) diff --git a/common/lsof/lsof_other.go b/common/lsof/lsof_other.go index 2273327..996dae2 100644 --- a/common/lsof/lsof_other.go +++ b/common/lsof/lsof_other.go @@ -2,10 +2,6 @@ package lsof -import ( - "errors" -) - func GetCommandNameBySocket(network string, addr string, port uint16) (string, error) { - return "", errors.New("not implemented") + return "", ErrNotImplemented } diff --git a/common/lsof/lsof_unix.go b/common/lsof/lsof_unix.go index b7e7946..c03c112 100644 --- a/common/lsof/lsof_unix.go +++ b/common/lsof/lsof_unix.go @@ -20,7 +20,7 @@ func GetCommandNameBySocket(network string, addr string, port uint16) (string, e // listen on the same udp port. Moreover, if // the application closes the socket immediately // after sending out the packet (e.g. it just - // uploading data but not receving any data), + // uploading data but not receiving any data), // we may not be able to find it. pattern = fmt.Sprintf("-i%s:%d", network, port) default: @@ -38,8 +38,8 @@ func GetCommandNameBySocket(network string, addr string, port uint16) (string, e // sockets in the list, just take // the first one for simplicity. if strings.HasPrefix(line, "c") { - return line[1:len(line)], nil + return line[1:], nil } } - return "", errors.New("not found") + return "", ErrNotFound } diff --git a/common/lsof/lsof_windows.go b/common/lsof/lsof_windows.go index 15a080c..88f7520 100644 --- a/common/lsof/lsof_windows.go +++ b/common/lsof/lsof_windows.go @@ -3,7 +3,6 @@ package lsof import ( - "errors" "fmt" "syscall" "unsafe" @@ -24,7 +23,7 @@ func GetCommandNameBySocket(network string, addr string, port uint16) (string, e return getNameByPid(uint32(row.OwningPid)) } } - return "", errors.New("not found") + return "", ErrNotFound case "udp": var udpTable win.MIB_UDPTABLE_OWNER_PID err := getUdpTable( @@ -56,9 +55,9 @@ func GetCommandNameBySocket(network string, addr string, port uint16) (string, e // } // } - return "", errors.New("not found") + return "", ErrNotFound default: - return "", errors.New("not found") + return "", ErrNotFound } }