PcapPlusPlus
22.11
|
The NTP packet consists of an integral number of 32-bit (4 octet) words in network byte order. The packet format consists of three components: the header itself, one or more optional extension fields (for v4), and an optional message authentication code (MAC). Currently the extension fields are not supported. The NTP header is: More...
#include <NtpLayer.h>
Public Types | |
enum | LeapIndicator { NoWarning = 0, Last61Secs, Last59Secs, Unknown } |
enum | Mode { Reserved = 0, SymActive, SymPassive, Client, Server, Broadcast, Control, PrivateUse } |
enum | ClockSource { GOES = ('G') | ('O' << 8) | ('E' << 16) | ('S' << 24), GPS = ('G') | ('P' << 8) | ('S' << 16), GAL = ('G') | ('A' << 8) | ('L' << 16), PPS = ('P') | ('P' << 8) | ('S' << 16), IRIG = ('I') | ('R' << 8) | ('I' << 16) | ('G' << 24), WWVB = ('W') | ('W' << 8) | ('V' << 16) | ('B' << 24), DCF = ('D') | ('C' << 8) | ('F' << 16), HBG = ('H') | ('B' << 8) | ('G' << 16), MSF = ('M') | ('S' << 8) | ('F' << 16), JJY = ('J') | ('J' << 8) | ('Y' << 16), LORC = ('L') | ('O' << 8) | ('R' << 16) | ('C' << 24), TDF = ('T') | ('D' << 8) | ('F' << 16), CHU = ('C') | ('H' << 8) | ('U' << 16), WWV = ('W') | ('W' << 8) | ('V' << 16), WWVH = ('W') | ('W' << 8) | ('V' << 16) | ('H' << 24), NIST = ('N') | ('I' << 8) | ('S' << 16) | ('T' << 24), ACTS = ('A') | ('C' << 8) | ('T' << 16) | ('S' << 24), USNO = ('U') | ('S' << 8) | ('N' << 16) | ('O' << 24), PTB = ('P') | ('T' << 8) | ('B' << 16), DCFa = ('D') | ('C' << 8) | ('F' << 16) | ('a' << 24), DCFp = ('D') | ('C' << 8) | ('F' << 16) | ('p' << 24), GPSs = ('G') | ('P' << 8) | ('S' << 16) | ('s' << 24), GPSi = ('G') | ('P' << 8) | ('S' << 16) | ('i' << 24), GLNs = ('G') | ('L' << 8) | ('N' << 16) | ('s' << 24), GLNi = ('G') | ('L' << 8) | ('N' << 16) | ('i' << 24), LCL = ('L') | ('C' << 8) | ('L' << 16), LOCL = ('L') | ('O' << 8) | ('C' << 16) | ('L' << 24), DCN = ('D') | ('C' << 8) | ('N' << 16), TSP = ('T') | ('S' << 8) | ('P' << 16), DTS = ('D') | ('T' << 8) | ('S' << 16), ATOM = ('A') | ('T' << 8) | ('O' << 16) | ('M' << 24), VLF = ('V') | ('L' << 8) | ('F' << 16) } |
Public Member Functions | |
NtpLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) | |
NtpLayer () | |
LeapIndicator | getLeapIndicator () const |
void | setLeapIndicator (LeapIndicator val) |
uint8_t | getVersion () const |
void | setVersion (uint8_t val) |
Mode | getMode () const |
std::string | getModeString () const |
void | setMode (Mode val) |
uint8_t | getStratum () const |
void | setStratum (uint8_t val) |
int8_t | getPollInterval () const |
void | setPollInterval (int8_t val) |
double | getPollIntervalInSecs () const |
int8_t | getPrecision () const |
void | setPrecision (int8_t val) |
double | getPrecisionInSecs () const |
uint32_t | getRootDelay () const |
void | setRootDelay (uint32_t val) |
double | getRootDelayInSecs () const |
void | setRootDelayInSecs (double val) |
uint32_t | getRootDispersion () const |
void | setRootDispersion (uint32_t val) |
double | getRootDispersionInSecs () const |
void | setRootDispersionInSecs (double val) |
uint32_t | getReferenceIdentifier () const |
void | setReferenceIdentifier (IPv4Address val) |
void | setReferenceIdentifier (ClockSource val) |
std::string | getReferenceIdentifierString () const |
uint64_t | getReferenceTimestamp () const |
void | setReferenceTimestamp (uint64_t val) |
double | getReferenceTimestampInSecs () const |
void | setReferenceTimestampInSecs (double val) |
std::string | getReferenceTimestampAsString () |
uint64_t | getOriginTimestamp () const |
void | setOriginTimestamp (uint64_t val) |
double | getOriginTimestampInSecs () const |
void | setOriginTimestampInSecs (double val) |
std::string | getOriginTimestampAsString () |
uint64_t | getReceiveTimestamp () const |
void | setReceiveTimestamp (uint64_t val) |
double | getReceiveTimestampInSecs () const |
void | setReceiveTimestampInSecs (double val) |
std::string | getReceiveTimestampAsString () |
uint64_t | getTransmitTimestamp () const |
void | setTransmitTimestamp (uint64_t val) |
double | getTransmitTimestampInSecs () const |
void | setTransmitTimestampInSecs (double val) |
std::string | getTransmitTimestampAsString () |
uint32_t | getKeyID () const |
std::string | getDigest () const |
void | parseNextLayer () |
Parses the next layer. NTP is the always last so does nothing for this layer. | |
size_t | getHeaderLen () const |
void | computeCalculateFields () |
Does nothing for this layer. | |
OsiModelLayer | getOsiModelLayer () const |
std::string | toString () const |
Public Member Functions inherited from pcpp::Layer | |
virtual | ~Layer () |
Layer * | getNextLayer () const |
Layer * | getPrevLayer () const |
ProtocolType | getProtocol () const |
uint8_t * | getData () const |
size_t | getDataLen () const |
uint8_t * | getLayerPayload () const |
size_t | getLayerPayloadSize () const |
bool | isAllocatedToPacket () const |
void | copyData (uint8_t *toArr) const |
uint8_t * | getDataPtr (size_t offset=0) const |
Static Public Member Functions | |
static double | convertFromShortFormat (const uint32_t val) |
static double | convertFromTimestampFormat (const uint64_t val) |
static uint32_t | convertToShortFormat (const double val) |
static uint64_t | convertToTimestampFormat (const double val) |
static std::string | convertToIsoFormat (const double timestamp) |
static std::string | convertToIsoFormat (const uint64_t timestampInNTPformat) |
static bool | isDataValid (const uint8_t *data, size_t dataSize) |
static bool | isNTPPort (uint16_t port) |
The NTP packet consists of an integral number of 32-bit (4 octet) words in network byte order. The packet format consists of three components: the header itself, one or more optional extension fields (for v4), and an optional message authentication code (MAC). Currently the extension fields are not supported. The NTP header is:
Represents a NTP (Network Time Protocol) layer
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |LI | VN |Mode | Stratum | Poll | Precision | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Root Delay | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Root Dispersion | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Reference ID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | + Reference Timestamp (64) + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | + Origin Timestamp (64) + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | + Receive Timestamp (64) + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | + Transmit Timestamp (64) + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | . . . Extension Field 1 (variable, only v4) . . . | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | . . . Extension Field 1 (variable, only v4) . . . | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Key Identifier | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | dgst (128 for v4, 64 for v3) | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32-bit code identifying the particular server or reference clock. The interpretation depends on the value in the stratum field.
Enumerator | |
---|---|
GOES | Geosynchronous Orbit Environment Satellite. |
GPS | Global Position System. |
GAL | Galileo Positioning System. |
PPS | Generic pulse-per-second. |
IRIG | Inter-Range Instrumentation Group. |
WWVB | LF Radio WWVB Ft. Collins, CO 60 kHz. |
DCF | LF Radio DCF77 Mainflingen, DE 77.5 kHz. |
HBG | LF Radio HBG Prangins, HB 75 kHz. |
MSF | LF Radio MSF Anthorn, UK 60 kHz. |
JJY | LF Radio JJY Fukushima, JP 40 kHz, Saga, JP 60 kHz. |
LORC | MF Radio LORAN C station, 100 kHz. |
TDF | MF Radio Allouis, FR 162 kHz. |
CHU | HF Radio CHU Ottawa, Ontario. |
WWV | HF Radio WWV Ft. Collins, CO. |
WWVH | HF Radio WWVH Kauai, HI. |
NIST | NIST telephone modem. |
ACTS | NIST telephone modem. |
USNO | USNO telephone modem. |
PTB | European telephone modem. |
DCFa | Meinberg DCF77 with amplitude modulation (Ref: https://www.meinbergglobal.com/english/info/ntp-refid.htm) |
DCFp | Meinberg DCF77 with phase modulation)/pseudo random phase modulation (Ref: https://www.meinbergglobal.com/english/info/ntp-refid.htm) |
GPSs | Meinberg GPS (with shared memory access) (Ref: https://www.meinbergglobal.com/english/info/ntp-refid.htm) |
GPSi | Meinberg GPS (with interrupt based access) (Ref: https://www.meinbergglobal.com/english/info/ntp-refid.htm) |
GLNs | Meinberg GPS/GLONASS (with shared memory access) (Ref: https://www.meinbergglobal.com/english/info/ntp-refid.htm) |
GLNi | Meinberg GPS/GLONASS (with interrupt based access) (Ref: https://www.meinbergglobal.com/english/info/ntp-refid.htm) |
LCL | Meinberg Undisciplined local clock (Ref: https://www.meinbergglobal.com/english/info/ntp-refid.htm) |
LOCL | Meinberg Undisciplined local clock (Ref: https://www.meinbergglobal.com/english/info/ntp-refid.htm) |
DCN | DCN routing protocol. |
TSP | TSP time protocol. |
DTS | Digital Time Service. |
ATOM | Atomic clock (calibrated) |
VLF | VLF radio (OMEGA, etc.) |
enum pcpp::NtpLayer::Mode |
|
inline |
A constructor that creates the layer from an existing packet raw data
[in] | data | A pointer to the raw data |
[in] | dataLen | Size of the data in bytes |
[in] | prevLayer | A pointer to the previous layer |
[in] | packet | A pointer to the Packet instance where layer will be stored in |
pcpp::NtpLayer::NtpLayer | ( | ) |
Empty c'tor
|
static |
Convert NTP short format to seconds from the Unix Epoch
[in] | val | Value in NTP short format |
|
static |
Convert NTP timestamp format to seconds from the Unix Epoch
[in] | val | Value in NTP timestamp format |
|
static |
A static method to convert timestamp value to ISO8601 date time format
[in] | timestamp | Value in seconds from the Unix Epoch |
|
static |
A static method to convert timestamp value to ISO8601 date time format
[in] | timestampInNTPformat | Value in NTP timestamp format |
|
static |
Convert seconds from the Unix Epoch to NTP short format
[in] | val | Value in seconds from Unix Epoch (1 Jan 1970) |
|
static |
Convert seconds from the Unix Epoch to NTP timestamp format
[in] | val | Value in seconds from Unix Epoch (1 Jan 1970) |
std::string pcpp::NtpLayer::getDigest | ( | ) | const |
|
inlinevirtual |
Implements pcpp::Layer.
uint32_t pcpp::NtpLayer::getKeyID | ( | ) | const |
LeapIndicator pcpp::NtpLayer::getLeapIndicator | ( | ) | const |
Mode pcpp::NtpLayer::getMode | ( | ) | const |
std::string pcpp::NtpLayer::getModeString | ( | ) | const |
uint64_t pcpp::NtpLayer::getOriginTimestamp | ( | ) | const |
std::string pcpp::NtpLayer::getOriginTimestampAsString | ( | ) |
double pcpp::NtpLayer::getOriginTimestampInSecs | ( | ) | const |
|
inlinevirtual |
Implements pcpp::Layer.
int8_t pcpp::NtpLayer::getPollInterval | ( | ) | const |
double pcpp::NtpLayer::getPollIntervalInSecs | ( | ) | const |
int8_t pcpp::NtpLayer::getPrecision | ( | ) | const |
double pcpp::NtpLayer::getPrecisionInSecs | ( | ) | const |
uint64_t pcpp::NtpLayer::getReceiveTimestamp | ( | ) | const |
std::string pcpp::NtpLayer::getReceiveTimestampAsString | ( | ) |
double pcpp::NtpLayer::getReceiveTimestampInSecs | ( | ) | const |
uint32_t pcpp::NtpLayer::getReferenceIdentifier | ( | ) | const |
std::string pcpp::NtpLayer::getReferenceIdentifierString | ( | ) | const |
uint64_t pcpp::NtpLayer::getReferenceTimestamp | ( | ) | const |
std::string pcpp::NtpLayer::getReferenceTimestampAsString | ( | ) |
double pcpp::NtpLayer::getReferenceTimestampInSecs | ( | ) | const |
uint32_t pcpp::NtpLayer::getRootDelay | ( | ) | const |
double pcpp::NtpLayer::getRootDelayInSecs | ( | ) | const |
uint32_t pcpp::NtpLayer::getRootDispersion | ( | ) | const |
double pcpp::NtpLayer::getRootDispersionInSecs | ( | ) | const |
uint8_t pcpp::NtpLayer::getStratum | ( | ) | const |
uint64_t pcpp::NtpLayer::getTransmitTimestamp | ( | ) | const |
std::string pcpp::NtpLayer::getTransmitTimestampAsString | ( | ) |
double pcpp::NtpLayer::getTransmitTimestampInSecs | ( | ) | const |
uint8_t pcpp::NtpLayer::getVersion | ( | ) | const |
|
static |
A static method that takes a byte array and detects whether it is a NTP message
[in] | data | A byte array |
[in] | dataSize | The byte array size (in bytes) |
|
inlinestatic |
A static method that checks whether the port is considered as NTP
[in] | port | The port number to be checked |
void pcpp::NtpLayer::setLeapIndicator | ( | LeapIndicator | val | ) |
Set the leap indicator
void pcpp::NtpLayer::setMode | ( | Mode | val | ) |
Set the mode
void pcpp::NtpLayer::setOriginTimestamp | ( | uint64_t | val | ) |
Set the value of origin timestamp
[in] | val | Value in NTP timestamp format |
void pcpp::NtpLayer::setOriginTimestampInSecs | ( | double | val | ) |
Set the value of origin timestamp
[in] | val | Value in seconds from Unix Epoch (1 Jan 1970) |
void pcpp::NtpLayer::setPollInterval | ( | int8_t | val | ) |
Set the value of poll interval
[in] | val | Poll interval in log2 seconds |
void pcpp::NtpLayer::setPrecision | ( | int8_t | val | ) |
Set the value of precision
[in] | val | Precision in log2 seconds |
void pcpp::NtpLayer::setReceiveTimestamp | ( | uint64_t | val | ) |
Set the value of receive timestamp
[in] | val | Value in NTP timestamp format |
void pcpp::NtpLayer::setReceiveTimestampInSecs | ( | double | val | ) |
Set the value of receive timestamp
[in] | val | Value in seconds from Unix Epoch (1 Jan 1970) |
void pcpp::NtpLayer::setReferenceIdentifier | ( | IPv4Address | val | ) |
Set the value of reference identifier
[in] | val | Value of the reference identifier as IPv4 address |
void pcpp::NtpLayer::setReferenceIdentifier | ( | ClockSource | val | ) |
Set the value of reference identifier
[in] | val | Value of the reference identifier as ClockSource |
void pcpp::NtpLayer::setReferenceTimestamp | ( | uint64_t | val | ) |
Set the value of reference timestamp
[in] | val | Timestamp in NTP timestamp format |
void pcpp::NtpLayer::setReferenceTimestampInSecs | ( | double | val | ) |
Set the value of reference timestamp
[in] | val | Value in seconds from Unix Epoch (1 Jan 1970) |
void pcpp::NtpLayer::setRootDelay | ( | uint32_t | val | ) |
Set the value of root delay
[in] | val | Root delay in NTP short format |
void pcpp::NtpLayer::setRootDelayInSecs | ( | double | val | ) |
Set the value of root delay
[in] | val | Root delay in seconds |
void pcpp::NtpLayer::setRootDispersion | ( | uint32_t | val | ) |
Set the value of root delay
[in] | val | Root dispersion in NTP short format |
void pcpp::NtpLayer::setRootDispersionInSecs | ( | double | val | ) |
Set the value of root dispersion
[in] | val | Root dispersion in seconds |
void pcpp::NtpLayer::setStratum | ( | uint8_t | val | ) |
Set the value of stratum
void pcpp::NtpLayer::setTransmitTimestamp | ( | uint64_t | val | ) |
Set the value of transmit timestamp
[in] | val | Value in NTP timestamp format |
void pcpp::NtpLayer::setTransmitTimestampInSecs | ( | double | val | ) |
Set the value of transmit timestamp
[in] | val | Value in seconds from Unix Epoch (1 Jan 1970) |
void pcpp::NtpLayer::setVersion | ( | uint8_t | val | ) |
Set the version of NTP
|
virtual |
Implements pcpp::Layer.