From 10a10f6e0aea1f9d3c8071354e7a0c5b7d08a7a9 Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Mon, 26 Jan 2026 20:11:15 +0100 Subject: [PATCH] fix: correct checksum byte order and use monotonic clock --- includes/icmp.h | 8 +++++++- src/packet/build.c | 3 ++- src/utils/time.c | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/includes/icmp.h b/includes/icmp.h index 883f2d5..5c36d3e 100644 --- a/includes/icmp.h +++ b/includes/icmp.h @@ -4,6 +4,7 @@ #include #include #include +#include #include /* Opaque handle type */ @@ -45,4 +46,9 @@ int icmp_process(icmp_handle_t *h, icmp_callback_t cb, void *userdata); const char *icmp_strerror(const icmp_handle_t *h); int icmp_should_retry(const icmp_handle_t *h); -#endif /* ICMP_H */ +/* Time helpers */ +int icmp_get_time(struct timespec *ts); +int64_t icmp_time_diff_ns(const struct timespec *start, + const struct timespec *end); + +#endif diff --git a/src/packet/build.c b/src/packet/build.c index 7a52dd5..280410e 100644 --- a/src/packet/build.c +++ b/src/packet/build.c @@ -3,6 +3,7 @@ #include "internal/icmp_utils.h" #include #include +#include /* Forward declarations */ static void write_icmp_header(struct icmp_header *hdr, uint8_t type, @@ -57,5 +58,5 @@ copy_payload(void *dest, const void *src, size_t len) static void compute_and_set_checksum(struct icmp_header *hdr, size_t total_len) { - hdr->checksum = icmp_checksum(hdr, total_len); + hdr->checksum = htons(icmp_checksum(hdr, total_len)); } diff --git a/src/utils/time.c b/src/utils/time.c index 0e8c123..006d770 100644 --- a/src/utils/time.c +++ b/src/utils/time.c @@ -4,7 +4,7 @@ int icmp_get_time(struct timespec *ts) { - if (0 != clock_gettime(CLOCK_REALTIME, ts)) + if (0 != clock_gettime(CLOCK_MONOTONIC, ts)) return -1; return 0; }