Skip to content

Commit

Permalink
Update Changes and example script
Browse files Browse the repository at this point in the history
  • Loading branch information
abh committed Jan 1, 2015
1 parent c4e017e commit d42b376
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
Revision history for Perl extension Net::NTP.

1.4 January 1, 2015
- Add calculated 'Offset' and 'Delay' to response
- Fix ntp originate timestamp to be NTP epoch's
- Minor tweaks to improve timeouts
- Lower default timeout to 5 seconds
- Tiny refactor; make sure Time::HiRes is loaded

1.3 June 4, 2011
- Use IO::Socket::INET6 if available (Martin v. Löwis, RT#38234)
- Don't reuse the "client timestamp" on all packets (Gordon M Lack, RT#38207)
Expand Down
20 changes: 1 addition & 19 deletions eg/test_ntp.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,15 @@
use Time::HiRes;

print "$Net::NTP::VERSION\n";
$Net::NTP::TIMEOUT = 20;
$Net::NTP::TIMEOUT = 4;

#my $time_then = $Net::NTP::CLIENT_TIME_SEND;
my $time_then = sprintf("%0.5f", Time::HiRes::time);
$Net::NTP::CLIENT_TIME_SEND = $time_then;
my %pkt = get_ntp_response(shift);
my $time_now = sprintf("%0.5f", Time::HiRes::time);
#my $time_now = time();
#my $time_now = $Net::NTP::CLIENT_TIME_RECEIVE;

while(my($k,$v) = each %pkt){
printf "%s = %s\n", $k, $v;
print scalar localtime($v),"\n" if $k =~ /Timestamp$/;
}

print "then: $time_then\tnow: $time_now\n";

my $dest_org = sprintf "%0.5f", ( ($time_now - $time_then) );
my $recv_trans = sprintf "%0.5f", ( $pkt{'Receive Timestamp'} - $pkt{'Transmit Timestamp'} );
my $delay = sprintf "%0.5f", ($dest_org + $recv_trans);

my $recv_org = sprintf "%0.5f", ( $pkt{'Receive Timestamp'} - $time_now );
my $trans_dest = sprintf "%0.5f", ( $pkt{'Transmit Timestamp'} - $time_then );
my $offset = sprintf "%0.5f", (($recv_org + $trans_dest) / 2);

print "Delay: $delay\n";
printf "Offset: %0.5f\n", $offset;
printf "Mode: %s\n", $Net::NTP::MODE{$pkt{'Mode'}};
printf "Stratum: %s\n", $Net::NTP::STRATUM{$pkt{'Stratum'}};
printf "Stratum One Text: %s\n",
Expand Down

0 comments on commit d42b376

Please sign in to comment.