tfSntpUserBind

Jump to: navigation, search

Table of Contents >> Application Reference >> Simple Network Time Protocol


#include <trsocket.h>


int tfSntpUserBind (
ttSntpHandle sntpHandle,
const struct sockaddr_storage TM_FAR * localAddrPtr
);


Function Description

Set a local port, address and address family at which to receive messages. This is a wrapper function that calls bind() on the underlying UDP socket (refer to that page for additional information).

This call is mandatory for broadcast mode associations. It is optional for unicast mode.


Example

int userFunction(void)
{
    struct sockaddr_storage serverAddr;
    struct sockaddr_storage localAddr;
    int                     errorCode;
 
    . . .
 
/* Create a broadcast SNTP client */
    sntpHandle = tfSntpUserCreate(&serverAddr, mySntpCBFunc, TM_SNTP_CREATE_BROADCAST | TM_BLOCKING_ON, &errorCode);
    assert((sntpHandle[0] != TM_SNTP_INVALID_HANDLE) && (errorCode == TM_ENOERROR));
 
/* Bind to the standard NTP port (123), any IPv4 local address */
    memset(&localAddr, 0, sizeof(localAddr));
    localAddr.ss_len = sizeof(localAddr);
    localAddr.ss_family = AF_INET;
    sntpHandle = tfSntpUserBind(sntpHandle, &localAddr);
    assert(errorCode == TM_ENOERROR);
 
/* Run the SNTP client */
    errorCode = tfSntpUserExecute(sntpHandle);
    assert(errorCode == TM_ENOERROR);
 
    . . .
 
}


Parameters

  • sntpHandle
    The SNTP client handle returned by tfSntpUserCreate().
  • localAddrPtr
    The local port and address to receive on. Specify a port number of zero to bind to the default NTP port, 123. More information about this parameter can found on the socket bind() page.


Returns

  • TM_ENOERROR
    Success.
  • TM_EINVAL
    Invalid handle or localAddrPtr is NULL or contains invalid data.
  • TM_EPERM
    Must be called before calling tfSntpUserExecute().
  • (more)
    Other socket errors are possible. See bind().


Table of Contents >> Application Reference >> Simple Network Time Protocol