code wiki / (root) / ntp.nx

ntp.nx

buildroot/runtime/ntp.nx

7759 B193 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

ntp.nx -- NTPv4 packet parser + builder (RFC 5905). Fixed 48-byte client/server packet over UDP port 123. Lets the Nishi stack sync clock against a time server without ntpd, chrony, or systemd-timesyncd. Essential for: - file mtimes that survive reboots - TLS certificate validity checks - log timestamp ordering across machines - obligation-ledger timestamps (nishi-prm) Packet layout (big-endian multi-byte): 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |LI | VN |Mode | Stratum | Poll | Precision | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Root Delay | +---------------------------------------------------------------+ | Root Dispersion | +---------------------------------------------------------------+ | Reference ID | +---------------------------------------------------------------+ | Reference Timestamp (64) | +---------------------------------------------------------------+ | Origin Timestamp (64) | +---------------------------------------------------------------+ | Receive Timestamp (64) | +---------------------------------------------------------------+ | Transmit Timestamp (64) | +---------------------------------------------------------------+ NTP 64-bit timestamps: seconds since 1900-01-01 00:00 UTC in the upper 32 bits; fractional seconds in the lower 32 bits (each tick = 1/2^32 seconds ≈ 232 picoseconds). Unix epoch differs by 2208988800 seconds (NTP era 0). Mode values (LI=0, VN=4 typical): 3 client 4 server 5 broadcast

dependencies 1 imports · 0 importers

syscalls.nx ntp.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main ntp_build_client ntp_write_ts ntp_write_u32_be ntp_parse ntp_read_u32_be ntp_read_ts ntp_read_u32_be ↻

structs

63struct NtpPacket {

consts

54const NTP_PACKET_SIZE: i64 = 48
55const NTP_UNIX_EPOCH_DELTA: i64 = 2208988800
57const NTP_MODE_CLIENT: i64 = 3
58const NTP_MODE_SERVER: i64 = 4
59const NTP_MODE_BROADCAST: i64 = 5
61const NTP_ERR_SHORT: i64 = -1

functions

84func ntp_read_u32_be(buf: *u8, off: i64) -> i64 {
93func ntp_write_u32_be(buf: *u8, off: i64, v: i64) -> i64 {
called by 1: ntp_write_ts
103func ntp_read_ts(buf: *u8, off: i64,
called by 1: ntp_parse calls 1: ntp_read_u32_be
116func ntp_write_ts(buf: *u8, off: i64, unix_sec: i64, frac: i64) -> i64 {
called by 1: ntp_build_client calls 1: ntp_write_u32_be
125func ntp_parse(buf: *u8, n: i64, pkt: *NtpPacket) -> i64 {
called by 1: main calls 2: ntp_read_u32_bentp_read_ts
152func ntp_build_client(buf: *u8, cap: i64,
called by 1: main calls 1: ntp_write_ts
170func main() -> i64 {