Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Simple Network Time Protocol API. More...

Data Structures

struct  sntp_time
 Time as returned by SNTP API, fractional seconds since 1 Jan 1970. More...
 
struct  sntp_ctx
 SNTP context. More...
 

Functions

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

Detailed Description

Simple Network Time Protocol API.

Function Documentation

◆ sntp_close()

void sntp_close ( struct sntp_ctx ctx)

#include <include/zephyr/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/zephyr/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/zephyr/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 ts 
)

#include <include/zephyr/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
tsTimestamp including integer and fractional seconds since 1 Jan 1970 (output).
Returns
0 if ok, <0 if error (-ETIMEDOUT if timeout).

◆ sntp_simple_addr()

int sntp_simple_addr ( struct sockaddr addr,
socklen_t  addr_len,
uint32_t  timeout,
struct sntp_time ts 
)

#include <include/zephyr/net/sntp.h>

Convenience function to query SNTP in one-shot fashion using a pre-initialized address struct.

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

Parameters
addrIP address of NTP/SNTP server.
addr_lenIP address length of NTP/SNTP server.
timeoutQuery timeout
tsTimestamp including integer and fractional seconds since 1 Jan 1970 (output).
Returns
0 if ok, <0 if error (-ETIMEDOUT if timeout).