process.go 778 B

12345678910111213141516171819202122232425262728293031323334
  1. package process
  2. import (
  3. "errors"
  4. "net/netip"
  5. C "github.com/metacubex/mihomo/constant"
  6. )
  7. var (
  8. ErrInvalidNetwork = errors.New("invalid network")
  9. ErrPlatformNotSupport = errors.New("not support on this platform")
  10. ErrNotFound = errors.New("process not found")
  11. )
  12. const (
  13. TCP = "tcp"
  14. UDP = "udp"
  15. )
  16. func FindProcessName(network string, srcIP netip.Addr, srcPort int) (uint32, string, error) {
  17. return findProcessName(network, srcIP, srcPort)
  18. }
  19. type PackageNameResolver func(metadata *C.Metadata) (string, error)
  20. var DefaultPackageNameResolver PackageNameResolver
  21. func FindPackageName(metadata *C.Metadata) (string, error) {
  22. if resolver := DefaultPackageNameResolver; resolver != nil {
  23. return resolver(metadata)
  24. }
  25. return "", ErrPlatformNotSupport
  26. }