]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
sntp cleanup
authorHarlan Stenn <stenn@ntp.org>
Sat, 28 Nov 2009 06:43:01 +0000 (01:43 -0500)
committerHarlan Stenn <stenn@ntp.org>
Sat, 28 Nov 2009 06:43:01 +0000 (01:43 -0500)
bk: 4b10c675DdnIywGGr1FZuH-pn3-HLw

ChangeLog
sntp/main.c
sntp/networking.h
sntp/sntp-opts.def

index f1d4bf4d1c6cb46b25a6e9ee64ec8a35a4b7ef18..6761b65960c2cb275e60a83176ff99d3be1289ce 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+* 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.
index 8a440c953d6cd4a0fbb56c1dff3c7917af477e30..722f047e78f89bc1c232e8d8ed37fb1cfbf328ab 100644 (file)
@@ -116,7 +116,7 @@ sntp_main (
         * 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;
@@ -166,13 +166,14 @@ on_wire (
        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));
@@ -245,6 +246,8 @@ on_wire (
                        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);
@@ -257,9 +260,22 @@ on_wire (
                                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");
@@ -304,8 +320,14 @@ on_wire (
 
                        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))
@@ -368,12 +390,8 @@ set_time (
                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 {
@@ -385,11 +403,8 @@ set_time (
                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 {
index 811246a51978f5932444bf89ab3658c83635b681..4bfe70ba70d61ed00417370140f5385790516df7 100644 (file)
@@ -66,7 +66,7 @@ struct speer {
        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;
index 5b2d02c2b273b8371ef582e1f183a5a80ab477b5..676f846bf4d0aebf80b0740d19a8d34a278aa3cc 100644 (file)
@@ -131,6 +131,7 @@ flag = {
        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.
@@ -181,12 +182,13 @@ to query an NTP or SNTP server and either
 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;
 
@@ -197,85 +199,25 @@ the time or set the local system's time (given suitable privilege).  It can be
 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: