diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-12-02 09:01:21 +0000 |
---|---|---|
committer | <> | 2014-12-04 16:11:25 +0000 |
commit | bdab5265fcbf3f472545073a23f8999749a9f2b9 (patch) | |
tree | c6018dd03dea906f8f1fb5f105f05b71a7dc250a /scripts/ntptrace/ntptrace.in | |
download | ntp-bdab5265fcbf3f472545073a23f8999749a9f2b9.tar.gz |
Imported from /home/lorry/working-area/delta_ntp/ntp-dev-4.2.7p482.tar.gz.ntp-dev-4.2.7p482
Diffstat (limited to 'scripts/ntptrace/ntptrace.in')
-rwxr-xr-x | scripts/ntptrace/ntptrace.in | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/scripts/ntptrace/ntptrace.in b/scripts/ntptrace/ntptrace.in new file mode 100755 index 0000000..7cc5ce7 --- /dev/null +++ b/scripts/ntptrace/ntptrace.in @@ -0,0 +1,80 @@ +#! @PATH_PERL@ -w +# John Hay -- John.Hay@icomtek.csir.co.za / jhay@FreeBSD.org + +package ntptrace; +use 5.006_000; +use strict; +use lib "@PERLLIBDIR@"; +use NTP::Util qw(ntp_read_vars do_dns); + +exit run(@ARGV) unless caller; + +sub run { + my $opts; + if (!processOptions(\@_, $opts)) { + usage(1); + }; + + my $dodns = $opts->{numeric} ? 0 : 1; + my $max_hosts = $opts->{'max-hosts'}; + my $host = shift || $opts->{host}; + my $nb_host = 0; + + for (;;) { + $nb_host++; + + my %info = get_info($host); + last if not %info; + + my $dhost = $host; + if ($dodns) { + my $name = do_dns($host); + $dhost = $name if defined $name; + } + + printf "%s: stratum %d, offset %f, synch distance %f", + $dhost, $info{stratum}, $info{offset}, $info{syncdistance}; + printf ", refid '%s'", $info{refid} if $info{stratum} == 1; + print "\n"; + + last if $info{stratum} == 0 || $info{stratum} == 1 || + $info{stratum} == 16; + last if $info{refid} =~ /^127\.127\.\d{1,3}\.\d{1,3}$/; + last if $nb_host == $max_hosts; + + my $next_host = get_next_host($info{peer}, $host); + last if $next_host eq ''; + last if $next_host =~ /^127\.127\.\d{1,3}\.\d{1,3}$/; + + $host = $next_host; + } + return 0; +} + +sub get_info { + my ($host) = @_; + my ($rootdelay, $rootdisp, $info) = (0, 0); + + $info = ntp_read_vars(0, [], $host); + return if not defined $info; + return if not exists $info->{stratum}; + + $info->{offset} /= 1000; + $info->{syncdistance} = ($info->{rootdisp} + ($info->{rootdelay} / 2)) / 1000; + + return %$info; +} + + +sub get_next_host { + my ($peer, $host) = @_; + + my $info = ntp_read_vars($peer, [qw(srcadr)], $host); + return if not defined $info; + return $info->{srcadr}; +} + +@ntptrace_opts@ + +1; +__END__ |