netpkt/ntp.rs#
Source: lib/netpkt/ntp.rs
ntp -- the Network Time Protocol packet (RFC 5905: the 48-byte header; extension fields and
MACs are not read)
Ts(u64) 32.32 fixed-point seconds since 1900 (era 0, until 2036);
from_unix_ns / to_unix_ns round to the nearest step, so whole
nanoseconds survive the round trip
NtpView::parse(b) li, vn, mode, stratum, poll, precision, root_delay, root_disp,
refid, reference, origin, receive, transmit
Ntp { .. } read / to_bytes / client(vn, transmit)
offset_delay(t1, t2, t3, t4) -> (offset, delay) the on-wire calculation (RFC 5905 8)
civil(unix_secs) -> (year, month, day, hour, minute, second) UTC, for dissectors
MODE_* / LI_*; mode_name
NTP_LEN: usize = 48
/// seconds from 1900-01-01 to 1970-01-01
UNIX_OFFSET: u64 = 2_208_988_800
MODE_SYM_ACTIVE: u8 = 1
MODE_SYM_PASSIVE: u8 = 2
MODE_CLIENT: u8 = 3
MODE_SERVER: u8 = 4
MODE_BROADCAST: u8 = 5
LI_NONE: u8 = 0
/// the clock is not synchronised
LI_ALARM: u8 = 3
fn mode_name(m: u8) -> &'static strstruct Ts(pub u64)an NTP timestamp
impl Ts
fn from_unix_ns(ns: i64) -> Tsnanoseconds since 1970 (era 0)fn to_unix_ns(self) -> i64fn secs(self) -> u32fn frac(self) -> u32struct NtpView<'a>a received NTP packet
impl<'a> NtpView<'a>
fn parse(b: &'a [u8]) -> Option<NtpView<'a>>fn li(&self) -> u8fn vn(&self) -> u8fn mode(&self) -> u8fn stratum(&self) -> u8fn poll(&self) -> i8fn precision(&self) -> i8fn root_delay(&self) -> u3216.16 secondsfn root_disp(&self) -> u32fn refid(&self) -> [u8; 4]fn reference(&self) -> Tsfn origin(&self) -> Tsfn receive(&self) -> Tsfn transmit(&self) -> Tsstruct Ntpan NTP packet to writeli: u8vn: u8mode: u8stratum: u8poll: i8precision: i8root_delay: u32root_disp: u32refid: [u8; 4]reference: Tsorigin: Tsreceive: Tstransmit: Ts
impl Ntp
fn client(vn: u8, transmit: Ts) -> Ntpa client request: only the version, the mode and the transmit time (RFC 4330 style, as SNTP clients and chrony send)fn read(v: &NtpView) -> Ntpfn to_bytes(&self) -> Vec<u8>fn offset_delay(t1: i64, t2: i64, t3: i64, t4: i64) -> (i64, i64)the clock offset and the round-trip delay from the four times of an exchange (client send t1, server receive t2, server send t3, client receive t4; all in ns)fn civil(unix_secs: i64) -> (i32, u8, u8, u8, u8, u8)the UTC calendar date and time of a Unix time (days from civil, H. Hinnant)