1
1
Fork
You've already forked ntp_client
1
NTP client CLI in Zig
  • Zig 100%
2026年04月29日 14:07:58 +02:00
docs add leap seconds list from ftp.boulder.nist.gov 2025年04月22日 10:03:58 +02:00
src fix queue issue, re-implement timeout 2026年02月20日 10:04:57 +01:00
.gitattributes initial upload 2024年05月20日 16:40:05 +02:00
.gitignore rmv try for clock.real.now 2026年02月11日 09:15:08 +01:00
build.zig bump version 2026年04月18日 15:01:29 +02:00
build.zig.zon bump zdt 2026年04月29日 14:07:58 +02:00
CHANGELOG.md bump version 2026年04月18日 15:01:29 +02:00
LICENSE bump zdt 2026年04月29日 14:07:58 +02:00
README.md update readme 2025年06月18日 17:11:22 +02:00

Zig License: MIT

NTP Client

Command line app to query an NTP server, e.g. to verify your OS clock setting. Or get the time independent of your OS clock. Or mess with your local NTP server.

Usage

Building the binary

zig build -Dexe [--release=[safe|small|fast]]
# build and run, debug: zig build -Dexe run
# library tests: zig build test

NTP library

Currently targets SNTP (RFC4330), does not implement the full NTP spec. src/ntp.zig can be used independently in other projects; it is exposed via this project's build.zig and build.zig.zon files. Other dependencies of the binary are lazy, i.e. they won't be fetched if you use only the library in another project.

Usage of the binary

Usage: ntp_client [options]
Options:
 -s, --server NTP server to query (default: pool.ntp.org)
 -v, --protocol-version NTP protocol version, 3 or 4 (default: 4)
 -4, --ipv4 use IPv4 instead of the default IPv6
 --src-ip IP address to use for sending the query (default: 0::0 / IPv6 auto-select)
 --src-port UDP port to use for sending the query (default: 0 / any port)
 --dst-port UDP port of destination server (default: 123)
 -z, --timezone Timezone to use in console output (default: UTC)
 -j, --json Print result as a JSON string
 -i, --interval Interval for repeated queries in seconds (default: null / one-shot operation)
 -a, --all Query all IP addresses found for a given server URL (default: false / stop after first)
 -h, --help Show this help and exit

Demo output

zig build run -Dexe --release=safe -- -4 -z local
---***---
Server name: "pool.ntp.org"
Server address: "178.63.67.56:123"
---
LI=0 VN=4 Mode=4 Stratum=2 Poll=0 (0 s) Precision=-25 (29 ns)
ID: 0xDAA2684D
Server root dispersion: 686 us, root delay: 31036 us
---
Server last synced : 2025年06月18日T17:04:47.182320188+02:00
T1, packet created : 2025年06月18日T17:09:33.295124493+02:00
T2, server received : 2025年06月18日T17:09:33.286877204+02:00
T3, server replied : 2025年06月18日T17:09:33.286925770+02:00
T4, reply received : 2025年06月18日T17:09:33.316002877+02:00
(timezone displayed: Europe/Berlin)
---
Offset to timserver: -0.019 s (-18663 us)
Round-trip delay: 0.021 s (20829 us)
---
Result flags: 0 (OK)
---***---

Compatibility and Requirements

Developed & tested mostly on Debian Linux, on an x86 machine. Windows worked last time I tested (build.zig links libc for this), Mac OS might work (can't test this).

Zig version

I try to track Zig master with this package; might not compile with older versions.

Dependencies

  • flags for command line argument parsing
  • zdt to display timestamps as timezone-local datetimes

License

MIT. See the LICENSE file in the root directory of the repository.