Tim's NTP sample program

Tim's NTP sample program

This code is here to help others use the NTP time standards to keep the clocks on their devices correct.

Sample Code in Perl or in C

Network Time Protocol is a way to keep computers clocks correct. It works by propgating the time in such a way as the errors don't add up a great deal and the amount of error can be caluated and adjusted for. A poorly maintained NTP cluster will typicaly maintain its time within a second if only one of the computers can talk to a good clock once in a while.

All the details can be found At the NTP web site.

If your going to start working on NTP, I would recomend starting with the oboslite RFC 1059 because it is well written and easy to understand. It only discusses protocol version 1 but later protocols documents were written assuming a knowledge of version 1. Later documents get in to some strange concepts that most applications don't need.

What NTP server should I use?

NTP clocks have a "stratum" number that tell how far away they are from the offical time source. A stratum-1 clock will be something like the atomic clock at Greenwich. A stratum-2 clock will be a clock that gets its time from a stratum-1 clock. For reasons too complex to go into here, most public NTP servers are listed as either stratum-2 or 3. The stratum 2 servers are there to feed time out from the main clock sources and should never be used unless you have an essential use for them.

Never use a public server that you do not run as a default NTP server. The standards groups do not have the finances to run the needed hardware and network lines to support large numbers of users. Please do not abuse their systems.

For most applications, a stratum 4 or 5 server will be good enough. These will typically provide time better than a typical TV station and well under a second of accuracy. Most internet routers these days use NTP to coordinate their internal clocks and work as good NTP servers. You can ask your ISP if they provide an NTP server for your use (it will tend to have a name like clock.myisp.com or ntp.myisp.com). Chances are their routers are set up to provide NTP servers so can find out by running traceroute which will give you a list of routers. Try them starting to the closest until you find one that works and use it.

I have a small script that will find out routers near you that might run NTP servers. Locate NTP servers. The script might take several minutes to run.



Back to Tim's Homepage Back to current subject Related Links thogard@abnormal.com
 This page was last updated Saturday, 08-Dec-2007 00:05:47 UTC Copyright 2000-2020 thogard™ is a trademark of Tim Hogard