2 # John Hay -- John.Hay@icomtek.csir.co.za / jhay@FreeBSD.org
7 use lib "@PERLLIBDIR@";
8 use NTP::Util qw(ntp_read_vars do_dns);
10 exit run(@ARGV) unless caller;
14 if (!processOptions(\@_, $opts)) {
18 my $dodns = $opts->{numeric} ? 0 : 1;
19 my $max_hosts = $opts->{'max-hosts'};
20 my $host = shift || $opts->{host};
26 my %info = get_info($host);
31 my $name = do_dns($host);
32 $dhost = $name if defined $name;
35 printf "%s: stratum %d, offset %f, synch distance %f",
36 $dhost, $info{stratum}, $info{offset}, $info{syncdistance};
37 printf ", refid '%s'", $info{refid} if $info{stratum} == 1;
40 last if $info{stratum} == 0 || $info{stratum} == 1 ||
42 last if $info{refid} =~ /^127\.127\.\d{1,3}\.\d{1,3}$/;
43 last if $nb_host == $max_hosts;
45 my $next_host = get_next_host($info{peer}, $host);
46 last if $next_host eq '';
47 last if $next_host =~ /^127\.127\.\d{1,3}\.\d{1,3}$/;
56 my ($rootdelay, $rootdisp, $info) = (0, 0);
58 $info = ntp_read_vars(0, [], $host);
59 return if not defined $info;
60 return if not exists $info->{stratum};
62 $info->{offset} /= 1000;
63 $info->{syncdistance} = ($info->{rootdisp} + ($info->{rootdelay} / 2)) / 1000;
70 my ($peer, $host) = @_;
72 my $info = ntp_read_vars($peer, [qw(srcadr)], $host);
73 return if not defined $info;
74 return $info->{srcadr};