NTP Packet

The NTP packet module provides functionality to manipulate the NTP header. More...

Detailed Description

The NTP packet module provides functionality to manipulate the NTP header.

Files

file  ntp_packet.h
 NTP packet definitions.
 

Data Structures

struct  ntp_timestamp_t
 NTP timestamp. More...
 
struct  ntp_packet_t
 NTP packet. More...
 

Macros

#define NTP_VERSION   (4U)
 NTP version.
 
#define NTP_PORT   (123U)
 NTP port number.
 
#define NTP_UNIX_OFFSET   (2208988800)
 Offset in seconds of NTP timestamp (seconds from 1990-01-01 00:00:00 UTC) to UNIX timestamp (seconds from 1970-01-01 00:00:00 UTC).
 

Enumerations

enum  ntp_mode_t {
  NTP_MODE_RESERVED = 0, NTP_MODE_SYM_ACTIVE, NTP_MODE_SYM_PASSIVE, NTP_MODE_CLIENT,
  NTP_MODE_SERVER, NTP_MODE_BROADCAST, NTP_MODE_PRIV
}
 NTP modes. More...
 

Functions

static void ntp_packet_set_li (ntp_packet_t *packet, uint8_t li)
 Set leap indicator in a NTP packet. More...
 
static void ntp_packet_set_vn (ntp_packet_t *packet)
 Set version in a NTP packet. More...
 
static void ntp_packet_set_mode (ntp_packet_t *packet, ntp_mode_t mode)
 Set mode in a NTP packet. More...
 
static uint8_t ntp_packet_get_li (ntp_packet_t *packet)
 Get leap indicator from a NTP packet. More...
 
static uint8_t ntp_packet_get_vn (ntp_packet_t *packet)
 Get version from a NTP packet. More...
 
static ntp_mode_t ntp_packet_get_mode (ntp_packet_t *packet)
 Get mode from a NTP packet. More...
 
#define NTP_PACKET_LI_POS   (6U)
 Bit positions and masks for ntp_packet_t::li_vn_mode. More...
 
#define NTP_PACKET_LI_MASK   (0xc0)
 leap indicator mask
 
#define NTP_PACKET_VN_POS   (3U)
 version position
 
#define NTP_PACKET_VN_MASK   (0x38)
 version mask
 
#define NTP_PACKET_MODE_MASK   (0x07)
 mode mask
 

Macro Definition Documentation

◆ NTP_PACKET_LI_POS

#define NTP_PACKET_LI_POS   (6U)

Bit positions and masks for ntp_packet_t::li_vn_mode.

Leap indicator position

Definition at line 39 of file ntp_packet.h.

Enumeration Type Documentation

◆ ntp_mode_t

enum ntp_mode_t

NTP modes.

Enumerator
NTP_MODE_RESERVED 

reserved

NTP_MODE_SYM_ACTIVE 

symmetric active

NTP_MODE_SYM_PASSIVE 

symmetric passive

NTP_MODE_CLIENT 

client

NTP_MODE_SERVER 

server

NTP_MODE_BROADCAST 

broadcast

NTP_MODE_PRIV 

reserved for private use

Definition at line 58 of file ntp_packet.h.

Function Documentation

◆ ntp_packet_get_li()

static uint8_t ntp_packet_get_li ( ntp_packet_t packet)
inlinestatic

Get leap indicator from a NTP packet.

Parameters
[in]packetThe NTP packet
Returns
The leap indicator of packet

Definition at line 139 of file ntp_packet.h.

◆ ntp_packet_get_mode()

static ntp_mode_t ntp_packet_get_mode ( ntp_packet_t packet)
inlinestatic

Get mode from a NTP packet.

Parameters
[in]packetThe NTP packet
Returns
The version of packet

Definition at line 163 of file ntp_packet.h.

◆ ntp_packet_get_vn()

static uint8_t ntp_packet_get_vn ( ntp_packet_t packet)
inlinestatic

Get version from a NTP packet.

Parameters
[in]packetThe NTP packet
Returns
The version of packet

Definition at line 151 of file ntp_packet.h.

◆ ntp_packet_set_li()

static void ntp_packet_set_li ( ntp_packet_t packet,
uint8_t  li 
)
inlinestatic

Set leap indicator in a NTP packet.

Parameters
[in]packetThe NTP packet
[in]liLeap indicator

Definition at line 103 of file ntp_packet.h.

◆ ntp_packet_set_mode()

static void ntp_packet_set_mode ( ntp_packet_t packet,
ntp_mode_t  mode 
)
inlinestatic

Set mode in a NTP packet.

Parameters
[in]packetThe NTP packet
[in]modeMode

Definition at line 126 of file ntp_packet.h.

◆ ntp_packet_set_vn()

static void ntp_packet_set_vn ( ntp_packet_t packet)
inlinestatic

Set version in a NTP packet.

Parameters
[in]packetThe NTP packet

Definition at line 114 of file ntp_packet.h.