Zephyr API Documentation  3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
sntp.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Linaro Limited
3 * Copyright (c) 2019 Intel Corporation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
13#ifndef ZEPHYR_INCLUDE_NET_SNTP_H_
14#define ZEPHYR_INCLUDE_NET_SNTP_H_
15
16#include <zephyr/net/socket.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
30struct sntp_time {
33#if defined(CONFIG_SNTP_UNCERTAINTY)
34 uint64_t uptime_us;
35 uint32_t uncertainty_us;
36#endif
37};
38
40struct sntp_ctx {
41
43 struct {
44 struct zsock_pollfd fds[1];
45 int nfds;
46 int fd;
47 } sock;
55};
56
66int sntp_init(struct sntp_ctx *ctx, struct sockaddr *addr,
67 socklen_t addr_len);
68
79int sntp_query(struct sntp_ctx *ctx, uint32_t timeout,
80 struct sntp_time *time);
81
87void sntp_close(struct sntp_ctx *ctx);
88
102int sntp_simple(const char *server, uint32_t timeout,
103 struct sntp_time *ts);
104
120int sntp_simple_addr(struct sockaddr *addr, socklen_t addr_len, uint32_t timeout,
121 struct sntp_time *ts);
122
123#ifdef __cplusplus
124}
125#endif
126
131#endif
size_t socklen_t
Length of a socket address.
Definition: net_ip.h:168
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.
int sntp_query(struct sntp_ctx *ctx, uint32_t timeout, struct sntp_time *time)
Perform SNTP query.
int sntp_init(struct sntp_ctx *ctx, struct sockaddr *addr, socklen_t addr_len)
Initialize SNTP context.
time_t time(time_t *tloc)
BSD Sockets compatible API definitions.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT64_TYPE__ uint64_t
Definition: stdint.h:91
SNTP context.
Definition: sntp.h:40
struct sntp_time expected_orig_ts
Timestamp when the request was sent from client to server.
Definition: sntp.h:54
Time as returned by SNTP API, fractional seconds since 1 Jan 1970.
Definition: sntp.h:30
uint64_t seconds
Second value.
Definition: sntp.h:31
uint32_t fraction
Fractional seconds value.
Definition: sntp.h:32
Generic sockaddr struct.
Definition: net_ip.h:385
Definition of the monitored socket/file descriptor.
Definition: socket_poll.h:28