Explorar o código

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

apevogoci %!s(int64=3) %!d(string=hai) anos
pai
achega
d753ca7225
Modificáronse 1 ficheiros con 15 adicións e 7 borrados
  1. 15 7
      core/src/main/golang/native/platform/procfs.go

+ 15 - 7
core/src/main/golang/native/platform/procfs.go

@@ -26,7 +26,7 @@ func QuerySocketUidFromProcFs(source, _ net.Addr) int {
 
 	network := source.Network()
 
-	if strings.HasSuffix(network, "4") {
+	if strings.HasSuffix(network, "4") || strings.HasSuffix(network, "6") {
 		network = network[:len(network)-1]
 	}
 
@@ -46,16 +46,24 @@ func QuerySocketUidFromProcFs(source, _ net.Addr) int {
 		return -1
 	}
 
-	if strings.HasSuffix(source.Network(), "6") {
-		sIP = sIP.To16()
-	} else {
-		sIP = sIP.To4()
-	}
-
+	sIP = sIP.To16()
 	if sIP == nil {
 		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)
 	if err != nil {
 		return -1