Fix: macOS udp find process should use unspecified fallback
This commit is contained in:
parent
460934fc06
commit
179989317c
1 changed files with 19 additions and 6 deletions
|
@ -44,6 +44,8 @@ func findProcessName(network string, ip net.IP, port int) (string, error) {
|
|||
// rup8(sizeof(xtcpcb_n))
|
||||
itemSize += 208
|
||||
}
|
||||
|
||||
var fallbackUDPProcess string
|
||||
// skip the first xinpgen(24 bytes) block
|
||||
for i := 24; i+itemSize <= len(buf); i += itemSize {
|
||||
// offset of xinpcb_n and xsocket_n
|
||||
|
@ -57,11 +59,15 @@ func findProcessName(network string, ip net.IP, port int) (string, error) {
|
|||
// xinpcb_n.inp_vflag
|
||||
flag := buf[inp+44]
|
||||
|
||||
var srcIP net.IP
|
||||
var (
|
||||
srcIP net.IP
|
||||
srcIsIPv4 bool
|
||||
)
|
||||
switch {
|
||||
case flag&0x1 > 0 && isIPv4:
|
||||
// ipv4
|
||||
srcIP = net.IP(buf[inp+76 : inp+80])
|
||||
srcIsIPv4 = true
|
||||
case flag&0x2 > 0 && !isIPv4:
|
||||
// ipv6
|
||||
srcIP = net.IP(buf[inp+64 : inp+80])
|
||||
|
@ -69,13 +75,20 @@ func findProcessName(network string, ip net.IP, port int) (string, error) {
|
|||
continue
|
||||
}
|
||||
|
||||
if !ip.Equal(srcIP) {
|
||||
continue
|
||||
if ip.Equal(srcIP) {
|
||||
// xsocket_n.so_last_pid
|
||||
pid := readNativeUint32(buf[so+68 : so+72])
|
||||
return getExecPathFromPID(pid)
|
||||
}
|
||||
|
||||
// xsocket_n.so_last_pid
|
||||
pid := readNativeUint32(buf[so+68 : so+72])
|
||||
return getExecPathFromPID(pid)
|
||||
// udp packet connection may be not equal with srcIP
|
||||
if network == UDP && srcIP.IsUnspecified() && isIPv4 == srcIsIPv4 {
|
||||
fallbackUDPProcess, _ = getExecPathFromPID(readNativeUint32(buf[so+68 : so+72]))
|
||||
}
|
||||
}
|
||||
|
||||
if network == UDP && fallbackUDPProcess != "" {
|
||||
return fallbackUDPProcess, nil
|
||||
}
|
||||
|
||||
return "", ErrNotFound
|
||||
|
|
Loading…
Reference in a new issue