fix: correct checksum byte order and use monotonic clock
This commit is contained in:
parent
8fb109e2a0
commit
10a10f6e0a
3 changed files with 10 additions and 3 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
/* 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
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "internal/icmp_utils.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
/* 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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue