Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(sinsp): Fix infer_defaults_to_first_non_loopback TC #1989

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions userspace/libsinsp/test/ifinfo.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ 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);
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
return d << 24 | c << 16 | b << 8 | a;
#else
return d | c << 8 | b << 16 | a << 24;
#endif
}

static uint32_t parse_ipv4_netmask(const char *dotted_notation)
Expand Down Expand Up @@ -56,6 +60,7 @@ static sinsp_ipv4_ifinfo make_ipv4_localhost()

static void convert_to_string(char* dest, size_t len, uint32_t addr)
{
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
snprintf(
dest,
len,
Expand All @@ -64,6 +69,16 @@ static void convert_to_string(char* dest, size_t len, uint32_t addr)
((addr & 0xFF00) >> 8),
((addr & 0xFF0000) >> 16),
((addr & 0xFF000000) >> 24));
#else
snprintf(
dest,
len,
"%d.%d.%d.%d",
((addr >> 24) & 0xFF),
((addr >> 16) & 0xFF),
((addr >> 8) & 0xFF),
(addr & 0xFF));
#endif
}

#define EXPECT_ADDR_EQ(dotted_notation,addr) {\
Expand Down
Loading