pub struct Packet {Show 13 fields
pub leap_indicator: LeapIndicator,
pub version: Version,
pub mode: Mode,
pub stratum: Stratum,
pub poll: i8,
pub precision: i8,
pub root_delay: ShortFormat,
pub root_dispersion: ShortFormat,
pub reference_id: ReferenceIdentifier,
pub reference_timestamp: TimestampFormat,
pub origin_timestamp: TimestampFormat,
pub receive_timestamp: TimestampFormat,
pub transmit_timestamp: TimestampFormat,
}Expand description
Packet Header - The most important state variables from an external point of view are the packet header variables described here.
The NTP packet header 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, and an optional message authentication code (MAC).
+-----------+------------+-----------------------+
| Name | Formula | Description |
+-----------+------------+-----------------------+
| leap | leap | leap indicator (LI) |
| version | version | version number (VN) |
| mode | mode | mode |
| stratum | stratum | stratum |
| poll | poll | poll exponent |
| precision | rho | precision exponent |
| rootdelay | delta_r | root delay |
| rootdisp | epsilon_r | root dispersion |
| refid | refid | reference ID |
| reftime | reftime | reference timestamp |
| org | T1 | origin timestamp |
| rec | T2 | receive timestamp |
| xmt | T3 | transmit timestamp |
| dst | T4 | destination timestamp |
| keyid | keyid | key ID |
| dgst | dgst | message digest |
+-----------+------------+-----------------------+§Format
The NTP packet is a UDP datagram [RFC0768]. Some fields use multiple words and others are packed in smaller fields within a word. The NTP packet header shown below has 12 words followed by optional extension fields and finally an optional message authentication code (MAC) consisting of the Key Identifier field and Message Digest field.
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) .
. .
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
. .
. Extension Field 2 (variable) .
. .
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Key Identifier |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| dgst (128) |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+Fields§
§leap_indicator: LeapIndicatorLeap indicator warning of impending leap second.
version: VersionNTP protocol version number (1-4).
mode: ModeAssociation mode (client, server, broadcast, etc.).
stratum: StratumStratum level of the time source (0-15).
poll: i88-bit signed integer representing the maximum interval between successive messages, in log2 seconds. Suggested default limits for minimum and maximum poll intervals are 6 and 10, respectively.
precision: i88-bit signed integer representing the precision of the system clock, in log2 seconds. For instance, a value of -18 corresponds to a precision of about one microsecond. The precision can be determined when the service first starts up as the minimum time of several iterations to read the system clock.
root_delay: ShortFormatTotal round-trip delay to the reference clock, in NTP short format.
root_dispersion: ShortFormatTotal dispersion to the reference clock, in NTP short format.
reference_id: ReferenceIdentifierReference identifier (clock source or server address).
reference_timestamp: TimestampFormatTime when the system clock was last set or corrected.
origin_timestamp: TimestampFormatTime at the client when the request departed for the server.
receive_timestamp: TimestampFormatTime at the server when the request arrived from the client.
transmit_timestamp: TimestampFormatTime at the server when the response left for the client.
Trait Implementations§
Source§impl ConstPackedSizeBytes for Packet
impl ConstPackedSizeBytes for Packet
Source§const PACKED_SIZE_BYTES: usize
const PACKED_SIZE_BYTES: usize
Source§impl FromBytes for Packet
impl FromBytes for Packet
Source§fn from_bytes(buf: &[u8]) -> Result<(Self, usize), ParseError>
fn from_bytes(buf: &[u8]) -> Result<(Self, usize), ParseError>
buf.Source§impl ReadFromBytes for Packet
Available on crate feature std only.
impl ReadFromBytes for Packet
std only.Source§fn read_from_bytes<R: ReadBytesExt>(reader: R) -> Result<Self>
fn read_from_bytes<R: ReadBytesExt>(reader: R) -> Result<Self>
Source§impl ToBytes for Packet
impl ToBytes for Packet
Source§fn to_bytes(&self, buf: &mut [u8]) -> Result<usize, ParseError>
fn to_bytes(&self, buf: &mut [u8]) -> Result<usize, ParseError>
ParseError::BufferTooShort if buf is too short.Source§impl WriteToBytes for Packet
Available on crate feature std only.
impl WriteToBytes for Packet
std only.