Prosody SNTP Client: API

The following functions are provided by the Prosody SNTP Client API:

API call W Description
sm_sntp_config()   Configure the SNTP client to send IPv4 requests
sm_sntp_config_ipv6()   Configure the SNTP client to send IPv6 requests
sm_sntp_create()   Create an SNTP Client
sm_sntp_destroy()   Destroy an SNTP Client
sm_sntp_get_event()   Get an event for the SNTP client
sm_sntp_status()   Fetch status info on a SNTP client

This document is also available as separate pages for each function.


Prosody SNTP Client: API: sm_sntp_config

Prototype Definition

int sm_sntp_config(struct sm_sntp_config_parms *configp)

Parameters

*configp
a structure of the following type:
typedef struct sm_sntp_config_parms {
	tSMSNTPId sntp;						/* in */
	SOCKADDR_IN server;					/* in */
	int TOS;						/* in */
	tSM_UT32 no_reply_delay;				/* in */
	tSM_UT32 had_reply_delay;				/* in */
} SM_SNTP_CONFIG_PARMS;

Description

This function configures the NTP server used by the SNTP client. If the reply to a NTP request is not received within no_reply_delay then the next request is sent. Otherwise the next NTP request is sent had_reply_delay after the previous request.

Fields

sntp
The SNTP client to configure.
server
The SOCKADDR_IN structure specifying the destination IP address and port of the NTP server to use. A struct SOCKADDR_IN must be configured with an address family, an IP address and a port. Note that most operating systems define this structure such that fields are in network byte order. The structure must be correctly cast such that an IP V4 address is specified.
TOS
The Type Of Service (TOS) indicator to be sent in the NTP packets.
no_reply_delay
The delay, in ms, between requests when no reply has been received.
had_reply_delay
The delay, in ms, between requests when a reply has been received.

Returns

0 if call completed successfully, otherwise a standard error such as:


Prosody SNTP Client: API: sm_sntp_config_ipv6

Prototype Definition

int sm_sntp_config_ipv6(struct sm_sntp_config_ipv6_parms *configp)

Parameters

*configp
a structure of the following type:
typedef struct sm_sntp_config_ipv6_parms {
	tSMSNTPId sntp;						/* in */
	SOCKADDR_IN6 server;					/* in */
	tSM_UT32 no_reply_delay;				/* in */
	tSM_UT32 had_reply_delay;				/* in */
} SM_SNTP_CONFIG_IPV6_PARMS;

Description

This function configures the NTP server used by the SNTP client. If the reply to a NTP request is not received within no_reply_delay then the next request is sent. Otherwise the next NTP request is sent had_reply_delay after the previous request.

Fields

sntp
The SNTP client to configure.
server
The SOCKADDR_IN6 structure specifying the destination IP address and port of the NTP server to use. A struct SOCKADDR_IN6 must be configured with an address family, an IPv6 address and a port. Note that most operating systems define this structure such that fields are in network byte order.
no_reply_delay
The delay, in ms, between requests when no reply has been received.
had_reply_delay
The delay, in ms, between requests when a reply has been received.

Returns

0 if call completed successfully, otherwise a standard error such as:


Prosody SNTP Client: API: sm_sntp_create

Prototype Definition

int sm_sntp_create(struct sm_sntp_create_parms *createp)

Parameters

*createp
a structure of the following type:
typedef struct sm_sntp_create_parms {
	tSMSNTPId sntp;						/* out */
	tSMModuleId module;					/* in */
	enum kSMSNTPType {
		kSMSNTPTypeIPv4,
		kSMSNTPTypeIPv6,
	} type;							/* in */
	struct in_addr address;					/* in */
	struct in6_addr ipv6_address;				/* in */
} SM_SNTP_CREATE_PARMS;

Description

Creates an SNTP Client.

Fields

sntp
The created SNTP client.
module
A value obtained from sm_open_module() Indicates the module on which the SNTP client is to be created.
type
One of these values:
kSMSNTPTypeIPv4
The SNTP client is to receive IPv4 packets
kSMSNTPTypeIPv6
The SNTP client is to receive IPv6 packets
address
The address on which the SNTP client listens for replies if type is kSMSNTPTypeIPv4.
ipv6_address
The address on which the SNTP client listens for replies if type is kSMSNTPTypeIPv6.

Returns

0 if call completed successfully, otherwise a standard error such as:


Prosody SNTP Client: API: sm_sntp_destroy

Prototype Definition

int sm_sntp_destroy(tSMSNTPId sntp)

Parameters

sntp
The SNTP client to destroy. Must have been previously created by a call to sm_sntp_create().

Description

Destroys an SNTP Client.

Returns

0 if call completed successfully, otherwise a standard error such as:


Prosody SNTP Client: API: sm_sntp_get_event

Prototype Definition

int sm_sntp_get_event(struct sm_sntp_event_parms *eventp)

Parameters

*eventp
a structure of the following type:
typedef struct sm_sntp_event_parms {
	tSMSNTPId sntp;						/* in */
	tSMEventId event;					/* out */
} SM_SNTP_EVENT_PARMS;

Description

the event will be signalled when a status change occurs on the SNTP client.

Fields

sntp
The SNTP client.
event
The event identifier

Returns

0 if call completed successfully, otherwise a standard error such as:


Prosody SNTP Client: API: sm_sntp_status

Prototype Definition

int sm_sntp_status(struct sm_sntp_status_parms *statusp)

Parameters

*statusp
a structure of the following type:
typedef struct sm_sntp_status_parms {
	tSMSNTPId sntp;						/* in */
	enum kSMSNTPStatus {
		kSMSNTPStatusRunning,
		kSMSNTPStatusStopped,
		kSMSNTPStatusSync,
	} status;						/* out */
	union {
		struct {
			int has_sync;				/* out */
		} sync;						/* out */
	} u;							/* out */
} SM_SNTP_STATUS_PARMS;

Description

returns the status of the SNTP client.

Fields

sntp
The SNTP client.
status
The status. One of these values:
kSMSNTPStatusRunning
The SNTP client is running
kSMSNTPStatusStopped
The SNTP client is not running
kSMSNTPStatusSync
The SNTP client synchronisation state has changed
u
Additional information relating to the current status of the SNTP client
sync
This field is only valid if the status is kSMSNTPStatusSync.
has_sync
An indicator of whether the SNTP client is synchronised with the NTP server

Returns

0 if call completed successfully, otherwise a standard error such as:


These functions constitute the Prosody SNTP Client API.