sntp_client.c File Reference

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

#include "core/net.h"
#include "sntp/sntp_client.h"
#include "error.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   SNTP_TRACE_LEVEL
 

Functions

error_t sntpClientGetTimestamp (NetInterface *interface, const IpAddr *serverIpAddr, NtpTimestamp *timestamp)
 Retrieve current time from NTP server using SNTP protocol. More...
 
error_t sntpSendRequest (SntpClientContext *context)
 Send NTP request using SNTP protocol. More...
 
error_t sntpWaitForResponse (SntpClientContext *context, systime_t timeout)
 Wait for a valid response from the NTP server. More...
 
error_t sntpParseResponse (SntpClientContext *context, const NtpHeader *message, size_t length)
 Parse NTP server response. More...
 
void sntpDumpMessage (const NtpHeader *message, size_t length)
 Dump NTP message for debugging purpose. More...
 
void sntpDumpTimestamp (const NtpTimestamp *timestamp)
 Dump NTP timestamp. More...
 

Detailed Description

SNTP client (Simple Network Time Protocol)

License

Copyright (C) 2010-2018 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.

Description

The Simple Network Time Protocol is used to synchronize computer clocks in the Internet. Refer to RFC 4330 for more details

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

Definition in file sntp_client.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   SNTP_TRACE_LEVEL

Definition at line 35 of file sntp_client.c.

Function Documentation

◆ sntpClientGetTimestamp()

error_t sntpClientGetTimestamp ( NetInterface interface,
const IpAddr serverIpAddr,
NtpTimestamp timestamp 
)

Retrieve current time from NTP server using SNTP protocol.

Parameters
[in]interfaceUnderlying network interface (optional parameter)
[in]serverIpAddrIP address of the NTP server
[out]timestampCurrent time
Returns
Error code

Definition at line 55 of file sntp_client.c.

◆ sntpDumpMessage()

void sntpDumpMessage ( const NtpHeader message,
size_t  length 
)

Dump NTP message for debugging purpose.

Parameters
[in]messagePointer to the NTP message
[in]lengthLength of the NTP message

Definition at line 280 of file sntp_client.c.

◆ sntpDumpTimestamp()

void sntpDumpTimestamp ( const NtpTimestamp timestamp)

Dump NTP timestamp.

Parameters
[in]timestampPointer to the NTP timestamp

Definition at line 345 of file sntp_client.c.

◆ sntpParseResponse()

error_t sntpParseResponse ( SntpClientContext context,
const NtpHeader message,
size_t  length 
)

Parse NTP server response.

Parameters
[in]contextPointer to the SNTP client context
[in]messageNTP response message to parse
[in]lengthLength of the incoming NTP message
Returns
Error code

Definition at line 238 of file sntp_client.c.

◆ sntpSendRequest()

error_t sntpSendRequest ( SntpClientContext context)

Send NTP request using SNTP protocol.

Parameters
[in]contextSNTP client context
Returns
Error code

Definition at line 142 of file sntp_client.c.

◆ sntpWaitForResponse()

error_t sntpWaitForResponse ( SntpClientContext context,
systime_t  timeout 
)

Wait for a valid response from the NTP server.

Parameters
[in]contextPointer to the SNTP client context
[in]timeoutMaximum time period to wait
Returns
Error code

Definition at line 186 of file sntp_client.c.