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:

```rust 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.getunixtime().unwrap(), 0); println!("{}", timestamp); } ```

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

```rust extern crate sntp_request;

use sntp_request::SntpRequest;

fn main() { let sntp = SntpRequest::new(); let timestamp = sntp.getrawtime().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:

ini [dependencies] sntp_request = "2.0.0"

and this to your crate root:

rust extern crate sntp_request;

Contributions

Pull Requests and Issues are welcome!

License

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