]> git.gsnw.org Git - fping.git/commitdiff
add local receive timestamp to --icmp-timestamp
authorErik Auerswald <auerswal@unix-ag.uni-kl.de>
Sat, 30 Nov 2024 19:15:20 +0000 (20:15 +0100)
committerErik Auerswald <auerswal@unix-ag.uni-kl.de>
Sat, 7 Dec 2024 19:04:17 +0000 (20:04 +0100)
This addresses GH issue #361.

ci/test-04-options-a-b.pl
ci/test-05-options-c-e.pl
src/fping.c

index b9c0fe4e5d757b9ef158f6e4acd2248a40b9cac9..f9e3c09eb789c88c4f6f9ad78fe83a828a1339a3 100755 (executable)
@@ -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("");
 }
 
index fc1d387e695a87701ecc6b268611a6aa7b75629b..9e7825d6f46402cec80a4168a5dfe87ac37991f5 100755 (executable)
@@ -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+
index 7f26ad9aa7947c2715be687d8d6f0fbc6e164195..90a91a96203d09beaf11410c96d2b79d25a9b5e3 100644 (file)
@@ -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