Clash.Meta/component/process/process.go

39 lines
939 B
Go
Raw Normal View History

package process
import (
"errors"
2022-04-20 01:52:51 +08:00
"net/netip"
2024-07-24 13:59:10 +08:00
C "github.com/metacubex/mihomo/constant"
)
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"
)
2023-01-14 02:23:30 +08:00
func FindProcessName(network string, srcIP netip.Addr, srcPort int) (uint32, string, error) {
return findProcessName(network, srcIP, srcPort)
}
2024-07-24 13:59:10 +08:00
// PackageNameResolver
2024-09-09 09:08:24 +08:00
// never change type traits because it's used in CMFA
2024-07-24 13:59:10 +08:00
type PackageNameResolver func(metadata *C.Metadata) (string, error)
// DefaultPackageNameResolver
2024-09-09 09:08:24 +08:00
// never change type traits because it's used in CMFA
2024-07-24 13:59:10 +08:00
var DefaultPackageNameResolver PackageNameResolver
func FindPackageName(metadata *C.Metadata) (string, error) {
if resolver := DefaultPackageNameResolver; resolver != nil {
return resolver(metadata)
}
return "", ErrPlatformNotSupport
}