Fix: macOS Ventura process name match

This commit is contained in:
gVisor bot 2022-10-27 11:25:18 +08:00
parent 3fda9ed896
commit 1bd2fabe77

View file

@ -3,6 +3,8 @@ package process
import ( import (
"encoding/binary" "encoding/binary"
"net" "net"
"strconv"
"strings"
"syscall" "syscall"
"unsafe" "unsafe"
@ -15,6 +17,22 @@ const (
proccallnumpidinfo = 0x2 proccallnumpidinfo = 0x2
) )
var structSize = func() int {
value, _ := syscall.Sysctl("kern.osproductversion")
major, _, _ := strings.Cut(value, ".")
n, _ := strconv.ParseInt(major, 10, 64)
switch true {
case n >= 13:
return 408
default:
// from darwin-xnu/bsd/netinet/in_pcblist.c:get_pcblist_n
// size/offset are round up (aligned) to 8 bytes in darwin
// rup8(sizeof(xinpcb_n)) + rup8(sizeof(xsocket_n)) +
// 2 * rup8(sizeof(xsockbuf_n)) + rup8(sizeof(xsockstat_n))
return 384
}
}()
func findProcessName(network string, ip net.IP, port int) (string, error) { func findProcessName(network string, ip net.IP, port int) (string, error) {
var spath string var spath string
switch network { switch network {
@ -34,12 +52,7 @@ func findProcessName(network string, ip net.IP, port int) (string, error) {
} }
buf := []byte(value) buf := []byte(value)
itemSize := structSize
// from darwin-xnu/bsd/netinet/in_pcblist.c:get_pcblist_n
// size/offset are round up (aligned) to 8 bytes in darwin
// rup8(sizeof(xinpcb_n)) + rup8(sizeof(xsocket_n)) +
// 2 * rup8(sizeof(xsockbuf_n)) + rup8(sizeof(xsockstat_n))
itemSize := 384
if network == TCP { if network == TCP {
// rup8(sizeof(xtcpcb_n)) // rup8(sizeof(xtcpcb_n))
itemSize += 208 itemSize += 208