- Zig 100%
| docs | add leap seconds list from ftp.boulder.nist.gov | |
| src | fix queue issue, re-implement timeout | |
| .gitattributes | initial upload | |
| .gitignore | rmv try for clock.real.now | |
| build.zig | bump version | |
| build.zig.zon | bump zdt | |
| CHANGELOG.md | bump version | |
| LICENSE | bump zdt | |
| README.md | update readme | |
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
License
MIT. See the LICENSE file in the root directory of the repository.