Simple Rust SNTP client
This crate provides a method for sending requests to NTP servers and process responses, extracting received timestamp.
Supported SNTP protocol versions:
Documentation
Installation
This crate works with Cargo and is on
crates.io. Add it to your Cargo.toml
like so:
[]
= "0.4.0"
By calling the get_time() method and providing a proper NTP pool or server you
should get a valid synchronization timestamp:
use UdpSocket;
use Duration;
no_std support
Currently, there are basic no_std support available, thanks to no-std-net
crate. There is an example available on how to use smoltcp stack and that should provide
general idea on how to bootstrap no_std networking and timestamping tools for sntpc library usage
async support
Feature async_tokio allows to use crate together with tokio.
Example available in the repository.
There is also no_std support with feature async, but it requires Rust >= 1.75-nightly version.
The example can be found in separate repository.
Examples
You can find several examples that shows how to use the library in details under [examples/] folder. Currently, there are examples that show:
- usage of SNTP library in
stdenvironment - usage of SNTP library with
smoltcpTCP/IP stack. Somestddependencies required only due to smoltcp available interfaces
Contribution
Contributions are always welcome! If you have an idea, it's best to float it by me before working on it to ensure no effort is wasted. If there's already an open issue for it, knock yourself out. See the contributing section for additional details
Thanks
- Frank A. Stevenson: for implementing stricter adherence to RFC4330 verification scheme
- Timothy Mertz: for fixing possible overflow in offset calculation
- HannesH: for fixing a typo in the README.md
- Richard Penney: for adding two indicators of the NTP server's accuracy into the
NtpResultstructure - Vitali Pikulik: for adding
asyncsupport - tsingwong: for fixing invalid link in the
README.md - Robert Bastian: for fixing the overflow issue in the
calculate_offset
Really appreciate all your efforts! Please let me know if I forgot someone.