2020-12-17 22:17:27 +08:00
|
|
|
package process
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2022-04-20 01:52:51 +08:00
|
|
|
"net/netip"
|
2020-12-17 22:17:27 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrInvalidNetwork = errors.New("invalid network")
|
|
|
|
ErrPlatformNotSupport = errors.New("not support on this platform")
|
|
|
|
ErrNotFound = errors.New("process not found")
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
TCP = "tcp"
|
|
|
|
UDP = "udp"
|
|
|
|
)
|
|
|
|
|
2022-05-19 20:43:41 +08:00
|
|
|
func FindProcessName(network string, srcIP netip.Addr, srcPort int) (int32, string, error) {
|
2020-12-17 22:17:27 +08:00
|
|
|
return findProcessName(network, srcIP, srcPort)
|
|
|
|
}
|
2022-03-13 01:21:23 +08:00
|
|
|
|
2022-04-22 16:27:51 +08:00
|
|
|
func FindUid(network string, srcIP netip.Addr, srcPort int) (int32, error) {
|
|
|
|
_, uid, err := resolveSocketByNetlink(network, srcIP, srcPort)
|
|
|
|
if err != nil {
|
|
|
|
return -1, err
|
|
|
|
}
|
|
|
|
return uid, nil
|
|
|
|
}
|