Skip to content

Commit b5cd6b6

Browse files
committed
Initial commit
0 parents  commit b5cd6b6

9 files changed

Lines changed: 268 additions & 0 deletions

File tree

usr/bin/ntp-keygen

250 KB
Binary file not shown.

usr/bin/ntpq

372 KB
Binary file not shown.

usr/bin/sntp

445 KB
Binary file not shown.

usr/sbin/ntp-wait

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#! /usr/bin/perl
2+
3+
package ntp_wait;
4+
use 5.006_000;
5+
use strict;
6+
use warnings;
7+
use lib "/usr/share/ntp/lib";
8+
use NTP::Util qw(ntp_read_vars);
9+
10+
exit run(@ARGV) unless caller;
11+
12+
sub run {
13+
my $opts;
14+
if (!processOptions(\@_, $opts)) {
15+
usage(1);
16+
};
17+
18+
my $tries = $opts->{tries}; # How many tries before we give up? (10 min+)
19+
my $sleep = $opts->{sleep}; # Seconds to sleep between tries (6s = 10/min)
20+
my $verbose = $opts->{verbose}; # Be verbose?
21+
22+
# Autoflush stdout
23+
$| = 1;
24+
25+
print "Waiting for ntpd to synchronize... " if $verbose;
26+
27+
for my $i (1 .. $tries) {
28+
my $info = ntp_read_vars(0, []);
29+
30+
if (!defined $info) {
31+
print "\bntpd is not running!\n" if $verbose;
32+
return 1;
33+
}
34+
35+
if (!exists $info->{status_line}{leap}) {
36+
print "\bLeap status not avalaible\n";
37+
return 1;
38+
}
39+
40+
my $leap = $info->{status_line}{leap};
41+
my $sync = $info->{status_line}{sync};
42+
43+
if ($leap =~ /(sync|leap)_alarm/) {
44+
print "\b".(substr "*+:.", $i % 4, 1) if $verbose;
45+
sleep $sleep if $i < $tries;
46+
next;
47+
}
48+
49+
if ($leap =~ /leap_(none|((add|del)_sec))/) {
50+
# We could check $sync here to make sure we like the source...
51+
print "\bOK!\n" if $verbose;
52+
return 0;
53+
}
54+
55+
print "\bUnexpected 'leap' status <$leap>\n";
56+
return 1;
57+
}
58+
59+
print "\bNo!\nntpd did not synchronize.\n" if $verbose;
60+
return 1;
61+
}
62+
63+
# EDIT THIS FILE WITH CAUTION (ntp-wait-opts)
64+
#
65+
# It has been AutoGen-ed December 19, 2014 at 07:44:43 AM by AutoGen 5.18.5pre4
66+
# From the definitions ntp-wait-opts.def
67+
# and the template file perlopt
68+
69+
use Getopt::Long qw(GetOptionsFromArray);
70+
Getopt::Long::Configure(qw(no_auto_abbrev no_ignore_case_always));
71+
72+
my $usage;
73+
74+
sub usage {
75+
my ($ret) = @_;
76+
print STDERR $usage;
77+
exit $ret;
78+
}
79+
80+
sub paged_usage {
81+
my ($ret) = @_;
82+
my $pager = $ENV{PAGER} || '(less || more)';
83+
84+
open STDOUT, "| $pager" or die "Can't fork a pager: $!";
85+
print $usage;
86+
87+
exit $ret;
88+
}
89+
90+
sub processOptions {
91+
my $args = shift;
92+
93+
my $opts = {
94+
'tries' => '100',
95+
'sleep' => '6',
96+
'verbose' => '',
97+
'help' => '', 'more-help' => ''
98+
};
99+
my $argument = '';
100+
my $ret = GetOptionsFromArray($args, $opts, (
101+
'tries|n=i', 'sleep|s=i', 'verbose|v',
102+
'help|?', 'more-help'));
103+
104+
$usage = <<'USAGE';
105+
ntp-wait - Wait for ntpd to stabilize the system clock - Ver. 4.2.8
106+
USAGE: ntp-wait [ -<flag> [<val>] | --<name>[{=| }<val>] ]...
107+
108+
-n, --tries=num Number of times to check ntpd
109+
-s, --sleep=num How long to sleep between tries
110+
-v, --verbose Be verbose
111+
-?, --help Display usage information and exit
112+
--more-help Pass the extended usage text through a pager
113+
114+
Options are specified by doubled hyphens and their name or by a single
115+
hyphen and the flag character.
116+
USAGE
117+
118+
usage(0) if $opts->{'help'};
119+
paged_usage(0) if $opts->{'more-help'};
120+
$_[0] = $opts;
121+
return $ret;
122+
}
123+
124+
END { close STDOUT };
125+
126+
1;
127+
__END__

usr/sbin/ntpd

810 KB
Binary file not shown.

usr/sbin/ntpdate

178 KB
Binary file not shown.

usr/sbin/ntpdc

336 KB
Binary file not shown.

usr/sbin/ntpsnmpd

382 KB
Binary file not shown.

usr/sbin/ntptrace

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#! /usr/bin/perl -w
2+
# John Hay -- John.Hay@icomtek.csir.co.za / jhay@FreeBSD.org
3+
4+
package ntptrace;
5+
use 5.006_000;
6+
use strict;
7+
use lib "/usr/share/ntp/lib";
8+
use NTP::Util qw(ntp_read_vars do_dns);
9+
10+
exit run(@ARGV) unless caller;
11+
12+
sub run {
13+
my $opts;
14+
if (!processOptions(\@_, $opts)) {
15+
usage(1);
16+
};
17+
18+
my $dodns = $opts->{numeric} ? 0 : 1;
19+
my $max_hosts = $opts->{'max-hosts'};
20+
my $host = shift || $opts->{host};
21+
my $nb_host = 0;
22+
23+
for (;;) {
24+
$nb_host++;
25+
26+
my %info = get_info($host);
27+
last if not %info;
28+
29+
my $dhost = $host;
30+
if ($dodns) {
31+
my $name = do_dns($host);
32+
$dhost = $name if defined $name;
33+
}
34+
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;
38+
print "\n";
39+
40+
last if $info{stratum} == 0 || $info{stratum} == 1 ||
41+
$info{stratum} == 16;
42+
last if $info{refid} =~ /^127\.127\.\d{1,3}\.\d{1,3}$/;
43+
last if $nb_host == $max_hosts;
44+
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}$/;
48+
49+
$host = $next_host;
50+
}
51+
return 0;
52+
}
53+
54+
sub get_info {
55+
my ($host) = @_;
56+
my ($rootdelay, $rootdisp, $info) = (0, 0);
57+
58+
$info = ntp_read_vars(0, [], $host);
59+
return if not defined $info;
60+
return if not exists $info->{stratum};
61+
62+
$info->{offset} /= 1000;
63+
$info->{syncdistance} = ($info->{rootdisp} + ($info->{rootdelay} / 2)) / 1000;
64+
65+
return %$info;
66+
}
67+
68+
69+
sub get_next_host {
70+
my ($peer, $host) = @_;
71+
72+
my $info = ntp_read_vars($peer, [qw(srcadr)], $host);
73+
return if not defined $info;
74+
return $info->{srcadr};
75+
}
76+
77+
# EDIT THIS FILE WITH CAUTION (ntptrace-opts)
78+
#
79+
# It has been AutoGen-ed December 19, 2014 at 07:45:02 AM by AutoGen 5.18.5pre4
80+
# From the definitions ntptrace-opts.def
81+
# and the template file perlopt
82+
83+
use Getopt::Long qw(GetOptionsFromArray);
84+
Getopt::Long::Configure(qw(no_auto_abbrev no_ignore_case_always));
85+
86+
my $usage;
87+
88+
sub usage {
89+
my ($ret) = @_;
90+
print STDERR $usage;
91+
exit $ret;
92+
}
93+
94+
sub paged_usage {
95+
my ($ret) = @_;
96+
my $pager = $ENV{PAGER} || '(less || more)';
97+
98+
open STDOUT, "| $pager" or die "Can't fork a pager: $!";
99+
print $usage;
100+
101+
exit $ret;
102+
}
103+
104+
sub processOptions {
105+
my $args = shift;
106+
107+
my $opts = {
108+
'numeric' => '',
109+
'max-hosts' => '99',
110+
'host' => '127.0.0.1',
111+
'help' => '', 'more-help' => ''
112+
};
113+
my $argument = '[host]';
114+
my $ret = GetOptionsFromArray($args, $opts, (
115+
'numeric|n', 'max-hosts|m=i', 'host|r=s',
116+
'help|?', 'more-help'));
117+
118+
$usage = <<'USAGE';
119+
ntptrace - Trace peers of an NTP server - Ver. 4.2.8
120+
USAGE: ntptrace [ -<flag> [<val>] | --<name>[{=| }<val>] ]... [host]
121+
122+
-n, --numeric Print IP addresses instead of hostnames
123+
-m, --max-hosts=num Maximum number of peers to trace
124+
-r, --host=str Single remote host
125+
-?, --help Display usage information and exit
126+
--more-help Pass the extended usage text through a pager
127+
128+
Options are specified by doubled hyphens and their name or by a single
129+
hyphen and the flag character.
130+
USAGE
131+
132+
usage(0) if $opts->{'help'};
133+
paged_usage(0) if $opts->{'more-help'};
134+
$_[0] = $opts;
135+
return $ret;
136+
}
137+
138+
END { close STDOUT };
139+
140+
1;
141+
__END__

0 commit comments

Comments
 (0)