Implement review suggestions

This commit is contained in:
Daniel
2020-04-20 13:57:07 +02:00
parent 033dceab5b
commit a33808685c
15 changed files with 90 additions and 61 deletions

View File

@@ -33,7 +33,7 @@ func GetPidOfConnection(localIP net.IP, localPort uint16, protocol uint8) (pid i
}
}
if !ok {
return -1, NoSocket
return unidentifiedProcessID, NoSocket
}
}
@@ -45,7 +45,7 @@ func GetPidOfConnection(localIP net.IP, localPort uint16, protocol uint8) (pid i
pid, ok = GetPidOfInode(uid, inode)
}
if !ok {
return -1, NoProcess
return unidentifiedProcessID, NoProcess
}
return
@@ -64,7 +64,7 @@ func GetPidOfIncomingConnection(localIP net.IP, localPort uint16, protocol uint8
}
if !ok {
return -1, NoSocket
return unidentifiedProcessID, NoSocket
}
}
@@ -76,7 +76,7 @@ func GetPidOfIncomingConnection(localIP net.IP, localPort uint16, protocol uint8
pid, ok = GetPidOfInode(uid, inode)
}
if !ok {
return -1, NoProcess
return unidentifiedProcessID, NoProcess
}
return

View File

@@ -7,6 +7,10 @@ import (
"net"
)
const (
unidentifiedProcessID = -1
)
// GetTCP4PacketInfo searches the network state tables for a TCP4 connection
func GetTCP4PacketInfo(localIP net.IP, localPort uint16, remoteIP net.IP, remotePort uint16, pktDirection bool) (pid int, direction bool, err error) {
return search(TCP4, localIP, localPort, pktDirection)
@@ -52,11 +56,11 @@ func search(protocol uint8, localIP net.IP, localPort uint16, pktDirection bool)
switch status {
case NoSocket:
return -1, direction, errors.New("could not find socket")
return unidentifiedProcessID, direction, errors.New("could not find socket")
case NoProcess:
return -1, direction, errors.New("could not find PID")
return unidentifiedProcessID, direction, errors.New("could not find PID")
default:
return -1, direction, nil
return unidentifiedProcessID, direction, nil
}
}

View File

@@ -77,7 +77,7 @@ func GetPidOfInode(uid, inode int) (int, bool) { //nolint:gocognit // TODO
}
}
return -1, false
return unidentifiedProcessID, false
}
func findSocketFromPid(pid, inode int) bool {

View File

@@ -100,7 +100,7 @@ func getConnectionSocket(localIP net.IP, localPort uint16, protocol uint8) (int,
socketData, err := os.Open(procFile)
if err != nil {
log.Warningf("process/proc: could not read %s: %s", procFile, err)
return -1, -1, false
return unidentifiedProcessID, unidentifiedProcessID, false
}
defer socketData.Close()
@@ -146,7 +146,7 @@ func getConnectionSocket(localIP net.IP, localPort uint16, protocol uint8) (int,
}
return -1, -1, false
return unidentifiedProcessID, unidentifiedProcessID, false
}
@@ -187,7 +187,7 @@ func getListeningSocket(localIP net.IP, localPort uint16, protocol uint8) (uid,
return data[0], data[1], true
}
return -1, -1, false
return unidentifiedProcessID, unidentifiedProcessID, false
}
func procDelimiter(c rune) bool {