Skip to content

Commit 5873ba8

Browse files
committed
Fix FindPid for Windows
1 parent 3fa6dfd commit 5873ba8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

common/winiphlpapi/helper.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net"
99
"net/netip"
1010
"os"
11+
"runtime"
1112
"time"
1213
"unsafe"
1314

@@ -95,7 +96,8 @@ func FindPid(network string, source netip.AddrPort) (uint32, error) {
9596
return 0, err
9697
}
9798
for _, row := range udpTable {
98-
if source == netip.AddrPortFrom(DwordToAddr(row.DwLocalAddr), DwordToPort(row.DwLocalPort)) {
99+
if source == netip.AddrPortFrom(DwordToAddr(row.DwLocalAddr), DwordToPort(row.DwLocalPort)) ||
100+
runtime.GOOS == "windows" && DwordToAddr(row.DwLocalAddr) == netip.IPv4Unspecified() && source.Port() == DwordToPort(row.DwLocalPort) {
99101
return row.DwOwningPid, nil
100102
}
101103
}
@@ -105,7 +107,8 @@ func FindPid(network string, source netip.AddrPort) (uint32, error) {
105107
return 0, err
106108
}
107109
for _, row := range udpTable {
108-
if source == netip.AddrPortFrom(netip.AddrFrom16(row.UcLocalAddr), DwordToPort(row.DwLocalPort)) {
110+
if source == netip.AddrPortFrom(netip.AddrFrom16(row.UcLocalAddr), DwordToPort(row.DwLocalPort)) ||
111+
runtime.GOOS == "windows" && netip.AddrFrom16(row.UcLocalAddr) == netip.IPv6Unspecified() && source.Port() == DwordToPort(row.DwLocalPort) {
109112
return row.DwOwningPid, nil
110113
}
111114
}

0 commit comments

Comments
 (0)