Skip to content

Commit

Permalink
Able to handle the case when there is only port data
Browse files Browse the repository at this point in the history
  • Loading branch information
JoukoVirtanen committed Oct 22, 2024
1 parent edf7ca3 commit 4b227bd
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions integration-tests/pkg/mock_sensor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,31 +501,28 @@ func (m *MockSensor) pushEndpoint(containerID string, endpoint *sensorAPI.Networ
// translateAddress is a helper function for converting binary representations
// of network addresses (in the signals) to usable forms for testing
func (m *MockSensor) translateAddress(addr *sensorAPI.NetworkAddress) string {
ipPortPair := utils.NetworkPeerID{}
address := utils.IPAddress{}
ipNetwork := utils.IPNetwork{}

addressData := addr.GetAddressData()
if len(addressData) > 0 {
address := utils.IPFromBytes(addressData)
ipPortPair = utils.NetworkPeerID{
Address: address,
Port: uint16(addr.GetPort()),
}
address = utils.IPFromBytes(addressData)
} else {
ipNetworkData := addr.GetIpNetwork()
if len(ipNetworkData) > 0 {
ipNetwork := utils.IPNetworkFromCIDRBytes(ipNetworkData)
ipNetwork = utils.IPNetworkFromCIDRBytes(ipNetworkData)
if ipNetwork.PrefixLen() == byte(32) {
address := ipNetwork.IP()
ipPortPair = utils.NetworkPeerID{
Address: address,
Port: uint16(addr.GetPort()),
}
} else {
ipPortPair = utils.NetworkPeerID{
IPNetwork: ipNetwork,
Port: uint16(addr.GetPort()),
}
address = ipNetwork.IP()
ipNetwork = utils.IPNetwork{}
}
}

}

ipPortPair := utils.NetworkPeerID{
Address: address,
IPNetwork: ipNetwork,
Port: uint16(addr.GetPort()),
}

return ipPortPair.String()
Expand Down

0 comments on commit 4b227bd

Please sign in to comment.