/*
* NTP uses two fixed point formats. The first (l_fp) is the "long"
* format and is 64 bits long with the decimal between bits 31 and 32.
* This is used for time stamps in the NTP packet header (in network
* byte order) and for internal computations of offsets (in local host
* byte order). We use the same structure for both signed and unsigned
* values, which is a big hack but saves rewriting all the operators
* twice. Just to confuse this, we also sometimes just carry the
* fractional part in calculations, in both signed and unsigned forms.
* Anyway, an l_fp looks like:
*ntp使用了两个定点的格式。这第一个l_fp是long型的在31和31位之间是小数点。在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
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Integral Part |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Fractional Part |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
typedef struct {
union {
u_int32 Xl_ui;
int32 Xl_i;
} Ul_i;
union {
u_int32 Xl_uf;
int32 Xl_f;
} Ul_f;
} l_fp;
#define l_ui Ul_i.Xl_ui /* unsigned integral part */
#define l_i Ul_i.Xl_i /* signed integral part */
#define l_uf Ul_f.Xl_uf /* unsigned fractional part */
#define l_f Ul_f.Xl_f /* signed fractional part */
/*
* Fractional precision (of an l_fp) is actually the number of
* bits in a long.
*/
#define FRACTION_PREC (32)
/*
* The second fixed point format is 32 bits, with the decimal between
* bits 15 and 16. There is a signed version (s_fp) and an unsigned
* version (u_fp). This is used to represent synchronizing distance
* and synchronizing dispersion in the NTP packet header (again, in
* network byte order) and internally to hold both distance and
* dispersion values (in local byte order). In network byte order
* it looks like:
*第二种固定点形式是32位的,小数点在15和16点之间,有一个有符号的和一个无符号的版本。这代表同步距离和同步偏差在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
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Integer Part | Fraction Part |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
typedef int32 s_fp;
typedef u_int32 u_fp;