sntp_request 2.0.0

Tiny Rust library to request timestamp from NTP servers trough SNTP protocol.
Documentation

sntp_request

Build Status Crates.io Documentation License

sntp_request Tiny Rust library to request timestamp from NTP servers trough SNTP protocol.

Example

The example below shows how to obtain precise timestamp from main NTP server:

extern crate chrono;
extern crate sntp_request;

use chrono::{Local, TimeZone};
use sntp_request::SntpRequest;

fn main() {
    let sntp = SntpRequest::new();
    let timestamp = Local.timestamp(sntp.get_unix_time().unwrap(), 0);
    println!("{}", timestamp);
}

Also, it is possible to get the raw timestamp, for example:

extern crate sntp_request;

use sntp_request::SntpRequest;

fn main() {
    let sntp = SntpRequest::new();
    let timestamp = sntp.get_raw_time().unwrap();
    let nsec = (timestamp.frac as f64 / u32::max_value() as f64) * 1000.0;
    println!("seconds: {} frac: {}", timestamp.secs, timestamp.frac);
    println!("milliseconds: {}", nsec);
}

Usage

Add this to your Cargo.toml:

[dependencies]
sntp_request = "2.0.0"

and this to your crate root:

extern crate sntp_request;

Contributions

Pull Requests and Issues are welcome!

License

sntp_request is licensed under either of the following, at your option: