The NTP packet on the wire (RFC 5905 sec 7.3, Figure 8), shared by the client and server.
More...
|
| #define | PROTOCORE_NTP_PACKET_LEN 48u |
| | One NTP packet on the wire is exactly 48 octets (no extension or MAC fields).
|
| |
| #define | PROTOCORE_NTP_UNIX_OFFSET 2208988800u |
| | Seconds between the NTP prime epoch (1900-01-01) and the Unix epoch (1970-01-01).
|
| |
| #define | PROTOCORE_NTP_PORT 123u |
| | UDP port NTP answers on (RFC 5905 sec 7.2).
|
| |
| #define | PROTOCORE_NTP_OFF_LI_VN_MODE 0u |
| | Leap indicator, version and mode, packed into the first octet.
|
| |
| #define | PROTOCORE_NTP_OFF_STRATUM 1u |
| | Stratum of the sender.
|
| |
| #define | PROTOCORE_NTP_OFF_POLL 2u |
| | Poll interval, log2 seconds, signed.
|
| |
| #define | PROTOCORE_NTP_OFF_PRECISION 3u |
| | Clock precision, log2 seconds, signed.
|
| |
| #define | PROTOCORE_NTP_OFF_ROOT_DELAY 4u |
| | Round-trip delay to the reference clock, 16.16 seconds.
|
| |
| #define | PROTOCORE_NTP_OFF_ROOT_DISP 8u |
| | Dispersion to the reference clock, 16.16 seconds.
|
| |
| #define | PROTOCORE_NTP_OFF_REFID 12u |
| | Reference identifier: a kiss code at stratum 0, a source ID at stratum 1.
|
| |
| #define | PROTOCORE_NTP_OFF_REF_SEC 16u |
| | Reference timestamp, when the sender's clock was last set.
|
| |
| #define | PROTOCORE_NTP_OFF_REF_FRAC 20u |
| |
| #define | PROTOCORE_NTP_OFF_ORIGIN_SEC 24u |
| | Origin timestamp: the client's transmit stamp, echoed by the server.
|
| |
| #define | PROTOCORE_NTP_OFF_ORIGIN_FRAC 28u |
| |
| #define | PROTOCORE_NTP_OFF_RX_SEC 32u |
| | Receive timestamp: when the request reached the server.
|
| |
| #define | PROTOCORE_NTP_OFF_RX_FRAC 36u |
| |
| #define | PROTOCORE_NTP_OFF_TX_SEC 40u |
| | Transmit timestamp: when the reply left, and the field a client reads the time from.
|
| |
| #define | PROTOCORE_NTP_OFF_TX_FRAC 44u |
| |
| #define | PROTOCORE_NTP_LI_VN_MODE(li, vn, mode) ((uint8_t)(((li) << 6) | ((vn) << 3) | (mode))) |
| | li (2) | vn (3) | mode (3), packed into the first octet.
|
| |
| #define | PROTOCORE_NTP_LI_OF(b) ((uint8_t)((b) >> 6)) |
| | The leap indicator carried in the first octet.
|
| |
| #define | PROTOCORE_NTP_VN_OF(b) ((uint8_t)(((b) >> 3) & 0x07u)) |
| | The version carried in the first octet.
|
| |
| #define | PROTOCORE_NTP_MODE_OF(b) ((uint8_t)((b) & 0x07u)) |
| | The mode carried in the first octet.
|
| |
| #define | PROTOCORE_NTP_VERSION 4u |
| | NTP version this speaks (RFC 5905).
|
| |
| #define | PROTOCORE_NTP_MODE_RESERVED 0u |
| |
| #define | PROTOCORE_NTP_MODE_SYM_ACTIVE 1u |
| |
| #define | PROTOCORE_NTP_MODE_SYM_PASSIVE 2u |
| |
| #define | PROTOCORE_NTP_MODE_CLIENT 3u |
| |
| #define | PROTOCORE_NTP_MODE_SERVER 4u |
| |
| #define | PROTOCORE_NTP_MODE_BROADCAST 5u |
| |
| #define | PROTOCORE_NTP_MODE_CONTROL 6u |
| |
| #define | PROTOCORE_NTP_MODE_PRIVATE 7u |
| |
| #define | PROTOCORE_NTP_LI_NONE 0u |
| |
| #define | PROTOCORE_NTP_LI_ADD_SEC 1u |
| |
| #define | PROTOCORE_NTP_LI_DEL_SEC 2u |
| |
| #define | PROTOCORE_NTP_LI_UNSYNC 3u |
| | Leap indicator 3, clock unsynchronized: RFC 4330 sec 5 discards a reply carrying it.
|
| |
| #define | PROTOCORE_NTP_STRATUM_KOD 0u |
| |
| #define | PROTOCORE_NTP_STRATUM_PRIMARY 1u |
| |
| #define | PROTOCORE_NTP_STRATUM_MAX 15u |
| |
| #define | PROTOCORE_NTP_STRATUM_UNSYNC 16u |
| |
| #define | PROTOCORE_NTP_REFID_LOCL 0x4C4F434Cu |
| | Reference ID "LOCL" - an undisciplined local clock (RFC 5905 sec 7.3).
|
| |
| #define | PROTOCORE_NTP_REFID_GPS 0x47505320u |
| | Reference ID "GPS " - a GPS-disciplined reference clock (use with stratum 1).
|
| |
The NTP packet on the wire (RFC 5905 sec 7.3, Figure 8), shared by the client and server.
Layout, field offsets, and the enumerated values either role tests. The client role lives in ntp_service/, the server role in ntp_server/; both read the format from here and neither states any of it a second time.
The header is 48 octets, twelve 32-bit words:
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) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
A timestamp is 32 bits of seconds since the prime epoch then 32 bits of fraction, so each one takes two offsets here. Every multi-octet field is big-endian.
- Author
- Douglas Quigg (dstroy0)
- Date
- 2026
Definition in file ntp.h.