Skip to content

Commit

Permalink
fixes infer_defaults_to_first_non_loopback TC failure on s390x arch
Browse files Browse the repository at this point in the history
Modifying parse_ipv4_addr function to ensure that the IP address is correctly parsed and combined into a 32-bit integer of the correct byte order for Big-Endian systems.

Modifying the convert_to_string function to extract the bytes in the correct order for Big-Endian systems.

Signed-off-by: Soham Munshi <[email protected]>
  • Loading branch information
SohamM-Ibm authored and poiana committed Aug 5, 2024
1 parent 2e87063 commit d22f7a4
Showing 1 changed file with 15 additions and 0 deletions.
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

0 comments on commit d22f7a4

Please sign in to comment.