Cover V04, I04
Figure 1
Listing 1
Sidebar 1


Sidebar: Time Resources and the Internet

The U.S. Naval Observatory is on the net with a delightful Web home page at USNO provides a great deal of information on how they operate in their role as chief astronomers and timekeepers of the Navy, and it's clear they have designed their Web pages with an eye toward the technical reader.

Their ftp service has a number of time utilities, including one (nistime.c) that sets your clock over the Internet. Look in for this information.

Surprisingly, many networks do not require accurate time as much as systemwide agreement on a common clock (even if this clock is wrong in absolute terms). Considering that filesystems are often cross-mounted between various machines, a timestamp that says "five minutes ago" on one computer might mean "five minutes from now" on another. This can cause havoc with the make utility when object files are "newer" than their source files by virtue of unsynchronized system clocks.

The Network Time Protocol (NTP) was designed to alleviate just these concerns. It permits a network of interconnected systems to make sure all their clocks agree and converge on a common time. This protocol is defined in Request For Comments (RFC) 1305, which is available from ftp://uunet/inet/rfc/rfc1305.Z. Source code for the NTP utilities is at ftp://uunet/networking/applic/ntp/ (among other locations).

For users with more modest requirements, it is possible to create simple set-the-time utilities by using TCP to synchronize with a master server (say, one that uses utc to set the clock). Most TCP implementations provide services that give easy access to the time on that machine. For instance,

telnet daytime

where is the name of a machine and daytime is typed literally and corresponds to TCP and UDP port 13. While implementations differ, most systems return the time in the same format as the date command. (For more information, see "A Server-Based Date/Time Synchronizer for TCP/IP," Sys Admin May/June 1995).

Even simpler is the time service (TCP and UDP port number 37), which returns a network long integer that reflects the system clock on the server machine. It is a straightforward matter to create a program that queries a remote system and sets the local clock with the time longword returned.