#include #include #include #include "internal/icmp_send.h" /* Test 1: Basic destination preparation */ Test(send_prepare_destination, basic) { struct sockaddr_in addr; struct in_addr dest; dest.s_addr = inet_addr("192.168.1.1"); send_prepare_destination(&addr, dest); cr_assert_eq(addr.sin_family, AF_INET, "Family should be AF_INET"); cr_assert_eq(addr.sin_addr.s_addr, dest.s_addr, "Address should match destination"); } /* Test 2: Verify sin_port is 0 for ICMP */ Test(send_prepare_destination, port_is_zero) { struct sockaddr_in addr; struct in_addr dest; dest.s_addr = inet_addr("127.0.0.1"); send_prepare_destination(&addr, dest); cr_assert_eq(addr.sin_port, 0, "Port should be 0 for ICMP"); } /* Test 3: Verify struct is zeroed */ Test(send_prepare_destination, struct_zeroed) { struct sockaddr_in addr; memset(&addr, 0xFF, sizeof(addr)); /* Fill with garbage */ struct in_addr dest; dest.s_addr = inet_addr("10.0.0.1"); send_prepare_destination(&addr, dest); /* Check sin_zero is zeroed */ for (size_t i = 0; i < sizeof(addr.sin_zero); i++) { cr_assert_eq(addr.sin_zero[i], 0, "sin_zero[%zu] should be 0", i); } } /* Test 4: Localhost address */ Test(send_prepare_destination, localhost) { struct sockaddr_in addr; struct in_addr dest; dest.s_addr = inet_addr("127.0.0.1"); send_prepare_destination(&addr, dest); cr_assert_eq(addr.sin_addr.s_addr, inet_addr("127.0.0.1"), "Should handle localhost"); }