fix process code

This commit is contained in:
MetaCubeX 2022-07-24 01:38:00 +08:00
parent b74320008a
commit 09419d88af

View file

@ -15,6 +15,10 @@ const (
proccallnumpidinfo = 0x2 proccallnumpidinfo = 0x2
) )
func resolveSocketByNetlink(network string, ip netip.Addr, srcPort int) (int32, int32, error) {
return 0, 0, ErrPlatformNotSupport
}
func findProcessName(network string, ip netip.Addr, port int) (int32, string, error) { func findProcessName(network string, ip netip.Addr, port int) (int32, string, error) {
var spath string var spath string
switch network { switch network {
@ -78,7 +82,8 @@ func findProcessName(network string, ip netip.Addr, port int) (int32, string, er
if ip == srcIP { if ip == srcIP {
// xsocket_n.so_last_pid // xsocket_n.so_last_pid
pid := readNativeUint32(buf[so+68 : so+72]) pid := readNativeUint32(buf[so+68 : so+72])
return getExecPathFromPID(pid) pp, err := getExecPathFromPID(pid)
return -1, pp, err
} }
// udp packet connection may be not equal with srcIP // udp packet connection may be not equal with srcIP
@ -88,10 +93,10 @@ func findProcessName(network string, ip netip.Addr, port int) (int32, string, er
} }
if network == UDP && fallbackUDPProcess != "" { if network == UDP && fallbackUDPProcess != "" {
return fallbackUDPProcess, nil return -1, fallbackUDPProcess, nil
} }
return "", ErrNotFound return -1, "", ErrNotFound
} }
func getExecPathFromPID(pid uint32) (string, error) { func getExecPathFromPID(pid uint32) (string, error) {