+* sntp: documentation cleanup.
+* sntp: clean up some error messages.
+* sntp: Use the precision to control how many offset digits are shown.
+* sntp: Show root dispersion.
* Cleanup from the automake/autoconf upgrades.
(4.2.5p248-RC) 2009/11/26 Released by Harlan Stenn <stenn@ntp.org>
* Prepare for the generation of sntp.html.
* everything is initialized properly
*/
resc = resolve_hosts(argv, argc, &resh, ai_fam_pref);
-
+
if (resc < 1) {
printf("Unable to resolve hostname(s)\n");
return -1;
struct pkt x_pkt;
struct pkt r_pkt;
char *ref;
-
+
for(try=0; try<5; try++) {
struct timeval tv_xmt, tv_dst;
- double t21, t34, delta, offset;
- int error, rpktl, sw_case;
+ double t21, t34, delta, offset, precision, root_dispersion;
+ int digits, error, rpktl, sw_case;
char *hostname = NULL, *ts_str = NULL;
char *log_str;
+ u_fp p_rdly, p_rdsp;
l_fp p_rec, p_xmt, p_ref, p_org, xmt, tmp, dst;
memset(&r_pkt, 0, sizeof(r_pkt));
case 1:
/* Convert timestamps from network to host byte order */
+ p_rdly = NTOHS_FP(r_pkt.rootdelay);
+ p_rdsp = NTOHS_FP(r_pkt.rootdisp);
NTOHL_FP(&r_pkt.reftime, &p_ref);
NTOHL_FP(&r_pkt.org, &p_org);
NTOHL_FP(&r_pkt.rec, &p_rec);
printf("sntp on_wire: Received %i bytes from %s\n", rpktl, addr_buf);
}
+ precision = LOGTOD(r_pkt.precision);
#ifdef DEBUG
+ printf("sntp precision: %f\n", precision);
+#endif /* DEBUG */
+ for (digits = 0; (precision *= 10.) < 1.; ++digits) ;
+ if (digits > 6)
+ digits = 6;
+
+ root_dispersion = FPTOD(p_rdsp);
+
+#ifdef DEBUG
+ printf("sntp rootdelay: %f\n", FPTOD(p_rdly));
+ printf("sntp rootdisp: %f\n", root_dispersion);
+
pkt_output(&r_pkt, rpktl, stdout);
-
+
printf("sntp on_wire: r_pkt.reftime:\n");
l_fp_output(&(r_pkt.reftime), stdout);
printf("sntp on_wire: r_pkt.org:\n");
if(offset > 0)
printf("+");
-
- printf("%.3f\n", offset);
+
+ printf("%.*f", digits, offset);
+
+ if (root_dispersion > 0.)
+ printf(" +/- %f secs", root_dispersion);
+
+ printf("\n");
+
free(ts_str);
if(ENABLED_OPT(SETTOD) || ENABLED_OPT(ADJTIME))
tp.tv_usec += offset - (double)((int)offset);
if(SETTIMEOFDAY(&tp, (struct timezone *)NULL) < 0) {
- if(errno == EPERM)
- printf("set_time: You don't have enough priviledges to call settimeofday(), cannot set time!\n");
-
- else
- printf("set_time: settimeofday() returned with an error, couldn't set time!\n");
-
+ printf("set_time: settimeofday(): Time not set: %s\n",
+ strerror(errno));
return -1;
}
else {
tp.tv_usec = offset - (double)((int)offset);
if(ADJTIMEOFDAY(&tp, NULL) < 0) {
- if(errno == EPERM)
- printf("set_time: You don't have enough priviledges to call adjtime(), cannot set time!\n");
- else
- printf("set_time: adjtime() returned with an error, couldn't set time!\n");
-
+ printf("set_time: adjtime(): Time not set: %s\n",
+ strerror(errno));
return -1;
}
else {
u_char pmode;
u_char stratum;
u_char ppoll;
- u_char precision;
+ u_char precision; /* should be s_char */
u_int32 refid;
l_fp reftime;
keyid_t keyid;
value = t;
descrip = "Specify the number of seconds to wait for broadcasts";
arg-type = number;
+ arg-default = 68;
doc = <<- _EndOfDoc_
When waiting for a broadcast packet SNTP will wait the number
of seconds specified before giving up. Default 68 seconds.
display the time
or
set the local system's time (given suitable privilege).
+
It can be
run interactively from the command line or as a
.I cron
job.
-NTP and SNTP are defined by draft-ietf-ntp-ntpv4-proto-11, which
+NTP and SNTP are defined by draft-ietf-ntp-ntpv4-proto-13, which
obsoletes RFC 4330 and RFC 1305.
_END_DETAIL;
run as an interactive command or in a
.I cron
job.
-NTP is the Network Time Protocol (RFC 1305) and SNTP is the
-Simple Network Time Protocol (RFC 2030, which supersedes RFC 1769).
-.SS Options
-.PP
-.I sntp
-recognizes the following options:
-.TP
-.B \-v
-indicates that diagnostic messages for non-fatal errors and a limited amount of
-tracing should be written to standard error. Fatal ones always produce a
-diagnostic. This option should be set when there is a suspected problem with
-the server, network or the source.
-.TP
-.B \-V
-requests more and less comprehensible output, mainly for investigating problems
-with apparently inconsistent timestamps. This option should be set when the
-program fails with a message indicating that is the trouble.
-.TP
-.B \-W
-requests very verbose debugging output, and will interfere with the timing
-when writing to the terminal (because of line buffered output from C). Note
-that the times produced by this are the corrections needed, and not the error
-in the local clock. This option should be set only when debugging the source.
-.TP
-.B \-r
-indicates that the system clock should be reset by
-.IR settod .
-Naturally, this will work only if the user has enough privilege.
-.TP
-.B \-a
-indicates that the system clock should be reset by
-.IR adjtime .
-Naturally, this will work only if the user has enough privilege.
+
+NTP (the Network Time Protocol) and SNTP (the Simple Network Time Protocol)
+are defined and described by
+draft-ietf-ntp-ntpv4-proto-13,
+which should become a full RFC any month now.
+
.PP
The default is to write the estimated correct local date and time (i.e. not
UTC) to the standard output in a format like
.BR "'1996 Oct 15 20:17:25.123 + 4.567 +/- 0.089 secs'" ,
where the
.B "'+ 4.567 +/- 0.089 secs'"
-indicates the estimated error in the time on the local system.
-.TP
-.BI \-l " lockfile"
-sets the name of the lock file to ensure that there is only
-one copy of
-.I sntp
-running at once. The default is installation-dependent, but will usually be
-.IR /etc/sntp.pid .
-.TP
-.BI \-c " count"
-sets the maximum number of NTP packets required to
-.IR count .
-Acceptable values are from 1 to 25 if a NTP host is specified and from 5 to 25
-otherwise, and the default is 5. If the maximum isn't enough, the system needs
-a better consistency algorithm than this program uses.
-.TP
-.B -4
-force IPv4 DNS resolution.
-.TP
-.B -6
-force IPv6 DNS resolution.
-.PP
-.B address(es)
-are the DNS names or IP numbers of hosts to use for the challenge and response
-protocol; if no names are given, the program waits for broadcasts. Polling a
-server is vastly more reliable than listening to broadcasts. Note that a
-single component numeric address is not allowed, to avoid ambiguities. If
-more than one name is give, they will be used in a round-robin fashion.
-.PP
-Constraints:
-.IP
-.BR delay / count "),"
-and
-.B count
-must be less than half of
-.BR delay .
-.IP
-In update mode,
-.B maxerr
-must be less than
+indicates the local clock is 4.567 seconds behind the correct time
+(so 4.567 seconds must be added to the local clock to get it to be correct),
+and the time of
+'1996 Oct 15 20:17:25.123'
+is believed to be correct to within
++/- 0.089
+seconds.
.SH USAGE
The simplest use of this program is as an unprivileged command to check the
current time and error in the local clock. For example: