Skip to content

Commit

Permalink
fix(userspace/libsinsp): solve compilation issues with ifinfo tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dellaluce <[email protected]>
  • Loading branch information
jasondellaluce committed Jan 29, 2024
1 parent 4fb6109 commit ee1dbbb
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions userspace/libsinsp/test/ifinfo.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ limitations under the License.
*/

#define VISIBILITY_PRIVATE

#include <libsinsp/sinsp.h>
#include <libsinsp/sinsp_int.h>
#include <libsinsp/ifinfo.h>

#include <gtest/gtest.h>


uint32_t parse_ipv4_addr(const char *dotted_notation)
static uint32_t parse_ipv4_addr(const char *dotted_notation)
{
uint32_t a, b, c, d;
sscanf(dotted_notation, "%d.%d.%d.%d", &a, &b, &c, &d);
return d << 24 | c << 16 | b << 8 | a;
}

uint32_t parse_ipv4_netmask(const char *dotted_notation)
static uint32_t parse_ipv4_netmask(const char *dotted_notation)
{
return parse_ipv4_addr(dotted_notation);
}

uint32_t parse_ipv4_broadcast(const char *dotted_notation)
static uint32_t parse_ipv4_broadcast(const char *dotted_notation)
{
return parse_ipv4_addr(dotted_notation);
}

sinsp_ipv4_ifinfo make_ipv4_interface(const char *addr, const char *netmask, const char* broadcast, const char *name)
static sinsp_ipv4_ifinfo make_ipv4_interface(const char *addr, const char *netmask, const char* broadcast, const char *name)
{
return sinsp_ipv4_ifinfo(
parse_ipv4_addr(addr),
Expand All @@ -50,13 +50,13 @@ sinsp_ipv4_ifinfo make_ipv4_interface(const char *addr, const char *netmask, con
name);
}

sinsp_ipv4_ifinfo make_ipv4_localhost()
static sinsp_ipv4_ifinfo make_ipv4_localhost()
{
return make_ipv4_interface("127.0.0.1", "255.0.0.0", "127.0.0.1", "lo");
}


void convert_to_string(char* dest, size_t len, uint32_t addr)
static void convert_to_string(char* dest, size_t len, uint32_t addr)
{
snprintf(
dest,
Expand All @@ -68,8 +68,6 @@ void convert_to_string(char* dest, size_t len, uint32_t addr)
((addr & 0xFF000000) >> 24));
}



#define EXPECT_ADDR_EQ(dotted_notation,addr) {\
char buf[17];\
convert_to_string(buf, sizeof(buf), addr);\
Expand All @@ -88,7 +86,7 @@ TEST(sinsp_network_interfaces, socket_is_of_wrong_type)
{
sinsp_fdinfo fd;
fd.m_type = SCAP_FD_IPV4_SOCK;
fd.m_info.m_ipv4info.m_fields.m_l4proto = SCAP_L4_TCP;
fd.m_sockinfo.m_ipv4info.m_fields.m_l4proto = SCAP_L4_TCP;
sinsp_network_interfaces interfaces;
interfaces.update_fd(fd);
}
Expand All @@ -97,9 +95,9 @@ TEST(sinsp_network_interfaces, sip_and_dip_are_not_zero)
{
sinsp_fdinfo fd;
fd.m_type = SCAP_FD_IPV4_SOCK;
fd.m_info.m_ipv4info.m_fields.m_l4proto = SCAP_L4_UDP;
fd.m_info.m_ipv4info.m_fields.m_sip = 1;
fd.m_info.m_ipv4info.m_fields.m_dip = 1;
fd.m_sockinfo.m_ipv4info.m_fields.m_l4proto = SCAP_L4_UDP;
fd.m_sockinfo.m_ipv4info.m_fields.m_sip = 1;
fd.m_sockinfo.m_ipv4info.m_fields.m_dip = 1;
sinsp_network_interfaces interfaces;
interfaces.update_fd(fd);
}
Expand Down

0 comments on commit ee1dbbb

Please sign in to comment.