2020-12-17 14:17:27 +00:00
|
|
|
package process
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2022-04-19 17:52:51 +00:00
|
|
|
"net/netip"
|
2020-12-17 14:17:27 +00: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-11-12 12:43:48 +00:00
|
|
|
func FindProcessName(network string, srcIP netip.Addr, srcPort int) (*uint32, string, error) {
|
2020-12-17 14:17:27 +00:00
|
|
|
return findProcessName(network, srcIP, srcPort)
|
|
|
|
}
|
2022-03-12 17:21:23 +00:00
|
|
|
|
2022-11-12 12:43:48 +00:00
|
|
|
func FindUid(network string, srcIP netip.Addr, srcPort int) (*uint32, error) {
|
2022-04-22 08:27:51 +00:00
|
|
|
_, uid, err := resolveSocketByNetlink(network, srcIP, srcPort)
|
|
|
|
if err != nil {
|
2022-11-12 12:43:48 +00:00
|
|
|
return nil, err
|
2022-04-22 08:27:51 +00:00
|
|
|
}
|
2022-11-12 12:43:48 +00:00
|
|
|
return &uid, nil
|
2022-04-22 08:27:51 +00:00
|
|
|
}
|