From d22f7a4c23f7d2ea881c36bea655ca08928c86f4 Mon Sep 17 00:00:00 2001 From: SohamM-Ibm <119834001+SohamM-Ibm@users.noreply.github.com> Date: Fri, 2 Aug 2024 16:14:12 +0530 Subject: [PATCH] fixes infer_defaults_to_first_non_loopback TC failure on s390x arch 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 --- userspace/libsinsp/test/ifinfo.ut.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/userspace/libsinsp/test/ifinfo.ut.cpp b/userspace/libsinsp/test/ifinfo.ut.cpp index 9aa8695c32..6b51bb81bb 100644 --- a/userspace/libsinsp/test/ifinfo.ut.cpp +++ b/userspace/libsinsp/test/ifinfo.ut.cpp @@ -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) @@ -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, @@ -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) {\