xref: /openbsd/usr.sbin/tcpdump/ntp.h (revision 73471bf0)
1 /*	$OpenBSD: ntp.h,v 1.7 2007/10/07 16:41:05 deraadt Exp $	*/
2 
3 /* $Id: ntp.h,v 1.7 2007/10/07 16:41:05 deraadt Exp $ */
4 
5 /*
6  * Based on ntp.h from the U of MD implementation
7  *	This file is based on Version 2 of the NTP spec (RFC1119).
8  */
9 
10 /*
11  *  Definitions for the masses
12  */
13 #define	JAN_1970	2208988800	/* 1970 - 1900 in seconds */
14 
15 /*
16  * Structure definitions for NTP fixed point values
17  *
18  *    0			  1		      2			  3
19  *    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
20  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
21  *   |			       Integer Part			     |
22  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
23  *   |			       Fraction Part			     |
24  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
25  *
26  *    0			  1		      2			  3
27  *    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
28  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29  *   |		  Integer Part	     |	   Fraction Part	     |
30  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31 */
32 struct l_fixedpt {
33 	u_int32_t int_part;
34 	u_int32_t fraction;
35 };
36 
37 struct s_fixedpt {
38 	u_short int_part;
39 	u_short fraction;
40 };
41 
42 /*  =================  Table 3.3. Packet Variables   ================= */
43 /*
44  *    0			  1		      2			  3
45  *    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
46  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47  *   |LI | VN  | Mode|	  Stratum    |	    Poll     |	 Precision   |
48  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49  *   |			   Synchronizing Distance		     |
50  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51  *   |			  Synchronizing Dispersion		     |
52  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53  *   |			Reference Clock Identifier		     |
54  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55  *   |								     |
56  *   |		       Reference Timestamp (64 bits)		     |
57  *   |								     |
58  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59  *   |								     |
60  *   |		       Originate Timestamp (64 bits)		     |
61  *   |								     |
62  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
63  *   |								     |
64  *   |			Receive Timestamp (64 bits)		     |
65  *   |								     |
66  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67  *   |								     |
68  *   |			Transmit Timestamp (64 bits)		     |
69  *   |								     |
70  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 */
72 struct ntpdata {
73 	u_char status;		/* status of local clock and leap info */
74 	u_char stratum;		/* Stratum level */
75 	u_char ppoll;		/* poll value */
76 	int precision:8;
77 	struct s_fixedpt distance;
78 	struct s_fixedpt dispersion;
79 	u_int32_t refid;
80 	struct l_fixedpt reftime;
81 	struct l_fixedpt org;
82 	struct l_fixedpt rec;
83 	struct l_fixedpt xmt;
84 };
85 /*
86  *	Leap Second Codes (high order two bits)
87  */
88 #define	NO_WARNING	0x00	/* no warning */
89 #define	PLUS_SEC	0x40	/* add a second (61 seconds) */
90 #define	MINUS_SEC	0x80	/* minus a second (59 seconds) */
91 #define	ALARM		0xc0	/* alarm condition (clock unsynchronized) */
92 
93 /*
94  *	Clock Status Bits that Encode Version
95  */
96 #define	NTPVERSION_1	0x08
97 #define	VERSIONMASK	0x38
98 #define LEAPMASK	0xc0
99 #define	MODEMASK	0x07
100 
101 /*
102  *	Code values
103  */
104 #define	MODE_UNSPEC	0	/* unspecified */
105 #define	MODE_SYM_ACT	1	/* symmetric active */
106 #define	MODE_SYM_PAS	2	/* symmetric passive */
107 #define	MODE_CLIENT	3	/* client */
108 #define	MODE_SERVER	4	/* server */
109 #define	MODE_BROADCAST	5	/* broadcast */
110 #define	MODE_RES1	6	/* reserved */
111 #define	MODE_RES2	7	/* reserved */
112 
113 /*
114  *	Stratum Definitions
115  */
116 #define	UNSPECIFIED	0
117 #define	PRIM_REF	1	/* radio clock */
118 #define	INFO_QUERY	62	/* **** THIS implementation dependent **** */
119 #define	INFO_REPLY	63	/* **** THIS implementation dependent **** */
120