xref: /netbsd-src/external/bsd/ntp/dist/sntp/invoke-sntp.texi (revision 8585484ef87f5a04d32332313cdb799625f4faf8)
1@node sntp Invocation
2@section Invoking sntp
3@pindex sntp
4@cindex standard Simple Network Time Protocol client program
5@ignore
6#
7# EDIT THIS FILE WITH CAUTION  (invoke-sntp.texi)
8#
9# It has been AutoGen-ed  December 24, 2013 at 11:40:00 AM by AutoGen 5.18.3pre5
10# From the definitions    sntp-opts.def
11# and the template file   agtexi-cmd.tpl
12@end ignore
13
14
15
16@code{sntp}
17can be used as an SNTP client to query a NTP or SNTP server and either display
18the time or set the local system's time (given suitable privilege).  It can be
19run as an interactive command or from a
20@code{cron}
21job.
22
23NTP (the Network Time Protocol) and SNTP (the Simple Network Time Protocol)
24are defined and described by RFC 5905.
25
26
27The default is to write the estimated correct local date and time (i.e. not
28UTC) to the standard output in a format like:
29
30@code{'1996-10-15 20:17:25.123 (+0800) +4.567 +/- 0.089 [host] IP sN'}
31
32where the
33@code{'(+0800)'}
34means that to get to UTC from the reported local time one must
35add 8 hours and 0 minutes,
36the
37@code{'+4.567'}
38indicates the local clock is 4.567 seconds behind the correct time
39(so 4.567 seconds must be added to the local clock to get it to be correct).
40Note that the number of decimals printed for this value will change
41based on the reported precision of the server.
42@code{'+/- 0.089'}
43is the reported
44@emph{synchronization} @emph{distance}
45(in seconds), which represents the maximum error due to all causes.
46If the server does not report valid data needed to calculate the
47synchronization distance, this will be reported as
48@code{'+/- ?'}.
49If the
50@emph{host}
51is different from the
52@emph{IP},
53both will be displayed.
54Otherwise, only the
55@emph{IP}
56is displayed.
57Finally, the
58@emph{stratum}
59of the host is reported.
60
61This section was generated by @strong{AutoGen},
62using the @code{agtexi-cmd} template and the option descriptions for the @code{sntp} program.
63This software is released under the NTP license, <http://ntp.org/license>.
64
65@menu
66* sntp usage::                  sntp help/usage (@option{--help})
67* sntp ipv4::                   ipv4 option (-4)
68* sntp ipv6::                   ipv6 option (-6)
69* sntp authentication::         authentication option (-a)
70* sntp broadcast::              broadcast option (-b)
71* sntp concurrent::             concurrent option (-c)
72* sntp gap::                    gap option (-g)
73* sntp kod::                    kod option (-K)
74* sntp keyfile::                keyfile option (-k)
75* sntp logfile::                logfile option (-l)
76* sntp steplimit::              steplimit option (-M)
77* sntp ntpversion::             ntpversion option (-o)
78* sntp usereservedport::        usereservedport option (-r)
79* sntp timeout::                timeout option (-t)
80* sntp wait::                   wait option
81* sntp config::                 presetting/configuring sntp
82* sntp exit status::            exit status
83* sntp Usage::                  Usage
84* sntp Authors::                Authors
85* sntp Notes::                  Notes
86@end menu
87
88@node sntp usage
89@subsection sntp help/usage (@option{--help})
90@cindex sntp help
91
92This is the automatically generated usage text for sntp.
93
94The text printed is the same whether selected with the @code{help} option
95(@option{--help}) or the @code{more-help} option (@option{--more-help}).  @code{more-help} will print
96the usage text by passing it through a pager program.
97@code{more-help} is disabled on platforms without a working
98@code{fork(2)} function.  The @code{PAGER} environment variable is
99used to select the program, defaulting to @file{more}.  Both will exit
100with a status code of 0.
101
102@exampleindent 0
103@example
104sntp - standard Simple Network Time Protocol client program - Ver. 4.2.7p404
105Usage:  sntp [ -<flag> [<val>] | --<name>[@{=| @}<val>] ]... \
106                [ hostname-or-IP ...]
107  Flg Arg Option-Name    Description
108   -4 no  ipv4           Force IPv4 DNS name resolution
109                                - prohibits the option 'ipv6'
110   -6 no  ipv6           Force IPv6 DNS name resolution
111                                - prohibits the option 'ipv4'
112   -a Num authentication Enable authentication with the key auth-keynumber
113   -b Str broadcast      Listen to the address specified for broadcast time sync
114                                - may appear multiple times
115   -c Str concurrent     Concurrently query all IPs returned for host-name
116                                - may appear multiple times
117   -d no  debug-level    Increase debug verbosity level
118                                - may appear multiple times
119   -D Num set-debug-level Set the debug verbosity level
120                                - may appear multiple times
121   -g Num gap            The gap (in milliseconds) between time requests
122   -K Fil kod            KoD history filename
123   -k Fil keyfile        Look in this file for the key specified with -a
124   -l Fil logfile        Log to specified logfile
125   -M Num steplimit      Adjustments less than steplimit msec will be slewed
126                                - it must be in the range:
127                                  greater than or equal to 0
128   -o Num ntpversion     Send int as our NTP protocol version
129                                - it must be in the range:
130                                  0 to 7
131   -r no  usereservedport Use the NTP Reserved Port (port 123)
132   -S no  step           OK to 'step' the time with settimeofday(2)
133   -s no  slew           OK to 'slew' the time with adjtime(2)
134   -t Num timeout        The number of seconds to wait for responses
135      no  wait           Wait for pending replies (if not setting the time)
136                                - disabled as '--no-wait'
137                                - enabled by default
138      opt version        output version information and exit
139   -? no  help           display extended usage information and exit
140   -! no  more-help      extended usage information passed thru pager
141   -> opt save-opts      save the option state to a config file
142   -< Str load-opts      load options from a config file
143                                - disabled as '--no-load-opts'
144                                - may appear multiple times
145
146Options are specified by doubled hyphens and their name or by a single
147hyphen and the flag character.
148
149
150The following option preset mechanisms are supported:
151 - reading file $HOME/.ntprc
152 - reading file ./.ntprc
153 - examining environment variables named SNTP_*
154
155Please send bug reports to:  <http://bugs.ntp.org, bugs@@ntp.org>
156
157exit 0
158@end example
159@exampleindent 4
160
161@node sntp ipv4
162@subsection ipv4 option (-4)
163@cindex sntp-ipv4
164
165This is the ``force ipv4 dns name resolution'' option.
166
167@noindent
168This option has some usage constraints.  It:
169@itemize @bullet
170@item
171must not appear in combination with any of the following options:
172ipv6.
173@end itemize
174
175Force DNS resolution of the following host names on the command line
176to the IPv4 namespace.
177@node sntp ipv6
178@subsection ipv6 option (-6)
179@cindex sntp-ipv6
180
181This is the ``force ipv6 dns name resolution'' option.
182
183@noindent
184This option has some usage constraints.  It:
185@itemize @bullet
186@item
187must not appear in combination with any of the following options:
188ipv4.
189@end itemize
190
191Force DNS resolution of the following host names on the command line
192to the IPv6 namespace.
193@node sntp authentication
194@subsection authentication option (-a)
195@cindex sntp-authentication
196
197This is the ``enable authentication with the key @var{auth-keynumber}'' option.
198This option takes a number argument @file{auth-keynumber}.
199Enable authentication using the key specified in this option's
200argument.  The argument of this option is the @option{keyid}, a
201number specified in the @option{keyfile} as this key's identifier.
202See the @option{keyfile} option (@option{-k}) for more details.
203@node sntp broadcast
204@subsection broadcast option (-b)
205@cindex sntp-broadcast
206
207This is the ``listen to the address specified for broadcast time sync'' option.
208This option takes a string argument @file{broadcast-address}.
209
210@noindent
211This option has some usage constraints.  It:
212@itemize @bullet
213@item
214may appear an unlimited number of times.
215@end itemize
216
217If specified @code{sntp} will listen to the specified address
218for NTP broadcasts.  The default maximum wait time
219can (and probably should) be modified with @option{-t}.
220@node sntp concurrent
221@subsection concurrent option (-c)
222@cindex sntp-concurrent
223
224This is the ``concurrently query all ips returned for host-name'' option.
225This option takes a string argument @file{host-name}.
226
227@noindent
228This option has some usage constraints.  It:
229@itemize @bullet
230@item
231may appear an unlimited number of times.
232@end itemize
233
234Requests from an NTP "client" to a "server" should never be sent
235more rapidly than one every 2 seconds.  By default, any IPs returned
236as part of a DNS lookup are assumed to be for a single instance of
237@code{ntpd}, and therefore @code{sntp} will send queries to these IPs
238one after another, with a 2-second gap in between each query.
239
240The @option{-c} or @option{--concurrent} flag says that any IPs
241returned for the DNS lookup of the supplied host-name are on
242different machines, so we can send concurrent queries.
243@node sntp gap
244@subsection gap option (-g)
245@cindex sntp-gap
246
247This is the ``the gap (in milliseconds) between time requests'' option.
248This option takes a number argument @file{milliseconds}.
249Since we're only going to use the first valid response we get and
250there is benefit to specifying a good number of servers to query,
251separate the queries we send out by the specified number of
252milliseconds.
253@node sntp kod
254@subsection kod option (-K)
255@cindex sntp-kod
256
257This is the ``kod history filename'' option.
258This option takes a file argument @file{file-name}.
259Specifies the filename to be used for the persistent history of KoD
260responses received from servers.
261@node sntp keyfile
262@subsection keyfile option (-k)
263@cindex sntp-keyfile
264
265This is the ``look in this file for the key specified with @option{-a}'' option.
266This option takes a file argument @file{file-name}.
267This option specifies the keyfile.
268@code{sntp} will search for the key specified with @option{-a}
269@file{keyno} in this file.  See @command{ntp.keys(5)} for more
270information.
271@node sntp logfile
272@subsection logfile option (-l)
273@cindex sntp-logfile
274
275This is the ``log to specified logfile'' option.
276This option takes a file argument @file{file-name}.
277This option causes the client to write log messages to the specified
278@file{logfile}.
279@node sntp steplimit
280@subsection steplimit option (-M)
281@cindex sntp-steplimit
282
283This is the ``adjustments less than @var{steplimit} msec will be slewed'' option.
284This option takes a number argument.
285If the time adjustment is less than @file{steplimit} milliseconds,
286slew the amount using @command{adjtime(2)}.  Otherwise, step the
287correction using @command{settimeofday(2)}.
288@node sntp ntpversion
289@subsection ntpversion option (-o)
290@cindex sntp-ntpversion
291
292This is the ``send @var{int} as our ntp protocol version'' option.
293This option takes a number argument.
294When sending requests to a remote server, tell them we are running
295NTP protocol version @file{ntpversion} .
296@node sntp usereservedport
297@subsection usereservedport option (-r)
298@cindex sntp-usereservedport
299
300This is the ``use the ntp reserved port (port 123)'' option.
301Use port 123, which is reserved for NTP, for our network
302communications.
303@node sntp timeout
304@subsection timeout option (-t)
305@cindex sntp-timeout
306
307This is the ``the number of seconds to wait for responses'' option.
308This option takes a number argument @file{seconds}.
309When waiting for a reply, @code{sntp} will wait the number
310of seconds specified before giving up.  The default should be
311more than enough for a unicast response.  If @code{sntp} is
312only waiting for a broadcast response a longer timeout is
313likely needed.
314@node sntp wait
315@subsection wait option
316@cindex sntp-wait
317
318This is the ``wait for pending replies (if not setting the time)'' option.
319
320@noindent
321This option has some usage constraints.  It:
322@itemize @bullet
323@item
324can be disabled with --no-wait.
325@item
326It is enabled by default.
327@end itemize
328
329If we are not setting the time, wait for all pending responses.
330
331
332@node sntp config
333@subsection presetting/configuring sntp
334
335Any option that is not marked as @i{not presettable} may be preset by
336loading values from configuration ("rc" or "ini") files, and values from environment variables named @code{SNTP} and @code{SNTP_<OPTION_NAME>}.  @code{<OPTION_NAME>} must be one of
337the options listed above in upper case and segmented with underscores.
338The @code{SNTP} variable will be tokenized and parsed like
339the command line.  The remaining variables are tested for existence and their
340values are treated like option arguments.
341
342
343@noindent
344@code{libopts} will search in 2 places for configuration files:
345@itemize @bullet
346@item
347$HOME
348@item
349$PWD
350@end itemize
351The environment variables @code{HOME}, and @code{PWD}
352are expanded and replaced when @file{sntp} runs.
353For any of these that are plain files, they are simply processed.
354For any that are directories, then a file named @file{.ntprc} is searched for
355within that directory and processed.
356
357Configuration files may be in a wide variety of formats.
358The basic format is an option name followed by a value (argument) on the
359same line.  Values may be separated from the option name with a colon,
360equal sign or simply white space.  Values may be continued across multiple
361lines by escaping the newline with a backslash.
362
363Multiple programs may also share the same initialization file.
364Common options are collected at the top, followed by program specific
365segments.  The segments are separated by lines like:
366@example
367[SNTP]
368@end example
369@noindent
370or by
371@example
372<?program sntp>
373@end example
374@noindent
375Do not mix these styles within one configuration file.
376
377Compound values and carefully constructed string values may also be
378specified using XML syntax:
379@example
380<option-name>
381   <sub-opt>...&lt;...&gt;...</sub-opt>
382</option-name>
383@end example
384@noindent
385yielding an @code{option-name.sub-opt} string value of
386@example
387"...<...>..."
388@end example
389@code{AutoOpts} does not track suboptions.  You simply note that it is a
390hierarchicly valued option.  @code{AutoOpts} does provide a means for searching
391the associated name/value pair list (see: optionFindValue).
392
393The command line options relating to configuration and/or usage help are:
394
395@subsubheading version (-)
396
397Print the program version to standard out, optionally with licensing
398information, then exit 0.  The optional argument specifies how much licensing
399detail to provide.  The default is to print just the version.  The licensing infomation may be selected with an option argument.
400Only the first letter of the argument is examined:
401
402@table @samp
403@item version
404Only print the version.  This is the default.
405@item copyright
406Name the copyright usage licensing terms.
407@item verbose
408Print the full copyright usage licensing terms.
409@end table
410
411@node sntp exit status
412@subsection sntp exit status
413
414One of the following exit values will be returned:
415@table @samp
416@item 0 (EXIT_SUCCESS)
417Successful program execution.
418@item 1 (EXIT_FAILURE)
419The operation failed or the command syntax was not valid.
420@item 66 (EX_NOINPUT)
421A specified configuration file could not be loaded.
422@item 70 (EX_SOFTWARE)
423libopts had an internal operational error.  Please report
424it to autogen-users@@lists.sourceforge.net.  Thank you.
425@end table
426@node sntp Usage
427@subsection sntp Usage
428@node sntp Authors
429@subsection sntp Authors
430@node sntp Notes
431@subsection sntp Notes
432