附录 B. NTP 数据格式
紧随 UDP 头部之后的 NTP 数据部分的格式,连同其各字段的说明,如下所示。
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 | Status | Type | Precision |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Estimated Error |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Estimated Drift Rate |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reference Clock Identifier |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Reference Timestamp (64 bits) |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Originate Timestamp (64 bits) |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Receive Timestamp (64 bits) |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Transmit Timestamp (64 bits) |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Leap Indicator (LI)
预告即将在当月最后一天结束时插入闰秒的代码。各位的编码如下:
00 no warning
01 +1 second (following minute has 61 seconds)
10 -1 second (following minute has 59 seconds)
11 reserved for future use
Status
指示本地时钟状态的代码。各值定义如下:
0 clock operating correctly
1 carrier loss
2 synch loss
3 format error
4 interface (Type 1) or link (Type 2) failure
(additional codes reserved for future use)
Reference Clock Type (Type)
标识参考时钟类型的代码。各值定义如下:
0 unspecified
1 primary reference (e.g. radio clock)
2 secondary reference using an Internet host via NTP
3 secondary reference using some other host or protocol
4 eyeball-and-wristwatch
(additional codes reserved for future use)
Precision
取值范围为 +32 到 -32 的有符号整数,以最接近的 2 的幂次的秒数表示本地时钟的精度。
Estimated Error
定点数,表示本地时钟在上次设置时的估计误差,以秒为单位,小数点位于第 15 位与第 16 位之间。
Estimated Drift Rate
有符号定点数,表示本地时钟的估计漂移率,单位无量纲,小数点位于最高位的左侧。
Reference Clock Identifier
标识具体参考时钟的代码。对于类型 1(主参考),这是一个左对齐、以零填充的 ASCII 字符串,用于标识该时钟,例如:
WWVB WWVB radio clock (60 KHz)
GOES GOES satellite clock (468 HMz)
WWV WWV radio clock (2.5/5/10/15/20 MHz)
(and others as necessary)
对于类型 2(次级参考),这是参考主机的 32 位互联网地址。在其他情况下,该字段保留供将来使用,并应置为零。
Reference Timestamp
本地时钟上次被设置或修正时的本地时间。
Originate Timestamp
请求从客户端主机发往服务主机时的本地时间。
Receive Timestamp
请求到达服务主机时的本地时间。
Transmit Timestamp
应答从服务主机发往客户端主机时的本地时间。