4 releases

0.2.0 Jan 3, 2020
0.1.2 Dec 22, 2019
0.1.1 Feb 15, 2019
0.1.0 Feb 15, 2019

#59 in Date and time

Download history 165/week @ 2021-02-24 178/week @ 2021-03-03 132/week @ 2021-03-10 127/week @ 2021-03-17 115/week @ 2021-03-24 104/week @ 2021-03-31 127/week @ 2021-04-07 209/week @ 2021-04-14 97/week @ 2021-04-21 206/week @ 2021-04-28 69/week @ 2021-05-05 26/week @ 2021-05-12 17/week @ 2021-05-19 81/week @ 2021-05-26 115/week @ 2021-06-02 74/week @ 2021-06-09

576 downloads per month
Used in ntpalert

BSD-3-Clause

22KB
485 lines

Build Status

Simple Rust NTP client

This crate provides a method for sending requests to NTP servers and process responses, extracting received timestamp

Documentation

https://docs.rs/sntpc

Installation

This crate works with Cargo and is on crates.io. Add it to your Cargo.toml like so:

[dependencies]
sntpc = "0.2"

By calling the request() method and providing a proper NTP pool or server you should get a valid synchronization timestamp:

use sntpc;

let result = sntpc::request("pool.ntp.org", 123);
if let Ok(sntpc::NtpResult {
    sec, nsec, roundtrip, offset
}) = result {
    println!("NTP server time: {}.{}", sec, nsec);
    println!("Roundtrip time: {}, offset: {}", roundtrip, offset);
}

Lightweight system time synchronization

The sntpc crate contains the timesync application that may sync system time with the given NTP server

Command-line options

USAGE:
    timesync [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -p, --port <port>        NTP server port [default: 123]
    -s, --server <server>    NTP server hostname [default: time.google.com]

This is the output of timesync -h.

Dependencies

~2MB
~28K SLoC