Improve: Try tcp6&udp6 files first when search UID for connection (#1514)

This commit is contained in:
apevogoci 2022-07-01 06:14:50 +03:00 committed by djoeni
parent a0cdb8acbe
commit d753ca7225

View File

@ -26,7 +26,7 @@ func QuerySocketUidFromProcFs(source, _ net.Addr) int {
network := source.Network() network := source.Network()
if strings.HasSuffix(network, "4") { if strings.HasSuffix(network, "4") || strings.HasSuffix(network, "6") {
network = network[:len(network)-1] network = network[:len(network)-1]
} }
@ -46,16 +46,24 @@ func QuerySocketUidFromProcFs(source, _ net.Addr) int {
return -1 return -1
} }
if strings.HasSuffix(source.Network(), "6") { sIP = sIP.To16()
sIP = sIP.To16()
} else {
sIP = sIP.To4()
}
if sIP == nil { if sIP == nil {
return -1 return -1
} }
uid := doQuery(path+"6", sIP, sPort)
if uid == -1 {
sIP = sIP.To4()
if sIP == nil {
return -1
}
uid = doQuery(path, sIP, sPort)
}
return uid
}
func doQuery(path string, sIP net.IP, sPort int) int {
file, err := os.Open(path) file, err := os.Open(path)
if err != nil { if err != nil {
return -1 return -1