sntp_client.h File Reference

SNTP client (Simple Network Time Protocol) More...

#include "core/net.h"
#include "sntp/ntp_common.h"

Go to the source code of this file.

Data Structures

struct  SntpClientContext
 SNTP client context. More...
 

Macros

#define SNTP_CLIENT_SUPPORT   ENABLED
 
#define SNTP_CLIENT_DEFAULT_TIMEOUT   30000
 
#define SNTP_CLIENT_INIT_RETRANSMIT_TIMEOUT   2000
 
#define SNTP_CLIENT_MAX_RETRANSMIT_TIMEOUT   15000
 
#define SNTP_CLIENT_PRIVATE_CONTEXT
 

Enumerations

enum  SntpClientState { SNTP_CLIENT_STATE_INIT = 0 , SNTP_CLIENT_STATE_SENDING = 2 , SNTP_CLIENT_STATE_RECEIVING = 3 , SNTP_CLIENT_STATE_COMPLETE = 4 }
 SNTP client states. More...
 

Functions

error_t sntpClientInit (SntpClientContext *context)
 Initialize SNTP client context. More...
 
error_t sntpClientSetTimeout (SntpClientContext *context, systime_t timeout)
 Set communication timeout. More...
 
error_t sntpClientBindToInterface (SntpClientContext *context, NetInterface *interface)
 Bind the SNTP client to a particular network interface. More...
 
error_t sntpClientSetServerAddr (SntpClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort)
 Specify the IP address of the NTP server. More...
 
error_t sntpClientGetTimestamp (SntpClientContext *context, NtpTimestamp *timestamp)
 Retrieve current time from NTP server. More...
 
uint32_t sntpClientGetKissCode (SntpClientContext *context)
 Retrieve the kiss code from a Kiss-of-Death message. More...
 
void sntpClientDeinit (SntpClientContext *context)
 Release SNTP client context. More...
 

Detailed Description

SNTP client (Simple Network Time Protocol)

Helper functions for SNTP client.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.0

Definition in file sntp_client.h.

Macro Definition Documentation

◆ SNTP_CLIENT_DEFAULT_TIMEOUT

#define SNTP_CLIENT_DEFAULT_TIMEOUT   30000

Definition at line 47 of file sntp_client.h.

◆ SNTP_CLIENT_INIT_RETRANSMIT_TIMEOUT

#define SNTP_CLIENT_INIT_RETRANSMIT_TIMEOUT   2000

Definition at line 54 of file sntp_client.h.

◆ SNTP_CLIENT_MAX_RETRANSMIT_TIMEOUT

#define SNTP_CLIENT_MAX_RETRANSMIT_TIMEOUT   15000

Definition at line 61 of file sntp_client.h.

◆ SNTP_CLIENT_PRIVATE_CONTEXT

#define SNTP_CLIENT_PRIVATE_CONTEXT

Definition at line 68 of file sntp_client.h.

◆ SNTP_CLIENT_SUPPORT

#define SNTP_CLIENT_SUPPORT   ENABLED

Definition at line 40 of file sntp_client.h.

Enumeration Type Documentation

◆ SntpClientState

SNTP client states.

Enumerator
SNTP_CLIENT_STATE_INIT 
SNTP_CLIENT_STATE_SENDING 
SNTP_CLIENT_STATE_RECEIVING 
SNTP_CLIENT_STATE_COMPLETE 

Definition at line 81 of file sntp_client.h.

Function Documentation

◆ sntpClientBindToInterface()

error_t sntpClientBindToInterface ( SntpClientContext context,
NetInterface interface 
)

Bind the SNTP client to a particular network interface.

Parameters
[in]contextPointer to the SNTP client context
[in]interfaceNetwork interface to be used
Returns
Error code

Definition at line 103 of file sntp_client.c.

◆ sntpClientDeinit()

void sntpClientDeinit ( SntpClientContext context)

Release SNTP client context.

Parameters
[in]contextPointer to the SNTP client context

Definition at line 259 of file sntp_client.c.

◆ sntpClientGetKissCode()

uint32_t sntpClientGetKissCode ( SntpClientContext context)

Retrieve the kiss code from a Kiss-of-Death message.

Parameters
[in]contextPointer to the SNTP client context
Returns
Kiss code

Definition at line 233 of file sntp_client.c.

◆ sntpClientGetTimestamp()

error_t sntpClientGetTimestamp ( SntpClientContext context,
NtpTimestamp timestamp 
)

Retrieve current time from NTP server.

Parameters
[in]contextPointer to the SNTP client context
[out]timestampPointer to the NTP timestamp
Returns
Error code

Definition at line 154 of file sntp_client.c.

◆ sntpClientInit()

error_t sntpClientInit ( SntpClientContext context)

Initialize SNTP client context.

Parameters
[in]contextPointer to the SNTP client context
Returns
Error code

Definition at line 55 of file sntp_client.c.

◆ sntpClientSetServerAddr()

error_t sntpClientSetServerAddr ( SntpClientContext context,
const IpAddr serverIpAddr,
uint16_t  serverPort 
)

Specify the IP address of the NTP server.

Parameters
[in]contextPointer to the SNTP client context
[in]serverIpAddrIP address of the NTP server
[in]serverPortPort number
Returns
Error code

Definition at line 126 of file sntp_client.c.

◆ sntpClientSetTimeout()

error_t sntpClientSetTimeout ( SntpClientContext context,
systime_t  timeout 
)

Set communication timeout.

Parameters
[in]contextPointer to the SNTP client context
[in]timeoutTimeout value, in milliseconds
Returns
Error code

Definition at line 82 of file sntp_client.c.