From: Erik Auerswald Date: Sat, 30 Nov 2024 19:15:20 +0000 (+0100) Subject: add local receive timestamp to --icmp-timestamp X-Git-Url: https://git.gsnw.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5124e35d07cc5b244287ea10c2a59a321b26fdf;p=fping.git add local receive timestamp to --icmp-timestamp This addresses GH issue #361. --- diff --git a/ci/test-04-options-a-b.pl b/ci/test-04-options-a-b.pl index b9c0fe4..f9e3c09 100755 --- a/ci/test-04-options-a-b.pl +++ b/ci/test-04-options-a-b.pl @@ -91,7 +91,7 @@ if($^O eq 'darwin') { } my $cmd = Test::Command->new(cmd => "fping --icmp-timestamp 127.0.0.1"); $cmd->exit_is_num(0); -$cmd->stdout_like(qr{127\.0\.0\.1 is alive \(Timestamp Originate=\d+ Receive=\d+ Transmit=\d+\)}); +$cmd->stdout_like(qr{127\.0\.0\.1 is alive \(Timestamp Originate=\d+ Receive=\d+ Transmit=\d+ Localreceive=\d+\)}); $cmd->stderr_is_eq(""); } diff --git a/ci/test-05-options-c-e.pl b/ci/test-05-options-c-e.pl index fc1d387..9e7825d 100755 --- a/ci/test-05-options-c-e.pl +++ b/ci/test-05-options-c-e.pl @@ -84,8 +84,8 @@ if($^O eq 'darwin') { } my $cmd = Test::Command->new(cmd => "fping -4 --icmp-timestamp -c 2 127.0.0.1"); $cmd->exit_is_num(0); -$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 20 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\), ICMP timestamp: Originate=\d+ Receive=\d+ Transmit=\d+ -127\.0\.0\.1 : \[1\], 20 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\), ICMP timestamp: Originate=\d+ Receive=\d+ Transmit=\d+ +$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 20 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\), ICMP timestamp: Originate=\d+ Receive=\d+ Transmit=\d+ Localreceive=\d+ +127\.0\.0\.1 : \[1\], 20 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\), ICMP timestamp: Originate=\d+ Receive=\d+ Transmit=\d+ Localreceive=\d+ }); $cmd->stderr_like(qr{127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+ diff --git a/src/fping.c b/src/fping.c index 7f26ad9..90a91a9 100644 --- a/src/fping.c +++ b/src/fping.c @@ -411,6 +411,7 @@ struct event *host_get_timeout_event(HOST_ENTRY *h, int index); void stats_add(HOST_ENTRY *h, int index, int success, int64_t latency); void update_current_time(); void print_timestamp_format(int64_t current_time_ns, int timestamp_format); +static uint32_t ms_since_midnight_utc(int64_t time_val); /************************************************************ @@ -2593,7 +2594,9 @@ int wait_for_reply(int64_t wait_time) } if (icmp_request_typ == 13) { - printf(" (Timestamp Originate=%u Receive=%u Transmit=%u)", ip_header_otime_ms, ip_header_rtime_ms, ip_header_ttime_ms); + printf(" (Timestamp Originate=%u Receive=%u Transmit=%u Localreceive=%u)", + ip_header_otime_ms, ip_header_rtime_ms, ip_header_ttime_ms, + ms_since_midnight_utc(recv_time)); } if (elapsed_flag) @@ -2635,7 +2638,9 @@ int wait_for_reply(int64_t wait_time) } if (icmp_request_typ == 13) { - printf(", ICMP timestamp: Originate=%u Receive=%u Transmit=%u", ip_header_otime_ms, ip_header_rtime_ms, ip_header_ttime_ms); + printf(", ICMP timestamp: Originate=%u Receive=%u Transmit=%u Localreceive=%u", + ip_header_otime_ms, ip_header_rtime_ms, ip_header_ttime_ms, + ms_since_midnight_utc(recv_time)); } printf("\n"); @@ -3101,6 +3106,27 @@ void print_timestamp_format(int64_t current_time_ns, int timestamp_format) } } +/************************************************************ + + Function: ms_since_midnight_utc + +************************************************************* + + Input: int64_t: current UTC time in ns + + Output: uint32_t: current time in ms since midnight UTC + + Description: + + Return ICMP Timestamp value corresponding to the given time value. + The given time value must be in UTC. + +*************************************************************/ +static uint32_t ms_since_midnight_utc(int64_t time_val) +{ + return (uint32_t)((time_val / 1000000) % (24 * 60 * 60 * 1000)); +} + /************************************************************ Function: usage