Setting the System Time via the TCP Time Service
$Date: 1999/05/24 16:40:59 $
This document describes a VxWorks module that queries a remote machine for the date and uses it to set the local system time.
This module provides a way to synchronize your VxWorks system time to a server on the network.
This facility is provided as both a loadable module and a linkable library. The module is called loadtime-1.1.o and is found in the module products directory. If you wish to automatically load the latest module, you should load via the symbolic link loadtime.o, which always points to the most recent version. If you would rather link with the library, the function prototypes are found in loadtime.h. You'll also need to link with libloadtime-1.1.a. Similarly, the symbolic link libloadtime.a always points to the most recent library.
The time service, used by this module, returns Greenwich Mean Time (GMT). In order to properly adjust the time to a local representation, the environment variable TIMEZONE must be set. For 1999, the proper setting for this variable is:
You can check to see if this variable has been set by using the envShow function.
A typical use of this module would be to set the time from our operational Unix box in a VxWorks startup script1:
hostAdd("fecode-bd", "184.108.40.206"); ld(1, 1, "vxworks_boot/module/PPC603/loadtime.o"); systemTimeSet("fecode-bd");
This section contains descriptions of all the available functions in the module.
STATUS systemTimeSet(char const* addr);
This function sets the system clock to the time obtained by a remote machine. The time is retrieved using the TCP/IP time service (TCP port 37). The addr parameter should point to the name of a machine. If DNS services aren't available, the machine name should first be defined using hostAdd().
This function simply prints, to the console, the local time. The time is set using GMT, so to get a valid local time, the TIMEZONE environment variable needs to be set to the proper value.
This is for a PowerPC-based system. 68K systems would replace PPC603 with MC68020. We are working on a way to make this transparent to the users of our products, but a solution hasn't been put in place, yet.