1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package tunservice
import (
"errors"
"net/netip"
"github.com/sagernet/sing/common/winiphlpapi"
"github.com/armanlife/firefox-vpn-client/core/internal/tunapi"
)
// ownerPath is the executable of the program whose socket has source as
// its local address: its process from Windows' table of sockets, by owner.
func ownerPath(udp bool, source netip.AddrPort) (string, error) {
network := "tcp"
if udp {
network = "udp"
}
pid, err := winiphlpapi.FindPid(network, source)
if err != nil {
return "", err
}
// The idle process and the kernel have no executable.
if pid == 0 || pid == 4 {
return "", errors.New("a connection of the system itself")
}
return tunapi.ProcessPath(pid)
}