From 29904cbec615ab8aa882bd4fe4d60971de8db68b Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Tue, 27 Jan 2026 21:36:26 +0100 Subject: [PATCH] refactor: use union instead of bit shifting for echo header --- src/send/api/echo.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/send/api/echo.c b/src/send/api/echo.c index 1c30bd3..b0b0fe7 100644 --- a/src/send/api/echo.c +++ b/src/send/api/echo.c @@ -1,5 +1,4 @@ #include "icmp.h" -#include "internal/icmp_send.h" #include "icmp_types.h" #include @@ -7,11 +6,13 @@ int icmp_send_echo(icmp_handle_t *h, struct in_addr dest, uint16_t id, uint16_t seq, uint8_t ttl) { - if (0 == send_validate_handle(h)) - return -1; + union { + struct { uint16_t id; uint16_t seq; } echo; + uint32_t raw; + } hdr_rest; - uint32_t header_rest = (uint32_t)id | ((uint32_t)seq << 16); - - return icmp_send_raw(h, ICMP_TYPE_ECHO_REQUEST, 0, header_rest, + hdr_rest.echo.id = id; + hdr_rest.echo.seq = seq; + return icmp_send_raw(h, ICMP_TYPE_ECHO_REQUEST, 0, hdr_rest.raw, NULL, 0, dest, ttl); }