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