Skip to content

Commit

Permalink
Add calculated 'Offset' and 'Delay' to response
Browse files Browse the repository at this point in the history
  • Loading branch information
abh committed Jan 1, 2015
1 parent f513f2e commit c4e017e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/Net/NTP.pm
Expand Up @@ -172,8 +172,9 @@ sub get_ntp_response {
};
alarm 0;

my $client_recvtime = time;

if (my $err = $@) {
warn "EVAL: $err";
return if $err =~ m/^Net::NTP timed out/;
die $err;
}
Expand Down Expand Up @@ -203,6 +204,18 @@ sub get_ntp_response {
(($tmp_pkt{trans_time} += $bin2frac->($tmp_pkt{trans_time_fb})) -= NTP_ADJ)
);

my $dest_org = sprintf "%0.5f", (($client_recvtime - $client_localtime));
my $recv_trans = sprintf "%0.5f", ($packet{'Receive Timestamp'} - $packet{'Transmit Timestamp'});
my $delay = sprintf "%0.5f", ($dest_org + $recv_trans);

my $recv_org = $packet{'Receive Timestamp'} - $client_recvtime;
my $trans_dest = $packet{'Transmit Timestamp'} - $client_localtime;
my $offset = ($recv_org + $trans_dest) / 2;

# Calculated offset / delay
$packet{Offset} = $offset;
$packet{Delay} = $delay;

return %packet;
}

Expand Down

0 comments on commit c4e017e

Please sign in to comment.