Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS

Simple Network Time Protocol API. More...

Data Structures

struct  sntp_ctx
 
struct  sntp_time
 

Functions

int sntp_init (struct sntp_ctx *ctx, struct sockaddr *addr, socklen_t addr_len)
 Initialize SNTP context. More...
 
int sntp_query (struct sntp_ctx *ctx, uint32_t timeout, struct sntp_time *time)
 Perform SNTP query. More...
 
void sntp_close (struct sntp_ctx *ctx)
 Release SNTP context. More...
 
int sntp_simple (const char *server, uint32_t timeout, struct sntp_time *time)
 Convenience function to query SNTP in one-shot fashion. More...
 

Detailed Description

Simple Network Time Protocol API.

Function Documentation

◆ sntp_close()

void sntp_close ( struct sntp_ctx ctx)

#include <include/net/sntp.h>

Release SNTP context.

Parameters
ctxAddress of sntp context.

◆ sntp_init()

int sntp_init ( struct sntp_ctx ctx,
struct sockaddr addr,
socklen_t  addr_len 
)

#include <include/net/sntp.h>

Initialize SNTP context.

Parameters
ctxAddress of sntp context.
addrIP address of NTP/SNTP server.
addr_lenIP address length of NTP/SNTP server.
Returns
0 if ok, <0 if error.

◆ sntp_query()

int sntp_query ( struct sntp_ctx ctx,
uint32_t  timeout,
struct sntp_time time 
)

#include <include/net/sntp.h>

Perform SNTP query.

Parameters
ctxAddress of sntp context.
timeoutTimeout of waiting for sntp response (in milliseconds).
timeTimestamp including integer and fractional seconds since 1 Jan 1970 (output).
Returns
0 if ok, <0 if error (-ETIMEDOUT if timeout).

◆ sntp_simple()

int sntp_simple ( const char *  server,
uint32_t  timeout,
struct sntp_time time 
)

#include <include/net/sntp.h>

Convenience function to query SNTP in one-shot fashion.

Convenience wrapper which calls getaddrinfo(), sntp_init(), sntp_query(), and sntp_close().

Parameters
serverAddress of server in format addr[:port]
timeoutQuery timeout
timeTimestamp including integer and fractional seconds since 1 Jan 1970 (output).
Returns
0 if ok, <0 if error (-ETIMEDOUT if timeout).