Skip to content

Commit

Permalink
add local receive timestamp to --icmp-timestamp
Browse files Browse the repository at this point in the history
This addresses GH issue schweikert#361.
  • Loading branch information
auerswal committed Dec 7, 2024
1 parent 8932ecd commit a5124e3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ci/test-04-options-a-b.pl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
}
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("");
}

Expand Down
4 changes: 2 additions & 2 deletions ci/test-05-options-c-e.pl
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
}
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+
Expand Down
30 changes: 28 additions & 2 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/************************************************************
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a5124e3

Please sign in to comment.