Skip to main content

Crate ntp_client

Crate ntp_client 

Source
Expand description

§Example

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

extern crate chrono;
extern crate ntp_client;

use chrono::TimeZone;

fn main() {
    let address = "time.nist.gov:123";
    let result = ntp_client::request(address).unwrap();
    let unix_time = ntp_client::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. NTP extension field parsing and NTS (Network Time Security) extension types.
protocol
NTP protocol types and constants (RFC 5905). 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.