Merge from vendor branch OPENSSH:
[dragonfly.git] / contrib / ntpd / ntp.h
1 /*      $OpenBSD: src/usr.sbin/ntpd/ntp.h,v 1.11 2004/12/13 12:22:52 dtucker Exp $ */
2
3 /*
4  * Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
5  * Copyright (c) 2004 Alexander Guy <alexander.guy@andern.org>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19
20 #ifndef _NTP_H_
21 #define _NTP_H_
22
23 /* Style borrowed from NTP ref/tcpdump and updated for SNTPv4 (RFC2030). */
24
25 /*
26  * RFC Section 3
27  *
28  *    0                   1                   2                   3
29  *    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
30  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31  *   |                         Integer Part                          |
32  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33  *   |                         Fraction Part                         |
34  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35  *
36  *    0                   1                   2                   3
37  *    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
38  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39  *   |            Integer Part       |     Fraction Part             |
40  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 */
42 struct l_fixedpt {
43         u_int32_t int_partl;
44         u_int32_t fractionl;
45 };
46
47 struct s_fixedpt {
48         u_int16_t int_parts;
49         u_int16_t fractions;
50 };
51
52 /* RFC Section 4
53  *
54  *    0                   1                   2                   3
55  *    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
56  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57  *   |LI | VN  | Mode|    Stratum    |      Poll     |   Precision   |
58  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59  *   |                     Synchronizing Distance                    |
60  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61  *   |                    Synchronizing Dispersion                   |
62  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
63  *   |                  Reference Clock Identifier                   |
64  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65  *   |                                                               |
66  *   |                 Reference Timestamp (64 bits)                 |
67  *   |                                                               |
68  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69  *   |                                                               |
70  *   |                 Originate Timestamp (64 bits)                 |
71  *   |                                                               |
72  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73  *   |                                                               |
74  *   |                  Receive Timestamp (64 bits)                  |
75  *   |                                                               |
76  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77  *   |                                                               |
78  *   |                  Transmit Timestamp (64 bits)                 |
79  *   |                                                               |
80  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
81  *   |                 Key Identifier (optional) (32)                |
82  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83  *   |                                                               |
84  *   |                                                               |
85  *   |                 Message Digest (optional) (128)               |
86  *   |                                                               |
87  *   |                                                               |
88  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
89  *
90  */
91
92 #define NTP_DIGESTSIZE          16
93 #define NTP_MSGSIZE_NOAUTH      48
94 #define NTP_MSGSIZE             (NTP_MSGSIZE_NOAUTH + 4 + NTP_DIGESTSIZE)
95
96 struct ntp_msg {
97         u_int8_t status;        /* status of local clock and leap info */
98         u_int8_t stratum;       /* Stratum level */
99         u_int8_t ppoll;         /* poll value */
100         int8_t precision;
101         struct s_fixedpt rootdelay;
102         struct s_fixedpt dispersion;
103         u_int32_t refid;
104         struct l_fixedpt reftime;
105         struct l_fixedpt orgtime;
106         struct l_fixedpt rectime;
107         struct l_fixedpt xmttime;
108         u_int32_t keyid;
109         u_int8_t digest[NTP_DIGESTSIZE];
110 };
111
112 struct ntp_query {
113         int                     fd;
114         struct ntp_msg          msg;
115         double                  xmttime;
116 };
117
118 /*
119  *      Leap Second Codes (high order two bits)
120  */
121 #define LI_NOWARNING    (0 << 6)        /* no warning */
122 #define LI_PLUSSEC      (1 << 6)        /* add a second (61 seconds) */
123 #define LI_MINUSSEC     (2 << 6)        /* minus a second (59 seconds) */
124 #define LI_ALARM        (3 << 6)        /* alarm condition */
125
126 /*
127  *      Status Masks
128  */
129 #define MODEMASK        (7 << 0)
130 #define VERSIONMASK     (7 << 3)
131 #define LIMASK          (3 << 6)
132
133 /*
134  *      Mode values
135  */
136 #define MODE_RES0       0       /* reserved */
137 #define MODE_SYM_ACT    1       /* symmetric active */
138 #define MODE_SYM_PAS    2       /* symmetric passive */
139 #define MODE_CLIENT     3       /* client */
140 #define MODE_SERVER     4       /* server */
141 #define MODE_BROADCAST  5       /* broadcast */
142 #define MODE_RES1       6       /* reserved for NTP control message */
143 #define MODE_RES2       7       /* reserved for private use */
144
145 #define JAN_1970        2208988800UL    /* 1970 - 1900 in seconds */
146
147 #define NTP_VERSION     4
148 #define NTP_MAXSTRATUM  15
149
150 #endif  /* _NTP_H_ */