VxWorks Reference Manual : Libraries

sntpsLib

NAME

sntpsLib - Simple Network Time Protocol (SNTP) server library

ROUTINES

sntpsClockSet( ) - assign a routine to access the reference clock
sntpsNsecToFraction( ) - convert portions of a second to NTP format
sntpsConfigSet( ) - change SNTP server broadcast settings

DESCRIPTION

This library implements the server side of the Simple Network Time Protocol (SNTP), a protocol that allows a system to maintain the accuracy of its internal clock based on time values reported by one or more remote sources. The library is included in the VxWorks image if INCLUDE_SNTPS is defined at the time the image is built.

USER INTERFACE

The routine sntpsInit( ) is called automatically during system startup when the SNTP server library is included in the VxWorks image. Depending on the value of SNTPS_MODE, the server executes in either a passive or an active mode. When SNTPS_MODE is set to SNTP_PASSIVE (0x2), the server waits for requests from clients, and sends replies containing an NTP timestamp. When the mode is set to SNTP_ACTIVE (0x1), the server transmits NTP timestamp information at fixed intervals.

When executing in active mode, the SNTP server uses the SNTPS_DSTADDR and SNTPS_INTERVAL definitions to determine the target IP address and broadcast interval. By default, the server will transmit the timestamp information to the local subnet broadcast address every 64 seconds. These settings can be changed with a call to the sntpsConfigSet( ) routine. The SNTP server operating in active mode will still respond to client requests.

The SNTP_PORT definition in assigns the source and destination UDP port. The default port setting is 123 as specified by the relevant RFC. Finally, the SNTP server requires access to a reliable external time source. The SNTPS_TIME_HOOK constant specifies the name of a routine with the following interface:

    STATUS sntpsTimeHook (int request, void *pBuffer);
This routine can be assigned directly by altering the value of SNTPS_TIME_HOOK or can be installed by a call to the sntpsClockSet( ) routine. The manual pages for sntpsClockSet( ) describe the parameters and required operation of the timestamp retrieval routine. Until this routine is specified, the SNTP server will not provide timestamp information.

INCLUDE FILES

sntpsLib.h

SEE ALSO

sntpsLib, sntpcLib, RFC 1769


Libraries : Routines

sntpsClockSet( )

NAME

sntpsClockSet( ) - assign a routine to access the reference clock

SYNOPSIS

STATUS sntpsClockSet
    (
    FUNCPTR pClockHookRtn /* new interface to reference clock */
    )

DESCRIPTION

This routine installs a hook routine that is called to access the reference clock used by the SNTP server. This hook routine must use the following interface:

    STATUS sntpsClockHook (int request, void *pBuffer);
The hook routine should copy one of three settings used by the server to construct outgoing NTP messages into pBuffer according to the value of the request parameter. If the requested setting is available, the installed routine should return OK (or ERROR otherwise).

This routine calls the given hook routine with the request parameter set to SNTPS_ID to get the 32-bit reference identifier in the format specified in RFC 1769. It also calls the hook routine with request set to SNTPS_RESOLUTION to retrieve a 32-bit value containing the clock resolution in nanoseconds. That value will be used to determine the 8-bit signed integer indicating the clock precision (according to the format specified in RFC 1769). Other library routines will set the request parameter to SNTPS_TIME to retrieve the current 64-bit NTP timestamp from pBuffer in host byte order. The routine sntpsNsecToFraction( ) will convert a value in nanoseconds to the format required for the NTP fractional part.

RETURNS

OK or ERROR.

ERRNO

N/A

SEE ALSO

sntpsLib


Libraries : Routines

sntpsNsecToFraction( )

NAME

sntpsNsecToFraction( ) - convert portions of a second to NTP format

SYNOPSIS

ULONG sntpsNsecToFraction
    (
    ULONG nsecs /* nanoseconds to convert to binary fraction */
    )

DESCRIPTION

This routine is provided for convenience in fulfilling an SNTPS_TIME request to the clock hook. It converts a value in nanoseconds to the fractional part of the NTP timestamp format. The routine is not designed to convert non-normalized values greater than or equal to one second. Although the NTP time format provides a precision of about 200 pico-seconds, rounding errors in the conversion process decrease the accuracy as the input value increases. In the worst case, only the 24 most significant bits are valid, which reduces the precision to tenths of a micro-second.

RETURNS

Value for NTP fractional part in host-byte order.

ERRNO

N/A

SEE ALSO

sntpsLib


Libraries : Routines

sntpsConfigSet( )

NAME

sntpsConfigSet( ) - change SNTP server broadcast settings

SYNOPSIS

STATUS sntpsConfigSet
    (
    int    setting, /* configuration option to change */
    void * pValue   /* new value for parameter */
    )

DESCRIPTION

This routine alters the configuration of the SNTP server when operating in broadcast mode. A setting value of SNTPS_DELAY interprets the contents of pValue as the new 16-bit broadcast interval. When setting equals SNTPS_ADDRESS, pValue should provide the string representation of an IP broadcast or multicast address (for example, "224.0.1.1"). Any changed settings will take effect after the current broadcast interval is completed and the corresponding NTP message is sent.

RETURNS

OK or ERROR.

ERRNO

 S_sntpsLib_INVALID_PARAMETER

SEE ALSO

sntpsLib