Skip to main content

Crate ntp

Crate ntp 

Source
Expand description

§Example

Shows how to use the ntp library to fetch the current time according to the requested ntp server.

extern crate chrono;
extern crate ntp;

use chrono::TimeZone;

fn main() {
    let address = "time.nist.gov:123";
    let result = ntp::request(address).unwrap();
    let unix_time = ntp::unix_time::Instant::from(result.transmit_timestamp);
    let local_time = chrono::Local.timestamp_opt(unix_time.secs(), unix_time.subsec_nanos() as _).unwrap();
    println!("{}", local_time);
    println!("Offset: {:.6} seconds", result.offset_seconds);
}

Modules§

error
Custom error types for buffer-based NTP packet parsing and serialization. Custom error types for buffer-based NTP packet parsing and serialization.
extension
NTP extension field parsing and NTS extension types.
protocol
Types and constants that precisely match the specification.
unix_time
Unix time conversion utilities for NTP timestamps.

Structs§

KissOfDeathError
Error returned when the server responds with a Kiss-o’-Death (KoD) packet.
NtpResult
The result of an NTP request, containing the server’s response packet along with computed timing information.

Functions§

request
Send a blocking request to an NTP server with a hardcoded 5 second timeout.
request_with_timeout
Send a blocking request to an NTP server with a configurable timeout.