Skip to content

Commit

Permalink
fix(userspace/libsinsp): restore windows build
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dellaluce <[email protected]>
  • Loading branch information
jasondellaluce authored and poiana committed Jan 30, 2024
1 parent 781ecf8 commit bfbc007
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
10 changes: 3 additions & 7 deletions userspace/libsinsp/ifinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ limitations under the License.
#include <string>
#include <vector>

#ifndef VISIBILITY_PRIVATE
#define VISIBILITY_PRIVATE private:
#endif

typedef struct scap_addrlist scap_addrlist;
typedef struct scap_ifinfo_ipv4 scap_ifinfo_ipv4;
typedef struct scap_ifinfo_ipv6 scap_ifinfo_ipv6;
Expand Down Expand Up @@ -85,13 +81,13 @@ class SINSP_PUBLIC sinsp_network_interfaces
std::vector<sinsp_ipv6_ifinfo>* get_ipv6_list();
inline void clear();

ipv6addr m_ipv6_loopback_addr;

VISIBILITY_PRIVATE
uint32_t infer_ipv4_address(uint32_t destination_address);
void import_ipv4_ifaddr_list(uint32_t count, scap_ifinfo_ipv4* plist);
ipv6addr infer_ipv6_address(ipv6addr &destination_address);
void import_ipv6_ifaddr_list(uint32_t count, scap_ifinfo_ipv6* plist);

private:
ipv6addr m_ipv6_loopback_addr;
std::vector<sinsp_ipv4_ifinfo> m_ipv4_interfaces;
std::vector<sinsp_ipv6_ifinfo> m_ipv6_interfaces;
};
Expand Down
16 changes: 7 additions & 9 deletions userspace/libsinsp/test/ifinfo.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ limitations under the License.
*/

#define VISIBILITY_PRIVATE

#include <libsinsp/sinsp.h>
#include <libsinsp/sinsp_int.h>
#include <libsinsp/ifinfo.h>
Expand Down Expand Up @@ -105,25 +103,25 @@ TEST(sinsp_network_interfaces, sip_and_dip_are_not_zero)
TEST(sinsp_network_interfaces, infer_finds_exact_match)
{
sinsp_network_interfaces interfaces;
interfaces.m_ipv4_interfaces.push_back(make_ipv4_localhost());
interfaces.m_ipv4_interfaces.push_back(make_ipv4_interface("192.168.22.149", "255.255.255.0", "192.168.22.255", "eth0"));
interfaces.get_ipv4_list()->push_back(make_ipv4_localhost());
interfaces.get_ipv4_list()->push_back(make_ipv4_interface("192.168.22.149", "255.255.255.0", "192.168.22.255", "eth0"));
EXPECT_ADDR_EQ("127.0.0.1",interfaces.infer_ipv4_address(parse_ipv4_addr("127.0.0.1")));
EXPECT_ADDR_EQ("192.168.22.149",interfaces.infer_ipv4_address(parse_ipv4_addr("192.168.22.149")));
}

TEST(sinsp_network_interfaces, infer_finds_same_subnet)
{
sinsp_network_interfaces interfaces;
interfaces.m_ipv4_interfaces.push_back(make_ipv4_localhost());
interfaces.m_ipv4_interfaces.push_back(make_ipv4_interface("192.168.22.149", "255.255.255.0", "192.168.22.255", "eth0"));
interfaces.get_ipv4_list()->push_back(make_ipv4_localhost());
interfaces.get_ipv4_list()->push_back(make_ipv4_interface("192.168.22.149", "255.255.255.0", "192.168.22.255", "eth0"));
EXPECT_ADDR_EQ("192.168.22.149",interfaces.infer_ipv4_address(parse_ipv4_addr("192.168.22.11")));
}

TEST(sinsp_network_interfaces, infer_defaults_to_first_non_loopback)
{
sinsp_network_interfaces interfaces;
interfaces.m_ipv4_interfaces.push_back(make_ipv4_localhost());
interfaces.m_ipv4_interfaces.push_back(make_ipv4_interface("192.168.22.149", "255.255.255.0", "192.168.22.255", "eth0"));
interfaces.m_ipv4_interfaces.push_back(make_ipv4_interface("192.168.22.150", "255.255.255.0", "192.168.22.255", "eth1"));
interfaces.get_ipv4_list()->push_back(make_ipv4_localhost());
interfaces.get_ipv4_list()->push_back(make_ipv4_interface("192.168.22.149", "255.255.255.0", "192.168.22.255", "eth0"));
interfaces.get_ipv4_list()->push_back(make_ipv4_interface("192.168.22.150", "255.255.255.0", "192.168.22.255", "eth1"));
EXPECT_ADDR_EQ("192.168.22.149",interfaces.infer_ipv4_address(parse_ipv4_addr("193.168.22.11")));
}

0 comments on commit bfbc007

Please sign in to comment.