ntp.nx
buildroot/runtime/ntp.nx
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
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 63 | struct NtpPacket { |
consts
| 54 | const NTP_PACKET_SIZE: i64 = 48 |
| 55 | const NTP_UNIX_EPOCH_DELTA: i64 = 2208988800 |
| 57 | const NTP_MODE_CLIENT: i64 = 3 |
| 58 | const NTP_MODE_SERVER: i64 = 4 |
| 59 | const NTP_MODE_BROADCAST: i64 = 5 |
| 61 | const NTP_ERR_SHORT: i64 = -1 |
functions
| 84 | func ntp_read_u32_be(buf: *u8, off: i64) -> i64 { |
| 93 | func ntp_write_u32_be(buf: *u8, off: i64, v: i64) -> i64 {
called by 1: ntp_write_ts |
| 103 | func ntp_read_ts(buf: *u8, off: i64, |
| 116 | func ntp_write_ts(buf: *u8, off: i64, unix_sec: i64, frac: i64) -> i64 { |
| 125 | func ntp_parse(buf: *u8, n: i64, pkt: *NtpPacket) -> i64 { |
| 152 | func ntp_build_client(buf: *u8, cap: i64, |
| 170 | func main() -> i64 { |