aboutsummaryrefslogtreecommitdiff
path: root/contrib/ntp/include
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ntp/include')
-rw-r--r--contrib/ntp/include/Makefile.am44
-rw-r--r--contrib/ntp/include/Makefile.in273
-rw-r--r--contrib/ntp/include/README4
-rw-r--r--contrib/ntp/include/adjtime.h63
-rw-r--r--contrib/ntp/include/ascii.h61
-rw-r--r--contrib/ntp/include/binio.h41
-rw-r--r--contrib/ntp/include/global.h51
-rw-r--r--contrib/ntp/include/gps.h53
-rw-r--r--contrib/ntp/include/ieee754io.h43
-rw-r--r--contrib/ntp/include/iosignal.h23
-rw-r--r--contrib/ntp/include/l_stdlib.h495
-rw-r--r--contrib/ntp/include/mbg_gps166.h538
-rw-r--r--contrib/ntp/include/md5.h51
-rw-r--r--contrib/ntp/include/mx4200.h40
-rw-r--r--contrib/ntp/include/ntif.h98
-rw-r--r--contrib/ntp/include/ntp.h714
-rw-r--r--contrib/ntp/include/ntp_calendar.h112
-rw-r--r--contrib/ntp/include/ntp_control.h260
-rw-r--r--contrib/ntp/include/ntp_datum.h30
-rw-r--r--contrib/ntp/include/ntp_filegen.h51
-rw-r--r--contrib/ntp/include/ntp_fp.h373
-rw-r--r--contrib/ntp/include/ntp_if.h54
-rw-r--r--contrib/ntp/include/ntp_io.h33
-rw-r--r--contrib/ntp/include/ntp_machine.h512
-rw-r--r--contrib/ntp/include/ntp_malloc.h19
-rw-r--r--contrib/ntp/include/ntp_proto.h8
-rw-r--r--contrib/ntp/include/ntp_refclock.h265
-rw-r--r--contrib/ntp/include/ntp_request.h790
-rw-r--r--contrib/ntp/include/ntp_select.h35
-rw-r--r--contrib/ntp/include/ntp_stdlib.h172
-rw-r--r--contrib/ntp/include/ntp_string.h48
-rw-r--r--contrib/ntp/include/ntp_syscall.h48
-rw-r--r--contrib/ntp/include/ntp_syslog.h77
-rw-r--r--contrib/ntp/include/ntp_types.h69
-rw-r--r--contrib/ntp/include/ntp_unixtime.h132
-rw-r--r--contrib/ntp/include/ntpd.h381
-rw-r--r--contrib/ntp/include/parse.h391
-rw-r--r--contrib/ntp/include/parse_conf.h54
-rw-r--r--contrib/ntp/include/recvbuff.h113
-rw-r--r--contrib/ntp/include/trimble.h125
40 files changed, 6744 insertions, 0 deletions
diff --git a/contrib/ntp/include/Makefile.am b/contrib/ntp/include/Makefile.am
new file mode 100644
index 000000000000..1f80c16cf4fb
--- /dev/null
+++ b/contrib/ntp/include/Makefile.am
@@ -0,0 +1,44 @@
+#AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies
+AUTOMAKE_OPTIONS = ../util/ansi2knr
+ETAGS_ARGS = $(srcdir)/Makefile.am
+#EXTRA_DIST = TAGS
+
+noinst_HEADERS = \
+ adjtime.h \
+ ascii.h \
+ binio.h \
+ global.h \
+ gps.h \
+ ieee754io.h \
+ iosignal.h \
+ l_stdlib.h \
+ mbg_gps166.h \
+ md5.h \
+ mx4200.h \
+ ntif.h \
+ ntp.h \
+ ntp_calendar.h \
+ ntp_control.h \
+ ntp_datum.h \
+ ntp_filegen.h \
+ ntp_fp.h \
+ ntp_if.h \
+ ntp_io.h \
+ ntp_machine.h \
+ ntp_malloc.h \
+ ntp_proto.h \
+ ntp_refclock.h \
+ ntp_request.h \
+ ntp_select.h \
+ ntp_stdlib.h \
+ ntp_string.h \
+ ntp_syscall.h \
+ ntp_syslog.h \
+ ntp_types.h \
+ ntp_unixtime.h \
+ ntpd.h \
+ parse.h \
+ parse_conf.h \
+ recvbuff.h \
+ trimble.h
+
diff --git a/contrib/ntp/include/Makefile.in b/contrib/ntp/include/Makefile.in
new file mode 100644
index 000000000000..0453bf4f00ea
--- /dev/null
+++ b/contrib/ntp/include/Makefile.in
@@ -0,0 +1,273 @@
+# Makefile.in generated automatically by automake 1.4a from Makefile.am
+
+# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+SHELL = @SHELL@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+infodir = @infodir@
+mandir = @mandir@
+includedir = @includedir@
+oldincludedir = /usr/include
+
+DESTDIR =
+
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+
+top_builddir = ..
+
+ACLOCAL = @ACLOCAL@
+AUTOCONF = @AUTOCONF@
+AUTOMAKE = @AUTOMAKE@
+AUTOHEADER = @AUTOHEADER@
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_FLAG =
+transform = @program_transform_name@
+
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_alias = @build_alias@
+build_triplet = @build@
+host_alias = @host_alias@
+host_triplet = @host@
+target_alias = @target_alias@
+target_triplet = @target@
+AMTAR = @AMTAR@
+AMTARFLAGS = @AMTARFLAGS@
+AWK = @AWK@
+CC = @CC@
+CFLAGS = @CFLAGS@
+CHUTEST = @CHUTEST@
+CLKTEST = @CLKTEST@
+CPP = @CPP@
+DCFD = @DCFD@
+LDFLAGS = @LDFLAGS@
+LIBPARSE = @LIBPARSE@
+LIBRSAREF = @LIBRSAREF@
+LN_S = @LN_S@
+MAKEINFO = @MAKEINFO@
+MAKE_ADJTIMED = @MAKE_ADJTIMED@
+MAKE_CHECK_Y2K = @MAKE_CHECK_Y2K@
+MAKE_LIBPARSE = @MAKE_LIBPARSE@
+MAKE_LIBPARSE_KERNEL = @MAKE_LIBPARSE_KERNEL@
+MAKE_LIBRSAREF = @MAKE_LIBRSAREF@
+MAKE_NTPTIME = @MAKE_NTPTIME@
+MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@
+MAKE_TICKADJ = @MAKE_TICKADJ@
+PACKAGE = @PACKAGE@
+PATH_SH = @PATH_SH@
+PROPDELAY = @PROPDELAY@
+RANLIB = @RANLIB@
+RSAREF = @RSAREF@
+TESTDCF = @TESTDCF@
+U = @U@
+VERSION = @VERSION@
+
+#AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies
+
+
+AUTOMAKE_OPTIONS = ../util/ansi2knr
+ETAGS_ARGS = $(srcdir)/Makefile.am
+#EXTRA_DIST = TAGS
+
+noinst_HEADERS = \
+ adjtime.h \
+ ascii.h \
+ binio.h \
+ global.h \
+ gps.h \
+ ieee754io.h \
+ iosignal.h \
+ l_stdlib.h \
+ mbg_gps166.h \
+ md5.h \
+ mx4200.h \
+ ntif.h \
+ ntp.h \
+ ntp_calendar.h \
+ ntp_control.h \
+ ntp_datum.h \
+ ntp_filegen.h \
+ ntp_fp.h \
+ ntp_if.h \
+ ntp_io.h \
+ ntp_machine.h \
+ ntp_malloc.h \
+ ntp_proto.h \
+ ntp_refclock.h \
+ ntp_request.h \
+ ntp_select.h \
+ ntp_stdlib.h \
+ ntp_string.h \
+ ntp_syscall.h \
+ ntp_syslog.h \
+ ntp_types.h \
+ ntp_unixtime.h \
+ ntpd.h \
+ parse.h \
+ parse_conf.h \
+ recvbuff.h \
+ trimble.h
+
+subdir = include
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = ../config.h
+CONFIG_CLEAN_FILES =
+DIST_SOURCES =
+HEADERS = $(noinst_HEADERS)
+
+DIST_COMMON = README $(noinst_HEADERS) Makefile.am Makefile.in
+
+
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+
+GZIP_ENV = --best
+all: all-redirect
+.SUFFIXES:
+$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+ cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps include/Makefile
+
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ cd $(top_builddir) \
+ && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP)
+ list='$(SOURCES) $(HEADERS)'; \
+ unique=`for i in $$list; do echo $$i; done | \
+ ${AWK:-awk} ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ here=`pwd` && cd $(srcdir) \
+ && mkid -f$$here/ID $$unique $(LISP)
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS)'; \
+ unique=`for i in $$list; do echo $$i; done | \
+ ${AWK:-awk} ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
+ || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
+
+mostlyclean-tags:
+
+clean-tags:
+
+distclean-tags:
+ -rm -f TAGS ID
+
+maintainer-clean-tags:
+
+distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
+
+distdir: $(DISTFILES)
+ @for file in $(DISTFILES); do \
+ d=$(srcdir); \
+ if test -d $$d/$$file; then \
+ cp -pr $$d/$$file $(distdir)/$$file; \
+ else \
+ test -f $(distdir)/$$file \
+ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
+ || cp -p $$d/$$file $(distdir)/$$file || :; \
+ fi; \
+ done
+info-am:
+info: info-am
+dvi-am:
+dvi: dvi-am
+check-am: all-am
+check: check-am
+installcheck-am:
+installcheck: installcheck-am
+install-exec-am:
+install-exec: install-exec-am
+
+install-data-am:
+install-data: install-data-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+install: install-am
+uninstall-am:
+uninstall: uninstall-am
+all-am: Makefile $(HEADERS)
+all-redirect: all-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install
+installdirs:
+
+
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -rm -f Makefile $(CONFIG_CLEAN_FILES)
+ -rm -f config.cache config.log stamp-h stamp-h[0-9]*
+
+maintainer-clean-generic:
+mostlyclean-am: mostlyclean-tags mostlyclean-generic
+
+mostlyclean: mostlyclean-am
+
+clean-am: clean-tags clean-generic mostlyclean-am
+
+clean: clean-am
+
+distclean-am: distclean-tags distclean-generic clean-am
+
+distclean: distclean-am
+
+maintainer-clean-am: maintainer-clean-tags maintainer-clean-generic \
+ distclean-am
+ @echo "This command is intended for maintainers to use;"
+ @echo "it deletes files that may require special tools to rebuild."
+
+maintainer-clean: maintainer-clean-am
+
+.PHONY: tags mostlyclean-tags distclean-tags clean-tags \
+maintainer-clean-tags distdir info-am info dvi-am dvi check check-am \
+installcheck-am installcheck install-exec-am install-exec \
+install-data-am install-data install-am install uninstall-am uninstall \
+all-redirect all-am all install-strip installdirs mostlyclean-generic \
+distclean-generic clean-generic maintainer-clean-generic clean \
+mostlyclean distclean maintainer-clean
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/contrib/ntp/include/README b/contrib/ntp/include/README
new file mode 100644
index 000000000000..5d818dc002f8
--- /dev/null
+++ b/contrib/ntp/include/README
@@ -0,0 +1,4 @@
+README file for directory ./include of the NTP Version 4 distribution
+
+This directory contains the include files used by most programs in this
+distribution.
diff --git a/contrib/ntp/include/adjtime.h b/contrib/ntp/include/adjtime.h
new file mode 100644
index 000000000000..74d91eb2719d
--- /dev/null
+++ b/contrib/ntp/include/adjtime.h
@@ -0,0 +1,63 @@
+/*************************************************************************/
+/* (c) Copyright Tai Jin, 1988. All Rights Reserved. */
+/* Hewlett-Packard Laboratories. */
+/* */
+/* Permission is hereby granted for unlimited modification, use, and */
+/* distribution. This software is made available with no warranty of */
+/* any kind, express or implied. This copyright notice must remain */
+/* intact in all versions of this software. */
+/* */
+/* The author would appreciate it if any bug fixes and enhancements were */
+/* to be sent back to him for incorporation into future versions of this */
+/* software. Please send changes to tai@iag.hp.com or ken@sdd.hp.com. */
+/*************************************************************************/
+
+/* "adjtime.h,v 3.1 1993/07/06 01:04:43 jbj Exp" */
+/* adjtime.h,v
+ * Revision 3.1 1993/07/06 01:04:43 jbj
+ * NTP release 3.1
+ *
+ *
+ * Revision 1.5 90/02/07 15:34:18 15:34:18 src (Source Hacker)
+ * CHANGED KEY !!!
+ *
+ * Revision 1.4 89/02/09 12:26:35 12:26:35 tai (Tai Jin (Guest))
+ * *** empty log message ***
+ *
+ * Revision 1.4 89/02/09 12:26:35 12:26:35 tai (Tai Jin)
+ * added comment
+ *
+ * Revision 1.3 88/08/30 01:08:29 01:08:29 tai (Tai Jin)
+ * fix copyright notice again
+ *
+ * Revision 1.2 88/08/30 00:51:55 00:51:55 tai (Tai Jin)
+ * fix copyright notice
+ *
+ * Revision 1.1 88/04/02 14:56:54 14:56:54 tai (Tai Jin)
+ * Initial revision
+ * */
+
+#include "ntp_types.h"
+
+#define KEY 659847L
+
+typedef union {
+ struct msgbuf msgp;
+ struct {
+ long mtype;
+ int code;
+ struct timeval tv;
+ } msgb;
+} MsgBuf;
+
+#define MSGSIZE (sizeof(int) + sizeof(struct timeval))
+/*
+ * mtype values
+ */
+#define CLIENT 1L
+#define SERVER 2L
+/*
+ * code values
+ */
+#define DELTA1 0
+#define DELTA2 1
diff --git a/contrib/ntp/include/ascii.h b/contrib/ntp/include/ascii.h
new file mode 100644
index 000000000000..c679362c1226
--- /dev/null
+++ b/contrib/ntp/include/ascii.h
@@ -0,0 +1,61 @@
+/*
+ * /src/NTP/ntp-4/include/ascii.h,v 4.1 1998/07/11 10:05:22 kardel RELEASE_19990228_A
+ *
+ * $Created: Sun Jul 20 11:42:53 1997 $
+ *
+ * Copyright (C) 1997 by Frank Kardel
+ */
+#ifndef ASCII_H
+#define ASCII_H
+
+/*
+ * just name the common ASCII control codes
+ */
+#define NUL 0
+#define SOH 1
+#define STX 2
+#define ETX 3
+#define EOT 4
+#define ENQ 5
+#define ACK 6
+#define BEL 7
+#define BS 8
+#define HT 9
+#define NL 10
+#define VT 11
+#define NP 12
+#define CR 13
+#define SO 14
+#define SI 15
+#define DLE 16
+#define DC1 17
+#define DC2 18
+#define DC3 19
+#define DC4 20
+#define NAK 21
+#define SYN 22
+#define ETB 23
+#define CAN 24
+#define EM 25
+#define SUB 26
+#define ESC 27
+#define FS 28
+#define GS 29
+#define RS 30
+#define US 31
+#define SP 32
+#define DEL 127
+
+#endif
+/*
+ * ascii.h,v
+ * Revision 4.1 1998/07/11 10:05:22 kardel
+ * Release 4.0.73d reconcilation
+ *
+ * Revision 4.0 1998/04/10 19:50:38 kardel
+ * Start 4.0 release version numbering
+ *
+ * Revision 4.0 1998/04/10 19:50:38 kardel
+ * Start 4.0 release version numbering
+ *
+ */
diff --git a/contrib/ntp/include/binio.h b/contrib/ntp/include/binio.h
new file mode 100644
index 000000000000..49feee9a21c9
--- /dev/null
+++ b/contrib/ntp/include/binio.h
@@ -0,0 +1,41 @@
+/*
+ * /src/NTP/ntp-4/include/binio.h,v 4.2 1998/06/28 16:52:15 kardel RELEASE_19990228_A
+ *
+ * $Created: Sun Jul 20 13:03:05 1997 $
+ *
+ * Copyright (C) 1997-1998 by Frank Kardel
+ */
+#ifndef BINIO_H
+#define BINIO_H
+
+#include "ntp_stdlib.h"
+
+long get_lsb_short P((unsigned char **));
+void put_lsb_short P((unsigned char **, long));
+long get_lsb_long P((unsigned char **));
+void put_lsb_long P((unsigned char **, long));
+
+long get_msb_short P((unsigned char **));
+void put_msb_short P((unsigned char **, long));
+long get_msb_long P((unsigned char **));
+void put_msb_long P((unsigned char **, long));
+
+#endif
+/*
+ * binio.h,v
+ * Revision 4.2 1998/06/28 16:52:15 kardel
+ * added binio MSB prototypes for {get,put}_msb_{short,long}
+ *
+ * Revision 4.1 1998/06/12 15:07:40 kardel
+ * fixed prototyping
+ *
+ * Revision 4.0 1998/04/10 19:50:38 kardel
+ * Start 4.0 release version numbering
+ *
+ * Revision 1.1 1998/04/10 19:27:32 kardel
+ * initial NTP VERSION 4 integration of PARSE with GPS166 binary support
+ *
+ * Revision 1.1 1997/10/06 20:55:37 kardel
+ * new parse structure
+ *
+ */
diff --git a/contrib/ntp/include/global.h b/contrib/ntp/include/global.h
new file mode 100644
index 000000000000..469572454d4c
--- /dev/null
+++ b/contrib/ntp/include/global.h
@@ -0,0 +1,51 @@
+/* GLOBAL.H - RSAREF types and constants */
+
+/* Copyright (C) RSA Laboratories, a division of RSA Data Security,
+ Inc., created 1991. All rights reserved.
+ */
+
+/*
+ * Note: the modifications are necessary for little-endian machines
+ */
+#include "ntp_types.h" /* local modification */
+
+#ifndef _GLOBAL_H_
+#define _GLOBAL_H_ 1
+
+/* PROTOTYPES should be set to one if and only if the compiler supports
+ function argument prototyping.
+ The following makes PROTOTYPES default to 1 if it has not already been
+ defined as 0 with C compiler flags.
+ */
+#ifdef HAVE_PROTOTYPES
+#define PROTOTYPES 1
+#endif
+
+/* POINTER defines a generic pointer type */
+typedef unsigned char *POINTER;
+
+/* UINT2 defines a two byte word */
+typedef unsigned short int UINT2;
+
+/* UINT4 defines a four byte word */
+typedef u_int32 UINT4; /* local modification */
+
+#ifndef NULL_PTR
+#define NULL_PTR ((POINTER)0)
+#endif
+
+#ifndef UNUSED_ARG
+#define UNUSED_ARG(x) x = *(&x);
+#endif
+
+/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
+ If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
+ returns an empty list.
+ */
+#if PROTOTYPES
+#define PROTO_LIST(list) list
+#else
+#define PROTO_LIST(list) ()
+#endif
+
+#endif /* end _GLOBAL_H_ */
diff --git a/contrib/ntp/include/gps.h b/contrib/ntp/include/gps.h
new file mode 100644
index 000000000000..d4f2dbc672ae
--- /dev/null
+++ b/contrib/ntp/include/gps.h
@@ -0,0 +1,53 @@
+/****************************************************************************/
+/* gps.h */
+/* TrueTime GPS-VME and VME-SG */
+/* VME controller hardware commands and parameters. */
+/* created 010694 res */
+/* History: revised for 747i 3/94 */
+/****************************************************************************/
+
+
+#define GPS_VME "/dev/vme2" /* the device file for the GPS board */
+ /* change it to whatever yours is */
+#define PRIO 120 /* set the realtime priority */
+#define NREGS 7 /* number of registers we will use */
+
+#define GFRZ1 0x0020 /* freeze cmd addr gen reg. 1 */
+#define GREG1A 0x0021 /* Gen reg. 1 Word A (units microsec to 0.001 sec) */
+#define GREG1B 0x0040 /* Gen reg. 1 Word B (units 0.01 sec to tens sec ) */
+#define GREG1C 0x0041 /* Gen reg 1 Word C (units mins and hours) */
+#define GREG1D 0x0042 /* Gen reg. 1 Word D (units days and status) */
+#define GREG1E 0x0043 /* Gen reg. 1 Word E (units Years ) */
+#define GUFRZ1 0x0022 /* unfreeze cmd addr gen reg 1 */
+
+#define MASKDAY 0x0FFF /* mask for units days */
+#define MASKHI 0xFF00
+#define MASKLO 0x00FF
+/* Use the following ASCII hex values: N(0x004e),S(0x0053),E(0x0045),
+ W(0x0057), +(0x002B), - (0x002D) */
+
+#define LAT1 0x0048 /* Lat (degrees) */
+#define LAT2 0x0049 /* Lat (min, sec) */
+#define LAT3 0x004A /* Lat (N/S, tenths sec) */
+#define LON1 0x004B /* Lon (degrees) */
+#define LON2 0x004C /* Lon (min, sec) */
+#define LON3 0x004D /* Lon (E/W, tenths sec) */
+#define ELV1 0x004E /* Elev. (sign, 10,000 and 1000 ) */
+#define ELV2 0x004F /* Elev. (100, 10s, units, and .1) */
+
+#define CFREG1 0x0050 /* config. register 1 */
+#define CFREG2 0x00A0 /* config. register 2 */
+#define PMODE 0x00A4 /* Position mode */
+#define LOCAL 0x0051 /* Local hours offset */
+#define RATE 0x0054 /* Pulse rate output select */
+#define DAC 0x0055 /* OSC Control (DAC) select */
+
+#define PUMS 0x0056 /* Gen. preset register unit millisec */
+#define PMS 0x0057 /* Gen. preset register units hundreds and tens ms */
+#define PSEC 0x0058 /* Gen. preset register units tens and unit seconds */
+#define PMIN 0x0059 /* Gen. preset register units tens and unit minutes */
+#define PHRS 0x005A /* Gen. preset register units tens and unit hours */
+#define PDYS1 0x005B /* Gen. preset register units tens and unit days */
+#define PDYS2 0x005C /* Gen. preset register units hundreds days */
+#define PYRS1 0x005D /* Gen. preset register units tens and unit years */
+#define PYRS2 0x005E /* Gen. preset reg. units thousands and hundreds yrs */
diff --git a/contrib/ntp/include/ieee754io.h b/contrib/ntp/include/ieee754io.h
new file mode 100644
index 000000000000..f691acc3c2ae
--- /dev/null
+++ b/contrib/ntp/include/ieee754io.h
@@ -0,0 +1,43 @@
+/*
+ * /src/NTP/ntp-4/include/ieee754io.h,v 4.0 1998/04/10 19:50:40 kardel RELEASE_19990228_A
+ *
+ * $Created: Sun Jul 13 12:22:11 1997 $
+ *
+ * Copyright (C) 1997 by Frank Kardel
+ */
+#ifndef IEEE754IO_H
+#define IEEE754IO_H
+
+#define IEEE_SINGLE 1
+#define IEEE_DOUBLE 2
+
+#define IEEE_MSB 1
+#define IEEE_LSB 2
+
+#define IEEE_OK 0 /* conversion ok */
+#define IEEE_BADCALL 1 /* bad call parameters */
+#define IEEE_NAN 2 /* found an NaN */
+#define IEEE_POSINFINITY 3 /* positive infinity */
+#define IEEE_NEGINFINITY 4 /* negative infinity */
+#define IEEE_POSOVERFLOW 5 /* positive overflow */
+#define IEEE_NEGOVERFLOW 6 /* negative overflow */
+
+#define IEEE_OFFSETS 8 /* number of byte positions */
+typedef unsigned char offsets_t[IEEE_OFFSETS];
+
+int fetch_ieee754 P((unsigned char **bufp, int size, l_fp *lfpp, offsets_t offsets));
+int put_ieee754 P((unsigned char **bufpp, int size, l_fp *lfpp, offsets_t offsets));
+
+#endif
+/*
+ * ieee754io.h,v
+ * Revision 4.0 1998/04/10 19:50:40 kardel
+ * Start 4.0 release version numbering
+ *
+ * Revision 1.1 1998/04/10 19:27:33 kardel
+ * initial NTP VERSION 4 integration of PARSE with GPS166 binary support
+ *
+ * Revision 1.1 1997/10/06 20:55:37 kardel
+ * new parse structure
+ *
+ */
diff --git a/contrib/ntp/include/iosignal.h b/contrib/ntp/include/iosignal.h
new file mode 100644
index 000000000000..bd74e096d00b
--- /dev/null
+++ b/contrib/ntp/include/iosignal.h
@@ -0,0 +1,23 @@
+#if !defined _ntp_iosignaled_h
+#define _ntp_iosignaled_h
+
+#include "ntp_refclock.h"
+
+#if defined(HAVE_SIGNALED_IO)
+extern void block_sigio P((void));
+extern void unblock_sigio P((void));
+extern int init_clock_sig P((struct refclockio *));
+extern void init_socket_sig P((int));
+extern void set_signal P((void));
+RETSIGTYPE sigio_handler P((int));
+
+# define BLOCKIO() ((void) block_sigio())
+# define UNBLOCKIO() ((void) unblock_sigio())
+
+#else
+
+# define BLOCKIO()
+# define UNBLOCKIO()
+#endif /* HAVE_SIGNALED_IO */
+
+#endif
diff --git a/contrib/ntp/include/l_stdlib.h b/contrib/ntp/include/l_stdlib.h
new file mode 100644
index 000000000000..fdabe67163f7
--- /dev/null
+++ b/contrib/ntp/include/l_stdlib.h
@@ -0,0 +1,495 @@
+/*
+ * Proto types for machines that are not ANSI and POSIX compliant.
+ * This is optional
+ */
+
+#ifndef _l_stdlib_h
+#define _l_stdlib_h
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+/* Needed for speed_t. */
+#ifdef HAVE_TERMIOS_H
+# include <termios.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+# include <errno.h>
+#endif
+
+#include "ntp_types.h"
+#include "ntp_proto.h"
+
+/* Let's try to keep this more or less alphabetized... */
+
+#ifdef DECL_ADJTIME_0
+struct timeval;
+extern int adjtime P((struct timeval *, struct timeval *));
+#endif
+
+#ifdef DECL_BCOPY_0
+#ifndef bcopy
+extern void bcopy P((const char *, char *, int));
+#endif
+#endif
+
+#ifdef DECL_BZERO_0
+#ifndef bzero
+extern void bzero P((char *, int));
+#endif
+#endif
+
+#ifdef DECL_CFSETISPEED_0
+struct termios;
+extern int cfsetispeed P((struct termios *, speed_t));
+extern int cfsetospeed P((struct termios *, speed_t));
+#endif
+
+extern char * getpass P((const char *));
+
+#ifdef DECL_INET_NTOA_0
+struct in_addr;
+extern char * inet_ntoa P((struct in_addr));
+#endif
+
+#ifdef DECL_IOCTL_0
+extern int ioctl P((int, u_long, char *));
+#endif
+
+#ifdef DECL_IPC_0
+struct sockaddr;
+extern int bind P((int, struct sockaddr *, int));
+extern int connect P((int, struct sockaddr *, int));
+extern int recv P((int, char *, int, int));
+extern int recvfrom P((int, char *, int, int, struct sockaddr *, int *));
+extern int send P((int, char *, int, int));
+extern int sendto P((int, char *, int, int, struct sockaddr *, int));
+extern int setsockopt P((int, int, int, char *, int));
+extern int socket P((int, int, int));
+#endif
+
+#ifdef DECL_MEMMOVE_0
+extern void * memmove P((void *, const void *, size_t));
+#endif
+
+#ifdef DECL_MEMSET_0
+extern char * memset P((char *, int, int));
+#endif
+
+#ifdef DECL_MKSTEMP_0
+extern int mkstemp P((char *));
+#endif
+
+#ifdef DECL_MKTEMP_0
+extern char *mktemp P((char *));
+#endif
+
+#ifdef DECL_MRAND48_0
+extern long mrand48 P((void));
+#endif
+
+#ifdef DECL_NLIST_0
+struct nlist;
+extern int nlist P((const char *, struct nlist *));
+#endif
+
+#ifdef DECL_PLOCK_0
+extern int plock P((int));
+#endif
+
+#ifdef DECL_RENAME_0
+extern int rename P((const char *, const char *));
+#endif
+
+#ifdef DECL_SELECT_0
+#ifdef _ntp_select_h
+extern int select P((int, fd_set *, fd_set *, fd_set *, struct timeval *));
+#endif
+#endif
+
+#ifdef DECL_SETITIMER_0
+struct itimerval;
+extern int setitimer P((int , struct itimerval *, struct itimerval *));
+#endif
+
+#ifdef PRIO_PROCESS
+#ifdef DECL_SETPRIORITY_0
+extern int setpriority P((int, int, int));
+#endif
+#ifdef DECL_SETPRIORITY_1
+extern int setpriority P((int, id_t, int));
+#endif
+#endif
+
+#ifdef DECL_SIGVEC_0
+struct sigvec;
+extern int sigvec P((int, struct sigvec *, struct sigvec *));
+#endif
+
+#ifdef DECL_SRAND48_0
+extern void srand48 P((long));
+#endif
+
+#ifdef DECL_STDIO_0
+#if defined(FILE) || defined(BUFSIZ)
+extern int _flsbuf P((int, FILE *));
+extern int _filbuf P((FILE *));
+extern int fclose P((FILE *));
+extern int fflush P((FILE *));
+extern int fprintf P((FILE *, const char *, ...));
+extern int fscanf P((FILE *, const char *, ...));
+extern int fputs P((const char *, FILE *));
+extern int fputc P((int, FILE *));
+extern int fread P((char *, int, int, FILE *));
+extern void perror P((const char *));
+extern int printf P((const char *, ...));
+extern int setbuf P((FILE *, char *));
+# ifdef HAVE_SETLINEBUF
+extern int setlinebuf P((FILE *));
+# endif
+extern int setvbuf P((FILE *, char *, int, int));
+extern int scanf P((const char *, ...));
+extern int sscanf P((const char *, const char *, ...));
+extern int vfprintf P((FILE *, const char *, ...));
+extern int vsprintf P((char *, const char *, ...));
+#endif
+#endif
+
+#ifdef DECL_STIME_0
+extern int stime P((const time_t *));
+#endif
+
+#ifdef DECL_STRERROR_0
+extern char * strerror P((int errnum));
+#endif
+
+#ifdef DECL_STRTOL_0
+extern long strtol P((const char *, char **, int));
+#endif
+
+#ifdef DECL_SYSCALL
+extern int syscall P((int, ...));
+#endif
+
+#ifdef DECL_SYSLOG_0
+extern void closelog P((void));
+#ifndef LOG_DAEMON
+extern void openlog P((const char *, int));
+#else
+extern void openlog P((const char *, int, int));
+#endif
+extern int setlogmask P((int));
+extern void syslog P((int, const char *, ...));
+#endif
+
+#ifdef DECL_TIME_0
+extern time_t time P((time_t *));
+#endif
+
+#ifdef DECL_TIMEOFDAY_0
+#ifdef SYSV_TIMEOFDAY
+extern int gettimeofday P((struct timeval *));
+extern int settimeofday P((struct timeval *));
+#else /* not SYSV_TIMEOFDAY */
+struct timezone;
+extern int gettimeofday P((struct timeval *, struct timezone *));
+extern int settimeofday P((struct timeval *, void *));
+#endif /* not SYSV_TIMEOFDAY */
+#endif
+
+#ifdef DECL_TOLOWER_0
+extern int tolower P((int));
+#endif
+
+#ifdef DECL_TOUPPER_0
+extern int toupper P((int));
+#endif
+
+/*
+ * Necessary variable declarations.
+ */
+#ifdef DECL_ERRNO
+extern int errno;
+#endif
+
+#ifdef DECL_H_ERRNO
+extern int h_errno;
+#endif
+
+/*******************************************************/
+
+#if 0
+/*
+ * Unprotoyped library functions for SunOS 4.x.x
+ */
+#ifdef SYS_SUNOS4
+extern void closelog P((void));
+extern void openlog P((char *, int, int));
+extern void syslog P((int, char *, ...));
+extern int setlogmask P((int));
+
+extern char * getpass P((char *));
+
+extern int setpriority P((int ,int ,int));
+
+extern long strtol P((char *, char **, int));
+
+#if !defined(NTP_POSIX_SOURCE)
+extern int atoi P((char *));
+extern int dup2 P((int, int));
+extern int execve P((char *, char **,char **));
+extern int fork P((void));
+extern int getdtablesize P((void));
+extern int qsort (void *, int , int,
+ int P((*compar)(void *, void *)));
+extern long random P((void));
+extern long mrand48 P((void));
+extern int setpgrp P((int, int));
+extern void srandom P((unsigned int));
+extern void bcopy P((const char *, char *, int));
+#endif
+
+#ifndef bzero /* XXX macro prototyping clash */
+extern void bzero P((char *, int));
+extern int bcmp P((char *, char *, int));
+extern void bcopy P((const char *, char *, int));
+#endif
+extern char *mktemp P((char *));
+
+extern int tolower P((int));
+
+extern int isatty P((int));
+
+extern unsigned sleep P((unsigned ));
+extern unsigned int alarm P((unsigned int));
+extern int pause P((void));
+
+extern int getpid P((void));
+extern int getppid P((void));
+
+extern int close P((int));
+extern int ioctl P((int, int, char *));
+extern int rename P((char *, char *));
+#if 0
+extern int read P((int, void *, size_t));
+extern int write P((int, const void *, size_t));
+#endif
+extern int unlink P((const char *));
+extern int link P((const char *, const char *));
+
+#ifdef FILE
+extern int fclose P((FILE *));
+extern int fflush P((FILE *));
+extern int fprintf P((FILE *, char *, ...));
+extern int fscanf P((FILE *, char *, ...));
+extern int fputs P((char *, FILE *));
+extern int fputc P((char, FILE *));
+extern int fread P((char *, int, int, FILE *));
+extern int printf P((char *, ...));
+extern int setbuf P((FILE *, char *));
+extern int setvbuf P((FILE *, char *, int, int));
+extern int scanf P((char *, ...));
+extern int sscanf P((char *, char *, ...));
+extern int vsprintf P((char *, char *, ...));
+extern int _flsbuf P((int, FILE *));
+extern int _filbuf P((FILE *));
+extern void perror P((char *));
+#ifdef HAVE_SETLINEBUF
+extern int setlinebuf P((FILE *));
+#endif
+#endif
+
+#ifdef _ntp_string_h
+#ifdef NTP_POSIX_SOURCE /* these are builtins */
+#ifndef NTP_NEED_BOPS /* but may be emulated by bops */
+extern char *memcpy P(());
+extern char *memset P(());
+extern int memcmp P(());
+#endif
+#endif
+#endif
+
+#ifdef _sys_socket_h
+extern int bind P((int, struct sockaddr *, int));
+extern int connect P((int, struct sockaddr *, int));
+extern int sendto P((int, char *, int, int, struct sockaddr *, int));
+extern int setsockopt P((int, int, int, char *, int));
+extern int socket P((int, int, int));
+extern int recvfrom P((int, char *, int, int, struct sockaddr *, int *));
+#endif /* _sys_socket_h */
+
+#ifdef _ntp_select_h
+extern int select P((int, fd_set *, fd_set *, fd_set *, struct timeval *));
+#endif
+
+#ifdef _sys_time_h
+extern int adjtime P((struct timeval *, struct timeval *));
+extern int setitimer P((int , struct itimerval *, struct itimerval *));
+#ifdef SYSV_TIMEOFDAY
+extern int gettimeofday P((struct timeval *));
+extern int settimeofday P((struct timeval *));
+#else /* ! SYSV_TIMEOFDAY */
+extern int gettimeofday P((struct timeval *, struct timezone *));
+extern int settimeofday P((struct timeval *, struct timezone *));
+#endif /* SYSV_TIMEOFDAY */
+#endif /* _sys_time_h */
+
+#ifdef __time_h
+extern time_t time P((time_t *));
+#endif
+
+#ifdef __setjmp_h
+extern int setjmp P((jmp_buf));
+extern void longjmp P((jmp_buf, int));
+#endif
+
+#ifdef _sys_resource_h
+extern int getrusage P((int, struct rusage *));
+#endif
+
+#ifdef _nlist_h
+extern int nlist P((char *, struct nlist *));
+#endif
+
+#endif /* SYS_SUNOS4 */
+
+/*
+ * Unprototyped library functions for DEC OSF/1
+ */
+#ifdef SYS_DECOSF1
+#ifndef _MACHINE_ENDIAN_H_
+#define _MACHINE_ENDIAN_H_
+extern u_short htons P((u_short));
+extern u_short ntohs P((u_short));
+extern u_int32 htonl P((u_int32));
+extern u_int32 ntohl P((u_int32));
+#endif /* _MACHINE_ENDIAN_H_ */
+
+/*
+extern char * getpass P((char *));
+*/
+extern char * mktemp P((char *));
+#ifndef SYS_IX86OSF1
+extern int ioctl P((int, u_long, char *));
+extern void bzero P((char *, int));
+#endif
+
+#ifdef SOCK_DGRAM
+extern int bind P((int, const struct sockaddr *, int));
+extern int connect P((int, const struct sockaddr *, int));
+extern int socket P((int, int, int));
+extern int sendto P((int, const void *, int, int, const struct sockaddr *, int));
+extern int setsockopt P((int, int, int, const void *, int));
+extern int recvfrom P((int, void *, int, int, struct sockaddr *, int *));
+#endif /* SOCK_STREAM */
+
+#ifdef _ntp_select_h
+extern int select P((int, fd_set *, fd_set *, fd_set *, struct timeval *));
+#endif
+
+#endif /* DECOSF1 */
+
+/*
+ * Unprototyped library functions for Ultrix
+ */
+#ifdef SYS_ULTRIX
+extern int close P((int));
+extern char * getpass P((char *));
+extern int getpid P((void));
+extern int ioctl P((int, int, char *));
+extern char *mktemp P((char *));
+extern int unlink P((const char *));
+extern int link P((const char *, const char *));
+
+extern void closelog P((void));
+extern void syslog P((int, char *, ...));
+#ifndef LOG_DAEMON
+extern void openlog P((char *, int));
+#else
+extern void openlog P((char *, int, int));
+#endif
+
+extern int setpriority P((int ,int ,int ));
+
+#ifdef SOCK_DGRAM
+extern int bind P((int, struct sockaddr *, int));
+extern int connect P((int, struct sockaddr *, int));
+extern int socket P((int, int, int));
+extern int sendto P((int, char *, int, int, struct sockaddr *, int));
+extern int setsockopt P((int, int, int, char *, int));
+extern int recvfrom P((int, char *, int, int, struct sockaddr *, int *));
+#endif /* SOCK_STREAM */
+
+#ifdef _TIME_H_
+extern int gettimeofday P((struct timeval *, struct timezone *));
+extern int settimeofday P((struct timeval *, struct timezone *));
+extern int adjtime P((struct timeval *, struct timeval *));
+extern int select P((int, fd_set *, fd_set *, fd_set *, struct timeval *));
+extern int setitimer P((int , struct itimerval *, struct itimerval *));
+#endif /* _TIME_H_ */
+
+#ifdef N_UNDF
+extern int nlist P((char *, struct nlist *));
+#endif
+
+#ifndef bzero /* XXX macro prototyping clash */
+extern void bzero P((char *, int));
+extern int bcmp P((char *, char *, int));
+extern void bcopy P((const char *, char *, int));
+#endif
+
+#ifndef NTP_POSIX_SOURCE
+extern int atoi P((char *));
+extern void bzero P((char *, int));
+extern int bcmp P((char *, char *, int));
+extern void bcopy P((const char *, char *, int));
+extern int execve P((char *, char **,char **));
+extern int fork P((void));
+extern int getdtablesize P((void));
+extern int ran P((void));
+extern int rand P((void));
+extern void srand P((unsigned int));
+#ifdef _TIME_H_
+extern int gettimeofday P((struct timeval *, struct timezone *));
+extern int settimeofday P((struct timeval *, struct timezone *));
+#endif
+#endif
+
+#ifdef _RESOURCE_H_
+extern int getrusage P((int, struct rusage *));
+#endif
+
+#endif /* SYS_ULTRIX */
+
+#if defined(__convex__)
+extern char * getpass P((char *));
+#endif
+
+#ifdef SYS_IRIX4
+extern char * getpass P((char *));
+#endif /* IRIX4 */
+
+#ifdef SYS_VAX
+extern char * getpass P((char *));
+#endif /* VAX */
+
+#ifdef SYS_DOMAINOS
+extern char * getpass P((char *));
+#endif /* SYS_DOMAINOS */
+
+#ifdef SYS_BSD
+#define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
+#endif
+
+#endif /* 0 */
+#endif /* l_stdlib_h */
diff --git a/contrib/ntp/include/mbg_gps166.h b/contrib/ntp/include/mbg_gps166.h
new file mode 100644
index 000000000000..71107517e9d2
--- /dev/null
+++ b/contrib/ntp/include/mbg_gps166.h
@@ -0,0 +1,538 @@
+/*
+ * /src/NTP/ntp-4/include/mbg_gps166.h,v 4.1 1998/06/12 15:07:30 kardel RELEASE_19990228_A
+ *
+ * $Created: Sun Jul 20 09:20:50 1997 $
+ *
+ * Copyright (C) 1997, 1998 by Frank Kardel
+ */
+#ifndef MBG_GPS166_H
+#define MBG_GPS166_H
+
+
+/***************************************************************************/
+/* */
+/* File: GPSSERIO.H 4.1 */
+/* */
+/* Project: Common C Library */
+/* */
+/* Compiler: Borland C++ */
+/* */
+/* Author: M. Burnicki, Meinberg Funkuhren */
+/* */
+/* */
+/* Description: */
+/* This file defines structures and codes to be used to access GPS166 */
+/* via its serial interface COM0. COM0 should be set to a high baud */
+/* rate, default is 19200. */
+/* */
+/* Standard GPS166 serial operation is to send a time string that is */
+/* compatible with Meinberg UA31 or PZF535 DCF77 radio remote clocks. */
+/* That string can be transmitted automatically once per second, once */
+/* per minute or on request per ASCII '?'. */
+/* */
+/* Parameter setup or parameter readout works using blocks of binary */
+/* data which have to be isolated from the standard string. A block of */
+/* data starts with a SOH code (ASCII Start Of Header, 0x01) followed */
+/* by a message header with constant length and a data portion with */
+/* variable length. The first field (cmd) of the message header holds */
+/* the command code rsp. the type of data to be transmitted. The next */
+/* field (len) gives the number of data bytes that are transmitted */
+/* after the header. This number ranges from 0 to sizeof( MSG_DATA ). */
+/* The third field (data_csum) holds a checksum of all data bytes and */
+/* the last field of the header finally holds the checksum of the. */
+/* header. */
+/* */
+/***************************************************************************/
+
+/* the control codes defined below are to be or'ed with a command/type code */
+
+#define GPS_REQACK 0x8000 /* to GPS166: request acknowledge */
+#define GPS_ACK 0x4000 /* from GPS166: acknowledge a command */
+#define GPS_NACK 0x2000 /* from GPS166: error receiving command */
+
+#define GPS_CTRL_MSK 0xF000 /* masks control code from command */
+
+
+/* The codes below specify commands/types of data to be supplied to GPS166: */
+
+/* GPS166 auto-message to host */
+/* þ host request, GPS166 response */
+/* þ þ host download to GPS166 */
+/* þ þ þ */
+enum { /* þ þ þ */
+ /* system data */
+ GPS_AUTO_ON = 0x000, /* þ þ þ X þ enable auto-messages from GPS166 */
+ GPS_AUTO_OFF, /* þ þ þ X þ disable auto-messages from GPS166 */
+ GPS_SW_REV, /* þ þ X þ þ request software revision */
+ GPS_STAT, /* þ þ X þ þ request status of buffered variables */
+ GPS_TIME, /* þ X þ þ X þ current time or capture or init board time */
+ GPS_POS_XYZ, /* þ þ X þ X þ current position in ECEF coords */
+ GPS_POS_LLA, /* þ þ X þ X þ current position in geographic coords */
+ GPS_TZDL, /* þ þ X þ X þ time zone / daylight saving */
+ GPS_PORT_PARM, /* þ þ X þ X þ parameters of the serial ports */
+ GPS_SYNTH, /* þ þ X þ X þ synthesizer's frequency and phase */
+ GPS_ANT_INFO, /* þ X þ X þ þ time diff after antenna disconnect */
+ GPS_UCAP, /* þ X þ X þ þ user capture */
+
+ /* GPS data */
+ GPS_CFGH = 0x100, /* þ þ X þ X þ SVs' configuration and health codes */
+ GPS_ALM, /* þ þ X þ X þ one SV's almanac */
+ GPS_EPH, /* þ þ X þ X þ one SV's ephemeris */
+ GPS_UTC, /* þ þ X þ X þ UTC correction parameters */
+ GPS_IONO, /* þ þ X þ X þ ionospheric correction parameters */
+ GPS_ASCII_MSG /* þ þ X þ þ the GPS ASCII message */
+};
+
+/*
+ * modelled after GPSDEFS.H Revision 1.5
+ */
+/***************************************************************************/
+/* */
+/* File: GPSDEFS.H 4.1 */
+/* */
+/* Project: Common C Library */
+/* */
+/* Compiler: Borland C++ */
+/* */
+/* Author: M. Burnicki, Meinberg Funkuhren */
+/* */
+/* */
+/* Description: */
+/* General definitions to be used with GPS166 */
+/* GPS166 Rev. 1.23 or above */
+/* */
+/* Modifications: see file GPSLIB.TXT */
+/* */
+/***************************************************************************/
+#define _GPSDEFS_H
+/* the type of various checksums */
+
+#ifndef _CSUM_DEFINED
+ typedef unsigned short CSUM;
+# define _CSUM_DEFINED
+#endif
+
+/* the message header */
+
+typedef struct {
+ unsigned short gps_cmd;
+ unsigned short gps_len;
+ unsigned short gps_data_csum;
+ unsigned short gps_hdr_csum;
+} GPS_MSG_HDR;
+
+/* a struct used to hold the software revision information */
+
+typedef struct {
+ unsigned short code; /* e.g. 0x0120 means rev. 1.20 */
+ unsigned char name[17]; /* used to identify customized versions */
+} SW_REV;
+
+/* GPS ASCII message */
+
+typedef struct {
+ CSUM csum; /* checksum of the remaining bytes */
+ short valid; /* flag data are valid */
+ char s[23]; /* 22 chars GPS ASCII message plus trailing zero */
+} ASCII_MSG;
+
+#define MIN_SVNO 1 /* min. SV number */
+#define MAX_SVNO 32 /* max. SV number */
+#define N_SVNO ( MAX_SVNO - MIN_SVNO + 1) /* number of possibly active SVs */
+
+
+typedef short SVNO; /* the number of a SV */
+typedef unsigned short HEALTH; /* a SV's health code */
+typedef unsigned short CFG; /* a SV's configuration code */
+typedef unsigned short IOD; /* Issue-Of-Data code */
+
+/* Date and time referred to the linear time scale defined by GPS. */
+/* GPS time is defined by the number of weeks since midnight from */
+/* January 5, 1980 to January 6, 1980 plus the number of seconds of */
+/* the current week plus fractions of a second. GPS time differs from */
+/* UTC because UTC is corrected with leap seconds while GPS time scale */
+/* is continuous. */
+
+typedef struct {
+ unsigned short wn; /* the week number since GPS has been installed */
+ unsigned long sec; /* the second of that week */
+ unsigned long tick; /* fractions of a second; scale: 1E-7 */
+} T_GPS;
+
+
+/* Local date and time computed from GPS time. The current number */
+/* of leap seconds have to be added to get UTC from GPS time. */
+/* Additional corrections could have been made according to the */
+/* time zone/daylight saving parameters (TZDL, see below) defined */
+/* by the user. The status field can be checked to see which corrections */
+/* have been applied. */
+
+#ifndef _TM_DEFINED
+ typedef struct {
+ short year; /* 0..9999 */
+ char month; /* 1..12 */
+ char mday; /* 1..31 */
+ short yday; /* 1..366 */
+ char wday; /* 0..6 == Sun..Sat */
+ char hour; /* 0..23 */
+ char minute; /* 0..59 */
+ char second; /* 0..59 */
+ long frac; /* fractions of a second, scale 1E-7 */
+ long offs_from_utc; /* local time's offset from UTC */
+ unsigned short status; /* flags */
+ } TM;
+
+ /* status flags used with conversion from GPS time to local time */
+
+# define TM_UTC 0x01 /* UTC correction has been made */
+# define TM_LOCAL 0x02 /* UTC has been converted to local time */
+# define TM_DL_ANN 0x04 /* state of daylight saving is going to change */
+# define TM_DL_ENB 0x08 /* daylight saving is enabled */
+# define TM_LS_ANN 0x10 /* leap second will be inserted */
+# define TM_LS_ENB 0x20 /* current second is leap second */
+
+# define _TM_DEFINED
+#endif
+
+
+/* the status flags below are defined starting with rev. 1.32 */
+
+#define TM_ANT_DISCONN 0x1000 /* antenna currently disconnected */
+#define TM_SYN_FLAG 0x2000 /* TIME_SYN output is low */
+#define TM_NO_SYNC 0x4000 /* not sync'ed after reset */
+#define TM_NO_POS 0x8000 /* position not computed after reset, */
+ /* LOCK LED off */
+
+/* a struct used to transmit information on date and time */
+
+typedef struct {
+ short channel; /* -1: the current time; 0, 1: capture 0, 1 */
+ T_GPS t; /* time in GPS format */
+ TM tm; /* that time converted to local time */
+} TTM;
+
+
+
+/* Two types of variables used to store a position. Type XYZ is */
+/* used with a position in earth centered, earth fixed (ECEF) */
+/* coordinates whereas type LLA holds such a position converted */
+/* to geographic coordinates as defined by WGS84 (World Geodetic */
+/* System from 1984). */
+
+#ifndef _XYZ_DEFINED
+ /* sequence and number of components of a cartesian position */
+ enum { XP, YP, ZP, N_XYZ };
+
+ /* a type of array holding a cartesian position */
+ typedef l_fp XYZ[N_XYZ]; /* values are in [m] */
+
+# define _XYZ_DEFINED
+#endif
+
+
+#ifndef _LLA_DEFINED
+ /* sequence and number of components of a geographic position */
+ enum { LAT, LON, ALT, N_LLA }; /* latitude, longitude, altitude */
+
+ /* a type of array holding a geographic position */
+ typedef l_fp LLA[N_LLA]; /* lon, lat in [rad], alt in [m] */
+
+# define _LLA_DEFINED
+#endif
+
+/* Synthesizer parameters. Synthesizer frequency is expressed as a */
+/* four digit decimal number (freq) to be multiplied by 0.1 Hz and an */
+/* base 10 exponent (range). If the effective frequency is less than */
+/* 10 kHz its phase is synchronized corresponding to the variable phase. */
+/* Phase may be in a range from -360° to +360° with a resolution of 0.1°, */
+/* so the resulting numbers to be stored are in a range of -3600 to +3600. */
+
+/* Example: */
+/* Assume the value of freq is 2345 (decimal) and the value of phase is 900. */
+/* If range == 0 the effective frequency is 234.5 Hz with a phase of +90°. */
+/* If range == 1 the synthesizer will generate a 2345 Hz output frequency */
+/* and so on. */
+
+/* Limitations: */
+/* If freq == 0 the synthesizer is disabled. If range == 0 the least */
+/* significant digit of freq is limited to 0, 3, 5 or 6. The resulting */
+/* frequency is shown in the examples below: */
+/* freq == 1230 --> 123.0 Hz */
+/* freq == 1233 --> 123 1/3 Hz (real 1/3 Hz, NOT 123.3 Hz) */
+/* freq == 1235 --> 123.5 Hz */
+/* freq == 1236 --> 123 2/3 Hz (real 2/3 Hz, NOT 123.6 Hz) */
+
+/* If range == MAX_RANGE the value of freq must not exceed 1200, so the */
+/* output frequency is limited to 12 MHz. */
+
+/* Phase will be ignored if the resulting frequency is greater or equal */
+/* to 10 kHz. */
+
+#define MAX_SYNTH_FREQ 1200 /* if range == MAX_SYNTH_RANGE */
+#define MIN_SYNTH_RANGE 0
+#define MAX_SYNTH_RANGE 5
+#define MAX_SYNTH_PHASE 3600
+
+typedef struct {
+ short freq; /* four digits used; scale: 0.1; e.g. 1234 -> 123.4 Hz */
+ short range; /* scale factor for freq; 0..MAX_SYNTH_RANGE */
+ short phase; /* -MAX_SYNTH_PHASE..+MAX_SYNTH_PHASE; >0 -> pulses later */
+} SYNTH;
+
+
+
+/* Time zone/daylight saving parameters. */
+
+/* the name of a time zone, 5 characters plus trailing zero */
+typedef char TZ_NAME[6];
+
+typedef struct {
+ long offs; /* offset from UTC to local time [sec] */
+ long offs_dl; /* additional offset if daylight saving enabled [sec] */
+ TM tm_on; /* date/time when daylight saving starts */
+ TM tm_off; /* date/time when daylight saving ends */
+ TZ_NAME name[2]; /* names without and with daylight saving enabled */
+} TZDL;
+
+/* The constant below is defined beginning with software rev. 1.29. */
+/* If the year in tzdl.tmon and tzdl.tm_off is or'ed with that constant, */
+/* the receiver automatically generates daylight saving year by year. */
+/* See GPSLIB.TXT for more information. */
+
+#define DL_AUTO_FLAG 0x8000
+
+/* Example: */
+/* for automatic daylight saving enable/disable in Central Europe, */
+/* the variables are to be set as shown below: */
+/* offs = 3600L one hour from UTC */
+/* offs_dl = 3600L one additional hour if daylight saving enabled */
+/* tm_on = first Sunday from March 25, 02:00:00h ( year |= DL_AUTO_FLAG ) */
+/* tm_off = first Sunday from Sept 24, 03:00:00h ( year |= DL_AUTO_FLAG ) */
+/* name[0] == "MEZ " name if daylight saving not enabled */
+/* name[1] == "MESZ " name if daylight saving is enabled */
+
+
+
+
+/* the structure below was defined in rev. 1.31. It reflects the status */
+/* of the antenna, the times of last disconnect/reconnect and the boards */
+/* clock offset after the phase of disconnection. */
+
+typedef struct {
+ short status; /* current status of antenna */
+ TM tm_disconn; /* time of antenna disconnect */
+ TM tm_reconn; /* time of antenna reconnect */
+ long delta_t; /* clock offset at reconnect time, units: TICKS_PER_SEC */
+} ANT_INFO;
+
+
+/* the status field may be set to one of the values below: */
+
+enum {
+ ANT_INVALID, /* struct not set yet because ant. has not been disconn. */
+ ANT_DISCONN, /* ant. now disconn., tm_reconn and delta_t not set */
+ ANT_RECONN /* ant. has been disconn. and reconn., all fields valid */
+};
+
+
+/* Summary of configuration and health data of all SVs. */
+
+typedef struct {
+ CSUM csum; /* checksum of the remaining bytes */
+ short valid; /* flag data are valid */
+
+ T_GPS tot_51; /* time of transmission, page 51 */
+ T_GPS tot_63; /* time of transmission, page 63 */
+ T_GPS t0a; /* complete reference time almanac */
+
+ CFG cfg[N_SVNO]; /* SV configuration from page 63 */
+ HEALTH health[N_SVNO]; /* SV health from pages 51, 63 */
+} CFGH;
+
+
+
+/* UTC correction parameters */
+
+typedef struct {
+ CSUM csum; /* checksum of the remaining bytes */
+ short valid; /* flag data are valid */
+
+ T_GPS t0t; /* Reference Time UTC Parameters [sec] */
+ l_fp A0; /* ± Clock Correction Coefficient 0 [sec] */
+ l_fp A1; /* ± Clock Correction Coefficient 1 [sec/sec] */
+
+ ushort WNlsf; /* week number of nearest leap second */
+ short DNt; /* the day number at the end of which LS is inserted */
+ char delta_tls; /* */
+ char delta_tlsf; /* */
+
+} UTC;
+
+/* a struct used to hold the settings of a serial port */
+
+#ifndef _COM_PARM_DEFINED
+ typedef long BAUD_RATE;
+
+ /* indices used to identify a parameter in the framing string */
+ enum { F_DBITS, F_PRTY, F_STBITS };
+
+ /* types of handshake */
+ enum { HS_NONE, HS_XONXOFF, HS_RTSCTS };
+
+ typedef struct {
+ BAUD_RATE baud_rate; /* e.g. 19200L */
+ char framing[4]; /* e.g. "8N1" */
+ short handshake; /* a numeric value, only HS_NONE supported yet */
+ } COM_PARM;
+
+#define _COM_PARM_DEFINED
+#endif
+
+
+
+/* the codes below define what has to comes out of the serial ports */
+
+enum { STR_ON_REQ, STR_PER_SEC,
+ STR_PER_MIN, N_STR_MODE_0, /* COM0 and COM1 */
+ STR_UCAP = N_STR_MODE_0,
+ STR_UCAP_REQ, N_STR_MODE_1 /* COM1 only */
+ };
+
+
+#define N_COM 2 /* the number of serial ports */
+
+/* the structure used to store the modes of both serial ports */
+
+typedef struct {
+ COM_PARM com[N_COM]; /* COM0 and COM1 settings */
+ u_char mode[N_COM]; /* COM0 and COM1 output mode */
+} PORT_PARM;
+
+/* Ephemeris parameters of one specific SV. Needed to compute the position */
+/* of a satellite at a given time with high precision. Valid for an */
+/* interval of 4 to 6 hours from start of transmission. */
+
+typedef struct {
+ CSUM csum; /* checksum of the remaining bytes */
+ short valid; /* flag data are valid */
+
+ HEALTH health; /* health indication of transmitting SV [---] */
+ IOD IODC; /* Issue Of Data, Clock */
+ IOD IODE2; /* Issue of Data, Ephemeris (Subframe 2) */
+ IOD IODE3; /* Issue of Data, Ephemeris (Subframe 3) */
+ T_GPS tt; /* time of transmission */
+ T_GPS t0c; /* Reference Time Clock [---] */
+ T_GPS t0e; /* Reference Time Ephemeris [---] */
+
+ l_fp sqrt_A; /* Square Root of semi-major Axis [sqrt(m)] */
+ l_fp e; /* Eccentricity [---] */
+ l_fp M0; /* ± Mean Anomaly at Ref. Time [rad] */
+ l_fp omega; /* ± Argument of Perigee [rad] */
+ l_fp OMEGA0; /* ± Longit. of Asc. Node of orbit plane [rad] */
+ l_fp OMEGADOT; /* ± Rate of Right Ascension [rad/sec] */
+ l_fp deltan; /* ± Mean Motion Diff. from computed value [rad/sec] */
+ l_fp i0; /* ± Inclination Angle [rad] */
+ l_fp idot; /* ± Rate of Inclination Angle [rad/sec] */
+ l_fp crc; /* ± Cosine Corr. Term to Orbit Radius [m] */
+ l_fp crs; /* ± Sine Corr. Term to Orbit Radius [m] */
+ l_fp cuc; /* ± Cosine Corr. Term to Arg. of Latitude [rad] */
+ l_fp cus; /* ± Sine Corr. Term to Arg. of Latitude [rad] */
+ l_fp cic; /* ± Cosine Corr. Term to Inclination Angle [rad] */
+ l_fp cis; /* ± Sine Corr. Term to Inclination Angle [rad] */
+
+ l_fp af0; /* ± Clock Correction Coefficient 0 [sec] */
+ l_fp af1; /* ± Clock Correction Coefficient 1 [sec/sec] */
+ l_fp af2; /* ± Clock Correction Coefficient 2 [sec/sec²] */
+ l_fp tgd; /* ± estimated group delay differential [sec] */
+
+ u_short URA; /* predicted User Range Accuracy */
+
+ u_char L2code; /* code on L2 channel [---] */
+ u_char L2flag; /* L2 P data flag [---] */
+
+} EPH;
+
+/* Almanac parameters of one specific SV. A reduced precision set of */
+/* parameters used to check if a satellite is in view at a given time. */
+/* Valid for an interval of more than 7 days from start of transmission. */
+
+typedef struct {
+ CSUM csum; /* checksum of the remaining bytes */
+ short valid; /* flag data are valid */
+
+ HEALTH health; /* [---] */
+ T_GPS t0a; /* Reference Time Almanac [sec] */
+
+ l_fp sqrt_A; /* Square Root of semi-major Axis [sqrt(m)] */
+ l_fp e; /* Eccentricity [---] */
+
+ l_fp M0; /* ± Mean Anomaly at Ref. Time [rad] */
+ l_fp omega; /* ± Argument of Perigee [rad] */
+ l_fp OMEGA0; /* ± Longit. of Asc. Node of orbit plane [rad] */
+ l_fp OMEGADOT; /* ± Rate of Right Ascension [rad/sec] */
+ l_fp deltai; /* ± [rad] */
+ l_fp af0; /* ± Clock Correction Coefficient 0 [sec] */
+ l_fp af1; /* ± Clock Correction Coefficient 1 [sec/sec] */
+} ALM;
+
+
+/* ionospheric correction parameters */
+
+typedef struct {
+ CSUM csum; /* checksum of the remaining bytes */
+ short valid; /* flag data are valid */
+
+ l_fp alpha_0; /* Ionosph. Corr. Coeff. Alpha 0 [sec] */
+ l_fp alpha_1; /* Ionosph. Corr. Coeff. Alpha 1 [sec/deg] */
+ l_fp alpha_2; /* Ionosph. Corr. Coeff. Alpha 2 [sec/deg^2] */
+ l_fp alpha_3; /* Ionosph. Corr. Coeff. Alpha 3 [sec/deg^3] */
+
+ l_fp beta_0; /* Ionosph. Corr. Coeff. Beta 0 [sec] */
+ l_fp beta_1; /* Ionosph. Corr. Coeff. Beta 1 [sec/deg] */
+ l_fp beta_2; /* Ionosph. Corr. Coeff. Beta 2 [sec/deg^2] */
+ l_fp beta_3; /* Ionosph. Corr. Coeff. Beta 3 [sec/deg^3] */
+
+} IONO;
+
+void mbg_tm_str P((unsigned char **, TM *));
+void mbg_tgps_str P((unsigned char **, T_GPS *));
+void get_mbg_header P((unsigned char **, GPS_MSG_HDR *));
+void put_mbg_header P((unsigned char **, GPS_MSG_HDR *));
+void get_mbg_sw_rev P((unsigned char **, SW_REV *));
+void get_mbg_ascii_msg P((unsigned char **, ASCII_MSG *));
+void get_mbg_svno P((unsigned char **, SVNO *));
+void get_mbg_health P((unsigned char **, HEALTH *));
+void get_mbg_cfg P((unsigned char **, CFG *));
+void get_mbg_tgps P((unsigned char **, T_GPS *));
+void get_mbg_tm P((unsigned char **, TM *));
+void get_mbg_ttm P((unsigned char **, TTM *));
+void get_mbg_synth P((unsigned char **, SYNTH *));
+void get_mbg_tzdl P((unsigned char **, TZDL *));
+void get_mbg_antinfo P((unsigned char **, ANT_INFO *));
+void get_mbg_cfgh P((unsigned char **, CFGH *));
+void get_mbg_utc P((unsigned char **, UTC *));
+void get_mbg_lla P((unsigned char **, LLA));
+void get_mbg_xyz P((unsigned char **, XYZ));
+void get_mbg_portparam P((unsigned char **, PORT_PARM *));
+void get_mbg_eph P((unsigned char **, EPH *));
+void get_mbg_alm P((unsigned char **, ALM *));
+void get_mbg_iono P((unsigned char **, IONO *));
+
+unsigned long mbg_csum P((unsigned char *, unsigned int));
+
+#endif
+/*
+ * mbg_gps166.h,v
+ * Revision 4.1 1998/06/12 15:07:30 kardel
+ * fixed prototyping
+ *
+ * Revision 4.0 1998/04/10 19:50:42 kardel
+ * Start 4.0 release version numbering
+ *
+ * Revision 1.1 1998/04/10 19:27:34 kardel
+ * initial NTP VERSION 4 integration of PARSE with GPS166 binary support
+ *
+ * Revision 1.1 1997/10/06 20:55:38 kardel
+ * new parse structure
+ *
+ */
diff --git a/contrib/ntp/include/md5.h b/contrib/ntp/include/md5.h
new file mode 100644
index 000000000000..8241647601b3
--- /dev/null
+++ b/contrib/ntp/include/md5.h
@@ -0,0 +1,51 @@
+/* MD5.H - header file for MD5C.C
+ */
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+ rights reserved.
+
+ License to copy and use this software is granted provided that it
+ is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+ Algorithm" in all material mentioning or referencing this software
+ or this function.
+
+ License is also granted to make and use derivative works provided
+ that such works are identified as "derived from the RSA Data
+ Security, Inc. MD5 Message-Digest Algorithm" in all material
+ mentioning or referencing the derived work.
+
+ RSA Data Security, Inc. makes no representations concerning either
+ the merchantability of this software or the suitability of this
+ software for any particular purpose. It is provided "as is"
+ without express or implied warranty of any kind.
+
+ These notices must be retained in any copies of any part of this
+ documentation and/or software.
+ */
+
+#ifndef _MD5_H_
+#define _MD5_H_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*#include "global.h" */
+
+/* MD5 context. */
+typedef struct {
+ UINT4 state[4]; /* state (ABCD) */
+ UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
+ unsigned char buffer[64]; /* input buffer */
+} MD5_CTX;
+
+void MD5Init PROTO_LIST ((MD5_CTX *));
+void MD5Update PROTO_LIST
+ ((MD5_CTX *, unsigned char *, unsigned int));
+void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/contrib/ntp/include/mx4200.h b/contrib/ntp/include/mx4200.h
new file mode 100644
index 000000000000..6ea2c6039cf6
--- /dev/null
+++ b/contrib/ntp/include/mx4200.h
@@ -0,0 +1,40 @@
+
+/* records transmitted from extern CDU to MX 4200 */
+#define PMVXG_S_INITMODEA 0 /* initialization/mode part A */
+#define PMVXG_S_INITMODEB 1 /* initialization/mode part B*/
+#define PMVXG_S_SATHEALTH 2 /* satellite health control */
+#define PMVXG_S_DIFFNAV 3 /* differential navigation control */
+#define PMVXG_S_PORTCONF 7 /* control port configuration */
+#define PMVXG_S_GETSELFTEST 13 /* self test (request results) */
+#define PMVXG_S_RTCMCONF 16 /* RTCM port configuration */
+#define PMVXG_S_PASSTHRU 17 /* equipment port pass-thru config */
+#define PMVXG_S_RESTART 18 /* restart control */
+#define PMVXG_S_OSCPARAM 19 /* oscillator parameter */
+#define PMVXG_S_DOSELFTEST 20 /* self test (activate a test) */
+#define PMVXG_S_TRECOVCONF 23 /* time recovery configuration */
+#define PMVXG_S_RAWDATASEL 24 /* raw data port data selection */
+#define PMVXG_S_EQUIPCONF 26 /* equipment port configuration */
+#define PMVXG_S_RAWDATACONF 27 /* raw data port configuration */
+
+/* records transmitted from MX 4200 to external CDU */
+#define PMVXG_D_STATUS 0 /* status */
+#define PMVXG_D_POSITION 1 /* position */
+#define PMVXG_D_OPDOPS 3 /* (optimum) DOPs */
+#define PMVXG_D_MODEDATA 4 /* mode data */
+#define PMVXG_D_SATPRED 5 /* satellite predictions */
+#define PMVXG_D_SATHEALTH 6 /* satellite health status */
+#define PMVXG_D_UNRECOG 7 /* unrecognized request response */
+#define PMVXG_D_SIGSTRLOC 8 /* sig strength & location (sats 1-4) */
+#define PMVXG_D_SPEEDHEAD 11 /* speed/heading data */
+#define PMVXG_D_OSELFTEST 12 /* (old) self-test results */
+#define PMVXG_D_SIGSTRLOC2 18 /* sig strength & location (sats 5-8) */
+#define PMVXG_D_OSCPARAM 19 /* oscillator parameter */
+#define PMVXG_D_SELFTEST 20 /* self test results */
+#define PMVXG_D_PHV 21 /* position, height & velocity */
+#define PMVXG_D_DOPS 22 /* DOPs */
+#define PMVXG_D_SOFTCONF 30 /* software configuration */
+#define PMVXG_D_DIFFGPSMODE 503 /* differential gps moding */
+#define PMVXG_D_TRECOVUSEAGE 523 /* time recovery usage */
+#define PMVXG_D_RAWDATAOUT 524 /* raw data port data output */
+#define PMVXG_D_TRECOVRESULT 828 /* time recovery results */
+#define PMVXG_D_TRECOVOUT 830 /* time recovery output message */
diff --git a/contrib/ntp/include/ntif.h b/contrib/ntp/include/ntif.h
new file mode 100644
index 000000000000..837785272d24
--- /dev/null
+++ b/contrib/ntp/include/ntif.h
@@ -0,0 +1,98 @@
+/* this is a hacked version of if.h from unix to contain the stuff we need only to build named (bind) with
+ the minimal amount of changes... by l. kahn */
+
+ /*
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef _NET_IF_H
+#define _NET_IF_H
+
+
+/* #pragma ident "@(#)if.h 1.3 93/06/30 SMI"
+/* if.h 1.26 90/05/29 SMI; from UCB 7.1 6/4/86 */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Structures defining a network interface, providing a packet
+ * transport mechanism (ala level 0 of the PUP protocols).
+ *
+ * Each interface accepts output datagrams of a specified maximum
+ * length, and provides higher level routines with input datagrams
+ * received from its medium.
+ *
+ * Output occurs when the routine if_output is called, with three parameters:
+ * (*ifp->if_output)(ifp, m, dst)
+ * Here m is the mbuf chain to be sent and dst is the destination address.
+ * The output routine encapsulates the supplied datagram if necessary,
+ * and then transmits it on its medium.
+ *
+ * On input, each interface unwraps the data received by it, and either
+ * places it on the input queue of a internetwork datagram routine
+ * and posts the associated software interrupt, or passes the datagram to a raw
+ * packet input routine.
+ *
+ * Routines exist for locating interfaces by their addresses
+ * or for locating a interface on a certain network, as well as more general
+ * routing and gateway routines maintaining information used to locate
+ * interfaces. These routines live in the files if.c and route.c
+ */
+
+/*
+ * Structure defining a queue for a network interface.
+ *
+ * (Would like to call this struct ``if'', but C isn't PL/1.)
+ */
+/*
+ * Interface request structure used for socket
+ * ioctl's. All interface ioctl's must have parameter
+ * definitions which begin with ifr_name. The
+ * remainder may be interface specific.
+ */
+#ifdef FD_SETSIZE
+#undef FD_SETSIZE
+#endif
+#define FD_SETSIZE 512
+#include <winsock.h>
+typedef char *caddr_t;
+
+int get_winnt_interfaces();
+
+struct ifreq {
+#define IFNAMSIZ 16
+ char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
+ struct sockaddr ifru_addr;
+ char nt_mask[IFNAMSIZ]; /* new field to store mask returned from nt lookup l. kahn */
+
+#define ifr_addr ifru_addr /* address */
+#define ifr_mask nt_mask /* nt mask in character form */
+
+};
+
+/*
+ * Structure used in SIOCGIFCONF request.
+ * Used to retrieve interface configuration
+ * for machine (useful for programs which
+ * must know all networks accessible).
+ */
+struct ifconf {
+ int ifc_len; /* size of associated buffer */
+ union {
+ caddr_t ifcu_buf;
+ struct ifreq *ifcu_req;
+ } ifc_ifcu;
+#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
+#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _NET_IF_H */
+
diff --git a/contrib/ntp/include/ntp.h b/contrib/ntp/include/ntp.h
new file mode 100644
index 000000000000..790e0a5e0aca
--- /dev/null
+++ b/contrib/ntp/include/ntp.h
@@ -0,0 +1,714 @@
+/*
+ * ntp.h - NTP definitions for the masses
+ */
+
+#ifndef NTP_H
+#define NTP_H
+
+#include "ntp_types.h"
+#include <math.h>
+
+ /* common definitions for Y2K repairs [ Y2KFixes */
+
+ /* (this might better be put in ntp_calendar.h) */
+#define YEAR_BREAK 500 /* assume years < this are tm_year values: */
+ /* Break < AnyFourDigitYear
+ && Break > Anytm_yearYear */
+#define YEAR_PIVOT 98 /* 97/98: assume years < this are year 2000+ */
+ /* FYI: official UNIX pivot year is 68/69 */
+
+ /* Number of Days since (mythical) 1.BC Gregorian to 1 January of given year*/
+#define julian0(year) \
+ ( \
+ ( (year) * 365 ) + ( (year) > 0 \
+ ? ( ((year)+3) / 4 - ((year-1) / 100) + ((year-1) / 400) ) \
+ : 0 ) \
+ )
+
+ /* Number of days since start of NTP time to 1 January of given year */
+#define ntp0(year) ( julian0(year) - julian0(1900) )
+
+ /* Number of days since start of UNIX time to 1 January of given year */
+#define unix0(year) ( julian0(year) - julian0(1970) )
+
+ /* LEAP YEAR test for full 4-digit years (e.g, 1999, 2010) */
+#define isleap_4(y) /* a TRUE and PROPER leap year test */ \
+ ((y)%4 == 0 && !((y)%100 == 0 && !(y%400 == 0)))
+ /* NOTE: year 2000 TRULY IS A LEAP YEAR!!! */
+
+ /* LEAP YEAR test for tm_year (struct tm) years (e.g, 99, 110) */
+#define isleap_tm(y) /* a TRUE and PROPER leap year test */ \
+ ((y)%4 == 0 && !((y)%100 == 0 && !(((y)+1900)%400 == 0)))
+
+ /* to convert simple two-digit years to tm_year style years:
+ if ( year < YEAR_PIVOT ) year += 100;
+
+ * to convert either two-digit OR tm_year years to four-digit years:
+ if ( year < YEAR_PIVOT ) year += 100;
+ if ( year < YEAR_BREAK ) year += 1900;
+
+ CALL TO STANDARD:
+ * As the Internet is an INTERNATIONAL network, it makes SENSE to use
+ the international standard ISO 8601 to format dates and times.
+ Basically this is yyyy-mm-dd for years and hh:mm:ss for times
+ (joining the two togeather in computer readable media calls for
+ yyyy-mm-ddThh:mm:ss, though yyyy-mm-dd hh:mm:ss is often used
+ for human readable forms even though it is not not strictly
+ valid ISO 8601). Standard time-zone offsets ([+-]hh:mm) are allowed.
+ ghealton ] Y2KFixes */
+
+/*
+ * How to get signed characters. On machines where signed char works,
+ * use it. On machines where signed char doesn't work, char had better
+ * be signed.
+ */
+#ifdef NEED_S_CHAR_TYPEDEF
+# if SIZEOF_SIGNED_CHAR
+typedef signed char s_char;
+# else
+typedef char s_char;
+# endif
+ /* XXX: Why is this sequent bit INSIDE this test? */
+# ifdef sequent
+# undef SO_RCVBUF
+# undef SO_SNDBUF
+# endif
+#endif
+#ifndef TRUE
+# define TRUE 1
+#endif /* TRUE */
+#ifndef FALSE
+# define FALSE 0
+#endif /* FALSE */
+
+/*
+ * NTP protocol parameters. See section 3.2.6 of the specification.
+ */
+#define NTP_VERSION ((u_char)4) /* current version number */
+#define NTP_OLDVERSION ((u_char)1) /* oldest credible version */
+#define NTP_PORT 123 /* included for sake of non-unix machines */
+#define NTP_MAXSTRATUM ((u_char)15) /* max stratum, infinity a la Bellman-Ford */
+#define NTP_MAXAGE 86400 /* one day in seconds */
+#define NTP_UNREACH 16 /* poll interval backoff count */
+#define NTP_MINDPOLL 6 /* log2 default min poll interval (64 s) */
+#define NTP_MAXDPOLL 10 /* log2 default max poll interval (~17 m) */
+#define NTP_MINPOLL 4 /* log2 min poll interval (16 s) */
+#define NTP_MAXPOLL 17 /* log2 max poll interval (~4.5 h) */
+#define NTP_MINCLOCK 3 /* minimum survivors */
+#define NTP_CANCLOCK 6 /* minimum candidates */
+#define NTP_MAXCLOCK 10 /* maximum candidates */
+#define NTP_WINDOW 8 /* reachability register size */
+#define NTP_SHIFT 8 /* 8 suitable for crystal time base */
+#define NTP_MAXKEY 65535 /* maximum authentication key number */
+#define NTP_MAXSESSION 100 /* maximum entries on session key list */
+#define NTP_AUTOMAX 12 /* log2 default max session key lifetime */
+#define KEY_REVOKE 16 /* log2 default key revoke timeout */
+#define NTP_FWEIGHT .5 /* clock filter weight */
+#define NTP_SWEIGHT .75 /* select weight */
+#define CLOCK_SGATE 10. /* popcorn spike gate */
+#define BURST_INTERVAL1 4 /* first interburst interval (log2) */
+#define BURST_INTERVAL2 1 /* succeeding interburst intervals (log2) */
+
+/*
+ * Operations for jitter (variance) calculations (these use doubles).
+ * Note that we carefully separate the jitter component from the dispersion
+ * component (frequency error plus precision). The frequency error
+ * component is computed as CLOCK_PHI times the difference between the epoch
+ * of the time measurement and the reference time. The precision componen
+ * is computed as the square root of the mean of the squares of a zero-
+ * mean, uniform distribution of unit maximum amplitude. Whether this
+ * makes statistical sense may be arguable.
+ */
+#define SQUARE(x) ((x) * (x))
+#define SQRT(x) (sqrt(x))
+#define DIFF(x, y) (SQUARE((x) - (y)))
+#define LOGTOD(a) ((a) < 0 ? 1. / (1L << -(a)) : \
+ 1L << (int)(a)) /* log2 to double */
+#define UNIVAR(x) (SQUARE(.28867513 * LOGTOD(x))) /* std uniform distr */
+#define ULOGTOD(a) (1L << (int)(a)) /* ulog2 to double */
+#define MAXDISPERSE 16. /* max dispersion (square) */
+#define MINDISPERSE .01 /* min dispersion */
+#define MAXDISTANCE 1. /* max root distance */
+
+/*
+ * Loop filter parameters. See section 5.1 of the specification.
+ *
+ * Note that these are appropriate for a crystal time base. If your
+ * system clock is line frequency controlled you should read the
+ * specification for appropriate modifications.
+ */
+#define CLOCK_PHI 15e-6 /* max frequency wander */
+
+#define EVENT_TIMEOUT 0 /* one second, that is */
+
+/*
+ * The interface structure is used to hold the addresses and socket
+ * numbers of each of the interfaces we are using.
+ */
+struct interface {
+ int fd; /* socket this is opened on */
+ int bfd; /* socket for receiving broadcasts */
+ struct sockaddr_in sin; /* interface address */
+ struct sockaddr_in bcast; /* broadcast address */
+ struct sockaddr_in mask; /* interface mask */
+ char name[8]; /* name of interface */
+ int flags; /* interface flags */
+ int last_ttl; /* last TTL specified */
+ volatile long received; /* number of incoming packets */
+ long sent; /* number of outgoing packets */
+ long notsent; /* number of send failures */
+};
+
+/*
+ * Flags for interfaces
+ */
+#define INT_BROADCAST 1 /* can broadcast out this interface */
+#define INT_BCASTOPEN 2 /* broadcast socket is open */
+#define INT_LOOPBACK 4 /* the loopback interface */
+#define INT_MULTICAST 8 /* multicasting enabled */
+
+/*
+ * Define flasher bits (tests 1 through 8 in packet procedure)
+ * These reveal the state at the last grumble from the peer and are
+ * most handy for diagnosing problems, even if not strictly a state
+ * variable in the spec. These are recorded in the peer structure.
+ */
+#define TEST1 0x0001 /* duplicate packet received */
+#define TEST2 0x0002 /* bogus packet received */
+#define TEST3 0x0004 /* protocol unsynchronized */
+#define TEST4 0x0008 /* peer delay/dispersion bounds check */
+#define TEST5 0x0010 /* peer authentication failed */
+#define TEST6 0x0020 /* peer clock unsynchronized */
+#define TEST7 0x0040 /* peer stratum out of bounds */
+#define TEST8 0x0080 /* root delay/dispersion bounds check */
+#define TEST9 0x0100 /* peer not authenticated */
+#define TEST10 0x0200 /* access denied */
+
+/*
+ * The peer structure. Holds state information relating to the guys
+ * we are peering with. Most of this stuff is from section 3.2 of the
+ * spec.
+ */
+struct peer {
+ struct peer *next;
+ struct peer *ass_next; /* link pointer in associd hash */
+ struct sockaddr_in srcadr; /* address of remote host */
+ struct interface *dstadr; /* pointer to address on local host */
+ struct refclockproc *procptr; /* pointer to reference clock stuff */
+ u_char leap; /* leap indicator */
+ u_char hmode; /* association mode with this peer */
+ u_char pmode; /* peer's association mode */
+ u_char stratum; /* stratum of remote peer */
+ s_char precision; /* peer's clock precision */
+ u_char ppoll; /* peer poll interval */
+ u_char hpoll; /* local host poll interval */
+ u_char minpoll; /* min local host poll interval */
+ u_char maxpoll; /* max local host poll interval */
+ u_char burst; /* packets remaining in burst */
+ u_char version; /* version number */
+ u_int flags; /* peer flags */
+ u_char cast_flags; /* flags MDF_?CAST */
+ u_int flash; /* protocol error tally bits */
+ u_char refclktype; /* reference clock type */
+ u_char refclkunit; /* reference clock unit number */
+ u_char sstclktype; /* clock type for system status word */
+ u_int32 refid; /* peer reference ID */
+ l_fp reftime; /* update epoch */
+ u_long keyid; /* current key ID */
+ u_long pkeyid; /* previous key ID (autokey) */
+ u_long *keylist; /* session key identifier list */
+ int keynumber; /* session key identifier number */
+ u_short associd; /* association ID, a unique integer */
+ u_char ttl; /* time to live (multicast) */
+
+/* **Start of clear-to-zero area.*** */
+/* Everything that is cleared to zero goes below here */
+ u_char valid; /* valid counter */
+#define clear_to_zero valid
+ double estbdelay; /* broadcast offset */
+ u_char status; /* peer status */
+ u_char pollsw; /* what it says */
+ u_char reach; /* reachability, NTP_WINDOW bits */
+ u_char unreach; /* unreachable count */
+ u_short filter_nextpt; /* index into filter shift register */
+ double filter_delay[NTP_SHIFT]; /* delay part of shift register */
+ double filter_offset[NTP_SHIFT]; /* offset part of shift register */
+ double filter_disp[NTP_SHIFT]; /* dispersion part of shift register */
+ u_long filter_epoch[NTP_SHIFT]; /* epoch part of shift register */
+ u_char filter_order[NTP_SHIFT]; /* we keep the filter sorted here */
+ l_fp org; /* originate time stamp */
+ l_fp rec; /* receive time stamp */
+ l_fp xmt; /* transmit time stamp */
+ double offset; /* peer clock offset */
+ double delay; /* peer roundtrip delay */
+ double variance; /* peer variance (jitter) */
+ double disp; /* peer dispersion */
+ double rootdelay; /* roundtrip delay to primary clock */
+ double rootdispersion; /* dispersion to primary clock */
+ u_long epoch; /* reference epoch */
+
+/* ***End of clear-to-zero area.*** */
+/* Everything that is cleared to zero goes above here */
+ u_long update; /* receive epoch */
+#define end_clear_to_zero update
+ u_long outdate; /* send time last packet */
+ u_long nextdate; /* send time next packet */
+ u_long nextaction; /* peer local activity timeout (refclocks mainly) */
+ void (*action) P((struct peer *));/* action timeout function */
+ /*
+ * statistic counters
+ */
+ u_long timereset; /* time stat counters were reset */
+ u_long sent; /* number of updates sent */
+ u_long received; /* number of frames received */
+ u_long timereceived; /* last time a frame received */
+ u_long timereachable; /* last reachable/unreachable event */
+ u_long processed; /* processed by the protocol */
+ u_long badauth; /* bad credentials detected */
+ u_long bogusorg; /* rejected due to bogus origin */
+ u_long oldpkt; /* rejected as duplicate packet */
+ u_long seldisptoolarge; /* too much dispersion for selection */
+ u_long selbroken; /* broken NTP detected in selection */
+ u_long seltooold; /* too long since sync in selection */
+ u_char last_event; /* set to code for last peer error */
+ u_char num_events; /* num. of events which have occurred */
+};
+
+/*
+ * Values for peer.leap, sys_leap
+ */
+#define LEAP_NOWARNING 0x0 /* normal, no leap second warning */
+#define LEAP_ADDSECOND 0x1 /* last minute of day has 61 seconds */
+#define LEAP_DELSECOND 0x2 /* last minute of day has 59 seconds */
+#define LEAP_NOTINSYNC 0x3 /* overload, clock is free running */
+
+/*
+ * Values for peer.mode
+ */
+#define MODE_UNSPEC 0 /* unspecified (probably old NTP version) */
+#define MODE_ACTIVE 1 /* symmetric active */
+#define MODE_PASSIVE 2 /* symmetric passive */
+#define MODE_CLIENT 3 /* client mode */
+#define MODE_SERVER 4 /* server mode */
+#define MODE_BROADCAST 5 /* broadcast mode */
+#define MODE_CONTROL 6 /* control mode packet */
+#define MODE_PRIVATE 7 /* implementation defined function */
+
+#define MODE_BCLIENT 8 /* a pseudo mode, used internally */
+#define MODE_MCLIENT 9 /* multicast mode, used internally */
+
+/*
+ * Values for peer.stratum, sys_stratum
+ */
+#define STRATUM_REFCLOCK ((u_char)0) /* stratum claimed by primary clock */
+#define STRATUM_PRIMARY ((u_char)1) /* host has a primary clock */
+#define STRATUM_INFIN ((u_char)NTP_MAXSTRATUM) /* infinity a la Bellman-Ford */
+/* A stratum of 0 in the packet is mapped to 16 internally */
+#define STRATUM_PKT_UNSPEC ((u_char)0) /* unspecified in packet */
+#define STRATUM_UNSPEC ((u_char)(NTP_MAXSTRATUM+(u_char)1)) /* unspecified */
+
+/*
+ * Values for peer.flags
+ */
+#define FLAG_CONFIG 0x1 /* association was configured */
+#define FLAG_AUTHENABLE 0x2 /* this guy needs authentication */
+#define FLAG_MCAST1 0x4 /* multicast client/server mode */
+#define FLAG_MCAST2 0x8 /* multicast client mode */
+#define FLAG_AUTHENTIC 0x10 /* last message was authentic */
+#define FLAG_REFCLOCK 0x20 /* this is actually a reference clock */
+#define FLAG_SYSPEER 0x40 /* this is one of the selected peers */
+#define FLAG_PREFER 0x80 /* this is the preferred peer */
+#define FLAG_BURST 0x100 /* burst mode */
+#define FLAG_SKEY 0x200 /* autokey authentication */
+#define FLAG_NOSELECT 0x400 /* this is a "noselect" peer */
+
+/*
+ * Definitions for the clear() routine. We use memset() to clear
+ * the parts of the peer structure which go to zero. These are
+ * used to calculate the start address and length of the area.
+ */
+#define CLEAR_TO_ZERO(p) ((char *)&((p)->clear_to_zero))
+#define END_CLEAR_TO_ZERO(p) ((char *)&((p)->end_clear_to_zero))
+#define LEN_CLEAR_TO_ZERO (END_CLEAR_TO_ZERO((struct peer *)0) \
+ - CLEAR_TO_ZERO((struct peer *)0))
+/*
+ * Reference clock identifiers (for pps signal)
+ */
+#define PPSREFID (u_int32)"PPS " /* used when pps controls stratum>1 */
+
+/*
+ * Reference clock types. Added as necessary.
+ */
+#define REFCLK_NONE 0 /* unknown or missing */
+#define REFCLK_LOCALCLOCK 1 /* external (e.g., lockclock) */
+#define REFCLK_GPS_TRAK 2 /* TRAK 8810 GPS Receiver */
+#define REFCLK_WWV_PST 3 /* PST/Traconex 1020 WWV/H */
+#define REFCLK_WWVB_SPECTRACOM 4 /* Spectracom 8170/Netclock WWVB */
+#define REFCLK_TRUETIME 5 /* TrueTime (generic) Receivers */
+#define REFCLK_IRIG_AUDIO 6 /* IRIG-B audio decoder */
+#define REFCLK_CHU 7 /* scratchbuilt CHU (Canada) */
+#define REFCLK_PARSE 8 /* generic driver (usually DCF77,GPS,MSF) */
+#define REFCLK_GPS_MX4200 9 /* Magnavox MX4200 GPS */
+#define REFCLK_GPS_AS2201 10 /* Austron 2201A GPS */
+#define REFCLK_GPS_ARBITER 11 /* Arbiter 1088A/B/ GPS */
+#define REFCLK_IRIG_TPRO 12 /* KSI/Odetics TPRO-S IRIG */
+#define REFCLK_ATOM_LEITCH 13 /* Leitch CSD 5300 Master Clock */
+#define REFCLK_MSF_EES 14 /* EES M201 MSF Receiver */
+#define REFCLK_GPSTM_TRUE 15 /* OLD TrueTime GPS/TM-TMD Receiver */
+#define REFCLK_IRIG_BANCOMM 16 /* Bancomm GPS/IRIG Interface */
+#define REFCLK_GPS_DATUM 17 /* Datum Programmable Time System */
+#define REFCLK_NIST_ACTS 18 /* NIST Auto Computer Time Service */
+#define REFCLK_WWV_HEATH 19 /* Heath GC1000 WWV/WWVH Receiver */
+#define REFCLK_GPS_NMEA 20 /* NMEA based GPS clock */
+#define REFCLK_GPS_VME 21 /* TrueTime GPS-VME Interface */
+#define REFCLK_ATOM_PPS 22 /* 1-PPS Clock Discipline */
+#define REFCLK_PTB_ACTS 23 /* PTB Auto Computer Time Service */
+#define REFCLK_USNO 24 /* Naval Observatory dialup */
+#define REFCLK_GPS_HP 26 /* HP 58503A Time/Frequency Receiver */
+#define REFCLK_ARCRON_MSF 27 /* ARCRON MSF radio clock. */
+#define REFCLK_SHM 28 /* clock attached thru shared memory */
+#define REFCLK_PALISADE 29 /* Trimble Navigation Palisade GPS */
+#define REFCLK_ONCORE 30 /* Motorola UT Oncore GPS */
+#define REFCLK_GPS_JUPITER 31 /* Rockwell Jupiter GPS receiver */
+#define REFCLK_CHRONOLOG 32 /* Chrono-log K WWVB receiver */
+#define REFCLK_DUMBCLOCK 33 /* Dumb localtime clock */
+#define REFCLK_ULINK 34 /* Ultralink M320 WWVB receiver */
+#define REFCLK_MAX 34 /* Grow as needed... */
+
+/*
+ * We tell reference clocks from real peers by giving the reference
+ * clocks an address of the form 127.127.t.u, where t is the type and
+ * u is the unit number. We define some of this here since we will need
+ * some sanity checks to make sure this address isn't interpretted as
+ * that of a normal peer.
+ */
+#define REFCLOCK_ADDR 0x7f7f0000 /* 127.127.0.0 */
+#define REFCLOCK_MASK 0xffff0000 /* 255.255.0.0 */
+
+#define ISREFCLOCKADR(srcadr) ((SRCADR(srcadr) & REFCLOCK_MASK) \
+ == REFCLOCK_ADDR)
+
+/*
+ * Macro for checking for invalid addresses. This is really, really
+ * gross, but is needed so no one configures a host on net 127 now that
+ * we're encouraging it the the configuration file.
+ */
+#define LOOPBACKADR 0x7f000001
+#define LOOPNETMASK 0xff000000
+
+#define ISBADADR(srcadr) (((SRCADR(srcadr) & LOOPNETMASK) \
+ == (LOOPBACKADR & LOOPNETMASK)) \
+ && (SRCADR(srcadr) != LOOPBACKADR))
+
+/*
+ * Utilities for manipulating addresses and port numbers
+ */
+#define NSRCADR(src) ((src)->sin_addr.s_addr) /* address in net byte order */
+#define NSRCPORT(src) ((src)->sin_port) /* port in net byte order */
+#define SRCADR(src) (ntohl(NSRCADR((src)))) /* address in host byte order */
+#define SRCPORT(src) (ntohs(NSRCPORT((src)))) /* host port */
+
+/*
+ * NTP packet format. The mac field is optional. It isn't really
+ * an l_fp either, but for now declaring it that way is convenient.
+ * See Appendix A in the specification.
+ *
+ * Note that all u_fp and l_fp values arrive in network byte order
+ * and must be converted (except the mac, which isn't, really).
+ */
+struct pkt {
+ u_char li_vn_mode; /* contains leap indicator, version and mode */
+ u_char stratum; /* peer's stratum */
+ u_char ppoll; /* the peer polling interval */
+ s_char precision; /* peer clock precision */
+ u_fp rootdelay; /* distance to primary clock */
+ u_fp rootdispersion; /* clock dispersion */
+ u_int32 refid; /* reference clock ID */
+ l_fp reftime; /* time peer clock was last updated */
+ l_fp org; /* originate time stamp */
+ l_fp rec; /* receive time stamp */
+ l_fp xmt; /* transmit time stamp */
+
+#define MIN_MAC_LEN (sizeof(u_int32) + 8) /* DES */
+#define MAX_MAC_LEN (sizeof(u_int32) + 16) /* MD5 */
+
+ /*
+ * The length of the packet less MAC must be a multiple of 64
+ * bits. For normal private-key cryptography, the cryptosum
+ * covers only the raw NTP header. For autokey cryptography,
+ * the heade is incresed by 64 bits to contain the field length
+ * and private value.
+ */
+ u_int32 keyid1; /* key identifier 1 */
+ u_int32 keyid2; /* key identifier 2 */
+ u_int32 keyid3; /* key identifier 3 */
+ u_char mac[MAX_MAC_LEN]; /* mac */
+};
+
+/*
+ * Packets can come in two flavours, one with a mac and one without.
+ */
+#define LEN_PKT_NOMAC (sizeof(struct pkt) - MAX_MAC_LEN - 3 * sizeof(u_int32))
+
+/*
+ * Minimum size of packet with a MAC: has to include at least a key number.
+ */
+#define LEN_PKT_MAC (LEN_PKT_NOMAC + sizeof(u_int32))
+
+/*
+ * Stuff for extracting things from li_vn_mode
+ */
+#define PKT_MODE(li_vn_mode) ((u_char)((li_vn_mode) & 0x7))
+#define PKT_VERSION(li_vn_mode) ((u_char)(((li_vn_mode) >> 3) & 0x7))
+#define PKT_LEAP(li_vn_mode) ((u_char)(((li_vn_mode) >> 6) & 0x3))
+
+/*
+ * Stuff for putting things back into li_vn_mode
+ */
+#define PKT_LI_VN_MODE(li, vn, md) \
+ ((u_char)((((li) << 6) & 0xc0) | (((vn) << 3) & 0x38) | ((md) & 0x7)))
+
+
+/*
+ * Dealing with stratum. 0 gets mapped to 16 incoming, and back to 0
+ * on output.
+ */
+#define PKT_TO_STRATUM(s) ((u_char)(((s) == (STRATUM_PKT_UNSPEC)) ?\
+ (STRATUM_UNSPEC) : (s)))
+
+#define STRATUM_TO_PKT(s) ((u_char)(((s) == (STRATUM_UNSPEC)) ?\
+ (STRATUM_PKT_UNSPEC) : (s)))
+
+
+/*
+ * Event codes. Used for reporting errors/events to the control module
+ */
+#define PEER_EVENT 0x80 /* this is a peer event */
+
+#define EVNT_UNSPEC 0
+#define EVNT_SYSRESTART 1
+#define EVNT_SYSFAULT 2
+#define EVNT_SYNCCHG 3
+#define EVNT_PEERSTCHG 4
+#define EVNT_CLOCKRESET 5
+#define EVNT_BADDATETIM 6
+#define EVNT_CLOCKEXCPT 7
+
+#define EVNT_PEERIPERR (1|PEER_EVENT)
+#define EVNT_PEERAUTH (2|PEER_EVENT)
+#define EVNT_UNREACH (3|PEER_EVENT)
+#define EVNT_REACH (4|PEER_EVENT)
+#define EVNT_PEERCLOCK (5|PEER_EVENT)
+
+/*
+ * Clock event codes
+ */
+#define CEVNT_NOMINAL 0
+#define CEVNT_TIMEOUT 1
+#define CEVNT_BADREPLY 2
+#define CEVNT_FAULT 3
+#define CEVNT_PROP 4
+#define CEVNT_BADDATE 5
+#define CEVNT_BADTIME 6
+#define CEVNT_MAX CEVNT_BADTIME
+
+/*
+ * Very misplaced value. Default port through which we send traps.
+ */
+#define TRAPPORT 18447
+
+
+/*
+ * To speed lookups, peers are hashed by the low order bits of the remote
+ * IP address. These definitions relate to that.
+ */
+#define HASH_SIZE 32
+#define HASH_MASK (HASH_SIZE-1)
+#define HASH_ADDR(src) ((SRCADR((src))^(SRCADR((src))>>8)) & HASH_MASK)
+
+/*
+ * How we randomize polls. The poll interval is a power of two.
+ * We chose a random value which is between 1/4 and 3/4 of the
+ * poll interval we would normally use and which is an even multiple
+ * of the EVENT_TIMEOUT. The random number routine, given an argument
+ * spread value of n, returns an integer between 0 and (1<<n)-1. This
+ * is shifted by EVENT_TIMEOUT and added to the base value.
+ */
+#if defined(HAVE_MRAND48)
+#define RANDOM (mrand48())
+#define SRANDOM(x) (srand48(x))
+#elif defined(HAVE_RANDOM)
+#define RANDOM (random())
+#define SRANDOM(x) (srandom(x))
+#else
+#define RANDOM (0)
+#define SRANDOM(x) (0)
+#endif
+
+#define RANDPOLL(x) ((1 << (x)) - 1 + (RANDOM & 0x3))
+#define RANDOM_SPREAD(poll) ((poll) - (EVENT_TIMEOUT+1))
+#define RANDOM_POLL(poll, rval) ((((rval)+1)<<EVENT_TIMEOUT) + (1<<((poll)-2)))
+
+/*
+ * min, min3 and max. Makes it easier to transliterate the spec without
+ * thinking about it.
+ */
+#define min(a,b) (((a) < (b)) ? (a) : (b))
+#define max(a,b) (((a) > (b)) ? (a) : (b))
+#define min3(a,b,c) min(min((a),(b)), (c))
+
+
+/*
+ * Configuration items. These are for the protocol module (proto_config())
+ */
+#define PROTO_BROADCLIENT 1
+#define PROTO_PRECISION 2 /* (not used) */
+#define PROTO_AUTHENTICATE 3
+#define PROTO_BROADDELAY 4
+#define PROTO_AUTHDELAY 5 /* (not used) */
+#define PROTO_MULTICAST_ADD 6
+#define PROTO_MULTICAST_DEL 7
+#define PROTO_NTP 8
+#define PROTO_KERNEL 9
+#define PROTO_MONITOR 10
+#define PROTO_FILEGEN 11
+
+/*
+ * Configuration items for the loop filter
+ */
+#define LOOP_DRIFTINIT 1 /* set initial frequency offset */
+#define LOOP_DRIFTCOMP 2 /* set frequency offset */
+#define LOOP_PPSDELAY 3 /* set pps delay */
+#define LOOP_PPSBAUD 4 /* set pps baud rate */
+
+/*
+ * Configuration items for the stats printer
+ */
+#define STATS_FREQ_FILE 1 /* configure drift file */
+#define STATS_STATSDIR 2 /* directory prefix for stats files */
+#define STATS_PID_FILE 3 /* configure ntpd PID file */
+
+#define MJD_1970 40587 /* MJD for 1 Jan 1970 */
+
+/*
+ * Default parameters. We use these in the absence of something better.
+ */
+#define DEFBROADDELAY 4e-3 /* default broadcast offset */
+#define INADDR_NTP 0xe0000101 /* NTP multicast address 224.0.1.1 */
+/*
+ * Structure used optionally for monitoring when this is turned on.
+ */
+struct mon_data {
+ struct mon_data *hash_next; /* next structure in hash list */
+ struct mon_data *mru_next; /* next structure in MRU list */
+ struct mon_data *mru_prev; /* previous structure in MRU list */
+ struct mon_data *fifo_next; /* next structure in FIFO list */
+ struct mon_data *fifo_prev; /* previous structure in FIFO list */
+ u_long lastdrop; /* last time dropped due to RES_LIMIT*/
+ u_long lasttime; /* last time data updated */
+ u_long firsttime; /* time structure initialized */
+ u_long count; /* count we have seen */
+ u_int32 rmtadr; /* address of remote host */
+ struct interface *interface; /* interface on which this arrived */
+ u_short rmtport; /* remote port last came from */
+ u_char mode; /* mode of incoming packet */
+ u_char version; /* version of incoming packet */
+ u_char cast_flags; /* flags MDF_?CAST */
+};
+
+#define MDF_UCAST 0x1 /* unicast packet */
+#define MDF_MCAST 0x2 /* multicast packet */
+#define MDF_BCAST 0x4 /* broadcast packet */
+#define MDF_LCAST 0x8 /* local packet */
+#define MDF_ACAST 0x10 /* manycast packet */
+
+/*
+ * Values used with mon_enabled to indicate reason for enabling monitoring
+ */
+#define MON_OFF 0x00 /* no monitoring */
+#define MON_ON 0x01 /* monitoring explicitly enabled */
+#define MON_RES 0x02 /* implicit monitoring for RES_LIMITED */
+/*
+ * Structure used for restrictlist entries
+ */
+struct restrictlist {
+ struct restrictlist *next; /* link to next entry */
+ u_int32 addr; /* host address (host byte order) */
+ u_int32 mask; /* mask for address (host byte order) */
+ u_long count; /* number of packets matched */
+ u_short flags; /* accesslist flags */
+ u_short mflags; /* match flags */
+};
+
+/*
+ * Access flags
+ */
+#define RES_IGNORE 0x1 /* ignore if matched */
+#define RES_DONTSERVE 0x2 /* don't give him any time */
+#define RES_DONTTRUST 0x4 /* don't trust if matched */
+#define RES_NOQUERY 0x8 /* don't allow queries if matched */
+#define RES_NOMODIFY 0x10 /* don't allow him to modify server */
+#define RES_NOPEER 0x20 /* don't allocate memory resources */
+#define RES_NOTRAP 0x40 /* don't allow him to set traps */
+#define RES_LPTRAP 0x80 /* traps set by him are low priority */
+#define RES_LIMITED 0x100 /* limit per net number of clients */
+
+#define RES_ALLFLAGS \
+ (RES_IGNORE|RES_DONTSERVE|RES_DONTTRUST|RES_NOQUERY\
+ |RES_NOMODIFY|RES_NOPEER|RES_NOTRAP|RES_LPTRAP|RES_LIMITED)
+
+/*
+ * Match flags
+ */
+#define RESM_INTERFACE 0x1 /* this is an interface */
+#define RESM_NTPONLY 0x2 /* match ntp port only */
+
+/*
+ * Restriction configuration ops
+ */
+#define RESTRICT_FLAGS 1 /* add flags to restrict entry */
+#define RESTRICT_UNFLAG 2 /* remove flags from restrict entry */
+#define RESTRICT_REMOVE 3 /* remove a restrict entry */
+
+
+/*
+ * Experimental alternate selection algorithm identifiers
+ */
+#define SELECT_1 1
+#define SELECT_2 2
+#define SELECT_3 3
+#define SELECT_4 4
+#define SELECT_5 5
+
+/*
+ * Endpoint structure for the select algorithm
+ */
+struct endpoint {
+ double val; /* offset of endpoint */
+ int type; /* interval entry/exit */
+};
+
+/*
+ * Defines for association matching
+ */
+#define AM_MODES 10 /* total number of modes */
+#define NO_PEER 0 /* action when no peer is found */
+
+/*
+ * Association matching AM[] return codes
+ */
+#define AM_ERR -1
+#define AM_NOMATCH 0
+#define AM_PROCPKT 1
+#define AM_FXMIT 2
+#define AM_MANYCAST 3
+#define AM_NEWPASS 4
+#define AM_NEWBCL 5
+#define AM_POSSBCL 6
+
+/* NetInfo configuration locations */
+#ifdef HAVE_NETINFO
+#define NETINFO_CONFIG_DIR "/config/ntp"
+#endif
+
+#endif /* NTP_H */
diff --git a/contrib/ntp/include/ntp_calendar.h b/contrib/ntp/include/ntp_calendar.h
new file mode 100644
index 000000000000..95e2c12974ba
--- /dev/null
+++ b/contrib/ntp/include/ntp_calendar.h
@@ -0,0 +1,112 @@
+/*
+ * ntp_calendar.h - definitions for the calendar time-of-day routine
+ */
+#ifndef NTP_CALENDAR_H
+#define NTP_CALENDAR_H
+
+#include "ntp_types.h"
+
+struct calendar {
+ u_short year; /* year (A.D.) */
+ u_short yearday; /* day of year, 1 = January 1 */
+ u_char month; /* month, 1 = January */
+ u_char monthday; /* day of month */
+ u_char hour; /* hour of day, midnight = 0 */
+ u_char minute; /* minute of hour */
+ u_char second; /* second of minute */
+};
+
+/*
+ * Days in each month. 30 days hath September...
+ */
+#define JAN 31
+#define FEB 28
+#define FEBLEAP 29
+#define MAR 31
+#define APR 30
+#define MAY 31
+#define JUN 30
+#define JUL 31
+#define AUG 31
+#define SEP 30
+#define OCT 31
+#define NOV 30
+#define DEC 31
+
+/*
+ * We deal in a 4 year cycle starting at March 1, 1900. We assume
+ * we will only want to deal with dates since then, and not to exceed
+ * the rollover day in 2036.
+ */
+#define SECSPERMIN (60) /* seconds per minute */
+#define MINSPERHR (60) /* minutes per hour */
+#define HRSPERDAY (24) /* hours per day */
+#define DAYSPERYEAR (365) /* days per year */
+
+#define SECSPERDAY (SECSPERMIN*MINSPERHR*HRSPERDAY)
+#define SECSPERYEAR (365 * SECSPERDAY) /* regular year */
+#define SECSPERLEAPYEAR (366 * SECSPERDAY) /* leap year */
+
+#define MAR1900 ((JAN+FEB) * SECSPERDAY) /* no leap year in 1900 */
+#define DAYSPERCYCLE (365+365+365+366) /* 3 normal years plus leap */
+#define SECSPERCYCLE (DAYSPERCYCLE*SECSPERDAY)
+#define YEARSPERCYCLE 4
+
+/*
+ * Gross hacks. I have illicit knowlege that there won't be overflows
+ * here, the compiler often can't tell this.
+ */
+#define TIMES60(val) ((((val)<<4) - (val))<<2) /* *(16 - 1) * 4 */
+#define TIMES24(val) (((val)<<4) + ((val)<<3)) /* *16 + *8 */
+#define TIMES7(val) (((val)<<3) - (val)) /* *8 - *1 */
+#define TIMESDPERC(val) (((val)<<10) + ((val)<<8) \
+ + ((val)<<7) + ((val)<<5) \
+ + ((val)<<4) + ((val)<<2) + (val)) /* *big* hack */
+
+/*
+ * Another big hack. Cycle 22 started on March 1, 1988. This is
+ * STARTCYCLE22 seconds after the start of cycle 0.
+ */
+#define CYCLE22 (22)
+#define STARTCYCLE22 (u_long)(0xa586b500) /* 2777068800 */
+#define MAR1988 (u_long)(STARTCYCLE22 + (u_long)MAR1900)
+
+/*
+ * The length of January + February in leap and non-leap years.
+ */
+#define JANFEBNOLEAP ((JAN+FEB) * SECSPERDAY)
+#define JANFEBLEAP ((JAN+FEBLEAP) * SECSPERDAY)
+
+
+extern void caljulian P((u_long, struct calendar *));
+extern u_long caltontp P((const struct calendar *));
+
+/*
+ * Additional support stuff for Ed Rheingold's calendrical calculations
+ */
+
+/*
+ * Start day of NTP time as days past the imaginary date 12/1/1 BC.
+ * P((This is the beginning of the Christian Era, or BCE.))
+ */
+#define DAY_NTP_STARTS 693596
+/*
+ * The Gregorian calendar is based on a 400 year cycle. This is the number
+ * of days in each cycle.
+ */
+#define GREGORIAN_CYCLE_DAYS 146097
+
+/*
+ * Days in a normal 100 year leap year calendar. We lose a leap year day
+ * in years evenly divisible by 100 but not by 400.
+ */
+#define GREGORIAN_NORMAL_CENTURY_DAYS 36524
+
+/*
+ * Days in a normal 4 year leap year calendar cycle.
+ */
+#define GREGORIAN_NORMAL_LEAP_CYCLE_DAYS 1461
+
+#define is_leapyear(y) (y%4 == 0 && !(y%100 == 0 && !(y%400 == 0)))
+
+#endif
diff --git a/contrib/ntp/include/ntp_control.h b/contrib/ntp/include/ntp_control.h
new file mode 100644
index 000000000000..dbcc2c659ff3
--- /dev/null
+++ b/contrib/ntp/include/ntp_control.h
@@ -0,0 +1,260 @@
+/*
+ * ntp_control.h - definitions related to NTP mode 6 control messages
+ */
+
+#include "ntp_types.h"
+
+struct ntp_control {
+ u_char li_vn_mode; /* leap, version, mode */
+ u_char r_m_e_op; /* response, more, error, opcode */
+ u_short sequence; /* sequence number of request */
+ u_short status; /* status word for association */
+ u_short associd; /* association ID */
+ u_short offset; /* offset of this batch of data */
+ u_short count; /* count of data in this packet */
+ u_char data[(480 + MAX_MAC_LEN)]; /* data + auth */
+};
+
+/*
+ * Length of the control header, in octets
+ */
+#define CTL_HEADER_LEN 12
+#define CTL_MAX_DATA_LEN 468
+
+
+/*
+ * Limits and things
+ */
+#define CTL_MAXTRAPS 3 /* maximum number of traps we allow */
+#define CTL_TRAPTIME (60*60) /* time out traps in 1 hour */
+#define CTL_MAXAUTHSIZE 64 /* maximum size of an authen'ed req */
+
+/*
+ * Decoding for the r_m_e_op field
+ */
+#define CTL_RESPONSE 0x80
+#define CTL_ERROR 0x40
+#define CTL_MORE 0x20
+#define CTL_OP_MASK 0x1f
+
+#define CTL_ISRESPONSE(r_m_e_op) (((r_m_e_op) & 0x80) != 0)
+#define CTL_ISMORE(r_m_e_op) (((r_m_e_op) & 0x20) != 0)
+#define CTL_ISERROR(r_m_e_op) (((r_m_e_op) & 0x40) != 0)
+#define CTL_OP(r_m_e_op) ((r_m_e_op) & CTL_OP_MASK)
+
+/*
+ * Opcodes
+ */
+#define CTL_OP_UNSPEC 0
+#define CTL_OP_READSTAT 1
+#define CTL_OP_READVAR 2
+#define CTL_OP_WRITEVAR 3
+#define CTL_OP_READCLOCK 4
+#define CTL_OP_WRITECLOCK 5
+#define CTL_OP_SETTRAP 6
+#define CTL_OP_ASYNCMSG 7
+#define CTL_OP_UNSETTRAP 31
+
+/*
+ * {En,De}coding of the system status word
+ */
+#define CTL_SST_TS_UNSPEC 0 /* time source unspecified */
+#define CTL_SST_TS_ATOM 1 /* time source calibrated atomic */
+#define CTL_SST_TS_LF 2 /* time source VLF or LF radio */
+#define CTL_SST_TS_HF 3 /* time source HF radio */
+#define CTL_SST_TS_UHF 4 /* time source UHF radio */
+#define CTL_SST_TS_LOCAL 5 /* time source LOCAL */
+#define CTL_SST_TS_NTP 6 /* time source NTP */
+#define CTL_SST_TS_UDPTIME 7 /* time source UDP/TIME */
+#define CTL_SST_TS_WRSTWTCH 8 /* time source is wristwatch */
+#define CTL_SST_TS_TELEPHONE 9 /* time source is telephone modem */
+#define CTL_SST_TS_PPS 0x20 /* time source is PPS signal */
+
+#define CTL_SYS_MAXEVENTS 15
+
+#define CTL_SYS_STATUS(li, source, nevnt, evnt) \
+ (((((unsigned short)(li))<< 14)&0xc000) | \
+ (((source)<<8)&0x3f00) | \
+ (((nevnt)<<4)&0x00f0) | \
+ ((evnt)&0x000f))
+
+#define CTL_SYS_LI(status) (((status)>>14) & 0x3)
+#define CTL_SYS_SOURCE(status) (((status)>>8) & 0x3f)
+#define CTL_SYS_NEVNT(status) (((status)>>4) & 0xf)
+#define CTL_SYS_EVENT(status) ((status) & 0xf)
+
+/*
+ * {En,De}coding of the peer status word
+ */
+#define CTL_PST_CONFIG 0x80
+#define CTL_PST_AUTHENABLE 0x40
+#define CTL_PST_AUTHENTIC 0x20
+#define CTL_PST_REACH 0x10
+#define CTL_PST_UNSPEC 0x08
+
+#define CTL_PST_SEL_REJECT 0 /* reject */
+#define CTL_PST_SEL_SANE 1 /* x falsetick */
+#define CTL_PST_SEL_CORRECT 2 /* . excess */
+#define CTL_PST_SEL_SELCAND 3 /* - outlyer */
+#define CTL_PST_SEL_SYNCCAND 4 /* + candidat */
+#define CTL_PST_SEL_DISTSYSPEER 5 /* # selected */
+#define CTL_PST_SEL_SYSPEER 6 /* * sys.peer */
+#define CTL_PST_SEL_PPS 7 /* o pps.peer */
+
+#define CTL_PEER_MAXEVENTS 15
+
+#define CTL_PEER_STATUS(status, nevnt, evnt) \
+ ((((status)<<8) & 0xff00) | \
+ (((nevnt)<<4) & 0x00f0) | \
+ ((evnt) & 0x000f))
+
+#define CTL_PEER_STATVAL(status)(((status)>>8) & 0xff)
+#define CTL_PEER_NEVNT(status) (((status)>>4) & 0xf)
+#define CTL_PEER_EVENT(status) ((status) & 0xf)
+
+/*
+ * {En,De}coding of the clock status word
+ */
+#define CTL_CLK_OKAY 0
+#define CTL_CLK_NOREPLY 1
+#define CTL_CLK_BADFORMAT 2
+#define CTL_CLK_FAULT 3
+#define CTL_CLK_PROPAGATION 4
+#define CTL_CLK_BADDATE 5
+#define CTL_CLK_BADTIME 6
+
+#define CTL_CLK_STATUS(status, event) \
+ ((((status)<<8) & 0xff00) | \
+ ((event) & 0x00ff))
+
+/*
+ * Error code responses returned when the E bit is set.
+ */
+#define CERR_UNSPEC 0
+#define CERR_PERMISSION 1
+#define CERR_BADFMT 2
+#define CERR_BADOP 3
+#define CERR_BADASSOC 4
+#define CERR_UNKNOWNVAR 5
+#define CERR_BADVALUE 6
+#define CERR_RESTRICT 7
+
+#define CERR_NORESOURCE CERR_PERMISSION /* wish there was a different code */
+
+
+/*
+ * System variables we understand
+ */
+#define CS_LEAP 1
+#define CS_STRATUM 2
+#define CS_PRECISION 3
+#define CS_ROOTDELAY 4
+#define CS_ROOTDISPERSION 5
+#define CS_REFID 6
+#define CS_REFTIME 7
+#define CS_POLL 8
+#define CS_PEERID 9
+#define CS_STATE 10
+#define CS_OFFSET 11
+#define CS_DRIFT 12
+#define CS_COMPLIANCE 13
+#define CS_CLOCK 14
+#define CS_PROCESSOR 15
+#define CS_SYSTEM 16
+#define CS_STABIL 17
+#define CS_VARLIST 18
+
+#define CS_MAXCODE CS_VARLIST
+
+/*
+ * Peer variables we understand
+ */
+#define CP_CONFIG 1
+#define CP_AUTHENABLE 2
+#define CP_AUTHENTIC 3
+#define CP_SRCADR 4
+#define CP_SRCPORT 5
+#define CP_DSTADR 6
+#define CP_DSTPORT 7
+#define CP_LEAP 8
+#define CP_HMODE 9
+#define CP_STRATUM 10
+#define CP_PPOLL 11
+#define CP_HPOLL 12
+#define CP_PRECISION 13
+#define CP_ROOTDELAY 14
+#define CP_ROOTDISPERSION 15
+#define CP_REFID 16
+#define CP_REFTIME 17
+#define CP_ORG 18
+#define CP_REC 19
+#define CP_XMT 20
+#define CP_REACH 21
+#define CP_VALID 22
+#define CP_TIMER 23
+#define CP_DELAY 24
+#define CP_OFFSET 25
+#define CP_JITTER 26
+#define CP_DISPERSION 27
+#define CP_KEYID 28
+#define CP_FILTDELAY 29
+#define CP_FILTOFFSET 30
+#define CP_PMODE 31
+#define CP_RECEIVED 32
+#define CP_SENT 33
+#define CP_FILTERROR 34
+#define CP_FLASH 35
+#define CP_DISP 36
+#define CP_VARLIST 37
+
+#define CP_MAXCODE CP_VARLIST
+
+/*
+ * Clock variables we understand
+ */
+#define CC_TYPE 1
+#define CC_TIMECODE 2
+#define CC_POLL 3
+#define CC_NOREPLY 4
+#define CC_BADFORMAT 5
+#define CC_BADDATA 6
+#define CC_FUDGETIME1 7
+#define CC_FUDGETIME2 8
+#define CC_FUDGEVAL1 9
+#define CC_FUDGEVAL2 10
+#define CC_FLAGS 11
+#define CC_DEVICE 12
+#define CC_VARLIST 13
+
+#define CC_MAXCODE CC_VARLIST
+
+/*
+ * Definition of the structure used internally to hold trap information.
+ * ntp_request.c wants to see this.
+ */
+struct ctl_trap {
+ struct sockaddr_in tr_addr; /* address of trap recipient */
+ struct interface *tr_localaddr; /* interface to send this through */
+ u_long tr_settime; /* time trap was set */
+ u_long tr_count; /* async messages sent to this guy */
+ u_long tr_origtime; /* time trap was originally set */
+ u_long tr_resets; /* count of resets for this trap */
+ u_short tr_sequence; /* trap sequence id */
+ u_char tr_flags; /* trap flags */
+ u_char tr_version; /* version number of trapper */
+};
+
+/*
+ * Flag bits
+ */
+#define TRAP_INUSE 0x1 /* this trap is active */
+#define TRAP_NONPRIO 0x2 /* this trap is non-priority */
+#define TRAP_CONFIGURED 0x4 /* this trap was configured */
+
+/*
+ * Types of things we may deal with
+ * shared between ntpq and library
+ */
+#define TYPE_SYS 1
+#define TYPE_PEER 2
+#define TYPE_CLOCK 3
diff --git a/contrib/ntp/include/ntp_datum.h b/contrib/ntp/include/ntp_datum.h
new file mode 100644
index 000000000000..2aa2cb742d01
--- /dev/null
+++ b/contrib/ntp/include/ntp_datum.h
@@ -0,0 +1,30 @@
+struct btfp_time /* Structure for reading 5 time words */
+ /* in one ioctl(2) operation. */
+{
+ unsigned short btfp_time[5]; /* Time words 0,1,2,3, and 4. (16bit)*/
+};
+
+/***** Simple ioctl commands *****/
+
+#define RUNLOCK _IO('X',19) /* Release Capture Lockout */
+#define RCR0 _IOR('X',22,unsigned int) /* Read control register */
+#define WCR0 _IOW('X',23,unsigned int) /* Write control register */
+
+/***** Compound ioctl commands *****/
+
+/* Read all 5 time words in one call. */
+#define READTIME _IOR('X',32,struct btfp_time)
+#define VMEFD "/dev/btfp0"
+
+ struct vmedate { /* structure returned by get_vmetime.c */
+ unsigned short year;
+ unsigned short doy;
+ unsigned short hr;
+ unsigned short mn;
+ unsigned short sec;
+ unsigned long frac;
+ unsigned short status;
+ };
+
+#define PRIO 120 /* set the realtime priority */
+#define NREGS 7 /* number of registers we will use */
diff --git a/contrib/ntp/include/ntp_filegen.h b/contrib/ntp/include/ntp_filegen.h
new file mode 100644
index 000000000000..8217dbc11670
--- /dev/null
+++ b/contrib/ntp/include/ntp_filegen.h
@@ -0,0 +1,51 @@
+/*
+ * ntp_filegen.h,v 3.9 1996/12/01 16:02:45 kardel Exp
+ *
+ * definitions for NTP file generations support
+ *
+ *
+ * Copyright (C) 1992, 1996 by Rainer Pruy
+ * Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
+ *
+ * This code may be modified and used freely
+ * provided the credits remain intact.
+ */
+
+#include "ntp_types.h"
+
+/*
+ * supported file generation types
+ */
+
+#define FILEGEN_NONE 255 /* no generations - use plain file name */
+#define FILEGEN_PID 1 /* one filegen per process incarnation */
+#define FILEGEN_DAY 2 /* one filegen per day */
+#define FILEGEN_WEEK 3 /* one filegen per week */
+#define FILEGEN_MONTH 4 /* one filegen per month */
+#define FILEGEN_YEAR 5 /* one filegen per year */
+#define FILEGEN_AGE 6 /* change filegen each FG_AGE_SECS */
+
+/*
+ * supported file generation flags
+ */
+
+#define FGEN_FLAG_LINK 0x01 /* make a link to base name */
+
+#define FGEN_FLAG_ENABLED 0x80 /* set this to really create files */
+ /* without this, open is suppressed */
+
+typedef struct FILEGEN
+ {
+ FILE *fp; /* file referring to current generation */
+ char *prefix; /* filename prefix and basename to be used*/
+ char *basename; /* for constructing filename of generation file */
+ /* WARNING: must be malloced !!! will be fed to free()*/
+ u_long id; /* id of current generation */
+ u_char type; /* type of file generation */
+ u_char flag; /* flags modifying processing of file generation */
+ } FILEGEN;
+
+extern void filegen_setup P((FILEGEN *, u_long));
+extern void filegen_config P((FILEGEN *, char *, u_int, u_int));
+extern FILEGEN *filegen_get P((char *));
+extern void filegen_register P((const char *, FILEGEN *));
diff --git a/contrib/ntp/include/ntp_fp.h b/contrib/ntp/include/ntp_fp.h
new file mode 100644
index 000000000000..027add32d9ba
--- /dev/null
+++ b/contrib/ntp/include/ntp_fp.h
@@ -0,0 +1,373 @@
+/*
+ * ntp_fp.h - definitions for NTP fixed/floating-point arithmetic
+ */
+
+#ifndef NTP_FP_H
+#define NTP_FP_H
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include "ntp_types.h"
+
+/*
+ * 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:
+ *
+ * 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:
+ *
+ * 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;
+
+/*
+ * A unit second in fp format. Actually 2**(half_the_bits_in_a_long)
+ */
+#define FP_SECOND (0x10000)
+
+/*
+ * Byte order conversions
+ */
+#define HTONS_FP(x) (htonl(x))
+#define HTONL_FP(h, n) do { (n)->l_ui = htonl((h)->l_ui); \
+ (n)->l_uf = htonl((h)->l_uf); } while (0)
+#define NTOHS_FP(x) (ntohl(x))
+#define NTOHL_FP(n, h) do { (h)->l_ui = ntohl((n)->l_ui); \
+ (h)->l_uf = ntohl((n)->l_uf); } while (0)
+#define NTOHL_MFP(ni, nf, hi, hf) \
+ do { (hi) = ntohl(ni); (hf) = ntohl(nf); } while (0)
+#define HTONL_MFP(hi, hf, ni, nf) \
+ do { (ni) = ntohl(hi); (nf) = ntohl(hf); } while (0)
+
+/* funny ones. Converts ts fractions to net order ts */
+#define HTONL_UF(uf, nts) \
+ do { (nts)->l_ui = 0; (nts)->l_uf = htonl(uf); } while (0)
+#define HTONL_F(f, nts) do { (nts)->l_uf = htonl(f); \
+ if ((f) & 0x80000000) \
+ (nts)->l_i = -1; \
+ else \
+ (nts)->l_i = 0; \
+ } while (0)
+
+/*
+ * Conversions between the two fixed point types
+ */
+#define MFPTOFP(x_i, x_f) (((x_i) >= 0x00010000) ? 0x7fffffff : \
+ (((x_i) <= -0x00010000) ? 0x80000000 : \
+ (((x_i)<<16) | (((x_f)>>16)&0xffff))))
+#define LFPTOFP(v) MFPTOFP((v)->l_i, (v)->l_f)
+
+#define UFPTOLFP(x, v) ((v)->l_ui = (u_fp)(x)>>16, (v)->l_uf = (x)<<16)
+#define FPTOLFP(x, v) (UFPTOLFP((x), (v)), (x) < 0 ? (v)->l_ui -= 0x10000 : 0)
+
+#define MAXLFP(v) ((v)->l_ui = 0x7fffffff, (v)->l_uf = 0xffffffff)
+#define MINLFP(v) ((v)->l_ui = 0x80000000, (v)->l_uf = 0)
+
+/*
+ * Primitive operations on long fixed point values. If these are
+ * reminiscent of assembler op codes it's only because some may
+ * be replaced by inline assembler for particular machines someday.
+ * These are the (kind of inefficient) run-anywhere versions.
+ */
+#define M_NEG(v_i, v_f) /* v = -v */ \
+ do { \
+ if ((v_f) == 0) \
+ (v_i) = -((s_fp)(v_i)); \
+ else { \
+ (v_f) = -((s_fp)(v_f)); \
+ (v_i) = ~(v_i); \
+ } \
+ } while(0)
+
+#define M_NEGM(r_i, r_f, a_i, a_f) /* r = -a */ \
+ do { \
+ if ((a_f) == 0) { \
+ (r_f) = 0; \
+ (r_i) = -(a_i); \
+ } else { \
+ (r_f) = -(a_f); \
+ (r_i) = ~(a_i); \
+ } \
+ } while(0)
+
+#define M_ADD(r_i, r_f, a_i, a_f) /* r += a */ \
+ do { \
+ register u_int32 lo_tmp; \
+ register u_int32 hi_tmp; \
+ \
+ lo_tmp = ((r_f) & 0xffff) + ((a_f) & 0xffff); \
+ hi_tmp = (((r_f) >> 16) & 0xffff) + (((a_f) >> 16) & 0xffff); \
+ if (lo_tmp & 0x10000) \
+ hi_tmp++; \
+ (r_f) = ((hi_tmp & 0xffff) << 16) | (lo_tmp & 0xffff); \
+ \
+ (r_i) += (a_i); \
+ if (hi_tmp & 0x10000) \
+ (r_i)++; \
+ } while (0)
+
+#define M_ADD3(r_ovr, r_i, r_f, a_ovr, a_i, a_f) /* r += a, three word */ \
+ do { \
+ register u_int32 lo_tmp; \
+ register u_int32 hi_tmp; \
+ \
+ lo_tmp = ((r_f) & 0xffff) + ((a_f) & 0xffff); \
+ hi_tmp = (((r_f) >> 16) & 0xffff) + (((a_f) >> 16) & 0xffff); \
+ if (lo_tmp & 0x10000) \
+ hi_tmp++; \
+ (r_f) = ((hi_tmp & 0xffff) << 16) | (lo_tmp & 0xffff); \
+ \
+ lo_tmp = ((r_i) & 0xffff) + ((a_i) & 0xffff); \
+ if (hi_tmp & 0x10000) \
+ lo_tmp++; \
+ hi_tmp = (((r_i) >> 16) & 0xffff) + (((a_i) >> 16) & 0xffff); \
+ if (lo_tmp & 0x10000) \
+ hi_tmp++; \
+ (r_i) = ((hi_tmp & 0xffff) << 16) | (lo_tmp & 0xffff); \
+ \
+ (r_ovr) += (a_ovr); \
+ if (hi_tmp & 0x10000) \
+ (r_ovr)++; \
+ } while (0)
+
+#define M_SUB(r_i, r_f, a_i, a_f) /* r -= a */ \
+ do { \
+ register u_int32 lo_tmp; \
+ register u_int32 hi_tmp; \
+ \
+ if ((a_f) == 0) { \
+ (r_i) -= (a_i); \
+ } else { \
+ lo_tmp = ((r_f) & 0xffff) + ((-((s_fp)(a_f))) & 0xffff); \
+ hi_tmp = (((r_f) >> 16) & 0xffff) \
+ + (((-((s_fp)(a_f))) >> 16) & 0xffff); \
+ if (lo_tmp & 0x10000) \
+ hi_tmp++; \
+ (r_f) = ((hi_tmp & 0xffff) << 16) | (lo_tmp & 0xffff); \
+ \
+ (r_i) += ~(a_i); \
+ if (hi_tmp & 0x10000) \
+ (r_i)++; \
+ } \
+ } while (0)
+
+#define M_RSHIFTU(v_i, v_f) /* v >>= 1, v is unsigned */ \
+ do { \
+ (v_f) = (u_int32)(v_f) >> 1; \
+ if ((v_i) & 01) \
+ (v_f) |= 0x80000000; \
+ (v_i) = (u_int32)(v_i) >> 1; \
+ } while (0)
+
+#define M_RSHIFT(v_i, v_f) /* v >>= 1, v is signed */ \
+ do { \
+ (v_f) = (u_int32)(v_f) >> 1; \
+ if ((v_i) & 01) \
+ (v_f) |= 0x80000000; \
+ if ((v_i) & 0x80000000) \
+ (v_i) = ((v_i) >> 1) | 0x80000000; \
+ else \
+ (v_i) = (v_i) >> 1; \
+ } while (0)
+
+#define M_LSHIFT(v_i, v_f) /* v <<= 1 */ \
+ do { \
+ (v_i) <<= 1; \
+ if ((v_f) & 0x80000000) \
+ (v_i) |= 0x1; \
+ (v_f) <<= 1; \
+ } while (0)
+
+#define M_LSHIFT3(v_ovr, v_i, v_f) /* v <<= 1, with overflow */ \
+ do { \
+ (v_ovr) <<= 1; \
+ if ((v_i) & 0x80000000) \
+ (v_ovr) |= 0x1; \
+ (v_i) <<= 1; \
+ if ((v_f) & 0x80000000) \
+ (v_i) |= 0x1; \
+ (v_f) <<= 1; \
+ } while (0)
+
+#define M_ADDUF(r_i, r_f, uf) /* r += uf, uf is u_int32 fraction */ \
+ M_ADD((r_i), (r_f), 0, (uf)) /* let optimizer worry about it */
+
+#define M_SUBUF(r_i, r_f, uf) /* r -= uf, uf is u_int32 fraction */ \
+ M_SUB((r_i), (r_f), 0, (uf)) /* let optimizer worry about it */
+
+#define M_ADDF(r_i, r_f, f) /* r += f, f is a int32 fraction */ \
+ do { \
+ if ((f) > 0) \
+ M_ADD((r_i), (r_f), 0, (f)); \
+ else if ((f) < 0) \
+ M_ADD((r_i), (r_f), (-1), (f));\
+ } while(0)
+
+#define M_ISNEG(v_i, v_f) /* v < 0 */ \
+ (((v_i) & 0x80000000) != 0)
+
+#define M_ISHIS(a_i, a_f, b_i, b_f) /* a >= b unsigned */ \
+ (((u_int32)(a_i)) > ((u_int32)(b_i)) || \
+ ((a_i) == (b_i) && ((u_int32)(a_f)) >= ((u_int32)(b_f))))
+
+#define M_ISGEQ(a_i, a_f, b_i, b_f) /* a >= b signed */ \
+ (((int32)(a_i)) > ((int32)(b_i)) || \
+ ((a_i) == (b_i) && ((u_int32)(a_f)) >= ((u_int32)(b_f))))
+
+#define M_ISEQU(a_i, a_f, b_i, b_f) /* a == b unsigned */ \
+ ((a_i) == (b_i) && (a_f) == (b_f))
+
+/*
+ * Operations on the long fp format
+ */
+#define L_ADD(r, a) M_ADD((r)->l_ui, (r)->l_uf, (a)->l_ui, (a)->l_uf)
+#define L_SUB(r, a) M_SUB((r)->l_ui, (r)->l_uf, (a)->l_ui, (a)->l_uf)
+#define L_NEG(v) M_NEG((v)->l_ui, (v)->l_uf)
+#define L_ADDUF(r, uf) M_ADDUF((r)->l_ui, (r)->l_uf, (uf))
+#define L_SUBUF(r, uf) M_SUBUF((r)->l_ui, (r)->l_uf, (uf))
+#define L_ADDF(r, f) M_ADDF((r)->l_ui, (r)->l_uf, (f))
+#define L_RSHIFT(v) M_RSHIFT((v)->l_i, (v)->l_uf)
+#define L_RSHIFTU(v) M_RSHIFT((v)->l_ui, (v)->l_uf)
+#define L_LSHIFT(v) M_LSHIFT((v)->l_ui, (v)->l_uf)
+#define L_CLR(v) ((v)->l_ui = (v)->l_uf = 0)
+
+#define L_ISNEG(v) (((v)->l_ui & 0x80000000) != 0)
+#define L_ISZERO(v) ((v)->l_ui == 0 && (v)->l_uf == 0)
+#define L_ISHIS(a, b) ((a)->l_ui > (b)->l_ui || \
+ ((a)->l_ui == (b)->l_ui && (a)->l_uf >= (b)->l_uf))
+#define L_ISGEQ(a, b) ((a)->l_i > (b)->l_i || \
+ ((a)->l_i == (b)->l_i && (a)->l_uf >= (b)->l_uf))
+#define L_ISEQU(a, b) M_ISEQU((a)->l_ui, (a)->l_uf, (b)->l_ui, (b)->l_uf)
+
+/*
+ * s_fp/double and u_fp/double conversions
+ */
+#define FRIC 65536. /* 2^16 as a double */
+#define DTOFP(r) ((s_fp)((r) * FRIC))
+#define DTOUFP(r) ((u_fp)((r) * FRIC))
+#define FPTOD(r) ((double)(r) / FRIC)
+
+/*
+ * l_fp/double conversions
+ */
+#define FRAC 4294967296. /* 2^32 as a double */
+#define M_DTOLFP(d, r_i, r_uf) /* double to l_fp */ \
+ do { \
+ register double d_tmp; \
+ \
+ d_tmp = (d); \
+ if (d_tmp < 0) { \
+ d_tmp = -d_tmp; \
+ (r_i) = (int32)(d_tmp); \
+ (r_uf) = (u_int32)(((d_tmp) - (double)(r_i)) * FRAC); \
+ M_NEG((r_i), (r_uf)); \
+ } else { \
+ (r_i) = (int32)(d_tmp); \
+ (r_uf) = (u_int32)(((d_tmp) - (double)(r_i)) * FRAC); \
+ } \
+ } while (0)
+#define M_LFPTOD(r_i, r_uf, d) /* l_fp to double */ \
+ do { \
+ register l_fp l_tmp; \
+ \
+ l_tmp.l_i = (r_i); \
+ l_tmp.l_f = (r_uf); \
+ if (l_tmp.l_i < 0) { \
+ M_NEG(l_tmp.l_i, l_tmp.l_uf); \
+ (d) = -((double)l_tmp.l_i + ((double)l_tmp.l_uf) / FRAC); \
+ } else { \
+ (d) = (double)l_tmp.l_i + ((double)l_tmp.l_uf) / FRAC; \
+ } \
+ } while (0)
+#define DTOLFP(d, v) M_DTOLFP((d), (v)->l_ui, (v)->l_uf)
+#define LFPTOD(v, d) M_LFPTOD((v)->l_ui, (v)->l_uf, (d))
+
+/*
+ * Prototypes
+ */
+extern char * dofptoa P((u_fp, int, int, int));
+extern char * dolfptoa P((u_long, u_long, int, int, int));
+
+extern int atolfp P((const char *, l_fp *));
+extern int buftvtots P((const char *, l_fp *));
+extern char * fptoa P((s_fp, int));
+extern char * fptoms P((s_fp, int));
+extern char * fptoms P((s_fp, int));
+extern int hextolfp P((const char *, l_fp *));
+extern void gpstolfp P((int, int, unsigned long, l_fp *));
+extern int mstolfp P((const char *, l_fp *));
+extern char * prettydate P((l_fp *));
+extern char * gmprettydate P((l_fp *));
+extern char * uglydate P((l_fp *));
+extern void mfp_mul P((int32 *, u_int32 *, int32, u_int32, int32, u_int32));
+
+extern void get_systime P((l_fp *));
+extern int step_systime P((double));
+extern int adj_systime P((double));
+
+#define lfptoa(_fpv, _ndec) mfptoa((_fpv)->l_ui, (_fpv)->l_uf, (_ndec))
+#define lfptoms(_fpv, _ndec) mfptoms((_fpv)->l_ui, (_fpv)->l_uf, (_ndec))
+
+#define ntoa(_sin) numtoa((_sin)->sin_addr.s_addr)
+#define ntohost(_sin) numtohost((_sin)->sin_addr.s_addr)
+
+#define ufptoa(_fpv, _ndec) dofptoa((_fpv), 0, (_ndec), 0)
+#define ufptoms(_fpv, _ndec) dofptoa((_fpv), 0, (_ndec), 1)
+#define ulfptoa(_fpv, _ndec) dolfptoa((_fpv)->l_ui, (_fpv)->l_uf, 0, (_ndec), 0)
+#define ulfptoms(_fpv, _ndec) dolfptoa((_fpv)->l_ui, (_fpv)->l_uf, 0, (_ndec), 1)
+#define umfptoa(_fpi, _fpf, _ndec) dolfptoa((_fpi), (_fpf), 0, (_ndec), 0)
+
+#endif /* NTP_FP_H */
diff --git a/contrib/ntp/include/ntp_if.h b/contrib/ntp/include/ntp_if.h
new file mode 100644
index 000000000000..0be015601234
--- /dev/null
+++ b/contrib/ntp/include/ntp_if.h
@@ -0,0 +1,54 @@
+/*
+ * Sockets are not standard.
+ * So hide uglyness in include file.
+ */
+/* was: defined(SYS_CONVEXOS9) */
+#if defined(HAVE__SYS_SYNC_QUEUE_H) && defined(HAVE__SYS_SYNC_SEMA_H)
+# include "/sys/sync/queue.h"
+# include "/sys/sync/sema.h"
+#endif
+
+/* was: defined(SYS_AIX) */
+#if defined(TIME_WITH_SYS_TIME)
+# include <sys/time.h>
+# include <time.h>
+#endif
+
+/* was: (defined(SYS_SOLARIS) && !defined(bsd)) || defined(SYS_SUNOS4) */
+/* was: defined(SYS_UNIXWARE1) */
+#ifdef HAVE_SYS_SOCKIO_H
+# include <sys/sockio.h>
+#endif
+
+/* was: #if defined(SYS_PTX) || defined(SYS_SINIXM) */
+#ifdef HAVE_SYS_STREAM_H
+# include <sys/stream.h>
+#endif
+#ifdef HAVE_SYS_STROPTS_H
+# include <sys/stropts.h>
+#endif
+
+/* Was: #if defined(SYS_SVR4) */
+#if defined(USE_STREAMS_DEVICE_FOR_IF_CONFIG)
+# include <netinet/ip.h>
+# undef SIOCGIFCONF
+# undef SIOCGIFFLAGS
+# undef SIOCGIFADDR
+# undef SIOCGIFBRDADDR
+# undef SIOCGIFNETMASK
+# define SIOCGIFCONF IPIOC_GETIFCONF
+# define SIOCGIFFLAGS IPIOC_GETIFFLAGS
+# define SIOCGIFADDR IPIOC_GETIFADDR
+# define SIOCGIFBRDADDR IPIOC_GETIFBRDADDR
+# define SIOCGIFNETMASK IPIOC_GETIFNETMASK
+#if 0 /* We don't need this now that sys/sockio.h is handled above */
+# else /* USE_STREAMS_DEVICE_FOR_IF_CONFIG */
+# include <sys/sockio.h>
+#endif
+# endif /* USE_STREAMS_DEVICE_FOR_IF_CONFIG */
+/* was #endif SYS_SVR4 */
+
+
+#ifdef HAVE_NET_IF_H
+# include <net/if.h>
+#endif /* HAVE_NET_IF_H */
diff --git a/contrib/ntp/include/ntp_io.h b/contrib/ntp/include/ntp_io.h
new file mode 100644
index 000000000000..0ef4fa65386f
--- /dev/null
+++ b/contrib/ntp/include/ntp_io.h
@@ -0,0 +1,33 @@
+#if !defined _NTP_IO_H
+#define _NTP_IO_H
+/*
+ * POSIX says use <fnct.h> to get O_* symbols and
+ * SEEK_SET symbol form <unistd.h>.
+ */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#include <stdio.h>
+#ifdef HAVE_SYS_FILE_H
+# include <sys/file.h>
+#endif
+#ifdef HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
+#if !defined(SEEK_SET) && defined(L_SET)
+# define SEEK_SET L_SET
+#endif
+
+#ifdef SYS_WINNT
+# include <io.h>
+# include "win32_io.h"
+#endif
+
+#endif
diff --git a/contrib/ntp/include/ntp_machine.h b/contrib/ntp/include/ntp_machine.h
new file mode 100644
index 000000000000..4f7f345d8eba
--- /dev/null
+++ b/contrib/ntp/include/ntp_machine.h
@@ -0,0 +1,512 @@
+/*
+ * Collect all machine dependent idiosyncrasies in one place.
+ */
+
+#ifndef __ntp_machine
+#define __ntp_machine
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
+#include "ntp_proto.h"
+
+/*
+
+ HEY! CHECK THIS OUT!
+
+ The first half of this file is obsolete, and is only there to help
+ reconcile "what went before" with "current behavior".
+
+ The per-system SYS_* #defins ARE NO LONGER USED, with the temporary
+ exception of SYS_WINNT.
+
+ If you find a hunk of code that is bracketed by a SYS_* macro and you
+ *know* that it is still needed, please let us know. In many cases the
+ code fragment is now handled somewhere else by autoconf choices.
+
+*/
+
+/*
+
+INFO ON NEW KERNEL PLL SYS CALLS
+
+ NTP_SYSCALLS_STD - use the "normal" ones
+ NTP_SYSCALL_GET - SYS_ntp_gettime id
+ NTP_SYSCALL_ADJ - SYS_ntp_adjtime id
+ NTP_SYSCALLS_LIBC - ntp_adjtime() and ntp_gettime() are in libc.
+
+HOW TO GET IP INTERFACE INFORMATION
+
+ Some UNIX V.4 machines implement a sockets library on top of
+ streams. For these systems, you must use send the SIOCGIFCONF down
+ the stream in an I_STR ioctl. This ususally also implies
+ USE_STREAMS_DEVICE FOR IF_CONFIG. Dell UNIX is a notable exception.
+
+ STREAMS_TLI - use ioctl(I_STR) to implement ioctl(SIOCGIFCONF)
+
+WHAT DOES IOCTL(SIOCGIFCONF) RETURN IN THE BUFFER
+
+ UNIX V.4 machines implement a sockets library on top of streams.
+ When requesting the IP interface configuration with an ioctl(2) calll,
+ an array of ifreq structures are placed in the provided buffer. Some
+ implementations also place the length of the buffer information in
+ the first integer position of the buffer.
+
+ SIZE_RETURNED_IN_BUFFER - size integer is in the buffer
+
+WILL IOCTL(SIOCGIFCONF) WORK ON A SOCKET
+
+ Some UNIX V.4 machines do not appear to support ioctl() requests for the
+ IP interface configuration on a socket. They appear to require the use
+ of the streams device instead.
+
+ USE_STREAMS_DEVICE_FOR_IF_CONFIG - use the /dev/ip device for configuration
+
+MISC
+
+ HAVE_PROTOTYPES - Prototype functions
+ DOSYNCTODR - Resync TODR clock every hour.
+ RETSIGTYPE - Define signal function type.
+ NO_SIGNED_CHAR_DECL - No "signed char" see include/ntp.h
+ LOCK_PROCESS - Have plock.
+ UDP_WILDCARD_DELIVERY
+ - these systems deliver broadcast packets to the wildcard
+ port instead to a port bound to the interface bound
+ to the correct broadcast address - are these
+ implementations broken or did the spec change ?
+*/
+
+/*
+ * Set up for prototyping (duplicated from ntp_types.h)
+ */
+#ifndef P
+#if defined(__STDC__) || defined(HAVE_PROTOTYPES)
+#define P(x) x
+#else /* not __STDC__ and not HAVE_PROTOTYPES */
+#define P(x) ()
+#endif /* not __STDC__ and not HAVE_PROTOTYPES */
+#endif /* P */
+
+#if 0
+
+/*
+ * IRIX 4.X and IRIX 5.x
+ */
+#if defined(SYS_IRIX4)||defined(SYS_IRIX5)
+# define ADJTIME_IS_ACCURATE
+# define LOCK_PROCESS
+#endif
+
+/*
+ * Ultrix
+ * Note: posix version has NTP_POSIX_SOURCE and HAVE_SIGNALED_IO
+ */
+#if defined(SYS_ULTRIX)
+# define S_CHAR_DEFINED
+# define NTP_SYSCALLS_STD
+# define HAVE_MODEM_CONTROL
+#endif
+
+/*
+ * AUX
+ */
+#if defined(SYS_AUX2) || defined(SYS_AUX3)
+# define NO_SIGNED_CHAR_DECL
+# define LOCK_PROCESS
+# define NTP_POSIX_SOURCE
+/*
+ * This requires that _POSIX_SOURCE be forced on the
+ * compiler command flag. We can't do it here since this
+ * file is included _after_ the system header files and we
+ * need to let _them_ know we're POSIX. We do this in
+ * compilers/aux3.gcc...
+ */
+# define LOG_NTP LOG_LOCAL1
+#endif
+
+/*
+ * HPUX
+ */
+#if defined(SYS_HPUX)
+# define getdtablesize() sysconf(_SC_OPEN_MAX)
+# define setlinebuf(f) setvbuf(f, NULL, _IOLBF, 0)
+# define NO_SIGNED_CHAR_DECL
+# define LOCK_PROCESS
+#endif
+
+/*
+ * BSD/OS 2.0 and above
+ */
+#if defined(SYS_BSDI)
+# define USE_FSETOWNCTTY /* this funny system demands a CTTY for FSETOWN */
+#endif
+
+/*
+ * FreeBSD 2.0 and above
+ */
+#ifdef SYS_FREEBSD
+# define KERNEL_PLL
+#endif
+
+/*
+ * Linux
+ */
+#if defined(SYS_LINUX)
+# define ntp_adjtime __adjtimex
+#endif
+
+/*
+ * PTX
+ */
+#if defined(SYS_PTX)
+# define LOCK_PROCESS
+struct timezone { int __0; }; /* unused placebo */
+/*
+ * no comment !@!
+ */
+typedef unsigned int u_int;
+# ifndef _NETINET_IN_SYSTM_INCLUDED /* i am about to comment... */
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+typedef unsigned long u_long;
+# endif
+#endif
+
+/*
+ * UNIX V.4 on and NCR 3000
+ */
+#if defined(SYS_SVR4)
+# define STREAM
+# define LOCK_PROCESS
+# define SIZE_RETURNED_IN_BUFFER
+#endif
+
+/*
+ * (Univel/Novell) Unixware1 SVR4 on intel x86 processor
+ */
+#if defined(SYS_UNIXWARE1)
+/* #define _POSIX_SOURCE */
+# define STREAM
+# define STREAMS
+# undef STEP_SLEW /* TWO step */
+# define LOCK_PROCESS
+# define SIZE_RETURNED_IN_BUFFER
+# include <sys/sockio.h>
+# include <sys/types.h>
+# include <netinet/in_systm.h>
+#endif
+
+/*
+ * DomainOS
+ */
+#if defined(SYS_DOMAINOS)
+# define NTP_SYSCALLS_STD
+/* older versions of domain/os don't have class D */
+# ifndef IN_CLASSD
+# define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
+# define IN_CLASSD_NET 0xf0000000
+# define IN_CLASSD_NSHIFT 28
+# define IN_CLASSD_HOST 0xfffffff
+# define IN_MULTICAST(i) IN_CLASSD(i)
+# endif
+#endif
+
+/*
+ * Fujitsu UXP/V
+ */
+#if defined(SYS_UXPV)
+# define LOCK_PROCESS
+# define SIZE_RETURNED_IN_BUFFER
+#endif
+
+
+#endif /* 0 */
+
+/*
+ * Windows NT
+ */
+#if defined(SYS_WINNT)
+# if !defined(HAVE_CONFIG_H) || !defined(__config)
+ error "NT requires config.h to be included"
+# endif /* HAVE_CONFIG_H) */
+
+#if defined SYS_WINNT
+# define ifreq _INTERFACE_INFO
+# define ifr_flags iiFlags
+# define ifr_addr iiAddress.AddressIn
+# define ifr_broadaddr iiBroadcastAddress.AddressIn
+# define ifr_mask iiNetmask.AddressIn
+#endif /* SYS_WINNT */
+
+# define isascii __isascii
+# define isatty _isatty
+# define mktemp _mktemp
+# define getpid GetCurrentProcessId
+# include <windows.h>
+# include <ws2tcpip.h>
+# undef interface
+ typedef char *caddr_t;
+#endif /* SYS_WINNT */
+
+int ntp_set_tod P((struct timeval *tvp, void *tzp));
+
+#if defined (SYS_CYGWIN32)
+#include <windows.h>
+#define __int64 long long
+#endif
+
+/*casey Tue May 27 15:45:25 SAT 1997*/
+#ifdef SYS_VXWORKS
+
+/* casey's new defines */
+#define NO_MAIN_ALLOWED 1
+#define NO_NETDB 1
+#define NO_RENAME 1
+
+/* in vxWorks we use FIONBIO, but the others are defined for old systems, so
+ * all hell breaks loose if we leave them defined we define USE_FIONBIO to
+ * undefine O_NONBLOCK FNDELAY O_NDELAY where necessary.
+ */
+#define USE_FIONBIO 1
+/* end my new defines */
+
+#define TIMEOFDAY 0x0 /* system wide realtime clock */
+#define HAVE_GETCLOCK 1 /* configure does not set this ... */
+#define HAVE_NO_NICE 1 /* configure does not set this ... */
+#define HAVE_RANDOM 1 /* configure does not set this ... */
+#define HAVE_SRANDOM 1 /* configure does not set this ... */
+
+#define NODETACH 1
+
+/* vxWorks specific additions to take care of its
+ * unix (non)complicance
+ */
+
+#include "vxWorks.h"
+#include "ioLib.h"
+#include "taskLib.h"
+#include "time.h"
+
+extern int sysClkRateGet P(());
+
+/* usrtime.h
+ * Bob Herlien's excellent time code find it at:
+ * ftp://ftp.atd.ucar.edu/pub/vxworks/vx/usrTime.shar
+ * I would recommend this instead of clock_[g|s]ettime() plus you get
+ * adjtime() too ... casey
+ */
+/*
+extern int gettimeofday P(( struct timeval *tp, struct timezone *tzp ));
+extern int settimeofday P((struct timeval *, struct timezone *));
+extern int adjtime P(( struct timeval *delta, struct timeval *olddelta ));
+ */
+
+/* in machines.c */
+extern void sleep P((int seconds));
+extern void alarm P((int seconds));
+/* machines.c */
+
+
+/* this is really this */
+#define getpid taskIdSelf
+#define getclock clock_gettime
+#define fcntl ioctl
+#define _getch getchar
+#define random rand
+#define srandom srand
+
+/* define this away for vxWorks */
+#define openlog(x,y)
+/* use local defines for these */
+#undef min
+#undef max
+
+#endif /* SYS_VXWORKS */
+
+#ifdef NO_NETDB
+/* These structures are needed for gethostbyname() etc... */
+/* structures used by netdb.h */
+struct hostent {
+ char *h_name; /* official name of host */
+ char **h_aliases; /* alias list */
+ int h_addrtype; /* host address type */
+ int h_length; /* length of address */
+ char **h_addr_list; /* list of addresses from name server */
+#define h_addr h_addr_list[0] /* address, for backward compatibility */
+};
+
+struct servent {
+ char *s_name; /* official service name */
+ char **s_aliases; /* alias list */
+ int s_port; /* port # */
+ char *s_proto; /* protocol to use */
+};
+extern int h_errno;
+
+#define TRY_AGAIN 2
+
+struct hostent *gethostbyname P((char * netnum));
+struct hostent *gethostbyaddr P((char * netnum, int size, int addr_type));
+/* type is the protocol */
+struct servent *getservbyname P((char *name, char *type));
+#endif /* NO_NETDB */
+
+#ifdef NO_MAIN_ALLOWED
+/* we have no main routines so lets make a plan */
+#define CALL(callname, progname, callmain) \
+ extern int callmain (int,char**); \
+ void callname (a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \
+ char *a0; \
+ char *a1; \
+ char *a2; \
+ char *a3; \
+ char *a4; \
+ char *a5; \
+ char *a6; \
+ char *a7; \
+ char *a8; \
+ char *a9; \
+ char *a10; \
+ { \
+ char *x[11]; \
+ int argc; \
+ char *argv[] = {progname,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; \
+ int i; \
+ for (i=0;i<11;i++) \
+ x[i] = NULL; \
+ x[0] = a0; \
+ x[1] = a1; \
+ x[2] = a2; \
+ x[3] = a3; \
+ x[4] = a4; \
+ x[5] = a5; \
+ x[6] = a6; \
+ x[7] = a7; \
+ x[8] = a8; \
+ x[9] = a9; \
+ x[10] = a10; \
+ argc=1; \
+ for (i=0; i<11;i++) \
+ if (x[i]) \
+ { \
+ argv[argc++] = x[i]; \
+ } \
+ callmain(argc,argv); \
+ }
+#endif /* NO_MAIN_ALLOWED */
+/*casey Tue May 27 15:45:25 SAT 1997*/
+
+/*
+ * Here's where autoconfig starts to take over
+ */
+#ifdef HAVE_SYS_STROPTS_H
+# ifdef HAVE_SYS_STREAM_H
+# define STREAM
+# endif
+#endif
+
+#ifndef RETSIGTYPE
+# if defined(NTP_POSIX_SOURCE)
+# define RETSIGTYPE void
+# else
+# define RETSIGTYPE int
+# endif
+#endif
+
+#ifdef NTP_SYSCALLS_STD
+# ifndef NTP_SYSCALL_GET
+# define NTP_SYSCALL_GET 235
+# endif
+# ifndef NTP_SYSCALL_ADJ
+# define NTP_SYSCALL_ADJ 236
+# endif
+#endif /* NTP_SYSCALLS_STD */
+
+#ifdef HAVE_RTPRIO
+# define HAVE_NO_NICE
+#else
+# ifdef HAVE_SETPRIORITY
+# define HAVE_BSD_NICE
+# else
+# ifdef HAVE_NICE
+# define HAVE_ATT_NICE
+# endif
+# endif
+#endif
+
+#if !defined(HAVE_ATT_NICE) \
+ && !defined(HAVE_BSD_NICE) \
+ && !defined(HAVE_NO_NICE) \
+ && !defined(SYS_WINNT)
+#include "ERROR: You must define one of the HAVE_xx_NICE defines!"
+#endif
+
+/*
+ * use only one tty model - no use in initialising
+ * a tty in three ways
+ * HAVE_TERMIOS is preferred over HAVE_SYSV_TTYS over HAVE_BSD_TTYS
+ */
+
+#ifdef HAVE_TERMIOS_H
+# define HAVE_TERMIOS
+#else
+# ifdef HAVE_TERMIO_H
+# define HAVE_SYSV_TTYS
+# else
+# ifdef HAVE_SGTTY_H
+# define HAVE_BSD_TTYS
+# endif
+# endif
+#endif
+
+#ifdef HAVE_TERMIOS
+# undef HAVE_BSD_TTYS
+# undef HAVE_SYSV_TTYS
+#endif
+
+#ifdef HAVE_SYSV_TTYS
+# undef HAVE_BSD_TTYS
+#endif
+
+#if !defined(SYS_WINNT) && !defined(VMS) && !defined(SYS_VXWORKS)
+# if !defined(HAVE_SYSV_TTYS) \
+ && !defined(HAVE_BSD_TTYS) \
+ && !defined(HAVE_TERMIOS)
+#include "ERROR: no tty type defined!"
+# endif
+#endif /* SYS_WINNT || VMS || SYS_VXWORKS*/
+
+#ifdef WORDS_BIGENDIAN
+# define XNTP_BIG_ENDIAN 1
+#else
+# define XNTP_LITTLE_ENDIAN 1
+#endif
+
+/*
+ * Byte order woes. The DES code is sensitive to byte order. This
+ * used to be resolved by calling ntohl() and htonl() to swap things
+ * around, but this turned out to be quite costly on Vaxes where those
+ * things are actual functions. The code now straightens out byte
+ * order troubles on its own, with no performance penalty for little
+ * end first machines, but at great expense to cleanliness.
+ */
+#if !defined(XNTP_BIG_ENDIAN) && !defined(XNTP_LITTLE_ENDIAN)
+ /*
+ * Pick one or the other.
+ */
+ BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
+#endif
+
+#if defined(XNTP_BIG_ENDIAN) && defined(XNTP_LITTLE_ENDIAN)
+ /*
+ * Pick one or the other.
+ */
+ BYTE_ORDER_NOT_DEFINED_FOR_AUTHENTICATION
+#endif
+
+#endif /* __ntp_machine */
diff --git a/contrib/ntp/include/ntp_malloc.h b/contrib/ntp/include/ntp_malloc.h
new file mode 100644
index 000000000000..099c83effe90
--- /dev/null
+++ b/contrib/ntp/include/ntp_malloc.h
@@ -0,0 +1,19 @@
+/*
+ * Define malloc and friends.
+ */
+#ifndef _ntp_malloc_h
+#define _ntp_malloc_h
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#else /* HAVE_STDLIB_H */
+# ifdef HAVE_MALLOC_H
+# include <malloc.h>
+# endif
+#endif /* HAVE_STDLIB_H */
+
+#endif /* _ntp_malloc_h */
diff --git a/contrib/ntp/include/ntp_proto.h b/contrib/ntp/include/ntp_proto.h
new file mode 100644
index 000000000000..2a888c2cc257
--- /dev/null
+++ b/contrib/ntp/include/ntp_proto.h
@@ -0,0 +1,8 @@
+#ifndef __ntp_proto_h
+#define __ntp_proto_h
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#endif /* __ntp_proto_h */
diff --git a/contrib/ntp/include/ntp_refclock.h b/contrib/ntp/include/ntp_refclock.h
new file mode 100644
index 000000000000..ad278a3c5576
--- /dev/null
+++ b/contrib/ntp/include/ntp_refclock.h
@@ -0,0 +1,265 @@
+/*
+ * ntp_refclock.h - definitions for reference clock support
+ */
+
+#ifndef NTP_REFCLOCK_H
+#define NTP_REFCLOCK_H
+
+#include "ntp_types.h"
+
+#if defined(HAVE_BSD_TTYS)
+#include <sgtty.h>
+#endif /* HAVE_BSD_TTYS */
+
+#if defined(HAVE_SYSV_TTYS)
+#include <termio.h>
+#endif /* HAVE_SYSV_TTYS */
+
+#if defined(HAVE_TERMIOS)
+# ifdef TERMIOS_NEEDS__SVID3
+# define _SVID3
+# endif
+# include <termios.h>
+# ifdef TERMIOS_NEEDS__SVID3
+# undef _SVID3
+# endif
+#endif
+
+#if defined(HAVE_SYS_MODEM_H)
+#include <sys/modem.h>
+#endif
+
+#if defined(STREAM)
+#include <stropts.h>
+#if defined(CLK)
+#include <sys/clkdefs.h>
+#endif /* CLK */
+#endif /* STREAM */
+
+#include "recvbuff.h"
+
+#if !defined(SYSV_TTYS) && !defined(STREAM) & !defined(BSD_TTYS)
+#define BSD_TTYS
+#endif /* SYSV_TTYS STREAM BSD_TTYS */
+
+#define SAMPLE(x) if ((pp->coderecv + 1) % MAXSTAGE != \
+ pp->codeproc % MAXSTAGE) \
+ pp->filter[pp->coderecv++ % MAXSTAGE] = \
+ (x);
+
+/*
+ * Macros to determine the clock type and unit numbers from a
+ * 127.127.t.u address
+ */
+#define REFCLOCKTYPE(srcadr) ((SRCADR(srcadr) >> 8) & 0xff)
+#define REFCLOCKUNIT(srcadr) (SRCADR(srcadr) & 0xff)
+
+/*
+ * List of reference clock names and descriptions. These must agree with
+ * lib/clocktypes.c and ntpd/refclock_conf.c.
+ */
+struct clktype {
+ int code; /* driver "major" number */
+ const char *clocktype; /* long description */
+ const char *abbrev; /* short description */
+};
+
+/*
+ * Configuration flag values
+ */
+#define CLK_HAVETIME1 0x1
+#define CLK_HAVETIME2 0x2
+#define CLK_HAVEVAL1 0x4
+#define CLK_HAVEVAL2 0x8
+
+#define CLK_FLAG1 0x1
+#define CLK_FLAG2 0x2
+#define CLK_FLAG3 0x4
+#define CLK_FLAG4 0x8
+
+#define CLK_HAVEFLAG1 0x10
+#define CLK_HAVEFLAG2 0x20
+#define CLK_HAVEFLAG3 0x40
+#define CLK_HAVEFLAG4 0x80
+
+/*
+ * Constant for disabling event reporting in
+ * refclock_receive. ORed in leap
+ * parameter
+ */
+#define REFCLOCK_OWN_STATES 0x80
+
+/*
+ * Structure for returning clock status
+ */
+struct refclockstat {
+ u_char type; /* clock type */
+ u_char flags; /* clock flags */
+ u_char haveflags; /* bit array of valid flags */
+ u_short lencode; /* length of last timecode */
+ const char *p_lastcode; /* last timecode received */
+ u_int32 polls; /* transmit polls */
+ u_int32 noresponse; /* no response to poll */
+ u_int32 badformat; /* bad format timecode received */
+ u_int32 baddata; /* invalid data timecode received */
+ u_int32 timereset; /* driver resets */
+ const char *clockdesc; /* ASCII description */
+ double fudgetime1; /* configure fudge time1 */
+ double fudgetime2; /* configure fudge time2 */
+ int32 fudgeval1; /* configure fudge value1 */
+ int32 fudgeval2; /* configure fudge value2 */
+ u_char currentstatus; /* clock status */
+ u_char lastevent; /* last exception event */
+ u_char leap; /* leap bits */
+ struct ctl_var *kv_list; /* additional variables */
+};
+
+/*
+ * Reference clock I/O structure. Used to provide an interface between
+ * the reference clock drivers and the I/O module.
+ */
+struct refclockio {
+ struct refclockio *next; /* link to next structure */
+ void (*clock_recv) P((struct recvbuf *)); /* completion routine */
+ int (*io_input) P((struct recvbuf *)); /* input routine -
+ to avoid excessive buffer use
+ due to small bursts
+ of refclock input data */
+ caddr_t srcclock; /* pointer to clock structure */
+ int datalen; /* lenth of data */
+ int fd; /* file descriptor */
+ u_long recvcount; /* count of receive completions */
+};
+
+/*
+ * Structure for returning debugging info
+ */
+#define NCLKBUGVALUES 16
+#define NCLKBUGTIMES 32
+
+struct refclockbug {
+ u_char nvalues; /* values following */
+ u_char ntimes; /* times following */
+ u_short svalues; /* values format sign array */
+ u_int32 stimes; /* times format sign array */
+ u_int32 values[NCLKBUGVALUES]; /* real values */
+ l_fp times[NCLKBUGTIMES]; /* real times */
+};
+
+/*
+ * Structure interface between the reference clock support
+ * ntp_refclock.c and the driver utility routines
+ */
+#define MAXSTAGE 60 /* max median filter stages */
+#define NSTAGE 5 /* default median filter stages */
+#define BMAX 128 /* max timecode length */
+#define GMT 0 /* I hope nobody sees this */
+#define MAXDIAL 60 /* max length of modem dial strings */
+
+/*
+ * Line discipline flags. These require line discipline or streams
+ * modules to be installed/loaded in the kernel. If specified, but not
+ * installed, the code runs as if unspecified.
+ */
+#define LDISC_STD 0x0 /* standard */
+#define LDISC_CLK 0x1 /* tty_clk \n intercept */
+#define LDISC_CLKPPS 0x2 /* tty_clk \377 intercept */
+#define LDISC_ACTS 0x4 /* tty_clk #* intercept */
+#define LDISC_CHU 0x8 /* tty_chu */
+#define LDISC_PPS 0x10 /* ppsclock */
+#define LDISC_RAW 0x20 /* raw binary */
+
+struct refclockproc {
+ struct refclockio io; /* I/O handler structure */
+ caddr_t unitptr; /* pointer to unit structure */
+ u_char leap; /* leap/synchronization code */
+ u_char currentstatus; /* clock status */
+ u_char lastevent; /* last exception event */
+ u_char type; /* clock type */
+ const char *clockdesc; /* clock description */
+
+ char a_lastcode[BMAX]; /* last timecode received */
+ u_short lencode; /* length of last timecode */
+
+ int year; /* year of eternity */
+ int day; /* day of year */
+ int hour; /* hour of day */
+ int minute; /* minute of hour */
+ int second; /* second of minute */
+ int msec; /* millisecond of second */
+ long usec; /* microsecond of second (alt) */
+ u_long yearstart; /* beginning of year */
+ int coderecv; /* put pointer */
+ int codeproc; /* get pointer */
+ l_fp lastref; /* timecode timestamp */
+ l_fp lastrec; /* local timestamp */
+ double offset; /* mean offset */
+ double disp; /* sample dispersion */
+ double variance; /* sample variance */
+ double filter[MAXSTAGE]; /* median filter */
+
+ /*
+ * Configuration data
+ */
+ double fudgetime1; /* fudge time1 */
+ double fudgetime2; /* fudge time2 */
+ u_int32 refid; /* reference identifier */
+ u_char sloppyclockflag; /* fudge flags */
+
+ /*
+ * Status tallies
+ */
+ u_long timestarted; /* time we started this */
+ u_long polls; /* polls sent */
+ u_long noreply; /* no replies to polls */
+ u_long badformat; /* bad format reply */
+ u_long baddata; /* bad data reply */
+};
+
+/*
+ * Structure interface between the reference clock support
+ * ntp_refclock.c and particular clock drivers. This must agree with the
+ * structure defined in the driver.
+ */
+#define noentry 0 /* flag for null routine */
+#define NOFLAGS 0 /* flag for null flags */
+
+struct refclock {
+ int (*clock_start) P((int, struct peer *));
+ void (*clock_shutdown) P((int, struct peer *));
+ void (*clock_poll) P((int, struct peer *));
+ void (*clock_control) P((int, struct refclockstat *,
+ struct refclockstat *, struct peer *));
+ void (*clock_init) P((void));
+ void (*clock_buginfo) P((int, struct refclockbug *, struct peer *));
+ u_long clock_flags;
+};
+
+/*
+ * Function prototypes
+ */
+/*
+ * auxiliary PPS interface (implemented by refclock_atom())
+ */
+extern int pps_sample P((l_fp *));
+extern int io_addclock_simple P((struct refclockio *));
+extern int io_addclock P((struct refclockio *));
+extern void io_closeclock P((struct refclockio *));
+
+#ifdef REFCLOCK
+extern void refclock_buginfo P((struct sockaddr_in *,
+ struct refclockbug *));
+extern void refclock_control P((struct sockaddr_in *,
+ struct refclockstat *,
+ struct refclockstat *));
+extern int refclock_open P((char *, int, int));
+extern void refclock_transmit P((struct peer *));
+extern int refclock_ioctl P((int, int));
+extern int refclock_process P((struct refclockproc *));
+extern void refclock_process_offset P((struct refclockproc *, l_fp, l_fp, double));
+extern void refclock_report P((struct peer *, int));
+extern int refclock_gtlin P((struct recvbuf *, char *, int,
+ l_fp *));
+#endif /* REFCLOCK */
+
+#endif /* NTP_REFCLOCK_H */
diff --git a/contrib/ntp/include/ntp_request.h b/contrib/ntp/include/ntp_request.h
new file mode 100644
index 000000000000..87dba8815433
--- /dev/null
+++ b/contrib/ntp/include/ntp_request.h
@@ -0,0 +1,790 @@
+/*
+ * ntp_request.h - definitions for the ntpd remote query facility
+ */
+
+#include "ntp_types.h"
+
+/*
+ * A mode 7 packet is used exchanging data between an NTP server
+ * and a client for purposes other than time synchronization, e.g.
+ * monitoring, statistics gathering and configuration. A mode 7
+ * packet has the following format:
+ *
+ * 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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |R|M| VN | Mode|A| Sequence | Implementation| Req Code |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Err | Number of data items | MBZ | Size of data item |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | |
+ * | Data (Minimum 0 octets, maximum 500 octets) |
+ * | |
+ * [...]
+ * | |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Encryption Keyid (when A bit set) |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | |
+ * | Message Authentication Code (when A bit set) |
+ * | |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ * where the fields are (note that the client sends requests, the server
+ * responses):
+ *
+ * Response Bit: This packet is a response (if clear, packet is a request).
+ *
+ * More Bit: Set for all packets but the last in a response which
+ * requires more than one packet.
+ *
+ * Version Number: 2 for current version
+ *
+ * Mode: Always 7
+ *
+ * Authenticated bit: If set, this packet is authenticated.
+ *
+ * Sequence number: For a multipacket response, contains the sequence
+ * number of this packet. 0 is the first in the sequence,
+ * 127 (or less) is the last. The More Bit must be set in
+ * all packets but the last.
+ *
+ * Implementation number: The number of the implementation this request code
+ * is defined by. An implementation number of zero is used
+ * for requst codes/data formats which all implementations
+ * agree on. Implementation number 255 is reserved (for
+ * extensions, in case we run out).
+ *
+ * Request code: An implementation-specific code which specifies the
+ * operation to be (which has been) performed and/or the
+ * format and semantics of the data included in the packet.
+ *
+ * Err: Must be 0 for a request. For a response, holds an error
+ * code relating to the request. If nonzero, the operation
+ * requested wasn't performed.
+ *
+ * 0 - no error
+ * 1 - incompatable implementation number
+ * 2 - unimplemented request code
+ * 3 - format error (wrong data items, data size, packet size etc.)
+ * 4 - no data available (e.g. request for details on unknown peer)
+ * 5-6 I don't know
+ * 7 - authentication failure (i.e. permission denied)
+ *
+ * Number of data items: number of data items in packet. 0 to 500
+ *
+ * MBZ: A reserved data field, must be zero in requests and responses.
+ *
+ * Size of data item: size of each data item in packet. 0 to 500
+ *
+ * Data: Variable sized area containing request/response data. For
+ * requests and responses the size in octets must be greater
+ * than or equal to the product of the number of data items
+ * and the size of a data item. For requests the data area
+ * must be exactly 40 octets in length. For responses the
+ * data area may be any length between 0 and 500 octets
+ * inclusive.
+ *
+ * Message Authentication Code: Same as NTP spec, in definition and function.
+ * May optionally be included in requests which require
+ * authentication, is never included in responses.
+ *
+ * The version number, mode and keyid have the same function and are
+ * in the same location as a standard NTP packet. The request packet
+ * is the same size as a standard NTP packet to ease receive buffer
+ * management, and to allow the same encryption procedure to be used
+ * both on mode 7 and standard NTP packets. The mac is included when
+ * it is required that a request be authenticated, the keyid should be
+ * zero in requests in which the mac is not included.
+ *
+ * The data format depends on the implementation number/request code pair
+ * and whether the packet is a request or a response. The only requirement
+ * is that data items start in the octet immediately following the size
+ * word and that data items be concatenated without padding between (i.e.
+ * if the data area is larger than data_items*size, all padding is at
+ * the end). Padding is ignored, other than for encryption purposes.
+ * Implementations using encryption might want to include a time stamp
+ * or other data in the request packet padding. The key used for requests
+ * is implementation defined, but key 15 is suggested as a default.
+ */
+
+/*
+ * A request packet. These are almost a fixed length.
+ */
+struct req_pkt {
+ u_char rm_vn_mode; /* response, more, version, mode */
+ u_char auth_seq; /* key, sequence number */
+ u_char implementation; /* implementation number */
+ u_char request; /* request number */
+ u_short err_nitems; /* error code/number of data items */
+ u_short mbz_itemsize; /* item size */
+ char data[32]; /* data area */
+ l_fp tstamp; /* time stamp, for authentication */
+ u_int32 keyid; /* encryption key */
+ char mac[MAX_MAC_LEN-sizeof(u_int32)]; /* (optional) 8 byte auth code */
+};
+
+/*
+ * Input packet lengths. One with the mac, one without.
+ */
+#define REQ_LEN_MAC (sizeof(struct req_pkt))
+#define REQ_LEN_NOMAC (sizeof(struct req_pkt) - MAX_MAC_LEN)
+
+/*
+ * A response packet. The length here is variable, this is a
+ * maximally sized one. Note that this implementation doesn't
+ * authenticate responses.
+ */
+#define RESP_HEADER_SIZE (8)
+#define RESP_DATA_SIZE (500)
+
+struct resp_pkt {
+ u_char rm_vn_mode; /* response, more, version, mode */
+ u_char auth_seq; /* key, sequence number */
+ u_char implementation; /* implementation number */
+ u_char request; /* request number */
+ u_short err_nitems; /* error code/number of data items */
+ u_short mbz_itemsize; /* item size */
+ char data[RESP_DATA_SIZE]; /* data area */
+};
+
+
+/*
+ * Information error codes
+ */
+#define INFO_OKAY 0
+#define INFO_ERR_IMPL 1 /* incompatable implementation */
+#define INFO_ERR_REQ 2 /* unknown request code */
+#define INFO_ERR_FMT 3 /* format error */
+#define INFO_ERR_NODATA 4 /* no data for this request */
+#define INFO_ERR_AUTH 7 /* authentication failure */
+
+/*
+ * Maximum sequence number.
+ */
+#define MAXSEQ 127
+
+
+/*
+ * Bit setting macros for multifield items.
+ */
+#define RESP_BIT 0x80
+#define MORE_BIT 0x40
+
+#define ISRESPONSE(rm_vn_mode) (((rm_vn_mode)&RESP_BIT)!=0)
+#define ISMORE(rm_vn_mode) (((rm_vn_mode)&MORE_BIT)!=0)
+#define INFO_VERSION(rm_vn_mode) ((u_char)(((rm_vn_mode)>>3)&0x7))
+#define INFO_MODE(rm_vn_mode) ((rm_vn_mode)&0x7)
+
+#define RM_VN_MODE(resp, more, version) \
+ ((u_char)(((resp)?RESP_BIT:0)\
+ |((more)?MORE_BIT:0)\
+ |((version?version:(NTP_OLDVERSION+1))<<3)\
+ |(MODE_PRIVATE)))
+
+#define INFO_IS_AUTH(auth_seq) (((auth_seq) & 0x80) != 0)
+#define INFO_SEQ(auth_seq) ((auth_seq)&0x7f)
+#define AUTH_SEQ(auth, seq) ((u_char)((((auth)!=0)?0x80:0)|((seq)&0x7f)))
+
+#define INFO_ERR(err_nitems) ((u_short)((ntohs(err_nitems)>>12)&0xf))
+#define INFO_NITEMS(err_nitems) ((u_short)(ntohs(err_nitems)&0xfff))
+#define ERR_NITEMS(err, nitems) (htons((u_short)((((u_short)(err)<<12)&0xf000)\
+ |((u_short)(nitems)&0xfff))))
+
+#define INFO_MBZ(mbz_itemsize) ((ntohs(mbz_itemsize)>>12)&0xf)
+#define INFO_ITEMSIZE(mbz_itemsize) (ntohs(mbz_itemsize)&0xfff)
+#define MBZ_ITEMSIZE(itemsize) (htons((u_short)(itemsize)))
+
+
+/*
+ * Implementation numbers. One for universal use and one for ntpd.
+ */
+#define IMPL_UNIV 0
+#define IMPL_XNTPD 2
+
+/*
+ * Some limits related to authentication. Frames which are
+ * authenticated must include a time stamp which differs from
+ * the receive time stamp by no more than 10 seconds.
+ */
+#define INFO_TS_MAXSKEW 10.
+
+/*
+ * Universal request codes go here. There aren't any.
+ */
+
+/*
+ * NTPD request codes go here.
+ */
+#define REQ_PEER_LIST 0 /* return list of peers */
+#define REQ_PEER_LIST_SUM 1 /* return summary info for all peers */
+#define REQ_PEER_INFO 2 /* get standard information on peer */
+#define REQ_PEER_STATS 3 /* get statistics for peer */
+#define REQ_SYS_INFO 4 /* get system information */
+#define REQ_SYS_STATS 5 /* get system stats */
+#define REQ_IO_STATS 6 /* get I/O stats */
+#define REQ_MEM_STATS 7 /* stats related to peer list maint */
+#define REQ_LOOP_INFO 8 /* info from the loop filter */
+#define REQ_TIMER_STATS 9 /* get timer stats */
+#define REQ_CONFIG 10 /* configure a new peer */
+#define REQ_UNCONFIG 11 /* unconfigure an existing peer */
+#define REQ_SET_SYS_FLAG 12 /* set system flags */
+#define REQ_CLR_SYS_FLAG 13 /* clear system flags */
+#define REQ_MONITOR 14 /* (not used) */
+#define REQ_NOMONITOR 15 /* (not used) */
+#define REQ_GET_RESTRICT 16 /* return restrict list */
+#define REQ_RESADDFLAGS 17 /* add flags to restrict list */
+#define REQ_RESSUBFLAGS 18 /* remove flags from restrict list */
+#define REQ_UNRESTRICT 19 /* remove entry from restrict list */
+#define REQ_MON_GETLIST 20 /* return data collected by monitor */
+#define REQ_RESET_STATS 21 /* reset stat counters */
+#define REQ_RESET_PEER 22 /* reset peer stat counters */
+#define REQ_REREAD_KEYS 23 /* reread the encryption key file */
+#define REQ_DO_DIRTY_HACK 24 /* (not used) */
+#define REQ_DONT_DIRTY_HACK 25 /* (not used) */
+#define REQ_TRUSTKEY 26 /* add a trusted key */
+#define REQ_UNTRUSTKEY 27 /* remove a trusted key */
+#define REQ_AUTHINFO 28 /* return authentication info */
+#define REQ_TRAPS 29 /* return currently set traps */
+#define REQ_ADD_TRAP 30 /* add a trap */
+#define REQ_CLR_TRAP 31 /* clear a trap */
+#define REQ_REQUEST_KEY 32 /* define a new request keyid */
+#define REQ_CONTROL_KEY 33 /* define a new control keyid */
+#define REQ_GET_CTLSTATS 34 /* get stats from the control module */
+#define REQ_GET_LEAPINFO 35 /* (not used) */
+#define REQ_GET_CLOCKINFO 36 /* get clock information */
+#define REQ_SET_CLKFUDGE 37 /* set clock fudge factors */
+#define REQ_GET_KERNEL 38 /* get kernel pll/pps information */
+#define REQ_GET_CLKBUGINFO 39 /* get clock debugging info */
+#define REQ_SET_PRECISION 41 /* (not used) */
+#define REQ_MON_GETLIST_1 42 /* return data collected by monitor v1 */
+
+/*
+ * Flags in the peer information returns
+ */
+#define INFO_FLAG_CONFIG 0x1
+#define INFO_FLAG_SYSPEER 0x2
+#define INFO_FLAG_BURST 0x4
+#define INFO_FLAG_REFCLOCK 0x8
+#define INFO_FLAG_PREFER 0x10
+#define INFO_FLAG_AUTHENABLE 0x20
+#define INFO_FLAG_SEL_CANDIDATE 0x40
+#define INFO_FLAG_SHORTLIST 0x80
+
+/*
+ * Flags in the system information returns
+ */
+#define INFO_FLAG_BCLIENT 0x1
+#define INFO_FLAG_AUTHENTICATE 0x2
+#define INFO_FLAG_NTP 0x4
+#define INFO_FLAG_KERNEL 0x8
+#define INFO_FLAG_MONITOR 0x40
+#define INFO_FLAG_FILEGEN 0x80
+#define INFO_FLAG_PLL_SYNC 0x10
+#define INFO_FLAG_PPS_SYNC 0x20
+
+/*
+ * Peer list structure. Used to return raw lists of peers. It goes
+ * without saying that everything returned is in network byte order.
+ */
+struct info_peer_list {
+ u_int32 address; /* address of peer */
+ u_short port; /* port number of peer */
+ u_char hmode; /* mode for this peer */
+ u_char flags; /* flags (from above) */
+};
+
+
+/*
+ * Peer summary structure. Sort of the info that ntpdc returns by default.
+ */
+struct info_peer_summary {
+ u_int32 dstadr; /* local address (zero for undetermined) */
+ u_int32 srcadr; /* source address */
+ u_short srcport; /* source port */
+ u_char stratum; /* stratum of peer */
+ s_char hpoll; /* host polling interval */
+ s_char ppoll; /* peer polling interval */
+ u_char reach; /* reachability register */
+ u_char flags; /* flags, from above */
+ u_char hmode; /* peer mode */
+ s_fp delay; /* peer.estdelay */
+ l_fp offset; /* peer.estoffset */
+ u_fp dispersion; /* peer.estdisp */
+};
+
+
+/*
+ * Peer information structure.
+ */
+struct info_peer {
+ u_int32 dstadr; /* local address */
+ u_int32 srcadr; /* remote address */
+ u_short srcport; /* remote port */
+ u_char flags; /* peer flags */
+ u_char leap; /* peer.leap */
+ u_char hmode; /* peer.hmode */
+ u_char pmode; /* peer.pmode */
+ u_char stratum; /* peer.stratum */
+ u_char ppoll; /* peer.ppoll */
+ u_char hpoll; /* peer.hpoll */
+ s_char precision; /* peer.precision */
+ u_char version; /* peer.version */
+ u_char valid; /* peer.valid */
+ u_char reach; /* peer.reach */
+ u_char unreach; /* peer.unreach */
+ u_char flash; /* old peer.flash */
+ u_char ttl; /* peer.ttl */
+ u_short flash2; /* new peer.flash */
+ u_short associd; /* association ID */
+ u_int32 keyid; /* peer.keyid */
+ u_int32 pkeyid; /* unused */
+ u_int32 refid; /* peer.refid */
+ u_int32 timer; /* peer.timer */
+ s_fp rootdelay; /* peer.distance */
+ u_fp rootdispersion; /* peer.dispersion */
+ l_fp reftime; /* peer.reftime */
+ l_fp org; /* peer.org */
+ l_fp rec; /* peer.rec */
+ l_fp xmt; /* peer.xmt */
+ s_fp filtdelay[NTP_SHIFT]; /* delay shift register */
+ l_fp filtoffset[NTP_SHIFT]; /* offset shift register */
+ u_char order[NTP_SHIFT]; /* order of peers from last filter */
+ s_fp delay; /* peer.estdelay */
+ u_fp dispersion; /* peer.estdisp */
+ l_fp offset; /* peer.estoffset */
+ u_fp selectdisp; /* peer select dispersion */
+ int32 unused1; /* (obsolete) */
+ int32 unused2;
+ int32 unused3;
+ int32 unused4;
+ int32 unused5;
+ int32 unused6;
+ int32 unused7;
+ s_fp estbdelay; /* broadcast offset */
+};
+
+
+/*
+ * Peer statistics structure
+ */
+struct info_peer_stats {
+ u_int32 dstadr; /* local address */
+ u_int32 srcadr; /* remote address */
+ u_short srcport; /* remote port */
+ u_short flags; /* peer flags */
+ u_int32 timereset; /* time counters were reset */
+ u_int32 timereceived; /* time since a packet received */
+ u_int32 timetosend; /* time until a packet sent */
+ u_int32 timereachable; /* time peer has been reachable */
+ u_int32 sent; /* number sent */
+ u_int32 unused1; /* (unused) */
+ u_int32 processed; /* number processed */
+ u_int32 unused2; /* (unused) */
+ u_int32 badauth; /* bad authentication */
+ u_int32 bogusorg; /* bogus origin */
+ u_int32 oldpkt; /* duplicate */
+ u_int32 unused3; /* (unused) */
+ u_int32 unused4; /* (unused) */
+ u_int32 seldisp; /* bad dispersion */
+ u_int32 selbroken; /* bad reference time */
+ u_int32 unused5; /* (unused) */
+ u_char candidate; /* select order */
+ u_char unused6; /* (unused) */
+ u_char unused7; /* (unused) */
+ u_char unused8; /* (unused) */
+};
+
+
+/*
+ * Loop filter variables
+ */
+struct info_loop {
+ l_fp last_offset;
+ l_fp drift_comp;
+ u_int32 compliance;
+ u_int32 watchdog_timer;
+};
+
+
+/*
+ * System info. Mostly the sys.* variables, plus a few unique to
+ * the implementation.
+ */
+struct info_sys {
+ u_int32 peer; /* system peer address */
+ u_char peer_mode; /* mode we are syncing to peer in */
+ u_char leap; /* system leap bits */
+ u_char stratum; /* our stratum */
+ s_char precision; /* local clock precision */
+ s_fp rootdelay; /* distance from sync source */
+ u_fp rootdispersion; /* dispersion from sync source */
+ u_int32 refid; /* reference ID of sync source */
+ l_fp reftime; /* system reference time */
+ u_int32 poll; /* system poll interval */
+ u_char flags; /* system flags */
+ u_char unused1; /* unused */
+ u_char unused2; /* unused */
+ u_char unused3; /* unused */
+ s_fp bdelay; /* default broadcast offset */
+ s_fp frequency; /* frequency residual (scaled ppm) */
+ l_fp authdelay; /* default authentication delay */
+ u_fp stability; /* clock stability (scaled ppm) */
+};
+
+
+/*
+ * System stats. These are collected in the protocol module
+ */
+struct info_sys_stats {
+ u_int32 timeup; /* time we have been up and running */
+ u_int32 timereset; /* time since these were last cleared */
+ u_int32 badstratum; /* packets claiming an invalid stratum */
+ u_int32 oldversionpkt; /* old version packets received */
+ u_int32 newversionpkt; /* new version packets received */
+ u_int32 unknownversion; /* don't know version packets */
+ u_int32 badlength; /* packets with bad length */
+ u_int32 processed; /* packets processed */
+ u_int32 badauth; /* packets dropped because of authorization */
+ u_int32 wanderhold; /* (obsolete) */
+ u_int32 limitrejected; /* rejected because of client limitation */
+};
+
+
+/*
+ * System stats - old version
+ */
+struct old_info_sys_stats {
+ u_int32 timeup; /* time we have been up and running */
+ u_int32 timereset; /* time since these were last cleared */
+ u_int32 badstratum; /* packets claiming an invalid stratum */
+ u_int32 oldversionpkt; /* old version packets received */
+ u_int32 newversionpkt; /* new version packets received */
+ u_int32 unknownversion; /* don't know version packets */
+ u_int32 badlength; /* packets with bad length */
+ u_int32 processed; /* packets processed */
+ u_int32 badauth; /* packets dropped because of authorization */
+ u_int32 wanderhold;
+};
+
+
+/*
+ * Peer memory statistics. Collected in the peer module.
+ */
+struct info_mem_stats {
+ u_int32 timereset; /* time since reset */
+ u_short totalpeermem;
+ u_short freepeermem;
+ u_int32 findpeer_calls;
+ u_int32 allocations;
+ u_int32 demobilizations;
+ u_char hashcount[HASH_SIZE];
+};
+
+
+/*
+ * I/O statistics. Collected in the I/O module
+ */
+struct info_io_stats {
+ u_int32 timereset; /* time since reset */
+ u_short totalrecvbufs; /* total receive bufs */
+ u_short freerecvbufs; /* free buffers */
+ u_short fullrecvbufs; /* full buffers */
+ u_short lowwater; /* number of times we've added buffers */
+ u_int32 dropped; /* dropped packets */
+ u_int32 ignored; /* ignored packets */
+ u_int32 received; /* received packets */
+ u_int32 sent; /* packets sent */
+ u_int32 notsent; /* packets not sent */
+ u_int32 interrupts; /* interrupts we've handled */
+ u_int32 int_received; /* received by interrupt handler */
+};
+
+
+/*
+ * Timer stats. Guess where from.
+ */
+struct info_timer_stats {
+ u_int32 timereset; /* time since reset */
+ u_int32 alarms; /* alarms we've handled */
+ u_int32 overflows; /* timer overflows */
+ u_int32 xmtcalls; /* calls to xmit */
+};
+
+
+/*
+ * Structure for passing peer configuration information
+ */
+struct conf_peer {
+ u_int32 peeraddr; /* address to poll */
+ u_char hmode; /* mode, either broadcast, active or client */
+ u_char version; /* version number to poll with */
+ u_char minpoll; /* min host poll interval */
+ u_char maxpoll; /* max host poll interval */
+ u_char flags; /* flags for this request */
+ u_char ttl; /* time to live (multicast) or refclock mode */
+ u_short unused; /* unused */
+ u_int32 keyid; /* key to use for this association */
+};
+
+#define CONF_FLAG_AUTHENABLE 0x1
+#define CONF_FLAG_PREFER 0x2
+#define CONF_FLAG_BURST 0x4
+#define CONF_FLAG_NOSELECT 0x8
+#define CONF_FLAG_SKEY 0x10
+
+/*
+ * Structure for passing peer deletion information. Currently
+ * we only pass the address and delete all configured peers with
+ * this addess.
+ */
+struct conf_unpeer {
+ u_int32 peeraddr; /* address of peer */
+};
+
+/*
+ * Structure for carrying system flags.
+ */
+struct conf_sys_flags {
+ u_int32 flags;
+};
+
+/*
+ * System flags we can set/clear
+ */
+#define SYS_FLAG_BCLIENT 0x1
+#define SYS_FLAG_AUTHENTICATE 0x2
+#define SYS_FLAG_NTP 0x4
+#define SYS_FLAG_KERNEL 0x8
+#define SYS_FLAG_MONITOR 0x10
+#define SYS_FLAG_FILEGEN 0x20
+
+/*
+ * Structure used for returning restrict entries
+ */
+struct info_restrict {
+ u_int32 addr; /* match address */
+ u_int32 mask; /* match mask */
+ u_int32 count; /* number of packets matched */
+ u_short flags; /* restrict flags */
+ u_short mflags; /* match flags */
+};
+
+
+/*
+ * Structure used for specifying restrict entries
+ */
+struct conf_restrict {
+ u_int32 addr; /* match address */
+ u_int32 mask; /* match mask */
+ u_short flags; /* restrict flags */
+ u_short mflags; /* match flags */
+};
+
+
+/*
+ * Structure used for returning monitor data
+ */
+struct info_monitor_1 {
+ u_int32 lasttime; /* last packet from this host */
+ u_int32 firsttime; /* first time we received a packet */
+ u_int32 lastdrop; /* last time we rejected a packet due to client limitation policy */
+ u_int32 count; /* count of packets received */
+ u_int32 addr; /* host address */
+ u_int32 daddr; /* destination host address */
+ u_int32 flags; /* flags about destination */
+ u_short port; /* port number of last reception */
+ u_char mode; /* mode of last packet */
+ u_char version; /* version number of last packet */
+};
+
+
+/*
+ * Structure used for returning monitor data
+ */
+struct info_monitor {
+ u_int32 lasttime; /* last packet from this host */
+ u_int32 firsttime; /* first time we received a packet */
+ u_int32 lastdrop; /* last time we rejected a packet due to client limitation policy */
+ u_int32 count; /* count of packets received */
+ u_int32 addr; /* host address */
+ u_short port; /* port number of last reception */
+ u_char mode; /* mode of last packet */
+ u_char version; /* version number of last packet */
+};
+
+/*
+ * Structure used for returning monitor data (old format
+ */
+struct old_info_monitor {
+ u_int32 lasttime; /* last packet from this host */
+ u_int32 firsttime; /* first time we received a packet */
+ u_int32 count; /* count of packets received */
+ u_int32 addr; /* host address */
+ u_short port; /* port number of last reception */
+ u_char mode; /* mode of last packet */
+ u_char version; /* version number of last packet */
+};
+
+/*
+ * Structure used for passing indication of flags to clear
+ */
+struct reset_flags {
+ u_int32 flags;
+};
+
+#define RESET_FLAG_ALLPEERS 0x01
+#define RESET_FLAG_IO 0x02
+#define RESET_FLAG_SYS 0x04
+#define RESET_FLAG_MEM 0x08
+#define RESET_FLAG_TIMER 0x10
+#define RESET_FLAG_AUTH 0x20
+#define RESET_FLAG_CTL 0x40
+
+#define RESET_ALLFLAGS \
+ (RESET_FLAG_ALLPEERS|RESET_FLAG_IO|RESET_FLAG_SYS \
+ |RESET_FLAG_MEM|RESET_FLAG_TIMER|RESET_FLAG_AUTH|RESET_FLAG_CTL)
+
+/*
+ * Structure used to return information concerning the authentication
+ * module.
+ */
+struct info_auth {
+ u_int32 timereset; /* time counters were reset */
+ u_int32 numkeys; /* number of keys we know */
+ u_int32 numfreekeys; /* number of free keys */
+ u_int32 keylookups; /* calls to authhavekey() */
+ u_int32 keynotfound; /* requested key unknown */
+ u_int32 encryptions; /* number of encryptions */
+ u_int32 decryptions; /* number of decryptions */
+ u_int32 expired; /* number of expired keys */
+ u_int32 keyuncached; /* calls to encrypt/decrypt with uncached key */
+};
+
+
+/*
+ * Structure used to pass trap information to the client
+ */
+struct info_trap {
+ u_int32 local_address; /* local interface address */
+ u_int32 trap_address; /* remote client's address */
+ u_short trap_port; /* remote port number */
+ u_short sequence; /* sequence number */
+ u_int32 settime; /* time trap last set */
+ u_int32 origtime; /* time trap originally set */
+ u_int32 resets; /* number of resets on this trap */
+ u_int32 flags; /* trap flags, as defined in ntp_control.h */
+};
+
+/*
+ * Structure used to pass add/clear trap information to the client
+ */
+struct conf_trap {
+ u_int32 local_address; /* local interface address */
+ u_int32 trap_address; /* remote client's address */
+ u_short trap_port; /* remote client's port */
+ u_short unused; /* (unused) */
+};
+
+
+/*
+ * Structure used to return statistics from the control module
+ */
+struct info_control {
+ u_int32 ctltimereset;
+ u_int32 numctlreq; /* number of requests we've received */
+ u_int32 numctlbadpkts; /* number of bad control packets */
+ u_int32 numctlresponses; /* # resp packets sent */
+ u_int32 numctlfrags; /* # of fragments sent */
+ u_int32 numctlerrors; /* number of error responses sent */
+ u_int32 numctltooshort; /* number of too short input packets */
+ u_int32 numctlinputresp; /* number of responses on input */
+ u_int32 numctlinputfrag; /* number of fragments on input */
+ u_int32 numctlinputerr; /* # input pkts with err bit set */
+ u_int32 numctlbadoffset; /* # input pkts with nonzero offset */
+ u_int32 numctlbadversion; /* # input pkts with unknown version */
+ u_int32 numctldatatooshort; /* data too short for count */
+ u_int32 numctlbadop; /* bad op code found in packet */
+ u_int32 numasyncmsgs; /* # async messages we've sent */
+};
+
+
+/*
+ * Structure used to return clock information
+ */
+struct info_clock {
+ u_int32 clockadr;
+ u_char type;
+ u_char flags;
+ u_char lastevent;
+ u_char currentstatus;
+ u_int32 polls;
+ u_int32 noresponse;
+ u_int32 badformat;
+ u_int32 baddata;
+ u_int32 timestarted;
+ l_fp fudgetime1;
+ l_fp fudgetime2;
+ int32 fudgeval1;
+ int32 fudgeval2;
+};
+
+
+/*
+ * Structure used for setting clock fudge factors
+ */
+struct conf_fudge {
+ u_int32 clockadr;
+ u_int32 which;
+ l_fp fudgetime;
+ int32 fudgeval_flags;
+};
+
+#define FUDGE_TIME1 1
+#define FUDGE_TIME2 2
+#define FUDGE_VAL1 3
+#define FUDGE_VAL2 4
+#define FUDGE_FLAGS 5
+
+
+/*
+ * Structure used for returning clock debugging info
+ */
+#define NUMCBUGVALUES 16
+#define NUMCBUGTIMES 32
+
+struct info_clkbug {
+ u_int32 clockadr;
+ u_char nvalues;
+ u_char ntimes;
+ u_short svalues;
+ u_int32 stimes;
+ u_int32 values[NUMCBUGVALUES];
+ l_fp times[NUMCBUGTIMES];
+};
+
+/*
+ * Structure used for returning kernel pll/PPS information
+ */
+struct info_kernel {
+ int32 offset;
+ int32 freq;
+ int32 maxerror;
+ int32 esterror;
+ u_short status;
+ u_short shift;
+ int32 constant;
+ int32 precision;
+ int32 tolerance;
+
+/*
+ * Variables used only if PPS signal discipline is implemented
+ */
+ int32 ppsfreq;
+ int32 jitter;
+ int32 stabil;
+ int32 jitcnt;
+ int32 calcnt;
+ int32 errcnt;
+ int32 stbcnt;
+};
diff --git a/contrib/ntp/include/ntp_select.h b/contrib/ntp/include/ntp_select.h
new file mode 100644
index 000000000000..79c0fc0a56bf
--- /dev/null
+++ b/contrib/ntp/include/ntp_select.h
@@ -0,0 +1,35 @@
+/*
+ * Not all machines define FD_SET in sys/types.h
+ */
+#ifndef _ntp_select_h
+#define _ntp_select_h
+
+/* Was: (defined(RS6000)||defined(SYS_PTX))&&!defined(_BSD) */
+/* Could say: !defined(FD_SET) && defined(HAVE_SYS_SELECT_H) */
+#if defined(HAVE_SYS_SELECT_H) && !defined(_BSD)
+#ifndef SYS_VXWORKS
+#include <sys/select.h>
+#else
+#include <sockLib.h>
+extern int select P((int width, fd_set *pReadFds, fd_set *pWriteFds,
+ fd_set *pExceptFds, struct timeval *pTimeOut));
+
+#endif
+#endif
+
+#if !defined(FD_SET) && !defined(SYS_WINNT)
+#define NFDBITS 32
+#define FD_SETSIZE 32
+#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
+#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
+#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
+#define FD_ZERO(p) memset((char *)(p), 0, sizeof(*(p)))
+#endif
+
+#if defined(VMS)
+typedef struct {
+ unsigned int fds_bits[1];
+} fd_set;
+#endif
+
+#endif /* _ntp_select_h */
diff --git a/contrib/ntp/include/ntp_stdlib.h b/contrib/ntp/include/ntp_stdlib.h
new file mode 100644
index 000000000000..6a2a85221267
--- /dev/null
+++ b/contrib/ntp/include/ntp_stdlib.h
@@ -0,0 +1,172 @@
+/*
+ * ntp_stdlib.h - Prototypes for NTP lib.
+ */
+#include <sys/types.h>
+
+#include "ntp_types.h"
+#include "ntp_string.h"
+#include "l_stdlib.h"
+
+/*
+ * Handle gcc __attribute__ if available.
+ */
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later. */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || (defined(__STRICT_ANSI__))
+# define __attribute__(Spec) /* empty */
+# endif
+/* The __-protected variants of `format' and `printf' attributes
+ are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+# define __format__ format
+# define __printf__ printf
+# endif
+#endif
+
+#if defined(__STDC__) || defined(HAVE_STDARG_H)
+# include <stdarg.h>
+extern void msyslog P((int, const char *, ...))
+ __attribute__((__format__(__printf__, 2, 3)));
+#else
+# include <varargs.h>
+extern void msyslog P(());
+#endif
+
+#if 0 /* HMS: These seem to be unused now */
+extern void auth_des P((u_long *, u_char *));
+extern void auth_delkeys P((void));
+extern int auth_parity P((u_long *));
+extern void auth_setkey P((u_long, u_long *));
+extern void auth_subkeys P((u_long *, u_char *, u_char *));
+#endif
+
+extern void auth1crypt P((u_long, u_int32 *, int));
+extern int auth2crypt P((u_long, u_int32 *, int));
+extern void auth_delkeys P((void));
+extern int auth_havekey P((u_long));
+extern int authdecrypt P((u_long, u_int32 *, int, int));
+extern int authencrypt P((u_long, u_int32 *, int));
+extern int authhavekey P((u_long));
+extern int authistrusted P((u_long));
+extern int authreadkeys P((const char *));
+extern void authtrust P((u_long, int));
+extern int authusekey P((u_long, int, const u_char *));
+
+extern u_long calleapwhen P((u_long));
+extern u_long calyearstart P((u_long));
+extern const char *clockname P((int));
+extern int clocktime P((int, int, int, int, int, u_long, u_long *, u_int32 *));
+#if defined SYS_WINNT && defined DEBUG
+# define emalloc(_c) debug_emalloc(_c, __FILE__, __LINE__)
+extern void * debug_emalloc P((u_int, char *, int));
+#else
+extern void * emalloc P((u_int));
+#endif
+extern int ntp_getopt P((int, char **, const char *));
+extern void init_auth P((void));
+extern void init_lib P((void));
+extern void init_random P((void));
+extern struct savekey *auth_findkey P((u_long));
+extern int auth_moremem P((void));
+extern int ymd2yd P((int, int, int));
+
+#ifdef DES
+extern int DESauthdecrypt P((u_char *, u_int32 *, int, int));
+extern int DESauthencrypt P((u_char *, u_int32 *, int));
+extern void DESauth_setkey P((u_long, const u_int32 *));
+extern void DESauth_subkeys P((const u_int32 *, u_char *, u_char *));
+extern void DESauth_des P((u_int32 *, u_char *));
+extern int DESauth_parity P((u_int32 *));
+#endif /* DES */
+
+#ifdef MD5
+extern int MD5authdecrypt P((u_char *, u_int32 *, int, int));
+extern int MD5authencrypt P((u_char *, u_int32 *, int));
+extern void MD5auth_setkey P((u_long, const u_char *, const int));
+extern u_long session_key P((u_int32, u_int32, u_long, u_long));
+#endif /* MD5 */
+
+extern int atoint P((const char *, long *));
+extern int atouint P((const char *, u_long *));
+extern int hextoint P((const char *, u_long *));
+extern char * humandate P((u_long));
+extern char * humanlogtime P((void));
+extern char * inttoa P((long));
+extern char * mfptoa P((u_long, u_long, int));
+extern char * mfptoms P((u_long, u_long, int));
+extern const char * modetoa P((int));
+extern const char * eventstr P((int));
+extern const char * ceventstr P((int));
+extern char * statustoa P((int, int));
+extern const char * sysstatstr P((int));
+extern const char * peerstatstr P((int));
+extern const char * clockstatstr P((int));
+extern u_int32 netof P((u_int32));
+extern char * numtoa P((u_int32));
+extern char * numtohost P((u_int32));
+extern int octtoint P((const char *, u_long *));
+extern u_long ranp2 P((int));
+extern char * refnumtoa P((u_int32));
+extern int tsftomsu P((u_long, int));
+extern char * uinttoa P((u_long));
+
+extern int decodenetnum P((const char *, u_int32 *));
+
+extern const char * FindConfig P((const char *));
+
+extern void signal_no_reset P((int, RETSIGTYPE (*func)(int)));
+
+extern void getauthkeys P((char *));
+extern void auth_agekeys P((void));
+extern void rereadkeys P((void));
+
+/*
+ * Variable declarations for libntp.
+ */
+
+/*
+ * Defined by any program.
+ */
+extern volatile int debug; /* debugging flag */
+
+/* authkeys.c */
+extern u_long authkeynotfound; /* keys not found */
+extern u_long authkeylookups; /* calls to lookup keys */
+extern u_long authnumkeys; /* number of active keys */
+extern u_long authkeyexpired; /* key lifetime expirations */
+extern u_long authkeyuncached; /* cache misses */
+extern u_long authencryptions; /* calls to encrypt */
+extern u_long authdecryptions; /* calls to decrypt */
+
+extern int authnumfreekeys;
+
+/*
+ * The key cache. We cache the last key we looked at here.
+ */
+extern u_long cache_keyid; /* key identifier */
+extern u_char * cache_key; /* key pointer */
+extern u_int cache_keylen; /* key length */
+
+/* clocktypes.c */
+struct clktype;
+extern struct clktype clktypes[];
+
+/* getopt.c */
+extern char * ntp_optarg; /* global argument pointer */
+extern int ntp_optind; /* global argv index */
+
+/* machines.c */
+extern const char *set_tod_using;
+
+/* mexit.c */
+#if defined SYS_WINNT || defined SYS_CYGWIN32
+extern HANDLE hServDoneEvent;
+#endif
+
+/* systime.c */
+extern int systime_10ms_ticks; /* adj sysclock in 10ms increments */
+
+extern double sys_maxfreq; /* max frequency correction */
+
+/* version.c */
+extern const char *Version; /* version declaration */
diff --git a/contrib/ntp/include/ntp_string.h b/contrib/ntp/include/ntp_string.h
new file mode 100644
index 000000000000..f7f0092ae493
--- /dev/null
+++ b/contrib/ntp/include/ntp_string.h
@@ -0,0 +1,48 @@
+/*
+ * Define string ops: strchr strrchr memcmp memmove memset
+ */
+
+#ifndef _ntp_string_h
+#define _ntp_string_h
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_MEMORY_H
+# include <memory.h>
+#endif
+
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+#ifdef HAVE_BSTRING_H
+# include <bstring.h>
+#endif
+
+#ifndef STDC_HEADERS
+# ifndef HAVE_STRCHR
+# include <strings.h>
+# define strchr index
+# define strrchr rindex
+# endif
+# ifndef __GNUC__
+char *strchr(), *strrchr();
+# endif
+# ifndef HAVE_MEMCPY
+# define NTP_NEED_BOPS
+# endif
+#endif /* STDC_HEADERS */
+
+#ifdef NTP_NEED_BOPS
+# define memcmp(a,b,c) bcmp(a,b,(int)c)
+# define memmove(t,f,c) bcopy(f,t,(int)c)
+# define memcpy(t,f,c) bcopy(f,t,(int)c)
+# define memset(a,x,c) if (x == 0x00) bzero(a,(int)c); else ntp_memset((char*)a,x,c)
+
+void ntp_memset P((char *, int, int));
+
+#endif /* NTP_NEED_BOPS */
+
+#endif /* _ntp_string_h */
diff --git a/contrib/ntp/include/ntp_syscall.h b/contrib/ntp/include/ntp_syscall.h
new file mode 100644
index 000000000000..ff649c9a10df
--- /dev/null
+++ b/contrib/ntp/include/ntp_syscall.h
@@ -0,0 +1,48 @@
+/*
+ * ntp_syscall.h - various ways to perform the ntp_adjtime() and ntp_gettime()
+ * system calls.
+ */
+
+#ifndef NTP_SYSCALL_H
+#define NTP_SYSCALL_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_SYS_TIMEX_H
+# include <sys/timex.h>
+#endif
+
+#ifdef NTP_SYSCALLS_STD
+# define ntp_adjtime(t) syscall(SYS_ntp_adjtime, (t))
+# define ntp_gettime(t) syscall(SYS_ntp_gettime, (t))
+#else /* !NTP_SYSCALLS_STD */
+# ifdef HAVE___ADJTIMEX
+extern int __adjtimex P((struct timex *));
+
+# define ntp_adjtime(t) __adjtimex((t))
+
+static inline int
+ntp_gettime(
+ struct ntptimeval *ntv
+ )
+{
+ struct timex tntx;
+ int result;
+
+ tntx.modes = 0;
+ result = __adjtimex (&tntx);
+ ntv->time = tntx.time;
+ ntv->maxerror = tntx.maxerror;
+ ntv->esterror = tntx.esterror;
+ return(result);
+}
+# else /* !HAVE__ADJTIMEX */
+# ifdef HAVE___NTP_GETTIME
+# define ntp_gettime(t) __ntp_gettime((t))
+# endif
+# endif /* !HAVE_ADJTIMEX */
+#endif /* !NTP_SYSCALLS_STD */
+
+#endif /* NTP_SYSCALL_H */
diff --git a/contrib/ntp/include/ntp_syslog.h b/contrib/ntp/include/ntp_syslog.h
new file mode 100644
index 000000000000..8e47c5673982
--- /dev/null
+++ b/contrib/ntp/include/ntp_syslog.h
@@ -0,0 +1,77 @@
+/*
+ * A hack for platforms which require specially built syslog facilities
+ */
+
+#ifndef NTP_SYSLOG_H
+#define NTP_SYSLOG_H
+
+#ifdef GIZMO
+# include "gizmo_syslog.h"
+#else /* !GIZMO */
+
+# ifdef VMS
+extern void msyslog();
+# else
+# ifndef SYS_VXWORKS
+# include <syslog.h>
+# endif
+# endif /* VMS */
+
+# include <stdio.h>
+
+#endif /* GIZMO */
+
+extern int syslogit;
+extern FILE *syslog_file;
+
+#if defined(VMS) || defined (SYS_VXWORKS)
+#define LOG_EMERG 0 /* system is unusable */
+#define LOG_ALERT 1 /* action must be taken immediately */
+#define LOG_CRIT 2 /* critical conditions */
+#define LOG_ERR 3 /* error conditions */
+#define LOG_WARNING 4 /* warning conditions */
+#define LOG_NOTICE 5 /* normal but signification condition */
+#define LOG_INFO 6 /* informational */
+#define LOG_DEBUG 7 /* debug-level messages */
+#endif /* VMS || VXWORKS */
+
+/*
+ * syslog output control
+ */
+#define NLOG_INFO 0x00000001
+#define NLOG_EVENT 0x00000002
+#define NLOG_STATUS 0x00000004
+#define NLOG_STATIST 0x00000008
+
+#define NLOG_OSYS 0 /* offset for system flags */
+#define NLOG_SYSMASK 0x0000000F /* system log events */
+#define NLOG_SYSINFO 0x00000001 /* system info log events */
+#define NLOG_SYSEVENT 0x00000002 /* system events */
+#define NLOG_SYSSTATUS 0x00000004 /* system status (sync/unsync) */
+#define NLOG_SYSSTATIST 0x00000008 /* system statistics output */
+
+#define NLOG_OPEER 4 /* offset for peer flags */
+#define NLOG_PEERMASK 0x000000F0 /* peer log events */
+#define NLOG_PEERINFO 0x00000010 /* peer info log events */
+#define NLOG_PEEREVENT 0x00000020 /* peer events */
+#define NLOG_PEERSTATUS 0x00000040 /* peer status (sync/unsync) */
+#define NLOG_PEERSTATIST 0x00000080 /* peer statistics output */
+
+#define NLOG_OCLOCK 8 /* offset for clock flags */
+#define NLOG_CLOCKMASK 0x00000F00 /* clock log events */
+#define NLOG_CLOCKINFO 0x00000100 /* clock info log events */
+#define NLOG_CLOCKEVENT 0x00000200 /* clock events */
+#define NLOG_CLOCKSTATUS 0x00000400 /* clock status (sync/unsync) */
+#define NLOG_CLOCKSTATIST 0x00000800 /* clock statistics output */
+
+#define NLOG_OSYNC 12 /* offset for sync flags */
+#define NLOG_SYNCMASK 0x0000F000 /* sync log events */
+#define NLOG_SYNCINFO 0x00001000 /* sync info log events */
+#define NLOG_SYNCEVENT 0x00002000 /* sync events */
+#define NLOG_SYNCSTATUS 0x00004000 /* sync status (sync/unsync) */
+#define NLOG_SYNCSTATIST 0x00008000 /* sync statistics output */
+
+extern unsigned long ntp_syslogmask;
+#define NLOG(_X_) if (ntp_syslogmask & (_X_))
+
+#endif /* NTP_SYSLOG_H */
diff --git a/contrib/ntp/include/ntp_types.h b/contrib/ntp/include/ntp_types.h
new file mode 100644
index 000000000000..820c72aeedd1
--- /dev/null
+++ b/contrib/ntp/include/ntp_types.h
@@ -0,0 +1,69 @@
+/*
+ * ntp_types.h - defines how int32 and u_int32 are treated.
+ * For 64 bit systems like the DEC Alpha, they have to be defined
+ * as int and u_int.
+ * For 32 bit systems, define them as long and u_long
+ */
+#include "ntp_machine.h"
+
+#ifndef _NTP_TYPES_
+#define _NTP_TYPES_
+
+/*
+ * This is another naming conflict.
+ * On NetBSD for MAC the macro "mac" is defined as 1
+ * this is fun for us as a packet structure contains an
+ * optional "mac" member - severe confusion results 8-)
+ * As we hopefully do not have to rely on that macro we
+ * just undefine that.
+ */
+#ifdef mac
+#undef mac
+#endif
+
+/*
+ * Set up for prototyping
+ */
+#ifndef P
+#if defined(__STDC__) || defined(HAVE_PROTOTYPES)
+#define P(x) x
+#else /* not __STDC__ and not HAVE_PROTOTYPES */
+#define P(x) ()
+#endif /* not __STDC__ and HAVE_PROTOTYPES */
+#endif /* P */
+
+/*
+ * VMS DECC (v4.1), {u_char,u_short,u_long} are only in SOCKET.H,
+ * and u_int isn't defined anywhere
+ */
+#if defined(VMS)
+#include <socket.h>
+typedef unsigned int u_int;
+/*
+ * Note: VMS DECC has long == int (even on __alpha),
+ * so the distinction below doesn't matter
+ */
+#endif /* VMS */
+
+#if (SIZEOF_INT == 4)
+# ifndef int32
+# define int32 int
+# endif
+# ifndef u_int32
+# define u_int32 unsigned int
+# endif
+#else /* not sizeof(int) == 4 */
+# if (SIZEOF_LONG == 4)
+# else /* not sizeof(long) == 4 */
+# ifndef int32
+# define int32 long
+# endif
+# ifndef u_int32
+# define u_int32 unsigned long
+# endif
+# endif /* not sizeof(long) == 4 */
+# include "Bletch: what's 32 bits on this machine?"
+#endif /* not sizeof(int) == 4 */
+
+#endif /* _NTP_TYPES_ */
+
diff --git a/contrib/ntp/include/ntp_unixtime.h b/contrib/ntp/include/ntp_unixtime.h
new file mode 100644
index 000000000000..9dd23f0e8eda
--- /dev/null
+++ b/contrib/ntp/include/ntp_unixtime.h
@@ -0,0 +1,132 @@
+/*
+ * ntp_unixtime.h - contains constants and macros for converting between
+ * NTP time stamps (l_fp) and Unix times (struct timeval)
+ */
+
+#include "ntp_types.h"
+
+#include <sys/time.h>
+
+/* gettimeofday() takes two args in BSD and only one in SYSV */
+# if defined(HAVE_SYS_TIMERS_H) && defined(HAVE_GETCLOCK)
+# include <sys/timers.h>
+int getclock (int clock_type, struct timespec *tp);
+/* Don't #define GETTIMEOFDAY because we shouldn't be using it in this case. */
+# define SETTIMEOFDAY(a, b) (settimeofday(a, b))
+# else /* not (HAVE_SYS_TIMERS_H && HAVE_GETCLOCK) */
+# ifdef SYSV_TIMEOFDAY
+# define GETTIMEOFDAY(a, b) (gettimeofday(a))
+# define SETTIMEOFDAY(a, b) (settimeofday(a))
+# else /* ! SYSV_TIMEOFDAY */
+#if defined SYS_CYGWIN32
+# define GETTIMEOFDAY(a, b) (gettimeofday(a, b))
+# define SETTIMEOFDAY(a, b) (settimeofday_NT(a))
+#else
+# define GETTIMEOFDAY(a, b) (gettimeofday(a, b))
+# define SETTIMEOFDAY(a, b) (settimeofday(a, b))
+#endif
+# endif /* SYSV_TIMEOFDAY */
+# endif /* not (HAVE_SYS_TIMERS_H && HAVE_GETCLOCK) */
+
+/*
+ * Time of day conversion constant. Ntp's time scale starts in 1900,
+ * Unix in 1970.
+ */
+#define JAN_1970 0x83aa7e80 /* 2208988800 1970 - 1900 in seconds */
+
+/*
+ * These constants are used to round the time stamps computed from
+ * a struct timeval to the microsecond (more or less). This keeps
+ * things neat.
+ */
+#define TS_MASK 0xfffff000 /* mask to usec, for time stamps */
+#define TS_ROUNDBIT 0x00000800 /* round at this bit */
+
+
+/*
+ * Convert usec to a time stamp fraction. If you use this the program
+ * must include the following declarations:
+ */
+extern u_long ustotslo[];
+extern u_long ustotsmid[];
+extern u_long ustotshi[];
+
+#define TVUTOTSF(tvu, tsf) \
+ (tsf) = ustotslo[(tvu) & 0xff] \
+ + ustotsmid[((tvu) >> 8) & 0xff] \
+ + ustotshi[((tvu) >> 16) & 0xf]
+
+/*
+ * Convert a struct timeval to a time stamp.
+ */
+#define TVTOTS(tv, ts) \
+ do { \
+ (ts)->l_ui = (u_long)(tv)->tv_sec; \
+ TVUTOTSF((tv)->tv_usec, (ts)->l_uf); \
+ } while(0)
+
+#define sTVTOTS(tv, ts) \
+ do { \
+ int isneg = 0; \
+ long usec; \
+ (ts)->l_ui = (tv)->tv_sec; \
+ usec = (tv)->tv_usec; \
+ if (((tv)->tv_sec < 0) || ((tv)->tv_usec < 0)) { \
+ usec = -usec; \
+ (ts)->l_ui = -(ts)->l_ui; \
+ isneg = 1; \
+ } \
+ TVUTOTSF(usec, (ts)->l_uf); \
+ if (isneg) { \
+ L_NEG((ts)); \
+ } \
+ } while(0)
+
+/*
+ * TV_SHIFT is used to turn the table result into a usec value. To round,
+ * add in TV_ROUNDBIT before shifting
+ */
+#define TV_SHIFT 3
+#define TV_ROUNDBIT 0x4
+
+
+/*
+ * Convert a time stamp fraction to microseconds. The time stamp
+ * fraction is assumed to be unsigned. To use this in a program, declare:
+ */
+extern long tstouslo[];
+extern long tstousmid[];
+extern long tstoushi[];
+
+#define TSFTOTVU(tsf, tvu) \
+ (tvu) = (tstoushi[((tsf) >> 24) & 0xff] \
+ + tstousmid[((tsf) >> 16) & 0xff] \
+ + tstouslo[((tsf) >> 9) & 0x7f] \
+ + TV_ROUNDBIT) >> TV_SHIFT
+/*
+ * Convert a time stamp to a struct timeval. The time stamp
+ * has to be positive.
+ */
+#define TSTOTV(ts, tv) \
+ do { \
+ (tv)->tv_sec = (ts)->l_ui; \
+ TSFTOTVU((ts)->l_uf, (tv)->tv_usec); \
+ if ((tv)->tv_usec == 1000000) { \
+ (tv)->tv_sec++; \
+ (tv)->tv_usec = 0; \
+ } \
+ } while (0)
+
+/*
+ * Convert milliseconds to a time stamp fraction. This shouldn't be
+ * here, but it is convenient since the guys who use the definition will
+ * often be including this file anyway.
+ */
+extern u_long msutotsflo[];
+extern u_long msutotsfhi[];
+
+#define MSUTOTSF(msu, tsf) \
+ (tsf) = msutotsfhi[((msu) >> 5) & 0x1f] + msutotsflo[(msu) & 0x1f]
+
+extern char * tvtoa P((const struct timeval *));
+extern char * utvtoa P((const struct timeval *));
diff --git a/contrib/ntp/include/ntpd.h b/contrib/ntp/include/ntpd.h
new file mode 100644
index 000000000000..1a83d6eb0a6c
--- /dev/null
+++ b/contrib/ntp/include/ntpd.h
@@ -0,0 +1,381 @@
+/*
+ * ntpd.h - Prototypes for ntpd.
+ */
+
+#include "ntp_syslog.h"
+#include "ntp_fp.h"
+#include "ntp.h"
+#include "ntp_select.h"
+#include "ntp_malloc.h"
+#include "ntp_refclock.h"
+#include "recvbuff.h"
+
+#define MAXINTERFACES 512
+
+#ifdef SYS_WINNT
+#define exit service_exit
+extern void service_exit (int);
+/* declare the service threads */
+void service_main (DWORD, LPTSTR *);
+void service_ctrl (DWORD);
+void worker_thread (void *);
+#define sleep(x) Sleep((DWORD) x * 1000 /* milliseconds */ );
+#else
+#define closesocket close
+#endif /* SYS_WINNT */
+
+/* ntp_config.c */
+extern void getstartup P((int, char **));
+extern void getconfig P((int, char **));
+
+/* ntp_config.c */
+extern void ctl_clr_stats P((void));
+extern int ctlclrtrap P((struct sockaddr_in *, struct interface *, int));
+extern u_short ctlpeerstatus P((struct peer *));
+extern int ctlsettrap P((struct sockaddr_in *, struct interface *, int, int));
+extern u_short ctlsysstatus P((void));
+extern void init_control P((void));
+extern void process_control P((struct recvbuf *, int));
+extern void report_event P((int, struct peer *));
+
+extern double fabs P((double));
+extern double sqrt P((double));
+
+/* ntp_control.c */
+/*
+ * Structure for translation tables between internal system
+ * variable indices and text format.
+ */
+struct ctl_var {
+ u_short code;
+ u_short flags;
+ char *text;
+};
+/*
+ * Flag values
+ */
+#define CAN_READ 0x01
+#define CAN_WRITE 0x02
+
+#define DEF 0x20
+#define PADDING 0x40
+#define EOV 0x80
+
+#define RO (CAN_READ)
+#define WO (CAN_WRITE)
+#define RW (CAN_READ|CAN_WRITE)
+
+extern char * add_var P((struct ctl_var **, unsigned long, int));
+extern void free_varlist P((struct ctl_var *));
+extern void set_var P((struct ctl_var **, const char *, unsigned long, int));
+extern void set_sys_var P((char *, unsigned long, int));
+
+/* ntp_intres.c */
+extern void ntp_intres P((void));
+
+/* ntp_io.c */
+extern struct interface *findbcastinter P((struct sockaddr_in *));
+extern struct interface *findinterface P((struct sockaddr_in *));
+
+extern void init_io P((void));
+extern void input_handler P((l_fp *));
+extern void io_clr_stats P((void));
+extern void io_setbclient P((void));
+extern void io_unsetbclient P((void));
+extern void io_multicast_add P((u_int32));
+extern void io_multicast_del P((u_int32));
+extern void kill_asyncio P((void));
+
+extern void sendpkt P((struct sockaddr_in *, struct interface *, int, struct pkt *, int));
+#ifdef HAVE_SIGNALED_IO
+extern void wait_for_signal P((void));
+extern void unblock_io_and_alarm P((void));
+extern void block_io_and_alarm P((void));
+#endif
+
+/* ntp_leap.c */
+extern void init_leap P((void));
+extern void leap_process P((void));
+extern int leap_setleap P((int, int));
+/*
+ * there seems to be a bug in the IRIX 4 compiler which prevents
+ * u_char from beeing used in prototyped functions.
+ * This is also true AIX compiler.
+ * So give up and define it to be int. WLJ
+ */
+extern int leap_actual P((int));
+
+/* ntp_loopfilter.c */
+extern void init_loopfilter P((void));
+extern int local_clock P((struct peer *, double, double));
+extern void adj_host_clock P((void));
+extern void loop_config P((int, double));
+
+/* ntp_monitor.c */
+extern void init_mon P((void));
+extern void mon_start P((int));
+extern void mon_stop P((int));
+extern void ntp_monitor P((struct recvbuf *));
+
+/* ntp_peer.c */
+extern void init_peer P((void));
+extern struct peer *findexistingpeer P((struct sockaddr_in *, struct peer *, int));
+extern struct peer *findpeer P((struct sockaddr_in *, struct interface *, int, int, int *));
+extern struct peer *findpeerbyassoc P((int));
+extern struct peer *newpeer P((struct sockaddr_in *, struct interface *, int, int, int, int, int, u_long));
+extern void peer_all_reset P((void));
+extern void peer_clr_stats P((void));
+extern struct peer *peer_config P((struct sockaddr_in *, struct interface *, int, int, int, int, int, int, u_long));
+extern void peer_reset P((struct peer *));
+extern int peer_unconfig P((struct sockaddr_in *, struct interface *, int));
+extern void unpeer P((struct peer *));
+extern void key_expire_all P((void));
+extern struct peer *findmanycastpeer P((l_fp *));
+extern void peer_config_manycast P((struct peer *, struct peer *));
+
+/* ntp_proto.c */
+extern void transmit P((struct peer *));
+extern void receive P((struct recvbuf *));
+extern void peer_clear P((struct peer *));
+extern int process_packet P((struct peer *, struct pkt *, l_fp *));
+extern void clock_select P((void));
+
+/*
+ * there seems to be a bug in the IRIX 4 compiler which prevents
+ * u_char from beeing used in prototyped functions.
+ * This is also true AIX compiler.
+ * So give up and define it to be int. WLJ
+ */
+extern void poll_update P((struct peer *, int));
+
+extern void clear P((struct peer *));
+extern void clock_filter P((struct peer *, double, double, double));
+extern void init_proto P((void));
+extern void proto_config P((int, u_long, double));
+extern void proto_clr_stats P((void));
+
+#ifdef REFCLOCK
+/* ntp_refclock.c */
+extern int refclock_newpeer P((struct peer *));
+extern void refclock_unpeer P((struct peer *));
+extern void refclock_receive P((struct peer *));
+extern void refclock_transmit P((struct peer *));
+extern void init_refclock P((void));
+#endif /* REFCLOCK */
+
+/* ntp_request.c */
+extern void init_request P((void));
+extern void process_private P((struct recvbuf *, int));
+
+/* ntp_restrict.c */
+extern void init_restrict P((void));
+extern int restrictions P((struct sockaddr_in *));
+extern void hack_restrict P((int, struct sockaddr_in *, struct sockaddr_in *, int, int));
+
+/* ntp_timer.c */
+extern void init_timer P((void));
+extern void timer P((void));
+extern void timer_clr_stats P((void));
+
+/* ntp_util.c */
+extern void init_util P((void));
+extern void hourly_stats P((void));
+extern void stats_config P((int, char *));
+extern void record_peer_stats P((struct sockaddr_in *, int, double, double, double, double));
+extern void record_loop_stats P((void));
+extern void record_clock_stats P((struct sockaddr_in *, const char *));
+extern void record_raw_stats P((struct sockaddr_in *, struct sockaddr_in *, l_fp *, l_fp *, l_fp *, l_fp *));
+
+/*
+ * Variable declarations for ntpd.
+ */
+
+/* ntp_config.c */
+extern char const * progname;
+extern char sys_phone[][MAXDIAL]; /* ACTS phone numbers */
+extern char pps_device[]; /* PPS device name */
+#if defined(HAVE_SCHED_SETSCHEDULER)
+extern int config_priority_override;
+extern int config_priority;
+#endif
+
+/* ntp_control.c */
+struct ctl_trap;
+extern struct ctl_trap ctl_trap[];
+extern int num_ctl_traps;
+extern u_long ctl_auth_keyid; /* keyid used for authenticating write requests */
+
+/*
+ * Statistic counters to keep track of requests and responses.
+ */
+extern u_long ctltimereset; /* time stats reset */
+extern u_long numctlreq; /* number of requests we've received */
+extern u_long numctlbadpkts; /* number of bad control packets */
+extern u_long numctlresponses; /* number of resp packets sent with data */
+extern u_long numctlfrags; /* number of fragments sent */
+extern u_long numctlerrors; /* number of error responses sent */
+extern u_long numctltooshort; /* number of too short input packets */
+extern u_long numctlinputresp; /* number of responses on input */
+extern u_long numctlinputfrag; /* number of fragments on input */
+extern u_long numctlinputerr; /* number of input pkts with err bit set */
+extern u_long numctlbadoffset; /* number of input pkts with nonzero offset */
+extern u_long numctlbadversion; /* number of input pkts with unknown version */
+extern u_long numctldatatooshort; /* data too short for count */
+extern u_long numctlbadop; /* bad op code found in packet */
+extern u_long numasyncmsgs; /* number of async messages we've sent */
+
+/* ntp_intres.c */
+extern u_long req_keyid; /* request keyid */
+extern char * req_file; /* name of the file with configuration info */
+
+/*
+ * Other statistics of possible interest
+ */
+extern volatile u_long packets_dropped; /* total number of packets dropped on reception */
+extern volatile u_long packets_ignored; /* packets received on wild card interface */
+extern volatile u_long packets_received;/* total number of packets received */
+extern u_long packets_sent; /* total number of packets sent */
+extern u_long packets_notsent; /* total number of packets which couldn't be sent */
+
+extern volatile u_long handler_calls; /* number of calls to interrupt handler */
+extern volatile u_long handler_pkts; /* number of pkts received by handler */
+extern u_long io_timereset; /* time counters were reset */
+
+/*
+ * Interface stuff
+ */
+extern struct interface *any_interface; /* pointer to default interface */
+extern struct interface *loopback_interface; /* point to loopback interface */
+
+/*
+ * File descriptor masks etc. for call to select
+ */
+extern fd_set activefds;
+extern int maxactivefd;
+
+/* ntp_loopfilter.c */
+extern double drift_comp; /* clock frequency (ppm) */
+extern double clock_stability; /* clock stability (ppm) */
+extern double clock_max; /* max offset allowed before step (s) */
+extern u_long pps_control; /* last pps sample time */
+
+/*
+ * Clock state machine control flags
+ */
+extern int ntp_enable; /* clock discipline enabled */
+extern int pll_control; /* kernel support available */
+extern int kern_enable; /* kernel support enabled */
+extern int ext_enable; /* external clock enabled */
+extern int pps_update; /* pps update valid */
+extern int allow_set_backward; /* step corrections allowed */
+extern int correct_any; /* corrections > 1000 s allowed */
+
+/*
+ * Clock state machine variables
+ */
+extern u_char sys_poll; /* log2 of system poll interval */
+extern int state; /* clock discipline state */
+extern int tc_counter; /* poll-adjust counter */
+extern u_long last_time; /* time of last clock update (s) */
+extern double last_offset; /* last clock offset (s) */
+extern double allan_xpt; /* Allan intercept (s) */
+extern double sys_error; /* system standard error (s) */
+
+/* ntp_monitor.c */
+extern struct mon_data mon_mru_list;
+extern struct mon_data mon_fifo_list;
+extern int mon_enabled;
+
+/* ntp_peer.c */
+extern struct peer *peer_hash[]; /* peer hash table */
+extern int peer_hash_count[]; /* count of peers in each bucket */
+extern struct peer *assoc_hash[]; /* association ID hash table */
+extern int assoc_hash_count[];
+extern int peer_free_count;
+
+/*
+ * Miscellaneous statistic counters which may be queried.
+ */
+extern u_long peer_timereset; /* time stat counters were zeroed */
+extern u_long findpeer_calls; /* number of calls to findpeer */
+extern u_long assocpeer_calls; /* number of calls to findpeerbyassoc */
+extern u_long peer_allocations; /* number of allocations from the free list */
+extern u_long peer_demobilizations; /* number of structs freed to free list */
+extern int total_peer_structs; /* number of peer structs in circulation */
+extern int peer_associations; /* number of active associations */
+
+/* ntp_proto.c */
+/*
+ * System variables are declared here. See Section 3.2 of the
+ * specification.
+ */
+extern u_char sys_leap; /* system leap indicator */
+extern u_char sys_stratum; /* stratum of system */
+extern s_char sys_precision; /* local clock precision */
+extern double sys_rootdelay; /* distance to current sync source */
+extern double sys_rootdispersion; /* dispersion of system clock */
+extern u_int32 sys_refid; /* reference source for local clock */
+extern l_fp sys_reftime; /* time we were last updated */
+extern struct peer *sys_peer; /* our current peer */
+extern u_long sys_automax; /* maximum session key lifetime */
+
+/*
+ * Nonspecified system state variables.
+ */
+extern int sys_bclient; /* we set our time to broadcasts */
+extern double sys_bdelay; /* broadcast client default delay */
+extern int sys_authenticate; /* requre authentication for config */
+extern l_fp sys_authdelay; /* authentication delay */
+extern u_long sys_private; /* private value for session seed */
+extern int sys_manycastserver; /* 1 => respond to manycast client pkts */
+
+/*
+ * Statistics counters
+ */
+extern u_long sys_stattime; /* time when we started recording */
+extern u_long sys_badstratum; /* packets with invalid stratum */
+extern u_long sys_oldversionpkt; /* old version packets received */
+extern u_long sys_newversionpkt; /* new version packets received */
+extern u_long sys_unknownversion; /* don't know version packets */
+extern u_long sys_badlength; /* packets with bad length */
+extern u_long sys_processed; /* packets processed */
+extern u_long sys_badauth; /* packets dropped because of auth */
+extern u_long sys_limitrejected; /* pkts rejected due to client count per net */
+
+/* ntp_refclock.c */
+#ifdef REFCLOCK
+#if defined(PPS) || defined(HAVE_PPSAPI)
+extern int fdpps; /* pps file descriptor */
+#endif /* PPS */
+#endif
+
+/* ntp_request.c */
+extern u_long info_auth_keyid; /* keyid used to authenticate requests */
+
+/* ntp_restrict.c */
+extern struct restrictlist *restrictlist; /* the restriction list */
+extern u_long client_limit;
+extern u_long client_limit_period;
+
+/* ntp_timer.c */
+extern volatile int alarm_flag; /* alarm flag */
+extern u_long sys_revoke; /* keys revoke timeout */
+extern volatile u_long alarm_overflow;
+extern u_long current_time; /* current time (s) */
+extern u_long timer_timereset;
+extern u_long timer_overflows;
+extern u_long timer_xmtcalls;
+
+/* ntp_util.c */
+extern int stats_control; /* write stats to fileset? */
+
+/* ntpd.c */
+extern volatile int debug; /* debugging flag */
+extern int nofork; /* no-fork flag */
+extern int initializing; /* initializing flag */
+
+/* refclock_conf.c */
+#ifdef REFCLOCK
+extern struct refclock *refclock_conf[]; /* refclock configuration table */
+extern u_char num_refclock_conf;
+#endif
diff --git a/contrib/ntp/include/parse.h b/contrib/ntp/include/parse.h
new file mode 100644
index 000000000000..56a92e95d15a
--- /dev/null
+++ b/contrib/ntp/include/parse.h
@@ -0,0 +1,391 @@
+/*
+ * /src/NTP/ntp-4/include/parse.h,v 4.5 1998/08/09 22:23:32 kardel RELEASE_19990228_A
+ *
+ * parse.h,v 4.5 1998/08/09 22:23:32 kardel RELEASE_19990228_A
+ *
+ * Copyright (C) 1989-1998 by Frank Kardel
+ * Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ */
+
+#ifndef __PARSE_H__
+#define __PARSE_H__
+#if !(defined(lint) || defined(__GNUC__))
+ static char parsehrcsid[]="parse.h,v 4.5 1998/08/09 22:23:32 kardel RELEASE_19990228_A";
+#endif
+
+#include "ntp_types.h"
+
+#include "parse_conf.h"
+
+/*
+ * we use the following datastructures in two modes
+ * either in the NTP itself where we use NTP time stamps at some places
+ * or in the kernel, where only struct timeval will be used.
+ */
+#undef PARSEKERNEL
+#if defined(KERNEL) || defined(_KERNEL)
+#ifndef PARSESTREAM
+#define PARSESTREAM
+#endif
+#endif
+#if defined(PARSESTREAM) && defined(HAVE_SYS_STREAM_H)
+#define PARSEKERNEL
+#endif
+#ifdef PARSEKERNEL
+#ifndef _KERNEL
+extern caddr_t kmem_alloc P((unsigned int));
+extern caddr_t kmem_free P((caddr_t, unsigned int));
+extern unsigned int splx P((unsigned int));
+extern unsigned int splhigh P((void));
+extern unsigned int splclock P((void));
+#define MALLOC(_X_) (char *)kmem_alloc(_X_)
+#define FREE(_X_, _Y_) kmem_free((caddr_t)_X_, _Y_)
+#else
+#include <sys/kmem.h>
+#define MALLOC(_X_) (char *)kmem_alloc(_X_, KM_SLEEP)
+#define FREE(_X_, _Y_) kmem_free((caddr_t)_X_, _Y_)
+#endif
+#else
+#define MALLOC(_X_) malloc(_X_)
+#define FREE(_X_, _Y_) free(_X_)
+#endif
+
+#if defined(PARSESTREAM) && defined(HAVE_SYS_STREAM_H)
+#include <sys/stream.h>
+#include <sys/stropts.h>
+#else /* STREAM */
+#include <stdio.h>
+#include "ntp_syslog.h"
+#ifdef DEBUG
+#define DD_PARSE 5
+#define DD_RAWDCF 4
+#define parseprintf(LEVEL, ARGS) if (debug > LEVEL) printf ARGS
+#else /* DEBUG */
+#define parseprintf(LEVEL, ARGS)
+#endif /* DEBUG */
+#endif /* PARSESTREAM */
+
+#if defined(timercmp) && defined(__GNUC__)
+#undef timercmp
+#endif
+
+#if !defined(timercmp)
+#define timercmp(tvp, uvp, cmp) \
+ ((tvp)->tv_sec cmp (uvp)->tv_sec || \
+ ((tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec))
+#endif
+
+#ifndef TIMES10
+#define TIMES10(_X_) (((_X_) << 3) + ((_X_) << 1))
+#endif
+
+/*
+ * state flags
+ */
+#define PARSEB_POWERUP 0x00000001 /* no synchronisation */
+#define PARSEB_NOSYNC 0x00000002 /* timecode currently not confirmed */
+
+/*
+ * time zone information
+ */
+#define PARSEB_ANNOUNCE 0x00000010 /* switch time zone warning (DST switch) */
+#define PARSEB_DST 0x00000020 /* DST in effect */
+#define PARSEB_UTC 0x00000040 /* UTC time */
+
+/*
+ * leap information
+ */
+#define PARSEB_LEAPDEL 0x00000100 /* LEAP deletion warning */
+#define PARSEB_LEAPADD 0x00000200 /* LEAP addition warning */
+#define PARSEB_LEAPS 0x00000300 /* LEAP warnings */
+#define PARSEB_LEAPSECOND 0x00000400 /* actual leap second */
+/*
+ * optional status information
+ */
+#define PARSEB_ALTERNATE 0x00001000 /* alternate antenna used */
+#define PARSEB_POSITION 0x00002000 /* position available */
+#define PARSEB_MESSAGE 0x00004000 /* addtitional message data */
+/*
+ * feature information
+ */
+#define PARSEB_S_LEAP 0x00010000 /* supports LEAP */
+#define PARSEB_S_ANTENNA 0x00020000 /* supports antenna information */
+#define PARSEB_S_PPS 0x00040000 /* supports PPS time stamping */
+#define PARSEB_S_POSITION 0x00080000 /* supports position information (GPS) */
+
+/*
+ * time stamp availability
+ */
+#define PARSEB_TIMECODE 0x10000000 /* valid time code sample */
+#define PARSEB_PPS 0x20000000 /* valid PPS sample */
+
+#define PARSE_TCINFO (PARSEB_ANNOUNCE|PARSEB_POWERUP|PARSEB_NOSYNC|PARSEB_DST|\
+ PARSEB_UTC|PARSEB_LEAPS|PARSEB_ALTERNATE|PARSEB_S_LEAP|\
+ PARSEB_S_LOCATION|PARSEB_TIMECODE|PARSEB_MESSAGE)
+
+#define PARSE_POWERUP(x) ((x) & PARSEB_POWERUP)
+#define PARSE_NOSYNC(x) (((x) & (PARSEB_POWERUP|PARSEB_NOSYNC)) == PARSEB_NOSYNC)
+#define PARSE_SYNC(x) (((x) & (PARSEB_POWERUP|PARSEB_NOSYNC)) == 0)
+#define PARSE_ANNOUNCE(x) ((x) & PARSEB_ANNOUNCE)
+#define PARSE_DST(x) ((x) & PARSEB_DST)
+#define PARSE_UTC(x) ((x) & PARSEB_UTC)
+#define PARSE_LEAPADD(x) (PARSE_SYNC(x) && (((x) & PARSEB_LEAPS) == PARSEB_LEAPADD))
+#define PARSE_LEAPDEL(x) (PARSE_SYNC(x) && (((x) & PARSEB_LEAPS) == PARSEB_LEAPDEL))
+#define PARSE_ALTERNATE(x) ((x) & PARSEB_ALTERNATE)
+#define PARSE_LEAPSECOND(x) (PARSE_SYNC(x) && ((x) & PARSEB_LEAP_SECOND))
+
+#define PARSE_S_LEAP(x) ((x) & PARSEB_S_LEAP)
+#define PARSE_S_ANTENNA(x) ((x) & PARSEB_S_ANTENNA)
+#define PARSE_S_PPS(x) ((x) & PARSEB_S_PPS)
+#define PARSE_S_POSITION(x) ((x) & PARSEB_S_POSITION)
+
+#define PARSE_TIMECODE(x) ((x) & PARSEB_TIMECODE)
+#define PARSE_PPS(x) ((x) & PARSEB_PPS)
+#define PARSE_POSITION(x) ((x) & PARSEB_POSITION)
+#define PARSE_MESSAGE(x) ((x) & PARSEB_MESSAGE)
+
+/*
+ * operation flags - lower nibble contains fudge flags
+ */
+#define PARSE_STATISTICS 0x08 /* enable statistics */
+#define PARSE_LEAP_DELETE 0x04 /* delete leap */
+#define PARSE_FIXED_FMT 0x10 /* fixed format */
+#define PARSE_PPSCLOCK 0x20 /* try to get PPS time stamp via ppsclock ioctl */
+
+/*
+ * size of buffers
+ */
+#define PARSE_TCMAX 400 /* maximum addition data size */
+
+typedef union timestamp
+{
+ struct timeval tv; /* timeval - kernel view */
+ l_fp fp; /* fixed point - ntp view */
+} timestamp_t;
+
+/*
+ * standard time stamp structure
+ */
+struct parsetime
+{
+ u_long parse_status; /* data status - CVT_OK, CVT_NONE, CVT_FAIL ... */
+ timestamp_t parse_time; /* PARSE timestamp */
+ timestamp_t parse_stime; /* telegram sample timestamp */
+ timestamp_t parse_ptime; /* PPS time stamp */
+ long parse_usecerror; /* sampled usec error */
+ u_long parse_state; /* current receiver state */
+ unsigned short parse_format; /* format code */
+ unsigned short parse_msglen; /* length of message */
+ unsigned char parse_msg[PARSE_TCMAX]; /* original messages */
+};
+
+typedef struct parsetime parsetime_t;
+
+/*---------- STREAMS interface ----------*/
+
+#ifdef HAVE_SYS_STREAM_H
+/*
+ * ioctls
+ */
+#define PARSEIOC_ENABLE (('D'<<8) + 'E')
+#define PARSEIOC_DISABLE (('D'<<8) + 'D')
+#define PARSEIOC_SETFMT (('D'<<8) + 'f')
+#define PARSEIOC_GETFMT (('D'<<8) + 'F')
+#define PARSEIOC_SETCS (('D'<<8) + 'C')
+#define PARSEIOC_TIMECODE (('D'<<8) + 'T')
+
+#endif
+
+/*------ IO handling flags (sorry) ------*/
+
+#define PARSE_IO_CSIZE 0x00000003
+#define PARSE_IO_CS5 0x00000000
+#define PARSE_IO_CS6 0x00000001
+#define PARSE_IO_CS7 0x00000002
+#define PARSE_IO_CS8 0x00000003
+
+/*
+ * ioctl structure
+ */
+union parsectl
+{
+ struct parsegettc
+ {
+ u_long parse_state; /* last state */
+ u_long parse_badformat; /* number of bad packets since last query */
+ unsigned short parse_format;/* last decoded format */
+ unsigned short parse_count; /* count of valid time code bytes */
+ char parse_buffer[PARSE_TCMAX+1]; /* timecode buffer */
+ } parsegettc;
+
+ struct parseformat
+ {
+ unsigned short parse_format;/* number of examined format */
+ unsigned short parse_count; /* count of valid string bytes */
+ char parse_buffer[PARSE_TCMAX+1]; /* format code string */
+ } parseformat;
+
+ struct parsesetcs
+ {
+ u_long parse_cs; /* character size (needed for stripping) */
+ } parsesetcs;
+};
+
+typedef union parsectl parsectl_t;
+
+/*------ for conversion routines --------*/
+
+struct parse /* parse module local data */
+{
+ int parse_flags; /* operation and current status flags */
+
+ int parse_ioflags; /* io handling flags (5-8 Bit control currently) */
+
+ /*
+ * private data - fixed format only
+ */
+ unsigned short parse_plen; /* length of private data */
+ void *parse_pdata; /* private data pointer */
+
+ /*
+ * time code input buffer (from RS232 or PPS)
+ */
+ unsigned short parse_index; /* current buffer index */
+ char *parse_data; /* data buffer */
+ unsigned short parse_dsize; /* size of data buffer */
+ unsigned short parse_lformat; /* last format used */
+ u_long parse_lstate; /* last state code */
+ char *parse_ldata; /* last data buffer */
+ unsigned short parse_ldsize; /* last data buffer length */
+ u_long parse_badformat; /* number of unparsable pakets */
+
+ timestamp_t parse_lastchar; /* last time a character was received */
+ parsetime_t parse_dtime; /* external data prototype */
+};
+
+typedef struct parse parse_t;
+
+struct clocktime /* clock time broken up from time code */
+{
+ long day;
+ long month;
+ long year;
+ long hour;
+ long minute;
+ long second;
+ long usecond;
+ long utcoffset; /* in seconds */
+ time_t utctime; /* the actual time - alternative to date/time */
+ u_long flags; /* current clock status */
+};
+
+typedef struct clocktime clocktime_t;
+
+/*
+ * parser related return/error codes
+ */
+#define CVT_MASK (unsigned)0x0000000F /* conversion exit code */
+#define CVT_NONE (unsigned)0x00000001 /* format not applicable */
+#define CVT_FAIL (unsigned)0x00000002 /* conversion failed - error code returned */
+#define CVT_OK (unsigned)0x00000004 /* conversion succeeded */
+#define CVT_SKIP (unsigned)0x00000008 /* conversion succeeded */
+#define CVT_ADDITIONAL (unsigned)0x00000010 /* additional data is available */
+#define CVT_BADFMT (unsigned)0x00000100 /* general format error - (unparsable) */
+#define CVT_BADDATE (unsigned)0x00000200 /* date field incorrect */
+#define CVT_BADTIME (unsigned)0x00000400 /* time field incorrect */
+
+/*
+ * return codes used by special input parsers
+ */
+#define PARSE_INP_SKIP 0x00 /* discard data - may have been consumed */
+#define PARSE_INP_TIME 0x01 /* time code assembled */
+#define PARSE_INP_PARSE 0x02 /* parse data using normal algorithm */
+#define PARSE_INP_DATA 0x04 /* additional data to pass up */
+#define PARSE_INP_SYNTH 0x08 /* just pass up synthesized time */
+
+/*
+ * PPS edge info
+ */
+#define SYNC_ZERO 0x00
+#define SYNC_ONE 0x01
+
+struct clockformat
+{
+ /* special input protocol - implies fixed format */
+ u_long (*input) P((parse_t *, unsigned int, timestamp_t *));
+ /* conversion routine */
+ u_long (*convert) P((unsigned char *, int, struct format *, clocktime_t *, void *));
+ /* routine for handling RS232 sync events (time stamps) */
+ /* PPS input routine */
+ u_long (*syncpps) P((parse_t *, int, timestamp_t *));
+ /* time code synthesizer */
+
+ void *data; /* local parameters */
+ const char *name; /* clock format name */
+ unsigned short length; /* maximum length of data packet */
+ unsigned short plen; /* length of private data - implies fixed format */
+};
+
+typedef struct clockformat clockformat_t;
+
+/*
+ * parse interface
+ */
+extern int parse_ioinit P((parse_t *));
+extern void parse_ioend P((parse_t *));
+extern int parse_ioread P((parse_t *, unsigned int, timestamp_t *));
+extern int parse_iopps P((parse_t *, int, timestamp_t *));
+extern void parse_iodone P((parse_t *));
+extern int parse_timecode P((parsectl_t *, parse_t *));
+extern int parse_getfmt P((parsectl_t *, parse_t *));
+extern int parse_setfmt P((parsectl_t *, parse_t *));
+extern int parse_setcs P((parsectl_t *, parse_t *));
+
+extern unsigned int parse_restart P((parse_t *, unsigned int));
+extern unsigned int parse_addchar P((parse_t *, unsigned int));
+extern unsigned int parse_end P((parse_t *));
+
+extern int Strok P((const unsigned char *, const unsigned char *));
+extern int Stoi P((const unsigned char *, long *, int));
+
+extern time_t parse_to_unixtime P((clocktime_t *, u_long *));
+extern u_long updatetimeinfo P((parse_t *, u_long));
+extern void syn_simple P((parse_t *, timestamp_t *, struct format *, u_long));
+extern u_long pps_simple P((parse_t *, int, timestamp_t *));
+extern u_long pps_one P((parse_t *, int, timestamp_t *));
+extern u_long pps_zero P((parse_t *, int, timestamp_t *));
+extern int parse_timedout P((parse_t *, timestamp_t *, struct timeval *));
+
+#endif
+
+/*
+ * History:
+ *
+ * parse.h,v
+ * Revision 4.5 1998/08/09 22:23:32 kardel
+ * 4.0.73e2 adjustments
+ *
+ * Revision 4.4 1998/06/14 21:09:27 kardel
+ * Sun acc cleanup
+ *
+ * Revision 4.3 1998/06/13 11:49:25 kardel
+ * STREAM macro gone in favor of HAVE_SYS_STREAM_H
+ *
+ * Revision 4.2 1998/06/12 15:14:25 kardel
+ * fixed prototypes
+ *
+ * Revision 4.1 1998/05/24 10:07:59 kardel
+ * removed old data structure cruft (new input model)
+ * new PARSE_INP* macros for input handling
+ * removed old SYNC_* macros from old input model
+ * (struct clockformat): removed old parse functions in favor of the
+ * new input model
+ * updated prototypes
+ *
+ * form V3 3.31 - log info deleted 1998/04/11 kardel
+ */
diff --git a/contrib/ntp/include/parse_conf.h b/contrib/ntp/include/parse_conf.h
new file mode 100644
index 000000000000..0a30eb635203
--- /dev/null
+++ b/contrib/ntp/include/parse_conf.h
@@ -0,0 +1,54 @@
+/*
+ * /src/NTP/ntp-4/include/parse_conf.h,v 4.2 1998/06/14 21:09:28 kardel RELEASE_19990228_A
+ *
+ * parse_conf.h,v 4.2 1998/06/14 21:09:28 kardel RELEASE_19990228_A
+ *
+ * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998 by Frank Kardel
+ * Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ */
+
+#ifndef __PARSE_CONF_H__
+#define __PARSE_CONF_H__
+#if !(defined(lint) || defined(__GNUC__))
+ static char prshrcsid[] = "parse_conf.h,v 4.2 1998/06/14 21:09:28 kardel RELEASE_19990228_A";
+#endif
+
+/*
+ * field location structure
+ */
+#define O_DAY 0
+#define O_MONTH 1
+#define O_YEAR 2
+#define O_HOUR 3
+#define O_MIN 4
+#define O_SEC 5
+#define O_WDAY 6
+#define O_FLAGS 7
+#define O_ZONE 8
+#define O_UTCHOFFSET 9
+#define O_UTCMOFFSET 10
+#define O_UTCSOFFSET 11
+#define O_COUNT (O_UTCSOFFSET+1)
+
+#define MBG_EXTENDED 0x00000001
+
+/*
+ * see below for field offsets
+ */
+
+struct format
+{
+ struct foff
+ {
+ unsigned short offset; /* offset into buffer */
+ unsigned short length; /* length of field */
+ } field_offsets[O_COUNT];
+ const unsigned char *fixed_string; /* string with must be chars (blanks = wildcards) */
+ u_long flags;
+};
+#endif
diff --git a/contrib/ntp/include/recvbuff.h b/contrib/ntp/include/recvbuff.h
new file mode 100644
index 000000000000..687bc9659a6d
--- /dev/null
+++ b/contrib/ntp/include/recvbuff.h
@@ -0,0 +1,113 @@
+#if !defined __recvbuff_h
+#define __recvbuff_h
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "ntp.h"
+#include "ntp_fp.h"
+#include "ntp_types.h"
+
+/*
+ * recvbuf memory management
+ */
+#define RECV_INIT 10 /* 10 buffers initially */
+#define RECV_LOWAT 3 /* when we're down to three buffers get more */
+#define RECV_INC 5 /* get 5 more at a time */
+#define RECV_TOOMANY 40 /* this is way too many buffers */
+
+#if defined HAVE_IO_COMPLETION_PORT
+# include "ntp_iocompletionport.h"
+#include "ntp_timer.h"
+
+# define RECV_BLOCK_IO() EnterCriticalSection(&RecvCritSection)
+# define RECV_UNBLOCK_IO() LeaveCriticalSection(&RecvCritSection)
+
+/* Return the event which is set when items are added to the full list
+ */
+extern HANDLE get_recv_buff_event P((void));
+#else
+# define RECV_BLOCK_IO()
+# define RECV_UNBLOCK_IO()
+#endif
+
+
+/*
+ * Format of a recvbuf. These are used by the asynchronous receive
+ * routine to store incoming packets and related information.
+ */
+
+/*
+ * the maximum length NTP packet is a full length NTP control message with
+ * the maximum length message authenticator. I hate to hard-code 468 and 12,
+ * but only a few modules include ntp_control.h...
+ */
+#define RX_BUFF_SIZE (468+12+MAX_MAC_LEN)
+
+struct recvbuf {
+ struct recvbuf *next; /* next buffer in chain */
+ union {
+ struct sockaddr_in X_recv_srcadr;
+ caddr_t X_recv_srcclock;
+ struct peer *X_recv_peer;
+ } X_from_where;
+#define recv_srcadr X_from_where.X_recv_srcadr
+#define recv_srcclock X_from_where.X_recv_srcclock
+#define recv_peer X_from_where.X_recv_peer
+#if defined HAVE_IO_COMPLETION_PORT
+ IoCompletionInfo iocompletioninfo;
+ WSABUF wsabuff;
+ DWORD AddressLength;
+#else
+ struct sockaddr_in srcadr; /* where packet came from */
+#endif
+ struct interface *dstadr; /* interface datagram arrived thru */
+ int fd; /* fd on which it was received */
+ l_fp recv_time; /* time of arrival */
+ void (*receiver) P((struct recvbuf *)); /* routine to receive buffer */
+ int recv_length; /* number of octets received */
+ union {
+ struct pkt X_recv_pkt;
+ u_char X_recv_buffer[RX_BUFF_SIZE];
+ } recv_space;
+#define recv_pkt recv_space.X_recv_pkt
+#define recv_buffer recv_space.X_recv_buffer
+};
+
+extern void init_recvbuff P((int));
+
+/* freerecvbuf - make a single recvbuf available for reuse
+ */
+extern void freerecvbuf P((struct recvbuf *));
+
+
+extern struct recvbuf * getrecvbufs P((void));
+
+/* Get a free buffer (typically used so an async
+ * read can directly place data into the buffer
+ *
+ * The buffer is removed from the free list. Make sure
+ * you put it back with freerecvbuf() or
+ */
+extern struct recvbuf *get_free_recv_buffer P((void));
+
+/* Add a buffer to the full list
+ */
+extern void add_full_recv_buffer P((struct recvbuf *));
+
+/*extern void process_recv_buffers P((void)); */
+
+/* number of recvbufs on freelist */
+extern u_long free_recvbuffs P((void));
+extern u_long full_recvbuffs P((void));
+extern u_long total_recvbuffs P((void));
+extern u_long lowater_additions P((void));
+
+/* Returns the next buffer in the full list.
+ *
+ */
+extern struct recvbuf *get_full_recv_buffer P((void));
+
+#endif /* defined __recvbuff_h */
+
diff --git a/contrib/ntp/include/trimble.h b/contrib/ntp/include/trimble.h
new file mode 100644
index 000000000000..58a1a3aa8cf9
--- /dev/null
+++ b/contrib/ntp/include/trimble.h
@@ -0,0 +1,125 @@
+/*
+ * /src/NTP/ntp-4/include/trimble.h,v 4.4 1999/02/28 11:41:11 kardel RELEASE_19990228_A
+ *
+ * $Created: Sun Aug 2 16:16:49 1998 $
+ *
+ * Copyright (C) 1998 by Frank Kardel
+ */
+#ifndef TRIMBLE_H
+#define TRIMBLE_H
+
+/*
+ * Trimble packet command codes - commands being sent/received
+ * keep comments formatted as shown - they are used to generate
+ * translation tables
+ */
+#define CMD_CCLROSC 0x1D /* clear oscillator offset */
+#define CMD_CCLRRST 0x1E /* clear battery backup and RESET */
+#define CMD_CVERSION 0x1F /* return software version */
+#define CMD_CALMANAC 0x20 /* almanac */
+#define CMD_CCURTIME 0x21 /* current time */
+#define CMD_CMODESEL 0x22 /* mode select (2-d, 3-D, auto) */
+#define CMD_CINITPOS 0x23 /* initial position */
+#define CMD_CRECVPOS 0x24 /* receiver position fix mode */
+#define CMD_CRESET 0x25 /* soft reset & selftest */
+#define CMD_CRECVHEALTH 0x26 /* receiver health */
+#define CMD_CSIGNALLV 0x27 /* signal levels */
+#define CMD_CMESSAGE 0x28 /* GPS system message */
+#define CMD_CALMAHEALTH 0x29 /* almanac healt page */
+#define CMD_C2DALTITUDE 0x2A /* altitude for 2-D mode */
+#define CMD_CINITPOSLLA 0x2B /* initial position LLA */
+#define CMD_COPERPARAM 0x2C /* operating parameters */
+#define CMD_COSCOFFSET 0x2D /* oscillator offset */
+#define CMD_CSETGPSTIME 0x2E /* set GPS time */
+#define CMD_CUTCPARAM 0x2F /* UTC parameters */
+#define CMD_CACCPOSXYZ 0x31 /* accurate initial position (XYZ/ECEF) */
+#define CMD_CACCPOS 0x32 /* accurate initial position */
+#define CMD_CANALOGDIG 0x33 /* analog to digital */
+#define CMD_CSAT1SAT 0x34 /* satellite for 1-Sat mode */
+#define CMD_CIOOPTIONS 0x35 /* I/O options */
+#define CMD_CVELOCAID 0x36 /* velocity aiding of acquisition */
+#define CMD_CSTATLSTPOS 0x37 /* status and values of last pos. and vel. */
+#define CMD_CLOADSSATDT 0x38 /* load satellite system data */
+#define CMD_CSATDISABLE 0x39 /* satellite disable */
+#define CMD_CLASTRAW 0x3A /* last raw measurement */
+#define CMD_CSTATSATEPH 0x3B /* satellite ephemeris status */
+#define CMD_CSTATTRACK 0x3C /* tracking status */
+#define CMD_CCHANADGPS 0x3D /* configure channel A for differential GPS */
+#define CMD_CADDITFIX 0x3E /* additional fix data */
+#define CMD_CDGPSFIXMD 0x62 /* set/request differential GPS position fix mode */
+#define CMD_CDGPSCORR 0x65 /* differential correction status */
+#define CMD_CPOSFILT 0x71 /* position filter parameters */
+#define CMD_CHEIGHTFILT 0x73 /* height filter control */
+#define CMD_CHIGH8CNT 0x75 /* high-8 (best 4) / high-6 (overdetermined) control */
+#define CMD_CMAXDGPSCOR 0x77 /* maximum rate of DGPS corrections */
+#define CMD_CSUPER 0x8E /* super paket */
+
+#define CMD_RDATAA 0x3D /* data channel A configuration:trimble_channelA:RO */
+#define CMD_RALMANAC 0x40 /* almanac data for sat:gps_almanac:RO */
+#define CMD_RCURTIME 0x41 /* GPS time:gps_time:RO */
+#define CMD_RSPOSXYZ 0x42 /* single precision XYZ position:gps_position(XYZ):RO|DEF */
+#define CMD_RVELOXYZ 0x43 /* velocity fix (XYZ ECEF):gps_velocity(XYZ):RO|DEF */
+#define CMD_RBEST4 0x44 /* best 4 satellite selection:trimble_best4:RO|DEF */
+#define CMD_RVERSION 0x45 /* software version:trimble_version:RO|DEF */
+#define CMD_RRECVHEALTH 0x46 /* receiver health:trimble_receiver_health:RO|DEF */
+#define CMD_RSIGNALLV 0x47 /* signal levels of all satellites:trimble_signal_levels:RO */
+#define CMD_RMESSAGE 0x48 /* GPS system message:gps-message:RO|DEF */
+#define CMD_RALMAHEALTH 0x49 /* almanac health page for all satellites:gps_almanac_health:RO */
+#define CMD_RSLLAPOS 0x4A /* single LLA position:gps_position(LLA):RO|DEF */
+#define CMD_RMACHSTAT 0x4B /* machine code / status:trimble_status:RO|DEF */
+#define CMD_ROPERPARAM 0x4C /* operating parameters:trimble_opparam:RO */
+#define CMD_ROSCOFFSET 0x4D /* oscillator offset:trimble_oscoffset:RO */
+#define CMD_RSETGPSTIME 0x4E /* response to set GPS time:trimble_setgpstime:RO */
+#define CMD_RUTCPARAM 0x4F /* UTC parameters:gps_utc_correction:RO|DEF */
+#define CMD_RANALOGDIG 0x53 /* analog to digital:trimble_analogdigital:RO */
+#define CMD_RSAT1BIAS 0x54 /* one-satellite bias & bias rate:trimble_sat1bias:RO */
+#define CMD_RIOOPTIONS 0x55 /* I/O options:trimble_iooptions:RO */
+#define CMD_RVELOCFIX 0x56 /* velocity fix (ENU):trimble_velocfix */
+#define CMD_RSTATLSTFIX 0x57 /* status and values of last pos. and vel.:trimble_status_lastpos:RO */
+#define CMD_RLOADSSATDT 0x58 /* response to load satellite system data:trimble_loaddata:RO */
+#define CMD_RSATDISABLE 0x59 /* satellite disable:trimble_satdisble:RO */
+#define CMD_RLASTRAW 0x5A /* last raw measurement:trimble_lastraw:RO */
+#define CMD_RSTATSATEPH 0x5B /* satellite ephemeris status:trimble_ephstatus:RO */
+#define CMD_RSTATTRACK 0x5C /* tracking status:trimble_tracking_status:RO|DEF */
+#define CMD_RADDITFIX 0x5E /* additional fix data:trimble_addfix:RO */
+#define CMD_RALLINVIEW 0x6D /* all in view satellite selection:trimble_satview:RO|DEF */
+#define CMD_RPOSFILT 0x72 /* position filter parameters:trimble_posfilt:RO */
+#define CMD_RHEIGHTFILT 0x74 /* height filter control:trimble_heightfilt:RO */
+#define CMD_RHIGH8CNT 0x76 /* high-8 (best 4) / high-6 (overdetermined) control:trimble_high8control:RO */
+#define CMD_RMAXAGE 0x78 /* DC MaxAge:trimble_dgpsmaxage:RO */
+#define CMD_RDGPSFIX 0x82 /* differential position fix mode:trimble_dgpsfixmode:RO */
+#define CMD_RDOUBLEXYZ 0x83 /* double precision XYZ:gps_position_ext(XYZ):RO|DEF */
+#define CMD_RDOUBLELLA 0x84 /* double precision LLA:gps_position_ext(LLA):RO|DEF */
+#define CMD_RDGPSSTAT 0x85 /* differential correction status:trimble_dgpsstatus:RO */
+#define CMD_RSUPER 0x8F /* super paket::0 */
+
+typedef struct cmd_info
+{
+ unsigned char cmd; /* command code */
+ const char *cmdname; /* command name */
+ const char *cmddesc; /* command description */
+ const char *varname; /* name of variable */
+ int varmode; /* mode of variable */
+} cmd_info_t;
+
+extern cmd_info_t trimble_rcmds[];
+extern cmd_info_t trimble_scmds[];
+
+extern cmd_info_t *trimble_convert P((unsigned int cmd, cmd_info_t *tbl));
+
+#endif
+/*
+ * trimble.h,v
+ * Revision 4.4 1999/02/28 11:41:11 kardel
+ * (CMD_RUTCPARAM): control variable name unification
+ *
+ * Revision 4.3 1998/12/20 23:45:25 kardel
+ * fix types and warnings
+ *
+ * Revision 4.2 1998/08/16 18:45:05 kardel
+ * (CMD_RSTATTRACK): renamed mode 6 variable name
+ *
+ * Revision 4.1 1998/08/09 22:24:35 kardel
+ * Trimble TSIP support
+ *
+ */