Skip to content
Snippets Groups Projects
Unverified Commit 178e6dcb authored by apevogoci's avatar apevogoci Committed by GitHub
Browse files

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

parent a405372f
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ func QuerySocketUidFromProcFs(source, _ net.Addr) int { ...@@ -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 { ...@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment