+/* negate a long float type */
+#define M_NEG(v_i, v_f) \
+ do { \
+ if ((v_f) == 0) \
+ (v_i) = -((uint32_t)(v_i)); \
+ else { \
+ (v_f) = -((uint32_t)(v_f)); \
+ (v_i) = ~(v_i); \
+ } \
+ } while(0)
+/* l_fp to double */
+#define M_LFPTOD(r_i, r_uf, d) \
+ do { \
+ register int32_t i; \
+ register uint32_t f; \
+ \
+ i = (r_i); \
+ f = (r_uf); \
+ if (i < 0) { \
+ M_NEG(i, f); \
+ (d) = -((double) i + ((double) f) / 4294967296.0); \
+ } else { \
+ (d) = (double) i + ((double) f) / 4294967296.0; \
+ } \
+ } while (0)
+
+#define REQ_PEER_LIST_SUM 1
+struct info_peer_summary
+{
+ uint32_t dstadr; /* local address (zero for undetermined) */
+ uint32_t srcadr; /* source address */
+ uint16_t srcport; /* source port */
+ uint8_t stratum; /* stratum of peer */
+ int8_t hpoll; /* host polling interval */
+ int8_t ppoll; /* peer polling interval */
+ uint8_t reach; /* reachability register */
+ uint8_t flags; /* flags, from above */
+ uint8_t hmode; /* peer mode */
+ int32_t delay; /* peer.estdelay; s_fp */
+ int32_t offset_int; /* peer.estoffset; integral part */
+ int32_t offset_frc; /* peer.estoffset; fractional part */
+ uint32_t dispersion; /* peer.estdisp; u_fp */
+ uint32_t v6_flag; /* is this v6 or not */
+ uint32_t unused1; /* (unused) padding for dstadr6 */
+ struct in6_addr dstadr6; /* local address (v6) */
+ struct in6_addr srcadr6; /* source address (v6) */
+};
+
+#define REQ_SYS_INFO 4
+struct info_sys
+{
+ uint32_t peer; /* system peer address (v4) */
+ uint8_t peer_mode; /* mode we are syncing to peer in */
+ uint8_t leap; /* system leap bits */
+ uint8_t stratum; /* our stratum */
+ int8_t precision; /* local clock precision */
+ int32_t rootdelay; /* distance from sync source */
+ uint32_t rootdispersion; /* dispersion from sync source */
+ uint32_t refid; /* reference ID of sync source */
+ uint64_t reftime; /* system reference time */
+ uint32_t poll; /* system poll interval */
+ uint8_t flags; /* system flags */
+ uint8_t unused1; /* unused */
+ uint8_t unused2; /* unused */
+ uint8_t unused3; /* unused */
+ int32_t bdelay; /* default broadcast offset */
+ int32_t frequency; /* frequency residual (scaled ppm) */
+ uint64_t authdelay; /* default authentication delay */
+ uint32_t stability; /* clock stability (scaled ppm) */
+ int32_t v6_flag; /* is this v6 or not */
+ int32_t unused4; /* unused, padding for peer6 */
+ struct in6_addr peer6; /* system peer address (v6) */
+};
+
+#define REQ_GET_KERNEL 38
+struct info_kernel
+{
+ int32_t offset;
+ int32_t freq;
+ int32_t maxerror;
+ int32_t esterror;
+ uint16_t status;
+ uint16_t shift;
+ int32_t constant;
+ int32_t precision;
+ int32_t tolerance;
+ /* pps stuff */
+ int32_t ppsfreq;
+ int32_t jitter;
+ int32_t stabil;
+ int32_t jitcnt;
+ int32_t calcnt;
+ int32_t errcnt;
+ int32_t stbcnt;
+};
+
+/* List of reference clock names */
+static char *refclock_names[] =
+{
+ "UNKNOWN", "LOCAL", "GPS_TRAK", "WWV_PST", /* 0- 3 */
+ "SPECTRACOM", "TRUETIME", "IRIG_AUDIO", "CHU_AUDIO", /* 4- 7 */
+ "GENERIC", "GPS_MX4200", "GPS_AS2201", "GPS_ARBITER", /* 8-11 */
+ "IRIG_TPRO", "ATOM_LEITCH", "MSF_EES", "GPSTM_TRUE", /* 12-15 */
+ "GPS_BANC", "GPS_DATUM", "ACTS_NIST", "WWV_HEATH", /* 16-19 */
+ "GPS_NMEA", "GPS_VME", "PPS", "ACTS_PTB", /* 20-23 */
+ "ACTS_USNO", "TRUETIME", "GPS_HP", "MSF_ARCRON", /* 24-27 */
+ "SHM", "GPS_PALISADE", "GPS_ONCORE", "GPS_JUPITER", /* 28-31 */
+ "CHRONOLOG", "DUMBCLOCK", "ULINK_M320", "PCF", /* 32-35 */
+ "WWV_AUDIO", "GPS_FG", "HOPF_S", "HOPF_P", /* 36-39 */
+ "JJY", "TT_IRIG", "GPS_ZYFER", "GPS_RIPENCC", /* 40-43 */
+ "NEOCLK4X", NULL /* 44 */
+};
+static int refclock_names_num = 45;
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * End of the copied stuff.. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+static int ntpd_config (const char *key, const char *value)