summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2014-12-02 09:01:21 +0000
committer <>2014-12-04 16:11:25 +0000
commitbdab5265fcbf3f472545073a23f8999749a9f2b9 (patch)
treec6018dd03dea906f8f1fb5f105f05b71a7dc250a /include
downloadntp-bdab5265fcbf3f472545073a23f8999749a9f2b9.tar.gz
Imported from /home/lorry/working-area/delta_ntp/ntp-dev-4.2.7p482.tar.gz.ntp-dev-4.2.7p482
Diffstat (limited to 'include')
-rw-r--r--include/Makefile.am77
-rw-r--r--include/Makefile.in808
-rw-r--r--include/README4
-rw-r--r--include/adjtime.h63
-rw-r--r--include/ascii.h96
-rw-r--r--include/audio.h14
-rw-r--r--include/binio.h76
-rw-r--r--include/declcond.h21
-rw-r--r--include/gps.h53
-rw-r--r--include/hopf6039.h144
-rw-r--r--include/icom.h87
-rw-r--r--include/ieee754io.h78
-rw-r--r--include/intreswork.h29
-rw-r--r--include/iosignal.h58
-rw-r--r--include/isc/Makefile.am5
-rw-r--r--include/isc/Makefile.in586
-rw-r--r--include/isc/mem.h68
-rw-r--r--include/l_stdlib.h224
-rw-r--r--include/lib_strbuf.h32
-rw-r--r--include/libntp.h16
-rw-r--r--include/mbg_gps166.h582
-rw-r--r--include/mx4200.h40
-rw-r--r--include/ntif.h98
-rw-r--r--include/ntp.h895
-rw-r--r--include/ntp_assert.h108
-rw-r--r--include/ntp_calendar.h416
-rw-r--r--include/ntp_cmdargs.h1
-rw-r--r--include/ntp_config.h322
-rw-r--r--include/ntp_control.h192
-rw-r--r--include/ntp_crypto.h190
-rw-r--r--include/ntp_datum.h30
-rw-r--r--include/ntp_debug.h27
-rw-r--r--include/ntp_filegen.h56
-rw-r--r--include/ntp_fp.h420
-rw-r--r--include/ntp_if.h27
-rw-r--r--include/ntp_intres.h45
-rw-r--r--include/ntp_io.h97
-rw-r--r--include/ntp_libopts.h14
-rw-r--r--include/ntp_lineedit.h13
-rw-r--r--include/ntp_lists.h443
-rw-r--r--include/ntp_machine.h297
-rw-r--r--include/ntp_malloc.h61
-rw-r--r--include/ntp_md5.h40
-rw-r--r--include/ntp_net.h238
-rw-r--r--include/ntp_prio_q.h83
-rw-r--r--include/ntp_proto.h6
-rw-r--r--include/ntp_random.h14
-rw-r--r--include/ntp_refclock.h239
-rw-r--r--include/ntp_request.h952
-rw-r--r--include/ntp_rfc2553.h253
-rw-r--r--include/ntp_select.h35
-rw-r--r--include/ntp_stdlib.h267
-rw-r--r--include/ntp_string.h37
-rw-r--r--include/ntp_syscall.h56
-rw-r--r--include/ntp_syslog.h85
-rw-r--r--include/ntp_tty.h103
-rw-r--r--include/ntp_types.h288
-rw-r--r--include/ntp_unixtime.h47
-rw-r--r--include/ntp_worker.h162
-rw-r--r--include/ntp_workimpl.h30
-rw-r--r--include/ntpd.h568
-rw-r--r--include/ntpsim.h146
-rw-r--r--include/parse.h421
-rw-r--r--include/parse_conf.h83
-rw-r--r--include/recvbuff.h123
-rw-r--r--include/refclock_atom.h15
-rw-r--r--include/ssl_applink.c74
-rw-r--r--include/timepps-SCO.h503
-rw-r--r--include/timepps-Solaris.h569
-rw-r--r--include/timepps-SunOS.h504
-rw-r--r--include/timespecops.h393
-rw-r--r--include/timetoa.h83
-rw-r--r--include/timevalops.h446
-rw-r--r--include/trimble.h160
-rw-r--r--include/vint64ops.h28
75 files changed, 13964 insertions, 0 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
new file mode 100644
index 0000000..5ab3e6e
--- /dev/null
+++ b/include/Makefile.am
@@ -0,0 +1,77 @@
+NULL =
+
+SUBDIRS = isc
+
+noinst_HEADERS = \
+ adjtime.h \
+ audio.h \
+ ascii.h \
+ audio.h \
+ binio.h \
+ declcond.h \
+ gps.h \
+ hopf6039.h \
+ icom.h \
+ ieee754io.h \
+ intreswork.h \
+ iosignal.h \
+ l_stdlib.h \
+ lib_strbuf.h \
+ libntp.h \
+ mbg_gps166.h \
+ mx4200.h \
+ ntif.h \
+ ntp.h \
+ ntp_assert.h \
+ ntp_calendar.h \
+ ntp_cmdargs.h \
+ ntp_config.h \
+ ntp_control.h \
+ ntp_crypto.h \
+ ntp_prio_q.h \
+ ntp_datum.h \
+ ntp_debug.h \
+ ntp_filegen.h \
+ ntp_fp.h \
+ ntp_if.h \
+ ntp_intres.h \
+ ntp_io.h \
+ ntp_libopts.h \
+ ntp_lineedit.h \
+ ntp_lists.h \
+ ntp_machine.h \
+ ntp_malloc.h \
+ ntp_md5.h \
+ ntp_net.h \
+ ntp_proto.h \
+ ntp_random.h \
+ ntp_refclock.h \
+ ntp_request.h \
+ ntp_rfc2553.h \
+ ntp_select.h \
+ ntp_stdlib.h \
+ ntp_string.h \
+ ntp_syscall.h \
+ ntp_syslog.h \
+ ntp_tty.h \
+ ntp_types.h \
+ ntp_unixtime.h \
+ ntp_worker.h \
+ ntp_workimpl.h \
+ ntpd.h \
+ ntpsim.h \
+ parse.h \
+ parse_conf.h \
+ recvbuff.h \
+ refclock_atom.h \
+ ssl_applink.c \
+ timepps-SCO.h \
+ timepps-Solaris.h \
+ timepps-SunOS.h \
+ timespecops.h \
+ timetoa.h \
+ timevalops.h \
+ trimble.h \
+ vint64ops.h \
+ $(NULL)
+
diff --git a/include/Makefile.in b/include/Makefile.in
new file mode 100644
index 0000000..e50f270
--- /dev/null
+++ b/include/Makefile.in
@@ -0,0 +1,808 @@
+# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009 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.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = include
+DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/Makefile.am \
+ $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/sntp/libopts/m4/libopts.m4 \
+ $(top_srcdir)/sntp/libopts/m4/stdnoreturn.m4 \
+ $(top_srcdir)/sntp/libevent/m4/openldap-thread-check.m4 \
+ $(top_srcdir)/sntp/libevent/m4/openldap.m4 \
+ $(top_srcdir)/sntp/m4/define_dir.m4 \
+ $(top_srcdir)/sntp/m4/hms_search_lib.m4 \
+ $(top_srcdir)/sntp/m4/libtool.m4 \
+ $(top_srcdir)/sntp/m4/ltoptions.m4 \
+ $(top_srcdir)/sntp/m4/ltsugar.m4 \
+ $(top_srcdir)/sntp/m4/ltversion.m4 \
+ $(top_srcdir)/sntp/m4/lt~obsolete.m4 \
+ $(top_srcdir)/sntp/m4/ntp_cacheversion.m4 \
+ $(top_srcdir)/sntp/m4/ntp_compiler.m4 \
+ $(top_srcdir)/sntp/m4/ntp_crosscompile.m4 \
+ $(top_srcdir)/sntp/m4/ntp_debug.m4 \
+ $(top_srcdir)/sntp/m4/ntp_dir_sep.m4 \
+ $(top_srcdir)/sntp/m4/ntp_facilitynames.m4 \
+ $(top_srcdir)/sntp/m4/ntp_googletest.m4 \
+ $(top_srcdir)/sntp/m4/ntp_ipv6.m4 \
+ $(top_srcdir)/sntp/m4/ntp_lib_m.m4 \
+ $(top_srcdir)/sntp/m4/ntp_libevent.m4 \
+ $(top_srcdir)/sntp/m4/ntp_libntp.m4 \
+ $(top_srcdir)/sntp/m4/ntp_lineeditlibs.m4 \
+ $(top_srcdir)/sntp/m4/ntp_locinfo.m4 \
+ $(top_srcdir)/sntp/m4/ntp_openssl.m4 \
+ $(top_srcdir)/sntp/m4/ntp_pkg_config.m4 \
+ $(top_srcdir)/sntp/m4/ntp_prog_cc.m4 \
+ $(top_srcdir)/sntp/m4/ntp_rlimit.m4 \
+ $(top_srcdir)/sntp/m4/ntp_sntp.m4 \
+ $(top_srcdir)/sntp/m4/ntp_ver_suffix.m4 \
+ $(top_srcdir)/sntp/m4/ntp_vpathhack.m4 \
+ $(top_srcdir)/sntp/m4/os_cflags.m4 \
+ $(top_srcdir)/sntp/m4/snprintf.m4 \
+ $(top_srcdir)/sntp/m4/version.m4 $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+AM_V_GEN = $(am__v_GEN_$(V))
+am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+am__v_GEN_0 = @echo " GEN " $@;
+AM_V_at = $(am__v_at_$(V))
+am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+am__v_at_0 = @
+SOURCES =
+DIST_SOURCES =
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
+ html-recursive info-recursive install-data-recursive \
+ install-dvi-recursive install-exec-recursive \
+ install-html-recursive install-info-recursive \
+ install-pdf-recursive install-ps-recursive install-recursive \
+ installcheck-recursive installdirs-recursive pdf-recursive \
+ ps-recursive uninstall-recursive
+HEADERS = $(noinst_HEADERS)
+RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \
+ distclean-recursive maintainer-clean-recursive
+AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
+ $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
+ distdir
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+am__relativize = \
+ dir0=`pwd`; \
+ sed_first='s,^\([^/]*\)/.*$$,\1,'; \
+ sed_rest='s,^[^/]*/*,,'; \
+ sed_last='s,^.*/\([^/]*\)$$,\1,'; \
+ sed_butlast='s,/*[^/]*$$,,'; \
+ while test -n "$$dir1"; do \
+ first=`echo "$$dir1" | sed -e "$$sed_first"`; \
+ if test "$$first" != "."; then \
+ if test "$$first" = ".."; then \
+ dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
+ dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
+ else \
+ first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
+ if test "$$first2" = "$$first"; then \
+ dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
+ else \
+ dir2="../$$dir2"; \
+ fi; \
+ dir0="$$dir0"/"$$first"; \
+ fi; \
+ fi; \
+ dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
+ done; \
+ reldir="$$dir2"
+ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CALC_TICKADJ_DB = @CALC_TICKADJ_DB@
+CALC_TICKADJ_DL = @CALC_TICKADJ_DL@
+CALC_TICKADJ_DS = @CALC_TICKADJ_DS@
+CALC_TICKADJ_MS = @CALC_TICKADJ_MS@
+CALC_TICKADJ_NI = @CALC_TICKADJ_NI@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CFLAGS_NTP = @CFLAGS_NTP@
+CHUTEST = @CHUTEST@
+CONFIG_SHELL = @CONFIG_SHELL@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CPPFLAGS_NTP = @CPPFLAGS_NTP@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DCFD = @DCFD@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EDITLINE_LIBS = @EDITLINE_LIBS@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+GTEST_CONFIG = @GTEST_CONFIG@
+GTEST_CPPFLAGS = @GTEST_CPPFLAGS@
+GTEST_CXXFLAGS = @GTEST_CXXFLAGS@
+GTEST_LDFLAGS = @GTEST_LDFLAGS@
+GTEST_LIBS = @GTEST_LIBS@
+HAVE_INLINE = @HAVE_INLINE@
+HAVE_RLIMIT_MEMLOCK = @HAVE_RLIMIT_MEMLOCK@
+HAVE_RLIMIT_STACK = @HAVE_RLIMIT_STACK@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDADD_LIBNTP = @LDADD_LIBNTP@
+LDADD_NLIST = @LDADD_NLIST@
+LDADD_NTP = @LDADD_NTP@
+LDFLAGS = @LDFLAGS@
+LDFLAGS_NTP = @LDFLAGS_NTP@
+LIBISC_PTHREADS_NOTHREADS = @LIBISC_PTHREADS_NOTHREADS@
+LIBM = @LIBM@
+LIBOBJS = @LIBOBJS@
+LIBOPTS_CFLAGS = @LIBOPTS_CFLAGS@
+LIBOPTS_DIR = @LIBOPTS_DIR@
+LIBOPTS_LDADD = @LIBOPTS_LDADD@
+LIBPARSE = @LIBPARSE@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LSCF = @LSCF@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MAKE_ADJTIMED = @MAKE_ADJTIMED@
+MAKE_CHECK_LAYOUT = @MAKE_CHECK_LAYOUT@
+MAKE_CHECK_Y2K = @MAKE_CHECK_Y2K@
+MAKE_LIBNTPSIM = @MAKE_LIBNTPSIM@
+MAKE_LIBPARSE = @MAKE_LIBPARSE@
+MAKE_LIBPARSE_KERNEL = @MAKE_LIBPARSE_KERNEL@
+MAKE_NTPDSIM = @MAKE_NTPDSIM@
+MAKE_NTPSNMPD = @MAKE_NTPSNMPD@
+MAKE_NTPTIME = @MAKE_NTPTIME@
+MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@
+MAKE_TICKADJ = @MAKE_TICKADJ@
+MAKE_TIMETRIM = @MAKE_TIMETRIM@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MANTAGFMT = @MANTAGFMT@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+NTPDATE_DB = @NTPDATE_DB@
+NTPDATE_DL = @NTPDATE_DL@
+NTPDATE_DS = @NTPDATE_DS@
+NTPDATE_MS = @NTPDATE_MS@
+NTPDATE_NI = @NTPDATE_NI@
+NTPDC_DB = @NTPDC_DB@
+NTPDC_DL = @NTPDC_DL@
+NTPDC_DS = @NTPDC_DS@
+NTPDC_MS = @NTPDC_MS@
+NTPDC_NI = @NTPDC_NI@
+NTPDSIM_DB = @NTPDSIM_DB@
+NTPDSIM_DL = @NTPDSIM_DL@
+NTPDSIM_DS = @NTPDSIM_DS@
+NTPDSIM_MS = @NTPDSIM_MS@
+NTPDSIM_NI = @NTPDSIM_NI@
+NTPD_DB = @NTPD_DB@
+NTPD_DL = @NTPD_DL@
+NTPD_DS = @NTPD_DS@
+NTPD_MS = @NTPD_MS@
+NTPD_NI = @NTPD_NI@
+NTPQ_DB = @NTPQ_DB@
+NTPQ_DL = @NTPQ_DL@
+NTPQ_DS = @NTPQ_DS@
+NTPQ_MS = @NTPQ_MS@
+NTPQ_NI = @NTPQ_NI@
+NTPSNMPD_DB = @NTPSNMPD_DB@
+NTPSNMPD_DL = @NTPSNMPD_DL@
+NTPSNMPD_DS = @NTPSNMPD_DS@
+NTPSNMPD_MS = @NTPSNMPD_MS@
+NTPSNMPD_NI = @NTPSNMPD_NI@
+NTPSWEEP_DB = @NTPSWEEP_DB@
+NTPSWEEP_DL = @NTPSWEEP_DL@
+NTPSWEEP_DS = @NTPSWEEP_DS@
+NTPSWEEP_MS = @NTPSWEEP_MS@
+NTPSWEEP_NI = @NTPSWEEP_NI@
+NTPTIME_DB = @NTPTIME_DB@
+NTPTIME_DL = @NTPTIME_DL@
+NTPTIME_DS = @NTPTIME_DS@
+NTPTIME_MS = @NTPTIME_MS@
+NTPTIME_NI = @NTPTIME_NI@
+NTPTRACE_DB = @NTPTRACE_DB@
+NTPTRACE_DL = @NTPTRACE_DL@
+NTPTRACE_DS = @NTPTRACE_DS@
+NTPTRACE_MS = @NTPTRACE_MS@
+NTPTRACE_NI = @NTPTRACE_NI@
+NTP_KEYGEN_DB = @NTP_KEYGEN_DB@
+NTP_KEYGEN_DL = @NTP_KEYGEN_DL@
+NTP_KEYGEN_DS = @NTP_KEYGEN_DS@
+NTP_KEYGEN_MS = @NTP_KEYGEN_MS@
+NTP_KEYGEN_NI = @NTP_KEYGEN_NI@
+NTP_KEYSDIR = @NTP_KEYSDIR@
+NTP_WAIT_DB = @NTP_WAIT_DB@
+NTP_WAIT_DL = @NTP_WAIT_DL@
+NTP_WAIT_DS = @NTP_WAIT_DS@
+NTP_WAIT_MS = @NTP_WAIT_MS@
+NTP_WAIT_NI = @NTP_WAIT_NI@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_NET_SNMP_CONFIG = @PATH_NET_SNMP_CONFIG@
+PATH_PERL = @PATH_PERL@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PATH_TEST = @PATH_TEST@
+PERLLIBDIR = @PERLLIBDIR@
+PKG_CONFIG = @PKG_CONFIG@
+POSIX_SHELL = @POSIX_SHELL@
+PROPDELAY = @PROPDELAY@
+PTHREAD_LIBS = @PTHREAD_LIBS@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SNMP_CFLAGS = @SNMP_CFLAGS@
+SNMP_CPPFLAGS = @SNMP_CPPFLAGS@
+SNMP_LIBS = @SNMP_LIBS@
+SNTP = @SNTP@
+SNTP_DB = @SNTP_DB@
+SNTP_DL = @SNTP_DL@
+SNTP_DS = @SNTP_DS@
+SNTP_MS = @SNTP_MS@
+SNTP_NI = @SNTP_NI@
+STDNORETURN_H = @STDNORETURN_H@
+STRIP = @STRIP@
+TESTDCF = @TESTDCF@
+TICKADJ_DB = @TICKADJ_DB@
+TICKADJ_DL = @TICKADJ_DL@
+TICKADJ_DS = @TICKADJ_DS@
+TICKADJ_MS = @TICKADJ_MS@
+TICKADJ_NI = @TICKADJ_NI@
+TIMETRIM_DB = @TIMETRIM_DB@
+TIMETRIM_DL = @TIMETRIM_DL@
+TIMETRIM_DS = @TIMETRIM_DS@
+TIMETRIM_MS = @TIMETRIM_MS@
+TIMETRIM_NI = @TIMETRIM_NI@
+VERSION = @VERSION@
+VER_SUFFIX = @VER_SUFFIX@
+YACC = @YACC@
+YFLAGS = @YFLAGS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+subdirs = @subdirs@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+NULL =
+SUBDIRS = isc
+noinst_HEADERS = \
+ adjtime.h \
+ audio.h \
+ ascii.h \
+ audio.h \
+ binio.h \
+ declcond.h \
+ gps.h \
+ hopf6039.h \
+ icom.h \
+ ieee754io.h \
+ intreswork.h \
+ iosignal.h \
+ l_stdlib.h \
+ lib_strbuf.h \
+ libntp.h \
+ mbg_gps166.h \
+ mx4200.h \
+ ntif.h \
+ ntp.h \
+ ntp_assert.h \
+ ntp_calendar.h \
+ ntp_cmdargs.h \
+ ntp_config.h \
+ ntp_control.h \
+ ntp_crypto.h \
+ ntp_prio_q.h \
+ ntp_datum.h \
+ ntp_debug.h \
+ ntp_filegen.h \
+ ntp_fp.h \
+ ntp_if.h \
+ ntp_intres.h \
+ ntp_io.h \
+ ntp_libopts.h \
+ ntp_lineedit.h \
+ ntp_lists.h \
+ ntp_machine.h \
+ ntp_malloc.h \
+ ntp_md5.h \
+ ntp_net.h \
+ ntp_proto.h \
+ ntp_random.h \
+ ntp_refclock.h \
+ ntp_request.h \
+ ntp_rfc2553.h \
+ ntp_select.h \
+ ntp_stdlib.h \
+ ntp_string.h \
+ ntp_syscall.h \
+ ntp_syslog.h \
+ ntp_tty.h \
+ ntp_types.h \
+ ntp_unixtime.h \
+ ntp_worker.h \
+ ntp_workimpl.h \
+ ntpd.h \
+ ntpsim.h \
+ parse.h \
+ parse_conf.h \
+ recvbuff.h \
+ refclock_atom.h \
+ ssl_applink.c \
+ timepps-SCO.h \
+ timepps-Solaris.h \
+ timepps-SunOS.h \
+ timespecops.h \
+ timetoa.h \
+ timevalops.h \
+ trimble.h \
+ vint64ops.h \
+ $(NULL)
+
+all: all-recursive
+
+.SUFFIXES:
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign include/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run `make' without going through this Makefile.
+# To change the values of `make' variables: instead of editing Makefiles,
+# (1) if the variable is set in `config.status', edit `config.status'
+# (which will cause the Makefiles to be regenerated when you run `make');
+# (2) otherwise, pass the desired values on the `make' command line.
+$(RECURSIVE_TARGETS):
+ @fail= failcom='exit 1'; \
+ for f in x $$MAKEFLAGS; do \
+ case $$f in \
+ *=* | --[!k]*);; \
+ *k*) failcom='fail=yes';; \
+ esac; \
+ done; \
+ dot_seen=no; \
+ target=`echo $@ | sed s/-recursive//`; \
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ echo "Making $$target in $$subdir"; \
+ if test "$$subdir" = "."; then \
+ dot_seen=yes; \
+ local_target="$$target-am"; \
+ else \
+ local_target="$$target"; \
+ fi; \
+ ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+ || eval $$failcom; \
+ done; \
+ if test "$$dot_seen" = "no"; then \
+ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+ fi; test -z "$$fail"
+
+$(RECURSIVE_CLEAN_TARGETS):
+ @fail= failcom='exit 1'; \
+ for f in x $$MAKEFLAGS; do \
+ case $$f in \
+ *=* | --[!k]*);; \
+ *k*) failcom='fail=yes';; \
+ esac; \
+ done; \
+ dot_seen=no; \
+ case "$@" in \
+ distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+ *) list='$(SUBDIRS)' ;; \
+ esac; \
+ rev=''; for subdir in $$list; do \
+ if test "$$subdir" = "."; then :; else \
+ rev="$$subdir $$rev"; \
+ fi; \
+ done; \
+ rev="$$rev ."; \
+ target=`echo $@ | sed s/-recursive//`; \
+ for subdir in $$rev; do \
+ echo "Making $$target in $$subdir"; \
+ if test "$$subdir" = "."; then \
+ local_target="$$target-am"; \
+ else \
+ local_target="$$target"; \
+ fi; \
+ ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+ || eval $$failcom; \
+ done && test -z "$$fail"
+tags-recursive:
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+ done
+ctags-recursive:
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
+ done
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ set x; \
+ here=`pwd`; \
+ if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
+ include_option=--etags-include; \
+ empty_fix=.; \
+ else \
+ include_option=--include; \
+ empty_fix=; \
+ fi; \
+ list='$(SUBDIRS)'; for subdir in $$list; do \
+ if test "$$subdir" = .; then :; else \
+ test ! -f $$subdir/TAGS || \
+ set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
+ fi; \
+ done; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: CTAGS
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+ @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+ if test "$$subdir" = .; then :; else \
+ test -d "$(distdir)/$$subdir" \
+ || $(MKDIR_P) "$(distdir)/$$subdir" \
+ || exit 1; \
+ fi; \
+ done
+ @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+ if test "$$subdir" = .; then :; else \
+ dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
+ $(am__relativize); \
+ new_distdir=$$reldir; \
+ dir1=$$subdir; dir2="$(top_distdir)"; \
+ $(am__relativize); \
+ new_top_distdir=$$reldir; \
+ echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \
+ echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \
+ ($(am__cd) $$subdir && \
+ $(MAKE) $(AM_MAKEFLAGS) \
+ top_distdir="$$new_top_distdir" \
+ distdir="$$new_distdir" \
+ am__remove_distdir=: \
+ am__skip_length_check=: \
+ am__skip_mode_fix=: \
+ distdir) \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-recursive
+all-am: Makefile $(HEADERS)
+installdirs: installdirs-recursive
+installdirs-am:
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-recursive
+
+clean-am: clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-recursive
+ -rm -f Makefile
+distclean-am: clean-am distclean-generic distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+html-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-recursive
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-recursive
+
+install-html-am:
+
+install-info: install-info-recursive
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-recursive
+
+install-pdf-am:
+
+install-ps: install-ps-recursive
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \
+ install-am install-strip tags-recursive
+
+.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
+ all all-am check check-am clean clean-generic clean-libtool \
+ ctags ctags-recursive distclean distclean-generic \
+ distclean-libtool distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-strip installcheck \
+ installcheck-am installdirs installdirs-am maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-generic \
+ mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \
+ uninstall uninstall-am
+
+
+# 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/include/README b/include/README
new file mode 100644
index 0000000..5d818dc
--- /dev/null
+++ b/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/include/adjtime.h b/include/adjtime.h
new file mode 100644
index 0000000..74d91eb
--- /dev/null
+++ b/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/include/ascii.h b/include/ascii.h
new file mode 100644
index 0000000..a789091
--- /dev/null
+++ b/include/ascii.h
@@ -0,0 +1,96 @@
+/*
+ * /src/NTP/ntp4-dev/include/ascii.h,v 4.4 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ *
+ * ascii.h,v 4.4 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ *
+ * $Created: Sun Jul 20 11:42:53 1997 $
+ *
+ * Copyright (c) 1997-2005 by Frank Kardel <kardel <AT> ntp.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#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
+/*
+ * History:
+ *
+ * ascii.h,v
+ * Revision 4.4 2005/04/16 17:32:10 kardel
+ * update copyright
+ *
+ * Revision 4.3 2004/11/14 15:29:41 kardel
+ * support PPSAPI, upgrade Copyright to Berkeley style
+ *
+ * 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/include/audio.h b/include/audio.h
new file mode 100644
index 0000000..1b969bd
--- /dev/null
+++ b/include/audio.h
@@ -0,0 +1,14 @@
+/*
+ * Header file for audio drivers
+ */
+#include "ntp_types.h"
+
+#define MAXGAIN 255 /* max codec gain */
+#define MONGAIN 127 /* codec monitor gain */
+
+/*
+ * Function prototypes
+ */
+int audio_init (char *, int, int);
+int audio_gain (int, int, int);
+void audio_show (void);
diff --git a/include/binio.h b/include/binio.h
new file mode 100644
index 0000000..d1ee944
--- /dev/null
+++ b/include/binio.h
@@ -0,0 +1,76 @@
+/*
+ * /src/NTP/ntp4-dev/include/binio.h,v 4.5 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ *
+ * binio.h,v 4.5 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ *
+ * $Created: Sun Jul 20 13:03:05 1997 $
+ *
+ * Copyright (c) 1997-2005 by Frank Kardel <kardel <AT> ntp.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#ifndef BINIO_H
+#define BINIO_H
+
+#include "ntp_stdlib.h"
+
+long get_lsb_short (unsigned char **);
+void put_lsb_short (unsigned char **, long);
+long get_lsb_long (unsigned char **);
+void put_lsb_long (unsigned char **, long);
+
+long get_msb_short (unsigned char **);
+void put_msb_short (unsigned char **, long);
+long get_msb_long (unsigned char **);
+void put_msb_long (unsigned char **, long);
+
+#endif
+/*
+ * History:
+ *
+ * binio.h,v
+ * Revision 4.5 2005/04/16 17:32:10 kardel
+ * update copyright
+ *
+ * Revision 4.4 2004/11/14 15:29:41 kardel
+ * support PPSAPI, upgrade Copyright to Berkeley style
+ *
+ * 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/include/declcond.h b/include/declcond.h
new file mode 100644
index 0000000..751eff9
--- /dev/null
+++ b/include/declcond.h
@@ -0,0 +1,21 @@
+/*
+ * declcond.h - declarations conditionalized for ntpd
+ *
+ * The NTP reference implementation distribution includes two distinct
+ * declcond.h files, one in ntpd/ used only by ntpd, and another in
+ * include/ used by libntp and utilities. This relies on the source
+ * file's directory being ahead of include/ in the include search.
+ *
+ * The ntpd variant of declcond.h declares "debug" only #ifdef DEBUG,
+ * as the --disable-debugging version of ntpd should not reference
+ * "debug". The libntp and utilities variant always declares debug,
+ * as it is used in those codebases even without DEBUG defined.
+ */
+#ifndef DECLCOND_H
+#define DECLCOND_H
+
+/* #ifdef DEBUG */ /* uncommented in ntpd/declcond.h */
+extern int debug;
+/* #endif */ /* uncommented in ntpd/declcond.h */
+
+#endif /* DECLCOND_H */
diff --git a/include/gps.h b/include/gps.h
new file mode 100644
index 0000000..d4f2dbc
--- /dev/null
+++ b/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/include/hopf6039.h b/include/hopf6039.h
new file mode 100644
index 0000000..8532099
--- /dev/null
+++ b/include/hopf6039.h
@@ -0,0 +1,144 @@
+/****************************************************************************/
+/* hopf6039.h */
+/* hopf Elektronik 6039 PCI radio clock header */
+/* (c) 1999, 2000 Bernd Altmeier <altmeier@ATLSoft.de> */
+/* Rev. 1.00 Date 25.03.2000 */
+/* History: */
+/****************************************************************************/
+
+#ifndef _hopf6039_H_
+#define _hopf6039_H_
+
+#define HOPF_MAXVERSION 8
+#define HOPF_CNTR_MEM_LEN 0x7f
+#define HOPF_DATA_MEM_LEN 0x3ff /* this is our memory size */
+
+/* macros and definition for 32 to 16 to 8 bit conversion */
+
+typedef unsigned long DWORD;
+typedef unsigned char BYTE;
+typedef unsigned short WORD;
+
+#define LOWORD(l) ((WORD)(l))
+#define HIWORD(l) ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
+#define LOBYTE(w) ((BYTE)(w))
+#define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
+
+/* iocntl codes for driver access */
+
+#define HOPF_CLOCK_CMD_MASK 0xff000
+
+#define HOPF_CLOCK_GET_LOCAL 0x10000
+#define HOPF_CLOCK_GET_UTC 0x20000
+#define HOPF_CLOCK_GET_ANTENNA 0x30000
+#define HOPF_CLOCK_GET_DIFFERENCE 0x40000
+#define HOPF_CLOCK_GET_VERSION 0x50000
+#define HOPF_CLOCK_GET_POSITION 0x60000
+#define HOPF_CLOCK_GET_SATDATA 0x70000
+#define HOPF_CLOCK_GET_SYSTEMBYTE 0x80000
+#define HOPF_CLOCK_GET_IRIG 0x90000
+
+#define HOPF_CLOCK_SET_DIFFERENCE 0x01000
+#define HOPF_CLOCK_SET_ANTENNA 0x02000
+#define HOPF_CLOCK_SET_TIME 0x03000
+#define HOPF_CLOCK_SET_POSITION 0x04000
+#define HOPF_CLOCK_SET_SATMODE 0x05000
+#define HOPF_CLOCK_SET_SYSTEMBYTE 0x06000
+#define HOPF_CLOCK_SET_RESET 0x07000
+#define HOPF_CLOCK_SET_IRIG 0x08000
+
+/* clock command codes */
+
+#define HOPF_CLOCK_HARDRESET 0x00008000
+#define HOPF_CLOCK_SOFTRESET 0x00004000
+
+/* sat-information */
+
+typedef struct SatStat{
+ BYTE wVisible;
+ BYTE wMode;
+ BYTE wSat0;
+ BYTE wRat0;
+ BYTE wSat1;
+ BYTE wRat1;
+ BYTE wSat2;
+ BYTE wRat2;
+ BYTE wSat3;
+ BYTE wRat3;
+ BYTE wSat4;
+ BYTE wRat4;
+ BYTE wSat5;
+ BYTE wRat5;
+ BYTE wSat6;
+ BYTE wRat6;
+ BYTE wSat7;
+ BYTE wRat7;
+} SatStat;
+
+/* GPS position */
+
+typedef struct GPSPos { /* Position */
+ long wAltitude;
+ long wLongitude;
+ long wLatitude;
+} GPSPos;
+
+/* clock hardware version */
+
+typedef struct ClockVersion {
+ char cVersion[255]; /* Hardware Version like " DCF-RECEIVER, VERSION 01.01, DAT: 23.NOV.1999" */
+ char dVersion[255]; /* Driver Version */
+} ClockVersion;
+
+/* hopftime what you think */
+
+typedef struct HOPFTIME {
+ unsigned int wYear;
+ unsigned int wMonth;
+ unsigned int wDayOfWeek;
+ unsigned int wDay;
+ unsigned int wHour;
+ unsigned int wMinute;
+ unsigned int wSecond;
+ unsigned int wMilliseconds;
+ unsigned int wStatus;
+} HOPFTIME;
+
+/* DCF77 antenna alignment */
+
+typedef struct DcfAntenne {
+ BYTE bStatus;
+ BYTE bStatus1;
+ WORD wAntValue;
+} DcfAntenne;
+
+/* hopf PCI clock */
+
+typedef struct hopfCard {
+ char name[32];
+ unsigned irq;
+ unsigned long membase; /* without mmap */
+ unsigned int port;
+
+ int versionlen;
+ char versionbuf[1024];
+ char *version[HOPF_MAXVERSION];
+ char cardname[32];
+ int interrupt;
+ void *mbase; /* this will be our memory base address */
+
+} hopfCard;
+
+typedef struct cardparams {
+ unsigned int port;
+ unsigned irq;
+ int cardtype;
+ int cardnr;
+ unsigned int membase;
+} cardparams;
+
+
+#define WRITE_REGISTER 0x00
+#define READ_REGISTER 0x01
+
+#endif /* _hopf6039_H_ */
diff --git a/include/icom.h b/include/icom.h
new file mode 100644
index 0000000..66d12e5
--- /dev/null
+++ b/include/icom.h
@@ -0,0 +1,87 @@
+/*
+ * Header file for ICOM radios
+ */
+#include "ntp_types.h"
+
+/*
+ * Common definitions
+ */
+#define P_ERMSG 0x1 /* trace bus error messages */
+#define P_TRACE 0x2 /* trace CI-V messges */
+#define RETRY 3 /* max packet retries */
+#define IBAUD B1200 /* autotune port speed */
+
+/*
+ * Radio identifier codes
+ */
+#define IC1271 0x24
+#define IC1275 0x18
+#define IC271 0x20
+#define IC275 0x10
+#define IC375 0x12
+#define IC471 0x22
+#define IC475 0x14
+#define IC575 0x16
+#define IC725 0x28
+#define IC726 0x30
+#define IC735 0x04
+#define IC751 0x1c
+#define IC761 0x1e
+#define IC765 0x2c
+#define IC775 0x46
+#define IC781 0x26
+#define IC970 0x2e
+#define R7000 0x08
+#define R71 0x1a
+#define R7100 0x34
+#define R72 0x32
+#define R8500 0x4a
+#define R9000 0x2a
+
+/*
+ * CI-V frame codes
+ */
+#define PR 0xfe /* preamble */
+#define TX 0xe0 /* controller address */
+#define FI 0xfd /* end of message */
+#define ACK 0xfb /* controller normal reply */
+#define NAK 0xfa /* controller error reply */
+#define PAD 0xff /* transmit padding */
+
+/*
+ * CI-V controller commands
+ */
+#define V_FREQT 0x00 /* freq set (transceive) */
+#define V_MODET 0x01 /* set mode (transceive) */
+#define V_RBAND 0x02 /* read band edge */
+#define V_RFREQ 0x03 /* read frequency */
+#define V_RMODE 0x04 /* read mode */
+#define V_SFREQ 0x05 /* set frequency */
+#define V_SMODE 0x06 /* set mode */
+#define V_SVFO 0x07 /* select vfo */
+#define V_SMEM 0x08 /* select channel/bank */
+#define V_WRITE 0x09 /* write channel */
+#define V_VFOM 0x0a /* memory -> vfo */
+#define V_CLEAR 0x0b /* clear channel */
+#define V_ROFFS 0x0c /* read tx offset */
+#define V_SOFFS 0x0d /* write tx offset */
+#define V_SCAN 0x0e /* scan control */
+#define V_SPLIT 0x0f /* split control */
+#define V_DIAL 0x10 /* set dial tuning step */
+#define V_ATTEN 0x11 /* set attenuator */
+#define V_SANT 0x12 /* select antenna */
+#define V_ANNC 0x13 /* announce control */
+#define V_WRCTL 0x14 /* write controls */
+#define V_RDCTL 0x15 /* read controls */
+#define V_TOGL 0x16 /* set switches */
+#define V_ASCII 0x17 /* send CW message */
+#define V_POWER 0x18 /* power control */
+#define V_RDID 0x19 /* read model ID */
+#define V_SETW 0x1a /* read/write channel/bank data */
+#define V_CTRL 0x7f /* miscellaneous control */
+
+/*
+ * Function prototypes
+ */
+int icom_init (char *, int, int);
+int icom_freq (int, int, double);
diff --git a/include/ieee754io.h b/include/ieee754io.h
new file mode 100644
index 0000000..73e7f79
--- /dev/null
+++ b/include/ieee754io.h
@@ -0,0 +1,78 @@
+/*
+ * /src/NTP/ntp4-dev/include/ieee754io.h,v 4.3 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ *
+ * ieee754io.h,v 4.3 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ *
+ * $Created: Sun Jul 13 12:22:11 1997 $
+ *
+ * Copyright (c) 1997-2005 by Frank Kardel <kardel <AT> ntp.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#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 (unsigned char **bufp, int size, l_fp *lfpp, offsets_t offsets);
+int put_ieee754 (unsigned char **bufpp, int size, l_fp *lfpp, offsets_t offsets);
+
+#endif
+/*
+ * History:
+ *
+ * ieee754io.h,v
+ * Revision 4.3 2005/04/16 17:32:10 kardel
+ * update copyright
+ *
+ * Revision 4.2 2004/11/14 15:29:41 kardel
+ * support PPSAPI, upgrade Copyright to Berkeley style
+ *
+ * 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/include/intreswork.h b/include/intreswork.h
new file mode 100644
index 0000000..c343ac0
--- /dev/null
+++ b/include/intreswork.h
@@ -0,0 +1,29 @@
+/*
+ * intreswork.h -- declarations private to ntp_intres.c, ntp_worker.c.
+ */
+#ifndef INTRESWORK_H
+#define INTRESWORK_H
+
+#include "ntp_worker.h"
+
+#ifdef WORKER
+
+extern int blocking_getaddrinfo(blocking_child *,
+ blocking_pipe_header *);
+extern int blocking_getnameinfo(blocking_child *,
+ blocking_pipe_header *);
+
+#ifdef TEST_BLOCKING_WORKER
+extern void gai_test_callback(int rescode, int gai_errno,
+ void *context, const char *name,
+ const char *service,
+ const struct addrinfo *hints,
+ const struct addrinfo *ai_res);
+extern void gni_test_callback(int rescode, int gni_errno,
+ sockaddr_u *psau, int flags,
+ const char *host,
+ const char *service, void *context);
+#endif /* TEST_BLOCKING_WORKER */
+#endif /* WORKER */
+
+#endif /* INTRESWORK_H */
diff --git a/include/iosignal.h b/include/iosignal.h
new file mode 100644
index 0000000..406804e
--- /dev/null
+++ b/include/iosignal.h
@@ -0,0 +1,58 @@
+#ifndef IOSIGNAL_H
+#define IOSIGNAL_H
+
+#include "ntp_refclock.h"
+
+ /*
+ * Some systems (MOST) define SIGPOLL == SIGIO, others SIGIO == SIGPOLL, and
+ * a few have separate SIGIO and SIGPOLL signals. This code checks for the
+ * SIGIO == SIGPOLL case at compile time.
+ * Do not define USE_SIGPOLL or USE_SIGIO.
+ * these are interal only to iosignal.c and ntpd/work_fork.c!
+ */
+#if defined(USE_SIGPOLL)
+# undef USE_SIGPOLL
+#endif
+#if defined(USE_SIGIO)
+# undef USE_SIGIO
+#endif
+
+/* type of input handler function - only shared between iosignal.c and ntp_io.c */
+typedef void (input_handler_t)(l_fp *);
+
+#if defined(HAVE_SIGNALED_IO)
+# if defined(USE_TTY_SIGPOLL) || defined(USE_UDP_SIGPOLL)
+# define USE_SIGPOLL
+# endif
+
+# if !defined(USE_TTY_SIGPOLL) || !defined(USE_UDP_SIGPOLL)
+# define USE_SIGIO
+# endif
+
+# if defined(USE_SIGIO) && defined(USE_SIGPOLL)
+# if SIGIO == SIGPOLL
+# define USE_SIGIO
+# undef USE_SIGPOLL
+# endif /* SIGIO == SIGPOLL */
+# endif /* USE_SIGIO && USE_SIGPOLL */
+
+#define USING_SIGIO() using_sigio
+
+extern int using_sigio;
+
+extern void block_sigio (void);
+extern void unblock_sigio (void);
+extern int init_clock_sig (struct refclockio *);
+extern void init_socket_sig (int);
+extern void set_signal (input_handler_t *);
+
+# define BLOCKIO() block_sigio()
+# define UNBLOCKIO() unblock_sigio()
+
+#else /* !HAVE_SIGNALED_IO follows */
+# define BLOCKIO() do {} while (0)
+# define UNBLOCKIO() do {} while (0)
+# define USING_SIGIO() FALSE
+#endif
+
+#endif /* IOSIGNAL_H */
diff --git a/include/isc/Makefile.am b/include/isc/Makefile.am
new file mode 100644
index 0000000..160203b
--- /dev/null
+++ b/include/isc/Makefile.am
@@ -0,0 +1,5 @@
+NULL =
+
+noinst_HEADERS = \
+ mem.h \
+ $(NULL)
diff --git a/include/isc/Makefile.in b/include/isc/Makefile.in
new file mode 100644
index 0000000..af01dcd
--- /dev/null
+++ b/include/isc/Makefile.in
@@ -0,0 +1,586 @@
+# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009 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.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = include/isc
+DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
+ $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/sntp/libopts/m4/libopts.m4 \
+ $(top_srcdir)/sntp/libopts/m4/stdnoreturn.m4 \
+ $(top_srcdir)/sntp/libevent/m4/openldap-thread-check.m4 \
+ $(top_srcdir)/sntp/libevent/m4/openldap.m4 \
+ $(top_srcdir)/sntp/m4/define_dir.m4 \
+ $(top_srcdir)/sntp/m4/hms_search_lib.m4 \
+ $(top_srcdir)/sntp/m4/libtool.m4 \
+ $(top_srcdir)/sntp/m4/ltoptions.m4 \
+ $(top_srcdir)/sntp/m4/ltsugar.m4 \
+ $(top_srcdir)/sntp/m4/ltversion.m4 \
+ $(top_srcdir)/sntp/m4/lt~obsolete.m4 \
+ $(top_srcdir)/sntp/m4/ntp_cacheversion.m4 \
+ $(top_srcdir)/sntp/m4/ntp_compiler.m4 \
+ $(top_srcdir)/sntp/m4/ntp_crosscompile.m4 \
+ $(top_srcdir)/sntp/m4/ntp_debug.m4 \
+ $(top_srcdir)/sntp/m4/ntp_dir_sep.m4 \
+ $(top_srcdir)/sntp/m4/ntp_facilitynames.m4 \
+ $(top_srcdir)/sntp/m4/ntp_googletest.m4 \
+ $(top_srcdir)/sntp/m4/ntp_ipv6.m4 \
+ $(top_srcdir)/sntp/m4/ntp_lib_m.m4 \
+ $(top_srcdir)/sntp/m4/ntp_libevent.m4 \
+ $(top_srcdir)/sntp/m4/ntp_libntp.m4 \
+ $(top_srcdir)/sntp/m4/ntp_lineeditlibs.m4 \
+ $(top_srcdir)/sntp/m4/ntp_locinfo.m4 \
+ $(top_srcdir)/sntp/m4/ntp_openssl.m4 \
+ $(top_srcdir)/sntp/m4/ntp_pkg_config.m4 \
+ $(top_srcdir)/sntp/m4/ntp_prog_cc.m4 \
+ $(top_srcdir)/sntp/m4/ntp_rlimit.m4 \
+ $(top_srcdir)/sntp/m4/ntp_sntp.m4 \
+ $(top_srcdir)/sntp/m4/ntp_ver_suffix.m4 \
+ $(top_srcdir)/sntp/m4/ntp_vpathhack.m4 \
+ $(top_srcdir)/sntp/m4/os_cflags.m4 \
+ $(top_srcdir)/sntp/m4/snprintf.m4 \
+ $(top_srcdir)/sntp/m4/version.m4 $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+AM_V_GEN = $(am__v_GEN_$(V))
+am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+am__v_GEN_0 = @echo " GEN " $@;
+AM_V_at = $(am__v_at_$(V))
+am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+am__v_at_0 = @
+SOURCES =
+DIST_SOURCES =
+HEADERS = $(noinst_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CALC_TICKADJ_DB = @CALC_TICKADJ_DB@
+CALC_TICKADJ_DL = @CALC_TICKADJ_DL@
+CALC_TICKADJ_DS = @CALC_TICKADJ_DS@
+CALC_TICKADJ_MS = @CALC_TICKADJ_MS@
+CALC_TICKADJ_NI = @CALC_TICKADJ_NI@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CFLAGS_NTP = @CFLAGS_NTP@
+CHUTEST = @CHUTEST@
+CONFIG_SHELL = @CONFIG_SHELL@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CPPFLAGS_NTP = @CPPFLAGS_NTP@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DCFD = @DCFD@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EDITLINE_LIBS = @EDITLINE_LIBS@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+GTEST_CONFIG = @GTEST_CONFIG@
+GTEST_CPPFLAGS = @GTEST_CPPFLAGS@
+GTEST_CXXFLAGS = @GTEST_CXXFLAGS@
+GTEST_LDFLAGS = @GTEST_LDFLAGS@
+GTEST_LIBS = @GTEST_LIBS@
+HAVE_INLINE = @HAVE_INLINE@
+HAVE_RLIMIT_MEMLOCK = @HAVE_RLIMIT_MEMLOCK@
+HAVE_RLIMIT_STACK = @HAVE_RLIMIT_STACK@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDADD_LIBNTP = @LDADD_LIBNTP@
+LDADD_NLIST = @LDADD_NLIST@
+LDADD_NTP = @LDADD_NTP@
+LDFLAGS = @LDFLAGS@
+LDFLAGS_NTP = @LDFLAGS_NTP@
+LIBISC_PTHREADS_NOTHREADS = @LIBISC_PTHREADS_NOTHREADS@
+LIBM = @LIBM@
+LIBOBJS = @LIBOBJS@
+LIBOPTS_CFLAGS = @LIBOPTS_CFLAGS@
+LIBOPTS_DIR = @LIBOPTS_DIR@
+LIBOPTS_LDADD = @LIBOPTS_LDADD@
+LIBPARSE = @LIBPARSE@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LSCF = @LSCF@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MAKE_ADJTIMED = @MAKE_ADJTIMED@
+MAKE_CHECK_LAYOUT = @MAKE_CHECK_LAYOUT@
+MAKE_CHECK_Y2K = @MAKE_CHECK_Y2K@
+MAKE_LIBNTPSIM = @MAKE_LIBNTPSIM@
+MAKE_LIBPARSE = @MAKE_LIBPARSE@
+MAKE_LIBPARSE_KERNEL = @MAKE_LIBPARSE_KERNEL@
+MAKE_NTPDSIM = @MAKE_NTPDSIM@
+MAKE_NTPSNMPD = @MAKE_NTPSNMPD@
+MAKE_NTPTIME = @MAKE_NTPTIME@
+MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@
+MAKE_TICKADJ = @MAKE_TICKADJ@
+MAKE_TIMETRIM = @MAKE_TIMETRIM@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MANTAGFMT = @MANTAGFMT@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+NTPDATE_DB = @NTPDATE_DB@
+NTPDATE_DL = @NTPDATE_DL@
+NTPDATE_DS = @NTPDATE_DS@
+NTPDATE_MS = @NTPDATE_MS@
+NTPDATE_NI = @NTPDATE_NI@
+NTPDC_DB = @NTPDC_DB@
+NTPDC_DL = @NTPDC_DL@
+NTPDC_DS = @NTPDC_DS@
+NTPDC_MS = @NTPDC_MS@
+NTPDC_NI = @NTPDC_NI@
+NTPDSIM_DB = @NTPDSIM_DB@
+NTPDSIM_DL = @NTPDSIM_DL@
+NTPDSIM_DS = @NTPDSIM_DS@
+NTPDSIM_MS = @NTPDSIM_MS@
+NTPDSIM_NI = @NTPDSIM_NI@
+NTPD_DB = @NTPD_DB@
+NTPD_DL = @NTPD_DL@
+NTPD_DS = @NTPD_DS@
+NTPD_MS = @NTPD_MS@
+NTPD_NI = @NTPD_NI@
+NTPQ_DB = @NTPQ_DB@
+NTPQ_DL = @NTPQ_DL@
+NTPQ_DS = @NTPQ_DS@
+NTPQ_MS = @NTPQ_MS@
+NTPQ_NI = @NTPQ_NI@
+NTPSNMPD_DB = @NTPSNMPD_DB@
+NTPSNMPD_DL = @NTPSNMPD_DL@
+NTPSNMPD_DS = @NTPSNMPD_DS@
+NTPSNMPD_MS = @NTPSNMPD_MS@
+NTPSNMPD_NI = @NTPSNMPD_NI@
+NTPSWEEP_DB = @NTPSWEEP_DB@
+NTPSWEEP_DL = @NTPSWEEP_DL@
+NTPSWEEP_DS = @NTPSWEEP_DS@
+NTPSWEEP_MS = @NTPSWEEP_MS@
+NTPSWEEP_NI = @NTPSWEEP_NI@
+NTPTIME_DB = @NTPTIME_DB@
+NTPTIME_DL = @NTPTIME_DL@
+NTPTIME_DS = @NTPTIME_DS@
+NTPTIME_MS = @NTPTIME_MS@
+NTPTIME_NI = @NTPTIME_NI@
+NTPTRACE_DB = @NTPTRACE_DB@
+NTPTRACE_DL = @NTPTRACE_DL@
+NTPTRACE_DS = @NTPTRACE_DS@
+NTPTRACE_MS = @NTPTRACE_MS@
+NTPTRACE_NI = @NTPTRACE_NI@
+NTP_KEYGEN_DB = @NTP_KEYGEN_DB@
+NTP_KEYGEN_DL = @NTP_KEYGEN_DL@
+NTP_KEYGEN_DS = @NTP_KEYGEN_DS@
+NTP_KEYGEN_MS = @NTP_KEYGEN_MS@
+NTP_KEYGEN_NI = @NTP_KEYGEN_NI@
+NTP_KEYSDIR = @NTP_KEYSDIR@
+NTP_WAIT_DB = @NTP_WAIT_DB@
+NTP_WAIT_DL = @NTP_WAIT_DL@
+NTP_WAIT_DS = @NTP_WAIT_DS@
+NTP_WAIT_MS = @NTP_WAIT_MS@
+NTP_WAIT_NI = @NTP_WAIT_NI@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_NET_SNMP_CONFIG = @PATH_NET_SNMP_CONFIG@
+PATH_PERL = @PATH_PERL@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PATH_TEST = @PATH_TEST@
+PERLLIBDIR = @PERLLIBDIR@
+PKG_CONFIG = @PKG_CONFIG@
+POSIX_SHELL = @POSIX_SHELL@
+PROPDELAY = @PROPDELAY@
+PTHREAD_LIBS = @PTHREAD_LIBS@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SNMP_CFLAGS = @SNMP_CFLAGS@
+SNMP_CPPFLAGS = @SNMP_CPPFLAGS@
+SNMP_LIBS = @SNMP_LIBS@
+SNTP = @SNTP@
+SNTP_DB = @SNTP_DB@
+SNTP_DL = @SNTP_DL@
+SNTP_DS = @SNTP_DS@
+SNTP_MS = @SNTP_MS@
+SNTP_NI = @SNTP_NI@
+STDNORETURN_H = @STDNORETURN_H@
+STRIP = @STRIP@
+TESTDCF = @TESTDCF@
+TICKADJ_DB = @TICKADJ_DB@
+TICKADJ_DL = @TICKADJ_DL@
+TICKADJ_DS = @TICKADJ_DS@
+TICKADJ_MS = @TICKADJ_MS@
+TICKADJ_NI = @TICKADJ_NI@
+TIMETRIM_DB = @TIMETRIM_DB@
+TIMETRIM_DL = @TIMETRIM_DL@
+TIMETRIM_DS = @TIMETRIM_DS@
+TIMETRIM_MS = @TIMETRIM_MS@
+TIMETRIM_NI = @TIMETRIM_NI@
+VERSION = @VERSION@
+VER_SUFFIX = @VER_SUFFIX@
+YACC = @YACC@
+YFLAGS = @YFLAGS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+subdirs = @subdirs@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+NULL =
+noinst_HEADERS = \
+ mem.h \
+ $(NULL)
+
+all: all-am
+
+.SUFFIXES:
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/isc/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign include/isc/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ set x; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(HEADERS)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-am
+ -rm -f Makefile
+distclean-am: clean-am distclean-generic distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-libtool ctags distclean distclean-generic \
+ distclean-libtool distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-generic \
+ mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \
+ uninstall-am
+
+
+# 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/include/isc/mem.h b/include/isc/mem.h
new file mode 100644
index 0000000..ba1bfeb
--- /dev/null
+++ b/include/isc/mem.h
@@ -0,0 +1,68 @@
+/*
+ * libntp local override of isc/mem.h to stub it out.
+ *
+ * include/isc is searched before any of the lib/isc include
+ * directories and should be used only for replacement NTP headers
+ * overriding headers of the same name under lib/isc.
+ *
+ * NOTE: this assumes the system malloc is thread-safe and does
+ * not use any normal lib/isc locking.
+ */
+
+/*
+ * Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 1997-2001 Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* $Id: mem.h,v 1.78.120.3 2009/02/11 03:07:01 jinmei Exp $ */
+
+#ifndef ISC_MEM_H
+#define ISC_MEM_H 1
+
+#include <stdio.h>
+
+#include <isc/lang.h>
+#include <isc/mutex.h>
+#include <isc/platform.h>
+#include <isc/types.h>
+#include <isc/xml.h>
+
+#include <ntp_stdlib.h>
+
+
+#define ISC_MEM_UNUSED_ARG(a) ((void)(a))
+
+#define isc_mem_allocate(c, cnt) isc_mem_get(c, cnt)
+#define isc_mem_get(c, cnt) \
+ ( ISC_MEM_UNUSED_ARG(c), emalloc(cnt) )
+
+#define isc_mem_reallocate(c, mem, cnt) \
+ ( ISC_MEM_UNUSED_ARG(c), erealloc((mem), cnt) )
+
+#define isc_mem_put(c, mem, cnt) \
+ ( ISC_MEM_UNUSED_ARG(cnt), isc_mem_free(c, (mem)) )
+
+#define isc_mem_free(c, mem) \
+ ( ISC_MEM_UNUSED_ARG(c), free(mem) )
+
+#define isc_mem_strdup(c, str) \
+ ( ISC_MEM_UNUSED_ARG(c), estrdup(str) )
+
+#define isc__mem_attach(src, ptgt) do { *(ptgt) = (src); } while (0)
+#define isc__mem_detach(c) ISC_MEM_UNUSED_ARG(c)
+#define isc__mem_printallactive(s) fprintf((s), \
+ "isc_mem_printallactive() stubbed.\n")
+
+#endif /* ISC_MEM_H */
diff --git a/include/l_stdlib.h b/include/l_stdlib.h
new file mode 100644
index 0000000..073ea46
--- /dev/null
+++ b/include/l_stdlib.h
@@ -0,0 +1,224 @@
+/*
+ * Proto types for machines that are not ANSI and POSIX compliant.
+ * This is optional
+ */
+
+#ifndef L_STDLIB_H
+#define L_STDLIB_H
+
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+
+#include <stdarg.h>
+#include <sys/types.h>
+
+/* 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 (struct timeval *, struct timeval *);
+#endif
+
+#ifdef DECL_BCOPY_0
+#ifndef bcopy
+extern void bcopy (const char *, char *, int);
+#endif
+#endif
+
+#ifdef DECL_BZERO_0
+#ifndef bzero
+extern void bzero (char *, int);
+#endif
+#endif
+
+#ifdef DECL_CFSETISPEED_0
+struct termios;
+extern int cfsetispeed (struct termios *, speed_t);
+extern int cfsetospeed (struct termios *, speed_t);
+#endif
+
+extern char * getpass (const char *);
+
+#ifdef DECL_HSTRERROR_0
+extern const char * hstrerror (int);
+#endif
+
+#ifdef DECL_INET_NTOA_0
+struct in_addr;
+extern char * inet_ntoa (struct in_addr);
+#endif
+
+#ifdef DECL_IOCTL_0
+extern int ioctl (int, u_long, char *);
+#endif
+
+#ifdef DECL_IPC_0
+struct sockaddr;
+extern int bind (int, struct sockaddr *, int);
+extern int connect (int, struct sockaddr *, int);
+extern int recv (int, char *, int, int);
+extern int recvfrom (int, char *, int, int, struct sockaddr *, int *);
+extern int send (int, char *, int, int);
+extern int sendto (int, char *, int, int, struct sockaddr *, int);
+extern int setsockopt (int, int, int, char *, int);
+extern int socket (int, int, int);
+#endif
+
+#ifdef DECL_MEMMOVE_0
+extern void * memmove (void *, const void *, size_t);
+#endif
+
+#ifdef DECL_MEMSET_0
+extern char * memset (char *, int, int);
+#endif
+
+#ifdef DECL_MKSTEMP_0
+extern int mkstemp (char *);
+#endif
+
+#ifdef DECL_MKTEMP_0
+extern char *mktemp (char *);
+#endif
+
+#ifdef DECL_NLIST_0
+struct nlist;
+extern int nlist (const char *, struct nlist *);
+#endif
+
+#ifdef DECL_PLOCK_0
+extern int plock (int);
+#endif
+
+#ifdef DECL_RENAME_0
+extern int rename (const char *, const char *);
+#endif
+
+#ifdef DECL_SELECT_0
+#ifdef NTP_SELECT_H
+extern int select (int, fd_set *, fd_set *, fd_set *, struct timeval *);
+#endif
+#endif
+
+#ifdef DECL_SETITIMER_0
+struct itimerval;
+extern int setitimer (int , struct itimerval *, struct itimerval *);
+#endif
+
+#ifdef PRIO_PROCESS
+#ifdef DECL_SETPRIORITY_0
+extern int setpriority (int, int, int);
+#endif
+#ifdef DECL_SETPRIORITY_1
+extern int setpriority (int, id_t, int);
+#endif
+#endif
+
+#ifdef DECL_SIGVEC_0
+struct sigvec;
+extern int sigvec (int, struct sigvec *, struct sigvec *);
+#endif
+
+#ifdef DECL_STDIO_0
+#if defined(FILE) || defined(BUFSIZ)
+extern int _flsbuf (int, FILE *);
+extern int _filbuf (FILE *);
+extern int fclose (FILE *);
+extern int fflush (FILE *);
+extern int fprintf (FILE *, const char *, ...);
+extern int fscanf (FILE *, const char *, ...);
+extern int fputs (const char *, FILE *);
+extern int fputc (int, FILE *);
+extern int fread (char *, int, int, FILE *);
+extern void perror (const char *);
+extern int printf (const char *, ...);
+extern int setbuf (FILE *, char *);
+# ifdef HAVE_SETLINEBUF
+extern int setlinebuf (FILE *);
+# endif
+extern int setvbuf (FILE *, char *, int, int);
+extern int scanf (const char *, ...);
+extern int sscanf (const char *, const char *, ...);
+extern int vfprintf (FILE *, const char *, ...);
+extern int vsprintf (char *, const char *, ...);
+#endif
+#endif
+
+#ifdef DECL_STIME_0
+extern int stime (const time_t *);
+#endif
+
+#ifdef DECL_STIME_1
+extern int stime (long *);
+#endif
+
+#ifdef DECL_STRERROR_0
+extern char * strerror (int errnum);
+#endif
+
+#ifdef DECL_STRTOL_0
+extern long strtol (const char *, char **, int);
+#endif
+
+#ifdef DECL_SYSCALL
+extern int syscall (int, ...);
+#endif
+
+#ifdef DECL_SYSLOG_0
+extern void closelog (void);
+#ifndef LOG_DAEMON
+extern void openlog (const char *, int);
+#else
+extern void openlog (const char *, int, int);
+#endif
+extern int setlogmask (int);
+extern void syslog (int, const char *, ...);
+#endif
+
+#ifdef DECL_TIME_0
+extern time_t time (time_t *);
+#endif
+
+#ifdef DECL_TIMEOFDAY_0
+#ifdef SYSV_TIMEOFDAY
+extern int gettimeofday (struct timeval *);
+extern int settimeofday (struct timeval *);
+#else /* not SYSV_TIMEOFDAY */
+struct timezone;
+extern int gettimeofday (struct timeval *, struct timezone *);
+extern int settimeofday (struct timeval *, void *);
+#endif /* not SYSV_TIMEOFDAY */
+#endif
+
+#ifdef DECL_TOLOWER_0
+extern int tolower (int);
+#endif
+
+#ifdef DECL_TOUPPER_0
+extern int toupper (int);
+#endif
+
+/*
+ * Necessary variable declarations.
+ */
+#ifdef DECL_ERRNO
+extern int errno;
+#endif
+
+#if defined(DECL_H_ERRNO) && !defined(h_errno)
+extern int h_errno;
+#endif
+
+#endif /* L_STDLIB_H */
diff --git a/include/lib_strbuf.h b/include/lib_strbuf.h
new file mode 100644
index 0000000..5ee92d6
--- /dev/null
+++ b/include/lib_strbuf.h
@@ -0,0 +1,32 @@
+/*
+ * lib_strbuf.h - definitions for routines which use the common string buffers
+ */
+#ifndef LIB_STRBUF_H
+#define LIB_STRBUF_H
+
+#include <ntp_types.h>
+#include <ntp_malloc.h> /* for ZERO() */
+
+/*
+ * Sizes of things
+ */
+#define LIB_NUMBUF 16
+#define LIB_BUFLENGTH 128
+
+typedef char libbufstr[LIB_BUFLENGTH];
+extern libbufstr lib_stringbuf[LIB_NUMBUF];
+extern int lib_nextbuf;
+extern int lib_inited;
+
+
+/*
+ * Macro to get a pointer to the next buffer
+ */
+#define LIB_GETBUF(bufp) \
+ do { \
+ ZERO(lib_stringbuf[lib_nextbuf]); \
+ (bufp) = &lib_stringbuf[lib_nextbuf++][0]; \
+ lib_nextbuf %= COUNTOF(lib_stringbuf); \
+ } while (FALSE)
+
+#endif /* LIB_STRBUF_H */
diff --git a/include/libntp.h b/include/libntp.h
new file mode 100644
index 0000000..8d87c02
--- /dev/null
+++ b/include/libntp.h
@@ -0,0 +1,16 @@
+/* libntp.h */
+
+#if defined(HAVE_SYSCONF) && defined(_SC_OPEN_MAX)
+#define GETDTABLESIZE() ((int)sysconf(_SC_OPEN_MAX))
+#elif defined(HAVE_GETDTABLESIZE)
+#define GETDTABLESIZE getdtablesize
+#else
+/*
+ * if we have no idea about the max fd value set up things
+ * so we will start at FOPEN_MAX
+ */
+#define GETDTABLESIZE() (FOPEN_MAX + FD_CHUNK)
+#endif
+
+extern void make_socket_nonblocking( SOCKET fd );
+extern SOCKET move_fd( SOCKET fd );
diff --git a/include/mbg_gps166.h b/include/mbg_gps166.h
new file mode 100644
index 0000000..974deba
--- /dev/null
+++ b/include/mbg_gps166.h
@@ -0,0 +1,582 @@
+/*
+ * /src/NTP/REPOSITORY/ntp4-dev/include/mbg_gps166.h,v 4.7 2006/06/22 18:41:43 kardel RELEASE_20060622_A
+ *
+ * mbg_gps166.h,v 4.7 2006/06/22 18:41:43 kardel RELEASE_20060622_A
+ *
+ * $Created: Sun Jul 20 09:20:50 1997 $
+ *
+ * File GPSSERIO.H Copyright (c) by Meinberg Funkuhren (www.meinberg.de)
+ *
+ * Linkage to PARSE:
+ * Copyright (c) 1997-2005 by Frank Kardel <kardel <AT> ntp.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#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 GPS166_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 GPS166_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] */
+
+ u_short 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 (char **, TM *, int);
+void mbg_tgps_str (char **, T_GPS *, int);
+void get_mbg_header (unsigned char **, GPS_MSG_HDR *);
+void put_mbg_header (unsigned char **, GPS_MSG_HDR *);
+void get_mbg_sw_rev (unsigned char **, SW_REV *);
+void get_mbg_ascii_msg (unsigned char **, ASCII_MSG *);
+void get_mbg_svno (unsigned char **, SVNO *);
+void get_mbg_health (unsigned char **, HEALTH *);
+void get_mbg_cfg (unsigned char **, CFG *);
+void get_mbg_tgps (unsigned char **, T_GPS *);
+void get_mbg_tm (unsigned char **, TM *);
+void get_mbg_ttm (unsigned char **, TTM *);
+void get_mbg_synth (unsigned char **, SYNTH *);
+void get_mbg_tzdl (unsigned char **, TZDL *);
+void get_mbg_antinfo (unsigned char **, ANT_INFO *);
+void get_mbg_cfgh (unsigned char **, CFGH *);
+void get_mbg_utc (unsigned char **, UTC *);
+void get_mbg_lla (unsigned char **, LLA);
+void get_mbg_xyz (unsigned char **, XYZ);
+void get_mbg_portparam (unsigned char **, PORT_PARM *);
+void get_mbg_eph (unsigned char **, EPH *);
+void get_mbg_alm (unsigned char **, ALM *);
+void get_mbg_iono (unsigned char **, IONO *);
+
+unsigned long mbg_csum (unsigned char *, unsigned int);
+
+#endif
+/*
+ * History:
+ *
+ * mbg_gps166.h,v
+ * Revision 4.7 2006/06/22 18:41:43 kardel
+ * clean up signedness (gcc 4)
+ *
+ * Revision 4.6 2005/10/07 22:11:56 kardel
+ * bounded buffer implementation
+ *
+ * Revision 4.5.2.1 2005/09/25 10:23:48 kardel
+ * support bounded buffers
+ *
+ * Revision 4.5 2005/06/25 10:58:45 kardel
+ * add missing log keywords
+ *
+ * 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/include/mx4200.h b/include/mx4200.h
new file mode 100644
index 0000000..6ea2c60
--- /dev/null
+++ b/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/include/ntif.h b/include/ntif.h
new file mode 100644
index 0000000..8377852
--- /dev/null
+++ b/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/include/ntp.h b/include/ntp.h
new file mode 100644
index 0000000..38343f2
--- /dev/null
+++ b/include/ntp.h
@@ -0,0 +1,895 @@
+/*
+ * ntp.h - NTP definitions for the masses
+ */
+#ifndef NTP_H
+#define NTP_H
+
+#include <stddef.h>
+#include <math.h>
+
+#include <ntp_fp.h>
+#include <ntp_types.h>
+#include <ntp_lists.h>
+#include <ntp_stdlib.h>
+#include <ntp_crypto.h>
+#include <ntp_random.h>
+#include <ntp_net.h>
+
+#include <isc/boolean.h>
+
+/*
+ * Calendar arithmetic - contributed by G. Healton
+ */
+#define YEAR_BREAK 500 /* years < this are tm_year values:
+ * Break < AnyFourDigitYear && Break >
+ * Anytm_yearYear */
+
+#define YEAR_PIVOT 98 /* 97/98: years < this are year 2000+
+ * FYI: official UNIX pivot year is
+ * 68/69 */
+
+/*
+ * Number of Days since 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) ((y) % 4 == 0 && !((y) % 100 == 0 && !(y % \
+ 400 == 0)))
+
+/*
+ * LEAP YEAR test for tm_year (struct tm) years (e.g, 99, 110)
+ */
+#define isleap_tm(y) ((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;
+ */
+
+/*
+ * 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
+
+/*
+ * 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 non-unix machines */
+
+/*
+ * Poll interval parameters
+ */
+#define NTP_UNREACH 10 /* poll unreach threshold */
+#define NTP_MINPOLL 3 /* log2 min poll interval (8 s) */
+#define NTP_MINDPOLL 6 /* log2 default min poll (64 s) */
+#define NTP_MAXDPOLL 10 /* log2 default max poll (~17 m) */
+#define NTP_MAXPOLL 17 /* log2 max poll interval (~36 h) */
+#define NTP_RETRY 3 /* max packet retries */
+#define NTP_MINPKT 2 /* guard time (s) */
+
+/*
+ * Clock filter algorithm tuning parameters
+ */
+#define MAXDISPERSE 16. /* max dispersion */
+#define NTP_SHIFT 8 /* clock filter stages */
+#define NTP_FWEIGHT .5 /* clock filter weight */
+
+/*
+ * Selection algorithm tuning parameters
+ */
+#define NTP_MINCLOCK 3 /* min survivors */
+#define NTP_MAXCLOCK 10 /* max candidates */
+#define MINDISPERSE .001 /* min distance */
+#define MAXDISTANCE 1.5 /* max root distance (select threshold) */
+#define CLOCK_SGATE 3. /* popcorn spike gate */
+#define HUFFPUFF 900 /* huff-n'-puff sample interval (s) */
+#define MAXHOP 2 /* anti-clockhop threshold */
+#define MAX_TTL 8 /* max ttl mapping vector size */
+#define BEACON 7200 /* manycast beacon interval */
+#define NTP_MAXEXTEN 2048 /* max extension field size */
+#define NTP_ORPHWAIT 300 /* orphan wair (s) */
+
+/*
+ * Miscellaneous stuff
+ */
+#define NTP_MAXKEY 65535 /* max authentication key number */
+#define KEY_TYPE_MD5 NID_md5 /* MD5 digest NID */
+/*
+ * Limits of things
+ */
+#define MAXFILENAME 256 /* max length of file name */
+#define MAXHOSTNAME 512 /* max length of host/node name */
+#define NTP_MAXSTRLEN 256 /* max string length */
+
+/*
+ * Operations for jitter 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 component 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) ldexp(1., (int)(a)) /* log2 to double */
+#define UNIVAR(x) (SQUARE(.28867513 * LOGTOD(x))) /* std uniform distr */
+#define ULOGTOD(a) ldexp(1., (int)(a)) /* ulog2 to double */
+
+#define EVENT_TIMEOUT 0 /* one second, that is */
+
+
+/*
+ * The interface structure is used to hold the addresses and socket
+ * numbers of each of the local network addresses we are using.
+ * Because "interface" is a reserved word in C++ and has so many
+ * varied meanings, a change to "endpt" (via typedef) is under way.
+ * Eventually the struct tag will change from interface to endpt_tag.
+ * endpt is unrelated to the select algorithm's struct endpoint.
+ */
+typedef struct interface endpt;
+struct interface {
+ endpt * elink; /* endpt list link */
+ endpt * mclink; /* per-AF_* multicast list */
+ SOCKET fd; /* socket descriptor */
+ SOCKET bfd; /* for receiving broadcasts */
+ u_int32 ifnum; /* endpt instance count */
+ sockaddr_u sin; /* unicast address */
+ sockaddr_u mask; /* subnet mask */
+ sockaddr_u bcast; /* broadcast address */
+ char name[32]; /* name of interface */
+ u_short family; /* AF_INET/AF_INET6 */
+ u_short phase; /* phase in update cycle */
+ u_int32 flags; /* interface flags */
+ int last_ttl; /* last TTL specified */
+ u_int32 addr_refid; /* IPv4 addr or IPv6 hash */
+ int num_mcast; /* mcast addrs enabled */
+ u_long starttime; /* current_time at creation */
+ volatile long received; /* number of incoming packets */
+ long sent; /* number of outgoing packets */
+ long notsent; /* number of send failures */
+ u_int ifindex; /* for IPV6_MULTICAST_IF */
+ isc_boolean_t ignore_packets; /* listen-read-drop this? */
+ struct peer * peers; /* list of peers using endpt */
+ u_int peercnt; /* count of same */
+};
+
+/*
+ * Flags for interfaces
+ */
+#define INT_UP 0x001 /* Interface is up */
+#define INT_PPP 0x002 /* Point-to-point interface */
+#define INT_LOOPBACK 0x004 /* the loopback interface */
+#define INT_BROADCAST 0x008 /* can broadcast out this interface */
+#define INT_MULTICAST 0x010 /* can multicast out this interface */
+#define INT_BCASTOPEN 0x020 /* broadcast receive socket is open */
+#define INT_MCASTOPEN 0x040 /* multicasting enabled */
+#define INT_WILDCARD 0x080 /* wildcard interface - usually skipped */
+#define INT_MCASTIF 0x100 /* bound directly to MCAST address */
+#define INT_PRIVACY 0x200 /* RFC 4941 IPv6 privacy address */
+#define INT_BCASTXMIT 0x400 /* socket setup to allow broadcasts */
+
+/*
+ * Define flasher bits (tests 1 through 11 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.
+ *
+ * Packet errors
+ */
+#define TEST1 0X0001 /* duplicate packet */
+#define TEST2 0x0002 /* bogus packet */
+#define TEST3 0x0004 /* protocol unsynchronized */
+#define TEST4 0x0008 /* access denied */
+#define TEST5 0x0010 /* bad authentication */
+#define TEST6 0x0020 /* bad synch or stratum */
+#define TEST7 0x0040 /* bad header */
+#define TEST8 0x0080 /* bad autokey */
+#define TEST9 0x0100 /* bad crypto */
+#define PKT_TEST_MASK (TEST1 | TEST2 | TEST3 | TEST4 | TEST5 |\
+ TEST6 | TEST7 | TEST8 | TEST9)
+/*
+ * Peer errors
+ */
+#define TEST10 0x0200 /* peer bad synch or stratum */
+#define TEST11 0x0400 /* peer distance exceeded */
+#define TEST12 0x0800 /* peer synchronization loop */
+#define TEST13 0x1000 /* peer unreacable */
+#define PEER_TEST_MASK (TEST10 | TEST11 | TEST12 | TEST13)
+
+/*
+ * 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 *p_link; /* link pointer in free & peer lists */
+ struct peer *adr_link; /* link pointer in address hash */
+ struct peer *aid_link; /* link pointer in associd hash */
+ struct peer *ilink; /* list of peers for interface */
+ sockaddr_u srcadr; /* address of remote host */
+ char * hostname; /* if non-NULL, remote name */
+ struct addrinfo *addrs; /* hostname query result */
+ struct addrinfo *ai; /* position within addrs */
+ endpt * dstadr; /* local address */
+ associd_t associd; /* association ID */
+ u_char version; /* version number */
+ u_char hmode; /* local association mode */
+ u_char hpoll; /* local poll interval */
+ u_char minpoll; /* min poll interval */
+ u_char maxpoll; /* max poll interval */
+ u_int flags; /* association flags */
+ u_char cast_flags; /* additional flags */
+ u_char last_event; /* last peer error code */
+ u_char num_events; /* number of error events */
+ u_int32 ttl; /* ttl/refclock mode */
+ char *ident; /* group identifier name */
+
+ /*
+ * Variables used by reference clock support
+ */
+#ifdef REFCLOCK
+ struct refclockproc *procptr; /* refclock structure pointer */
+ u_char refclktype; /* reference clock type */
+ u_char refclkunit; /* reference clock unit number */
+ u_char sstclktype; /* clock type for system status word */
+#endif /* REFCLOCK */
+
+ /*
+ * Variables set by received packet
+ */
+ u_char leap; /* local leap indicator */
+ u_char pmode; /* remote association mode */
+ u_char stratum; /* remote stratum */
+ u_char ppoll; /* remote poll interval */
+ s_char precision; /* remote clock precision */
+ double rootdelay; /* roundtrip delay to primary source */
+ double rootdisp; /* dispersion to primary source */
+ u_int32 refid; /* remote reference ID */
+ l_fp reftime; /* update epoch */
+
+ /*
+ * Variables used by authenticated client
+ */
+ keyid_t keyid; /* current key ID */
+#ifdef AUTOKEY
+#define clear_to_zero opcode
+ u_int32 opcode; /* last request opcode */
+ associd_t assoc; /* peer association ID */
+ u_int32 crypto; /* peer status word */
+ EVP_PKEY *pkey; /* public key */
+ const EVP_MD *digest; /* message digest algorithm */
+ char *subject; /* certificate subject name */
+ char *issuer; /* certificate issuer name */
+ struct cert_info *xinfo; /* issuer certificate */
+ keyid_t pkeyid; /* previous key ID */
+ keyid_t hcookie; /* host cookie */
+ keyid_t pcookie; /* peer cookie */
+ const struct pkey_info *ident_pkey; /* identity key */
+ BIGNUM *iffval; /* identity challenge (IFF, GQ, MV) */
+ const BIGNUM *grpkey; /* identity challenge key (GQ) */
+ struct value cookval; /* receive cookie values */
+ struct value recval; /* receive autokey values */
+ struct exten *cmmd; /* extension pointer */
+ u_long refresh; /* next refresh epoch */
+
+ /*
+ * Variables used by authenticated server
+ */
+ keyid_t *keylist; /* session key ID list */
+ int keynumber; /* current key number */
+ struct value encrypt; /* send encrypt values */
+ struct value sndval; /* send autokey values */
+#else /* !AUTOKEY follows */
+#define clear_to_zero status
+#endif /* !AUTOKEY */
+
+ /*
+ * Ephemeral state variables
+ */
+ u_char status; /* peer status */
+ u_char new_status; /* under-construction status */
+ u_char reach; /* reachability register */
+ int flash; /* protocol error test tally bits */
+ u_long epoch; /* reference epoch */
+ int burst; /* packets remaining in burst */
+ int retry; /* retry counter */
+ int flip; /* interleave mode control */
+ int filter_nextpt; /* index into filter shift register */
+ double filter_delay[NTP_SHIFT]; /* delay shift register */
+ double filter_offset[NTP_SHIFT]; /* offset shift register */
+ double filter_disp[NTP_SHIFT]; /* dispersion shift register */
+ u_long filter_epoch[NTP_SHIFT]; /* epoch shift register */
+ u_char filter_order[NTP_SHIFT]; /* filter sort index */
+ l_fp rec; /* receive time stamp */
+ l_fp xmt; /* transmit time stamp */
+ l_fp dst; /* destination timestamp */
+ l_fp aorg; /* origin timestamp */
+ l_fp borg; /* alternate origin timestamp */
+ double offset; /* peer clock offset */
+ double delay; /* peer roundtrip delay */
+ double jitter; /* peer jitter (squares) */
+ double disp; /* peer dispersion */
+ double xleave; /* interleave delay */
+ double bias; /* programmed offset bias */
+
+ /*
+ * Variables used to correct for packet length and asymmetry.
+ */
+ double t21; /* outbound packet delay */
+ int t21_bytes; /* outbound packet length */
+ int t21_last; /* last outbound packet length */
+ double r21; /* outbound data rate */
+ double t34; /* inbound packet delay */
+ int t34_bytes; /* inbound packet length */
+ double r34; /* inbound data rate */
+
+ /*
+ * End of clear-to-zero area
+ */
+ u_long update; /* receive epoch */
+#define end_clear_to_zero update
+ int unreach; /* watchdog counter */
+ int throttle; /* rate control */
+ u_long outdate; /* send time last packet */
+ u_long nextdate; /* send time next packet */
+
+ /*
+ * Statistic counters
+ */
+ u_long timereset; /* time stat counters were reset */
+ u_long timereceived; /* last packet received time */
+ u_long timereachable; /* last reachable/unreachable time */
+
+ u_long sent; /* packets sent */
+ u_long received; /* packets received */
+ u_long processed; /* packets processed */
+ u_long badauth; /* bad authentication (TEST5) */
+ u_long bogusorg; /* bogus origin (TEST2, TEST3) */
+ u_long oldpkt; /* old duplicate (TEST1) */
+ u_long seldisptoolarge; /* bad header (TEST6, TEST7) */
+ u_long selbroken; /* KoD received */
+};
+
+/*
+ * 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 and packet mode. Only the modes through
+ * MODE_BROADCAST and MODE_BCLIENT appear in the transition
+ * function. MODE_CONTROL and MODE_PRIVATE can appear in packets,
+ * but those never survive to the transition function.
+ * is a
+/ */
+#define MODE_UNSPEC 0 /* unspecified (old version) */
+#define MODE_ACTIVE 1 /* symmetric active mode */
+#define MODE_PASSIVE 2 /* symmetric passive mode */
+#define MODE_CLIENT 3 /* client mode */
+#define MODE_SERVER 4 /* server mode */
+#define MODE_BROADCAST 5 /* broadcast mode */
+/*
+ * These can appear in packets
+ */
+#define MODE_CONTROL 6 /* control mode */
+#define MODE_PRIVATE 7 /* private mode */
+/*
+ * This is a madeup mode for broadcast client.
+ */
+#define MODE_BCLIENT 6 /* broadcast client mode */
+
+/*
+ * Values for peer.stratum, sys_stratum
+ */
+#define STRATUM_REFCLOCK ((u_char)0) /* default stratum */
+/* 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)16) /* unspecified */
+
+/*
+ * Values for peer.flags
+ */
+#define FLAG_CONFIG 0x0001 /* association was configured */
+#define FLAG_PREEMPT 0x0002 /* preemptable association */
+#define FLAG_AUTHENTIC 0x0004 /* last message was authentic */
+#define FLAG_REFCLOCK 0x0008 /* this is actually a reference clock */
+#define FLAG_BC_VOL 0x0010 /* broadcast client volleying */
+#define FLAG_PREFER 0x0020 /* prefer peer */
+#define FLAG_BURST 0x0040 /* burst mode */
+#define FLAG_PPS 0x0080 /* steered by PPS */
+#define FLAG_IBURST 0x0100 /* initial burst mode */
+#define FLAG_NOSELECT 0x0200 /* never select */
+#define FLAG_TRUE 0x0400 /* force truechimer */
+#define FLAG_SKEY 0x0800 /* autokey authentication */
+#define FLAG_XLEAVE 0x1000 /* interleaved protocol */
+#define FLAG_XB 0x2000 /* interleaved broadcast */
+#define FLAG_XBOGUS 0x4000 /* interleaved bogus packet */
+#ifdef OPENSSL
+#define FLAG_ASSOC 0x8000 /* autokey request */
+#endif /* OPENSSL */
+
+/*
+ * 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(p) (END_CLEAR_TO_ZERO(p) - CLEAR_TO_ZERO(p))
+#define CRYPTO_TO_ZERO(p) ((char *)&((p)->clear_to_zero))
+#define END_CRYPTO_TO_ZERO(p) ((char *)&((p)->end_clear_to_zero))
+#define LEN_CRYPTO_TO_ZERO (END_CRYPTO_TO_ZERO((struct peer *)0) \
+ - CRYPTO_TO_ZERO((struct peer *)0))
+
+/*
+ * 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_SPECTRACOM 4 /* Spectracom (generic) Receivers */
+#define REFCLK_TRUETIME 5 /* TrueTime (generic) Receivers */
+#define REFCLK_IRIG_AUDIO 6 /* IRIG-B/W audio decoder */
+#define REFCLK_CHU_AUDIO 7 /* CHU audio demodulator/decoder */
+#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_ACTS 18 /* Generic 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 /* replaced by REFCLK_ACTS */
+#define REFCLK_USNO 24 /* replaced by REFCLK_ACTS */
+#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_PCF 35 /* Conrad parallel port radio clock */
+#define REFCLK_WWV_AUDIO 36 /* WWV/H audio demodulator/decoder */
+#define REFCLK_FG 37 /* Forum Graphic GPS */
+#define REFCLK_HOPF_SERIAL 38 /* hopf DCF77/GPS serial receiver */
+#define REFCLK_HOPF_PCI 39 /* hopf DCF77/GPS PCI receiver */
+#define REFCLK_JJY 40 /* JJY receiver */
+#define REFCLK_TT560 41 /* TrueTime 560 IRIG-B decoder */
+#define REFCLK_ZYFER 42 /* Zyfer GPStarplus receiver */
+#define REFCLK_RIPENCC 43 /* RIPE NCC Trimble driver */
+#define REFCLK_NEOCLOCK4X 44 /* NeoClock4X DCF77 or TDF receiver */
+#define REFCLK_TSYNCPCI 45 /* Spectracom TSYNC PCI timing board */
+#define REFCLK_GPSDJSON 46
+#define REFCLK_MAX 46
+
+
+/*
+ * 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; /* peer leap indicator */
+ u_char stratum; /* peer stratum */
+ u_char ppoll; /* peer poll interval */
+ s_char precision; /* peer clock precision */
+ u_fp rootdelay; /* roundtrip delay to primary source */
+ u_fp rootdisp; /* dispersion to primary source*/
+ u_int32 refid; /* reference id */
+ l_fp reftime; /* last update time */
+ l_fp org; /* originate time stamp */
+ l_fp rec; /* receive time stamp */
+ l_fp xmt; /* transmit time stamp */
+
+#define LEN_PKT_NOMAC (12 * sizeof(u_int32)) /* min header length */
+#define MIN_MAC_LEN (1 * sizeof(u_int32)) /* crypto_NAK */
+#define MAX_MD5_LEN (5 * sizeof(u_int32)) /* MD5 */
+#define MAX_MAC_LEN (6 * sizeof(u_int32)) /* SHA */
+
+ /*
+ * The length of the packet less MAC must be a multiple of 64
+ * with an RSA modulus and Diffie-Hellman prime of 256 octets
+ * and maximum host name of 128 octets, the maximum autokey
+ * command is 152 octets and maximum autokey response is 460
+ * octets. A packet can contain no more than one command and one
+ * response, so the maximum total extension field length is 864
+ * octets. But, to handle humungus certificates, the bank must
+ * be broke.
+ *
+ * The different definitions of the 'exten' field are here for
+ * the benefit of applications that want to send a packet from
+ * an auto variable in the stack - not using the AUTOKEY version
+ * saves 2KB of stack space. The receive buffer should ALWAYS be
+ * big enough to hold a full extended packet if the extension
+ * fields have to be parsed or skipped.
+ */
+#ifdef AUTOKEY
+ u_int32 exten[(NTP_MAXEXTEN + MAX_MAC_LEN) / sizeof(u_int32)];
+#else /* !AUTOKEY follows */
+ u_int32 exten[(MAX_MAC_LEN) / sizeof(u_int32)];
+#endif /* !AUTOKEY */
+};
+
+/*
+ * 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 in packets and vn_mode
+ * in ntp_monitor.c's mon_entry.
+ */
+#define VN_MODE(v, m) ((((v) & 7) << 3) | ((m) & 0x7))
+#define PKT_LI_VN_MODE(l, v, m) ((((l) & 3) << 6) | VN_MODE((v), (m)))
+
+
+/*
+ * 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 0x080 /* this is a peer event */
+#define CRPT_EVENT 0x100 /* this is a crypto event */
+
+/*
+ * System event codes
+ */
+#define EVNT_UNSPEC 0 /* unspecified */
+#define EVNT_NSET 1 /* freq not set */
+#define EVNT_FSET 2 /* freq set */
+#define EVNT_SPIK 3 /* spike detect */
+#define EVNT_FREQ 4 /* freq mode */
+#define EVNT_SYNC 5 /* clock sync */
+#define EVNT_SYSRESTART 6 /* restart */
+#define EVNT_SYSFAULT 7 /* panic stop */
+#define EVNT_NOPEER 8 /* no sys peer */
+#define EVNT_ARMED 9 /* leap armed */
+#define EVNT_DISARMED 10 /* leap disarmed */
+#define EVNT_LEAP 11 /* leap event */
+#define EVNT_CLOCKRESET 12 /* clock step */
+#define EVNT_KERN 13 /* kernel event */
+#define EVNT_TAI 14 /* TAI */
+#define EVNT_LEAPVAL 15 /* stale leapsecond values */
+
+/*
+ * Peer event codes
+ */
+#define PEVNT_MOBIL (1 | PEER_EVENT) /* mobilize */
+#define PEVNT_DEMOBIL (2 | PEER_EVENT) /* demobilize */
+#define PEVNT_UNREACH (3 | PEER_EVENT) /* unreachable */
+#define PEVNT_REACH (4 | PEER_EVENT) /* reachable */
+#define PEVNT_RESTART (5 | PEER_EVENT) /* restart */
+#define PEVNT_REPLY (6 | PEER_EVENT) /* no reply */
+#define PEVNT_RATE (7 | PEER_EVENT) /* rate exceeded */
+#define PEVNT_DENY (8 | PEER_EVENT) /* access denied */
+#define PEVNT_ARMED (9 | PEER_EVENT) /* leap armed */
+#define PEVNT_NEWPEER (10 | PEER_EVENT) /* sys peer */
+#define PEVNT_CLOCK (11 | PEER_EVENT) /* clock event */
+#define PEVNT_AUTH (12 | PEER_EVENT) /* bad auth */
+#define PEVNT_POPCORN (13 | PEER_EVENT) /* popcorn */
+#define PEVNT_XLEAVE (14 | PEER_EVENT) /* interleave mode */
+#define PEVNT_XERR (15 | PEER_EVENT) /* interleave error */
+
+/*
+ * Clock event codes
+ */
+#define CEVNT_NOMINAL 0 /* unspecified */
+#define CEVNT_TIMEOUT 1 /* no reply */
+#define CEVNT_BADREPLY 2 /* bad format */
+#define CEVNT_FAULT 3 /* fault */
+#define CEVNT_PROP 4 /* bad signal */
+#define CEVNT_BADDATE 5 /* bad date */
+#define CEVNT_BADTIME 6 /* bad time */
+#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 NTP_HASH_SIZE 128
+#define NTP_HASH_MASK (NTP_HASH_SIZE-1)
+#define NTP_HASH_ADDR(src) (sock_hash(src) & NTP_HASH_MASK)
+
+/*
+ * 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
+#define PROTO_PPS 12
+#define PROTO_CAL 13
+#define PROTO_MINCLOCK 14
+#define PROTO_MAXCLOCK 15
+#define PROTO_MINSANE 16
+#define PROTO_FLOOR 17
+#define PROTO_CEILING 18
+#define PROTO_COHORT 19
+#define PROTO_CALLDELAY 20
+#define PROTO_MINDISP 21
+#define PROTO_MAXDIST 22
+ /* available 23 */
+#define PROTO_MAXHOP 24
+#define PROTO_BEACON 25
+#define PROTO_ORPHAN 26
+#define PROTO_ORPHWAIT 27
+#define PROTO_MODE7 28
+
+/*
+ * Configuration items for the loop filter
+ */
+#define LOOP_DRIFTINIT 1 /* iniitialize frequency */
+#define LOOP_KERN_CLEAR 2 /* set initial frequency offset */
+#define LOOP_MAX 3 /* set step offset */
+#define LOOP_PANIC 4 /* set panic offseet */
+#define LOOP_PHI 5 /* set dispersion rate */
+#define LOOP_MINSTEP 6 /* set step timeout */
+#define LOOP_MINPOLL 7 /* set min poll interval (log2 s) */
+#define LOOP_ALLAN 8 /* set minimum Allan intercept */
+#define LOOP_HUFFPUFF 9 /* set huff-n'-puff filter length */
+#define LOOP_FREQ 10 /* set initial frequency */
+#define LOOP_CODEC 11 /* set audio codec frequency */
+#define LOOP_LEAP 12 /* insert leap after second 23:59 */
+#define LOOP_TICK 13 /* sim. low precision clock */
+
+/*
+ * 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 STATS_LEAP_FILE 4 /* configure ntpd leapseconds file */
+
+#define MJD_1900 15020 /* MJD for 1 Jan 1900 */
+
+/*
+ * Default parameters. We use these in the absence of something better.
+ */
+#define INADDR_NTP 0xe0000101 /* NTP multicast address 224.0.1.1 */
+
+/*
+ * Structure used optionally for monitoring when this is turned on.
+ */
+typedef struct mon_data mon_entry;
+struct mon_data {
+ mon_entry * hash_next; /* next structure in hash list */
+ DECL_DLIST_LINK(mon_entry, mru);/* MRU list link pointers */
+ struct interface * lcladr; /* address on which this arrived */
+ l_fp first; /* first time seen */
+ l_fp last; /* last time seen */
+ int leak; /* leaky bucket accumulator */
+ int count; /* total packet count */
+ u_short flags; /* restrict flags */
+ u_char vn_mode; /* packet mode & version */
+ u_char cast_flags; /* flags MDF_?CAST */
+ sockaddr_u rmtadr; /* address of remote host */
+};
+
+/*
+ * Values for cast_flags in mon_entry and struct peer. mon_entry uses
+ * only the first three, MDF_UCAST, MDF_MCAST, and MDF_BCAST.
+ */
+#define MDF_UCAST 0x01 /* unicast client */
+#define MDF_MCAST 0x02 /* multicast server */
+#define MDF_BCAST 0x04 /* broadcast server */
+#define MDF_POOL 0x08 /* pool client solicitor */
+#define MDF_ACAST 0x10 /* manycast client solicitor */
+#define MDF_BCLNT 0x20 /* eph. broadcast/multicast client */
+#define MDF_UCLNT 0x40 /* preemptible manycast or pool client */
+/*
+ * In the context of struct peer in ntpd, three of the cast_flags bits
+ * represent configured associations which never receive packets, and
+ * whose reach is always 0: MDF_BCAST, MDF_MCAST, and MDF_ACAST. The
+ * last can be argued as responses are received, but those responses do
+ * not affect the MDF_ACAST association's reach register, rather they
+ * (may) result in mobilizing ephemeral MDF_ACLNT associations.
+ */
+#define MDF_TXONLY_MASK (MDF_BCAST | MDF_MCAST | MDF_ACAST | MDF_POOL)
+/*
+ * manycastclient-like solicitor association cast_flags bits
+ */
+#define MDF_SOLICIT_MASK (MDF_ACAST | MDF_POOL)
+/*
+ * 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
+ */
+typedef struct res_addr4_tag {
+ u_int32 addr; /* IPv4 addr (host order) */
+ u_int32 mask; /* IPv4 mask (host order) */
+} res_addr4;
+
+typedef struct res_addr6_tag {
+ struct in6_addr addr; /* IPv6 addr (net order) */
+ struct in6_addr mask; /* IPv6 mask (net order) */
+} res_addr6;
+
+typedef struct restrict_u_tag restrict_u;
+struct restrict_u_tag {
+ restrict_u * link; /* link to next entry */
+ u_int32 count; /* number of packets matched */
+ u_short flags; /* accesslist flags */
+ u_short mflags; /* match flags */
+ u_long expire; /* valid until time */
+ union { /* variant starting here */
+ res_addr4 v4;
+ res_addr6 v6;
+ } u;
+};
+#define V4_SIZEOF_RESTRICT_U (offsetof(restrict_u, u) \
+ + sizeof(res_addr4))
+#define V6_SIZEOF_RESTRICT_U (offsetof(restrict_u, u) \
+ + sizeof(res_addr6))
+
+/*
+ * Access flags
+ */
+#define RES_IGNORE 0x0001 /* ignore packet */
+#define RES_DONTSERVE 0x0002 /* access denied */
+#define RES_DONTTRUST 0x0004 /* authentication required */
+#define RES_VERSION 0x0008 /* version mismatch */
+#define RES_NOPEER 0x0010 /* new association denied */
+#define RES_LIMITED 0x0020 /* packet rate exceeded */
+#define RES_FLAGS (RES_IGNORE | RES_DONTSERVE |\
+ RES_DONTTRUST | RES_VERSION |\
+ RES_NOPEER | RES_LIMITED)
+
+#define RES_NOQUERY 0x0040 /* mode 6/7 packet denied */
+#define RES_NOMODIFY 0x0080 /* mode 6/7 modify denied */
+#define RES_NOTRAP 0x0100 /* mode 6/7 set trap denied */
+#define RES_LPTRAP 0x0200 /* mode 6/7 low priority trap */
+
+#define RES_KOD 0x0400 /* send kiss of death packet */
+#define RES_MSSNTP 0x0800 /* enable MS-SNTP authentication */
+#define RES_FLAKE 0x1000 /* flakeway - drop 10% */
+#define RES_NOMRULIST 0x2000 /* mode 6 mrulist denied */
+
+#define RES_ALLFLAGS (RES_FLAGS | RES_NOQUERY | \
+ RES_NOMODIFY | RES_NOTRAP | \
+ RES_LPTRAP | RES_KOD | \
+ RES_MSSNTP | RES_FLAKE | \
+ RES_NOMRULIST)
+
+/*
+ * Match flags
+ */
+#define RESM_INTERFACE 0x1000 /* this is an interface */
+#define RESM_NTPONLY 0x2000 /* match source port 123 */
+#define RESM_SOURCE 0x4000 /* from "restrict source" */
+
+/*
+ * 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 */
+#define RESTRICT_REMOVEIF 4 /* remove an interface restrict entry */
+
+/*
+ * Endpoint structure for the select algorithm
+ */
+struct endpoint {
+ double val; /* offset of endpoint */
+ int type; /* interval entry/exit */
+};
+
+/*
+ * Association matching AM[] return codes
+ */
+#define AM_ERR -1 /* error */
+#define AM_NOMATCH 0 /* no match */
+#define AM_PROCPKT 1 /* server/symmetric packet */
+#define AM_BCST 2 /* broadcast packet */
+#define AM_FXMIT 3 /* client packet */
+#define AM_MANYCAST 4 /* manycast or pool */
+#define AM_NEWPASS 5 /* new passive */
+#define AM_NEWBCL 6 /* new broadcast */
+#define AM_POSSBCL 7 /* discard broadcast */
+
+/* NetInfo configuration locations */
+#ifdef HAVE_NETINFO
+#define NETINFO_CONFIG_DIR "/config/ntp"
+#endif
+
+/* ntpq -c mrulist rows per request limit in ntpd */
+#define MRU_ROW_LIMIT 256
+/* similar datagrams per response limit for ntpd */
+#define MRU_FRAGS_LIMIT 128
+#endif /* NTP_H */
diff --git a/include/ntp_assert.h b/include/ntp_assert.h
new file mode 100644
index 0000000..2f3bbc8
--- /dev/null
+++ b/include/ntp_assert.h
@@ -0,0 +1,108 @@
+/*
+ * ntp_assert.h - design by contract stuff
+ *
+ * example:
+ *
+ * int foo(char *a) {
+ * int result;
+ * int value;
+ *
+ * REQUIRE(a != NULL);
+ * ...
+ * bar(&value);
+ * INSIST(value > 2);
+ * ...
+ *
+ * ENSURE(result != 12);
+ * return result;
+ * }
+ *
+ * open question: when would we use INVARIANT()?
+ *
+ * For cases where the overhead for non-debug builds is deemed too high,
+ * use DEBUG_REQUIRE(), DEBUG_INSIST(), DEBUG_ENSURE(), and/or
+ * DEBUG_INVARIANT().
+ */
+
+#ifndef NTP_ASSERT_H
+#define NTP_ASSERT_H
+
+# ifdef CALYSTO
+/* see: http://www.domagoj-babic.com/index.php/ResearchProjects/Calysto */
+
+extern void calysto_assume(unsigned char cnd); /* assume this always holds */
+extern void calysto_assert(unsigned char cnd); /* check whether this holds */
+#define ALWAYS_REQUIRE(x) calysto_assert(x)
+#define ALWAYS_INSIST(x) calysto_assume(x) /* DLH calysto_assert()? */
+#define ALWAYS_INVARIANT(x) calysto_assume(x)
+#define ALWAYS_ENSURE(x) calysto_assert(x)
+
+/* # elif defined(__COVERITY__) */
+/*
+ * DH: try letting coverity scan our actual assertion macros, now that
+ * isc_assertioncallback_t is marked __attribute__ __noreturn__.
+ */
+
+/*
+ * Coverity has special knowledge that assert(x) terminates the process
+ * if x is not true. Rather than teach it about our assertion macros,
+ * just use the one it knows about for Coverity Prevent scans. This
+ * means our assertion code (and ISC's) escapes Coverity analysis, but
+ * that seems to be a reasonable trade-off.
+ */
+
+/*
+#define ALWAYS_REQUIRE(x) assert(x)
+#define ALWAYS_INSIST(x) assert(x)
+#define ALWAYS_INVARIANT(x) assert(x)
+#define ALWAYS_ENSURE(x) assert(x)
+*/
+
+
+#elif defined(__FLEXELINT__)
+
+#include <assert.h>
+
+#define ALWAYS_REQUIRE(x) assert(x)
+#define ALWAYS_INSIST(x) assert(x)
+#define ALWAYS_INVARIANT(x) assert(x)
+#define ALWAYS_ENSURE(x) assert(x)
+
+# else /* neither Calysto, Coverity or FlexeLint */
+
+#include "isc/assertions.h"
+
+#define ALWAYS_REQUIRE(x) ISC_REQUIRE(x)
+#define ALWAYS_INSIST(x) ISC_INSIST(x)
+#define ALWAYS_INVARIANT(x) ISC_INVARIANT(x)
+#define ALWAYS_ENSURE(x) ISC_ENSURE(x)
+
+# endif /* neither Coverity nor Calysto */
+
+#define REQUIRE(x) ALWAYS_REQUIRE(x)
+#define INSIST(x) ALWAYS_INSIST(x)
+#define INVARIANT(x) ALWAYS_INVARIANT(x)
+#define ENSURE(x) ALWAYS_ENSURE(x)
+
+/*
+ * We initially used NTP_REQUIRE() instead of REQUIRE() etc, but that
+ * is unneccesarily verbose, as libisc use of REQUIRE() etc shows.
+ */
+#define NTP_REQUIRE(x) REQUIRE(x)
+#define NTP_INSIST(x) INSIST(x)
+#define NTP_INVARIANT(x) INVARIANT(x)
+#define NTP_ENSURE(x) ENSURE(x)
+
+# ifdef DEBUG
+#define DEBUG_REQUIRE(x) REQUIRE(x)
+#define DEBUG_INSIST(x) INSIST(x)
+#define DEBUG_INVARIANT(x) INVARIANT(x)
+#define DEBUG_ENSURE(x) ENSURE(x)
+# else
+#define DEBUG_REQUIRE(x) do {} while (FALSE)
+#define DEBUG_INSIST(x) do {} while (FALSE)
+#define DEBUG_INVARIANT(x) do {} while (FALSE)
+#define DEBUG_ENSURE(x) do {} while (FALSE)
+# endif
+
+#endif /* NTP_ASSERT_H */
diff --git a/include/ntp_calendar.h b/include/ntp_calendar.h
new file mode 100644
index 0000000..3ee1ff7
--- /dev/null
+++ b/include/ntp_calendar.h
@@ -0,0 +1,416 @@
+/*
+ * ntp_calendar.h - definitions for the calendar time-of-day routine
+ */
+#ifndef NTP_CALENDAR_H
+#define NTP_CALENDAR_H
+
+#include <time.h>
+
+#include "ntp_types.h"
+
+/* gregorian calendar date */
+struct calendar {
+ uint16_t year; /* year (A.D.) */
+ uint16_t yearday; /* day of year, 1 = January 1 */
+ uint8_t month; /* month, 1 = January */
+ uint8_t monthday; /* day of month */
+ uint8_t hour; /* hour of day, midnight = 0 */
+ uint8_t minute; /* minute of hour */
+ uint8_t second; /* second of minute */
+ uint8_t weekday; /* 0..7, 0=Sunday */
+};
+
+/* ISO week calendar date */
+struct isodate {
+ uint16_t year; /* year (A.D.) */
+ uint8_t week; /* 1..53, week in year */
+ uint8_t weekday; /* 1..7, 1=Monday */
+ uint8_t hour; /* hour of day, midnight = 0 */
+ uint8_t minute; /* minute of hour */
+ uint8_t second; /* second of minute */
+};
+
+/* general split representation */
+typedef struct {
+ int32_t hi;
+ int32_t lo;
+} ntpcal_split;
+
+typedef time_t (*systime_func_ptr)(time_t *);
+
+/*
+ * set the function for getting the system time. This is mostly used for
+ * unit testing to provide a fixed / shifted time stamp. Setting the
+ * value to NULL restores the original function, that is, 'time()',
+ * which is also the automatic default.
+ */
+extern systime_func_ptr ntpcal_set_timefunc(systime_func_ptr);
+
+/*
+ * days-of-week
+ */
+#define CAL_SUNDAY 0
+#define CAL_MONDAY 1
+#define CAL_TUESDAY 2
+#define CAL_WEDNESDAY 3
+#define CAL_THURSDAY 4
+#define CAL_FRIDAY 5
+#define CAL_SATURDAY 6
+#define CAL_SUNDAY7 7 /* also sunday */
+
+/*
+ * 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 SECSPERHR (SECSPERMIN * MINSPERHR)
+#define SECSPERDAY (SECSPERHR * HRSPERDAY)
+#define SECSPERYEAR (365 * SECSPERDAY) /* regular year */
+#define SECSPERLEAPYEAR (366 * SECSPERDAY) /* leap year */
+#define SECSPERAVGYEAR 31556952 /* mean year length over 400yrs */
+
+/*
+ * 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 */
+
+
+extern const char * const months[12];
+extern const char * const daynames[7];
+
+extern void caljulian (uint32_t, struct calendar *);
+extern uint32_t caltontp (const struct calendar *);
+
+/*
+ * Convert between 'time_t' and 'vint64'
+ */
+extern vint64 time_to_vint64(const time_t *);
+extern time_t vint64_to_time(const vint64 *);
+
+/*
+ * Get the build date & time. ATTENTION: The time zone is not specified!
+ * This depends entirely on the C compilers' capabilities to properly
+ * expand the '__TIME__' and '__DATE__' macros, as required by the C
+ * standard.
+ */
+extern int
+ntpcal_get_build_date(struct calendar * /* jd */);
+
+/*
+ * Convert a timestamp in NTP scale to a time_t value in the UN*X
+ * scale with proper epoch unfolding around a given pivot or the
+ * current system time.
+ */
+extern vint64
+ntpcal_ntp_to_time(uint32_t /* ntp */, const time_t * /* pivot */);
+
+/*
+ * Convert a timestamp in NTP scale to a 64bit seconds value in the NTP
+ * scale with proper epoch unfolding around a given pivot or the current
+ * system time.
+ * Note: The pivot must be given in UN*X time scale!
+ */
+extern vint64
+ntpcal_ntp_to_ntp(uint32_t /* ntp */, const time_t * /* pivot */);
+
+/*
+ * Split a time stamp in seconds into elapsed days and elapsed seconds
+ * since midnight.
+ */
+extern ntpcal_split
+ntpcal_daysplit(const vint64 *);
+
+/*
+ * Merge a number of days and a number of seconds into seconds,
+ * expressed in 64 bits to avoid overflow.
+ */
+extern vint64
+ntpcal_dayjoin(int32_t /* days */, int32_t /* seconds */);
+
+/*
+ * Convert elapsed years in Era into elapsed days in Era.
+ */
+extern int32_t
+ntpcal_days_in_years(int32_t /* years */);
+
+/*
+ * Convert a number of elapsed month in a year into elapsed days
+ * in year.
+ *
+ * The month will be normalized, and 'res.hi' will contain the
+ * excessive years that must be considered when converting the years,
+ * while 'res.lo' will contain the days since start of the
+ * year. (Expect the resulting days to be negative, with a positive
+ * excess! But then, we need no leap year flag, either...)
+ */
+extern ntpcal_split
+ntpcal_days_in_months(int32_t /* months */);
+
+/*
+ * Convert ELAPSED years/months/days of gregorian calendar to elapsed
+ * days in Gregorian epoch. No range checks done here!
+ */
+extern int32_t
+ntpcal_edate_to_eradays(int32_t /* years */, int32_t /* months */, int32_t /* mdays */);
+
+/*
+ * Convert a time spec to seconds. No range checks done here!
+ */
+extern int32_t
+ntpcal_etime_to_seconds(int32_t /* hours */, int32_t /* minutes */, int32_t /* seconds */);
+
+/*
+ * Convert ELAPSED years/months/days of gregorian calendar to elapsed
+ * days in year.
+ *
+ * Note: This will give the true difference to the start of the given year,
+ * even if months & days are off-scale.
+ */
+extern int32_t
+ntpcal_edate_to_yeardays(int32_t /* years */, int32_t /* months */, int32_t /* mdays */);
+
+/*
+ * Convert the date part of a 'struct tm' (that is, year, month,
+ * day-of-month) into the RataDie of that day.
+ */
+extern int32_t
+ntpcal_tm_to_rd(const struct tm * /* utm */);
+
+/*
+ * Convert the date part of a 'struct calendar' (that is, year, month,
+ * day-of-month) into the RataDie of that day.
+ */
+extern int32_t
+ntpcal_date_to_rd(const struct calendar * /* jt */);
+
+/*
+ * Given the number of elapsed days in the calendar era, split this
+ * number into the number of elapsed years in 'res.quot' and the
+ * number of elapsed days of that year in 'res.rem'.
+ *
+ * if 'isleapyear' is not NULL, it will receive an integer that is 0
+ * for regular years and a non-zero value for leap years.
+ */
+extern ntpcal_split
+ntpcal_split_eradays(int32_t /* days */, int/*BOOL*/ * /* isleapyear */);
+
+/*
+ * Given a number of elapsed days in a year and a leap year indicator,
+ * split the number of elapsed days into the number of elapsed months
+ * in 'res.quot' and the number of elapsed days of that month in
+ * 'res.rem'.
+ */
+extern ntpcal_split
+ntpcal_split_yeardays(int32_t /* eyd */, int/*BOOL*/ /* isleapyear */);
+
+/*
+ * Convert a RataDie number into the date part of a 'struct
+ * calendar'. Return 0 if the year is regular year, !0 if the year is
+ * a leap year.
+ */
+extern int/*BOOL*/
+ntpcal_rd_to_date(struct calendar * /* jt */, int32_t /* rd */);
+
+/*
+ * Convert a RataDie number into the date part of a 'struct
+ * tm'. Return 0 if the year is regular year, !0 if the year is a leap
+ * year.
+ */
+extern int/*BOOL*/
+ntpcal_rd_to_tm(struct tm * /* utm */, int32_t /* rd */);
+
+/*
+ * Take a value of seconds since midnight and split it into hhmmss in
+ * a 'struct calendar'. Return excessive days.
+ */
+extern int32_t
+ntpcal_daysec_to_date(struct calendar * /* jt */, int32_t /* secs */);
+
+/*
+ * Take the time part of a 'struct calendar' and return the seconds
+ * since midnight.
+ */
+extern int32_t
+ntpcal_date_to_daysec(const struct calendar *);
+
+/*
+ * Take a value of seconds since midnight and split it into hhmmss in
+ * a 'struct tm'. Return excessive days.
+ */
+extern int32_t
+ntpcal_daysec_to_tm(struct tm * /* utm */, int32_t /* secs */);
+
+extern int32_t
+ntpcal_tm_to_daysec(const struct tm * /* utm */);
+
+/*
+ * convert a year number to rata die of year start
+ */
+extern int32_t
+ntpcal_year_to_ystart(int32_t /* year */);
+
+/*
+ * For a given RataDie, get the RataDie of the associated year start,
+ * that is, the RataDie of the last January,1st on or before that day.
+ */
+extern int32_t
+ntpcal_rd_to_ystart(int32_t /* rd */);
+
+/*
+ * convert a RataDie to the RataDie of start of the calendar month.
+ */
+extern int32_t
+ntpcal_rd_to_mstart(int32_t /* year */);
+
+
+extern int
+ntpcal_daysplit_to_date(struct calendar * /* jt */,
+ const ntpcal_split * /* ds */, int32_t /* dof */);
+
+extern int
+ntpcal_daysplit_to_tm(struct tm * /* utm */, const ntpcal_split * /* ds */,
+ int32_t /* dof */);
+
+extern int
+ntpcal_time_to_date(struct calendar * /* jd */, const vint64 * /* ts */);
+
+extern int32_t
+ntpcal_periodic_extend(int32_t /* pivot */, int32_t /* value */,
+ int32_t /* cycle */);
+
+extern int
+ntpcal_ntp64_to_date(struct calendar * /* jd */, const vint64 * /* ntp */);
+
+extern int
+ntpcal_ntp_to_date(struct calendar * /* jd */, uint32_t /* ntp */,
+ const time_t * /* pivot */);
+
+extern vint64
+ntpcal_date_to_ntp64(const struct calendar * /* jd */);
+
+extern uint32_t
+ntpcal_date_to_ntp(const struct calendar * /* jd */);
+
+extern time_t
+ntpcal_date_to_time(const struct calendar * /* jd */);
+
+/*
+ * ISO week-calendar conversions
+ */
+extern int32_t
+isocal_weeks_in_years(int32_t /* years */);
+
+extern ntpcal_split
+isocal_split_eraweeks(int32_t /* weeks */);
+
+extern int
+isocal_ntp64_to_date(struct isodate * /* id */, const vint64 * /* ntp */);
+
+extern int
+isocal_ntp_to_date(struct isodate * /* id */, uint32_t /* ntp */,
+ const time_t * /* pivot */);
+
+extern vint64
+isocal_date_to_ntp64(const struct isodate * /* id */);
+
+extern uint32_t
+isocal_date_to_ntp(const struct isodate * /* id */);
+
+
+/*
+ * day-of-week calculations
+ *
+ * Given a RataDie and a day-of-week, calculate a RDN that is reater-than,
+ * greater-or equal, closest, less-or-equal or less-than the given RDN
+ * and denotes the given day-of-week
+ */
+extern int32_t
+ntpcal_weekday_gt(int32_t /* rdn */, int32_t /* dow */);
+
+extern int32_t
+ntpcal_weekday_ge(int32_t /* rdn */, int32_t /* dow */);
+
+extern int32_t
+ntpcal_weekday_close(int32_t /* rdn */, int32_t /* dow */);
+
+extern int32_t
+ntpcal_weekday_le(int32_t /* rdn */, int32_t /* dow */);
+
+extern int32_t
+ntpcal_weekday_lt(int32_t /* rdn */, int32_t /* dow */);
+
+/*
+ * Additional support stuff for Ed Rheingold's calendrical calculations
+ */
+
+/*
+ * Start day of NTP time as days past the imaginary date 12/1/1 BC.
+ * (This is the beginning of the Christian Era, or BCE.)
+ */
+#define DAY_NTP_STARTS 693596
+
+/*
+ * Start day of the UNIX epoch. This is the Rata Die of 1970-01-01.
+ */
+#define DAY_UNIX_STARTS 719163
+
+/*
+ * Difference between UN*X and NTP epoch (25567).
+ */
+#define NTP_TO_UNIX_DAYS (DAY_UNIX_STARTS - DAY_NTP_STARTS)
+
+/*
+ * Days in a normal 4 year leap year calendar cycle (1461).
+ */
+#define GREGORIAN_NORMAL_LEAP_CYCLE_DAYS (3 * 365 + 366)
+
+/*
+ * Days in a normal 100 year leap year calendar (36524). We lose a
+ * leap day in years evenly divisible by 100 but not by 400.
+ */
+#define GREGORIAN_NORMAL_CENTURY_DAYS \
+ (25 * GREGORIAN_NORMAL_LEAP_CYCLE_DAYS - 1)
+
+/*
+ * The Gregorian calendar is based on a 400 year cycle. This is the
+ * number of days in each cycle (146097). We gain a leap day in years
+ * divisible by 400 relative to the "normal" century.
+ */
+#define GREGORIAN_CYCLE_DAYS (4 * GREGORIAN_NORMAL_CENTURY_DAYS + 1)
+
+/*
+ * Number of weeks in 400 years (20871).
+ */
+#define GREGORIAN_CYCLE_WEEKS (GREGORIAN_CYCLE_DAYS / 7)
+
+#define is_leapyear(y) (!((y) % 4) && !(!((y) % 100) && (y) % 400))
+
+#endif
diff --git a/include/ntp_cmdargs.h b/include/ntp_cmdargs.h
new file mode 100644
index 0000000..de45d8d
--- /dev/null
+++ b/include/ntp_cmdargs.h
@@ -0,0 +1 @@
+extern void getCmdOpts(int, char **);
diff --git a/include/ntp_config.h b/include/ntp_config.h
new file mode 100644
index 0000000..900688c
--- /dev/null
+++ b/include/ntp_config.h
@@ -0,0 +1,322 @@
+#ifndef NTP_CONFIG_H
+#define NTP_CONFIG_H
+
+#ifdef HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif /* HAVE_SYS_RESOURCE_H */
+
+#include "ntp_machine.h"
+#include "ntpsim.h"
+
+
+/*
+ * Configuration file name
+ */
+#ifndef CONFIG_FILE
+# ifndef SYS_WINNT
+# define CONFIG_FILE "/etc/ntp.conf"
+# else /* SYS_WINNT */
+# define CONFIG_FILE "%windir%\\system32\\drivers\\etc\\ntp.conf"
+# define ALT_CONFIG_FILE "%windir%\\ntp.conf"
+# define NTP_KEYSDIR "%windir%\\system32\\drivers\\etc"
+# endif /* SYS_WINNT */
+#endif /* not CONFIG_FILE */
+
+
+/*
+ * We keep config trees around for possible saveconfig use. When
+ * built with configure --disable-saveconfig, and when built with
+ * debugging enabled, include the free_config_*() routines. In the
+ * DEBUG case, they are used in an atexit() cleanup routine to make
+ * postmortem leak check reports more interesting.
+ */
+#if !defined(FREE_CFG_T) && (!defined(SAVECONFIG) || defined(DEBUG))
+#define FREE_CFG_T
+#endif
+
+/* Limits */
+#define MAXLINE 1024
+
+/* Configuration sources */
+
+#define CONF_SOURCE_FILE 0
+#define CONF_SOURCE_NTPQ 1
+
+/* list of servers from command line for config_peers() */
+extern int cmdline_server_count;
+extern char ** cmdline_servers;
+
+/* set to zero if admin doesn't want memory locked */
+extern int do_memlock;
+
+typedef struct int_range_tag {
+ int first;
+ int last;
+} int_range;
+
+/* Structure for storing an attribute-value pair */
+typedef struct attr_val_tag attr_val;
+struct attr_val_tag {
+ attr_val * link;
+ int attr;
+ int type; /* T_String, T_Integer, ... */
+ union val {
+ int i;
+ u_int u;
+ int_range r;
+ double d;
+ char * s;
+ } value;
+};
+
+typedef DECL_FIFO_ANCHOR(attr_val) attr_val_fifo;
+
+/* Structure for nodes on the syntax tree */
+typedef struct address_node_tag address_node;
+struct address_node_tag {
+ address_node * link;
+ char * address;
+ u_short type; /* family, AF_UNSPEC (0), AF_INET[6] */
+};
+
+typedef DECL_FIFO_ANCHOR(address_node) address_fifo;
+
+typedef struct int_node_tag int_node;
+struct int_node_tag {
+ int_node * link;
+ int i;
+};
+
+typedef DECL_FIFO_ANCHOR(int_node) int_fifo;
+
+typedef struct string_node_tag string_node;
+struct string_node_tag {
+ string_node * link;
+ char * s;
+};
+
+typedef DECL_FIFO_ANCHOR(string_node) string_fifo;
+
+typedef struct restrict_node_tag restrict_node;
+struct restrict_node_tag {
+ restrict_node * link;
+ address_node * addr;
+ address_node * mask;
+ int_fifo * flags;
+ int line_no;
+};
+
+typedef DECL_FIFO_ANCHOR(restrict_node) restrict_fifo;
+
+typedef struct peer_node_tag peer_node;
+struct peer_node_tag {
+ peer_node * link;
+ int host_mode;
+ address_node * addr;
+ attr_val_fifo * peerflags;
+ u_char minpoll;
+ u_char maxpoll;
+ u_int32 ttl;
+ u_char peerversion;
+ keyid_t peerkey;
+ char * group;
+};
+
+typedef DECL_FIFO_ANCHOR(peer_node) peer_fifo;
+
+typedef struct unpeer_node_tag unpeer_node;
+struct unpeer_node_tag {
+ unpeer_node * link;
+ associd_t assocID;
+ address_node * addr;
+};
+
+typedef DECL_FIFO_ANCHOR(unpeer_node) unpeer_fifo;
+
+typedef struct auth_node_tag auth_node;
+struct auth_node_tag {
+ int control_key;
+ int cryptosw;
+ attr_val_fifo * crypto_cmd_list;
+ char * keys;
+ char * keysdir;
+ int request_key;
+ int revoke;
+ attr_val_fifo * trusted_key_list;
+ char * ntp_signd_socket;
+};
+
+typedef struct filegen_node_tag filegen_node;
+struct filegen_node_tag {
+ filegen_node * link;
+ int filegen_token;
+ attr_val_fifo * options;
+};
+
+typedef DECL_FIFO_ANCHOR(filegen_node) filegen_fifo;
+
+typedef struct setvar_node_tag setvar_node;
+struct setvar_node_tag {
+ setvar_node * link;
+ char * var;
+ char * val;
+ int isdefault;
+};
+
+typedef DECL_FIFO_ANCHOR(setvar_node) setvar_fifo;
+
+typedef struct nic_rule_node_tag nic_rule_node;
+struct nic_rule_node_tag {
+ nic_rule_node * link;
+ int match_class;
+ char * if_name; /* or numeric address */
+ int action;
+};
+
+typedef DECL_FIFO_ANCHOR(nic_rule_node) nic_rule_fifo;
+
+typedef struct addr_opts_node_tag addr_opts_node;
+struct addr_opts_node_tag {
+ addr_opts_node *link;
+ address_node * addr;
+ attr_val_fifo * options;
+};
+
+typedef DECL_FIFO_ANCHOR(addr_opts_node) addr_opts_fifo;
+
+typedef struct sim_node_tag sim_node;
+struct sim_node_tag {
+ sim_node * link;
+ attr_val_fifo * init_opts;
+ server_info_fifo * servers;
+};
+
+typedef DECL_FIFO_ANCHOR(sim_node) sim_fifo;
+
+/* The syntax tree */
+typedef struct config_tree_tag config_tree;
+struct config_tree_tag {
+ config_tree * link;
+
+ attr_val source;
+ time_t timestamp;
+
+ peer_fifo * peers;
+ unpeer_fifo * unpeers;
+
+ /* Other Modes */
+ int broadcastclient;
+ address_fifo * manycastserver;
+ address_fifo * multicastclient;
+
+ attr_val_fifo * orphan_cmds; /* s/b renamed tos_options */
+
+ /* Monitoring Configuration */
+ int_fifo * stats_list;
+ char * stats_dir;
+ filegen_fifo * filegen_opts;
+
+ /* Access Control Configuration */
+ attr_val_fifo * discard_opts;
+ attr_val_fifo * mru_opts;
+ restrict_fifo * restrict_opts;
+
+ addr_opts_fifo *fudge;
+ attr_val_fifo * rlimit;
+ attr_val_fifo * tinker;
+ attr_val_fifo * enable_opts;
+ attr_val_fifo * disable_opts;
+
+ auth_node auth;
+
+ attr_val_fifo * logconfig;
+ string_fifo * phone;
+ setvar_fifo * setvar;
+ int_fifo * ttl;
+ addr_opts_fifo *trap;
+ attr_val_fifo * vars;
+ nic_rule_fifo * nic_rules;
+ int_fifo * reset_counters;
+
+ sim_fifo * sim_details;
+};
+
+
+/* Structure for holding a remote configuration command */
+struct REMOTE_CONFIG_INFO {
+ char buffer[MAXLINE];
+ char err_msg[MAXLINE];
+ int pos;
+ int err_pos;
+ int no_errors;
+};
+
+
+/*
+ * context for trap_name_resolved() to call ctlsettrap() once the
+ * name->address resolution completes.
+ */
+typedef struct settrap_parms_tag {
+ sockaddr_u ifaddr;
+ int ifaddr_nonnull;
+} settrap_parms;
+
+
+/* get text from T_ tokens */
+const char * token_name(int token);
+
+/* generic fifo routines for structs linked by 1st member */
+void* append_gen_fifo(void *fifo, void *entry);
+void * concat_gen_fifos(void *first, void *second);
+#define APPEND_G_FIFO(pf, pe) \
+ ((pf) = append_gen_fifo((pf), (pe)))
+#define CONCAT_G_FIFOS(first, second) \
+ ((first) = concat_gen_fifos((first), (second)))
+#define HEAD_PFIFO(pf) \
+ (((pf) != NULL) \
+ ? HEAD_FIFO(*(pf)) \
+ : NULL)
+
+peer_node *create_peer_node(int hmode, address_node *addr,
+ attr_val_fifo *options);
+unpeer_node *create_unpeer_node(address_node *addr);
+address_node *create_address_node(char *addr, int type);
+void destroy_address_node(address_node *my_node);
+attr_val *create_attr_dval(int attr, double value);
+attr_val *create_attr_ival(int attr, int value);
+attr_val *create_attr_uval(int attr, u_int value);
+attr_val *create_attr_rangeval(int attr, int first, int last);
+attr_val *create_attr_sval(int attr, char *s);
+filegen_node *create_filegen_node(int filegen_token,
+ attr_val_fifo *options);
+string_node *create_string_node(char *str);
+restrict_node *create_restrict_node(address_node *addr,
+ address_node *mask,
+ int_fifo *flags, int line_no);
+int_node *create_int_node(int val);
+addr_opts_node *create_addr_opts_node(address_node *addr,
+ attr_val_fifo *options);
+sim_node *create_sim_node(attr_val_fifo *init_opts,
+ server_info_fifo *servers);
+setvar_node *create_setvar_node(char *var, char *val, int isdefault);
+nic_rule_node *create_nic_rule_node(int match_class, char *if_name,
+ int action);
+
+script_info *create_sim_script_info(double duration,
+ attr_val_fifo *script_queue);
+server_info *create_sim_server(address_node *addr, double server_offset,
+ script_info_fifo *script);
+
+extern struct REMOTE_CONFIG_INFO remote_config;
+void config_remotely(sockaddr_u *);
+
+#ifdef SAVECONFIG
+int dump_config_tree(config_tree *ptree, FILE *df, int comment);
+int dump_all_config_trees(FILE *df, int comment);
+#endif
+
+#if defined(HAVE_SETRLIMIT)
+void ntp_rlimit(int, rlim_t, int, char *);
+#endif
+
+#endif /* !defined(NTP_CONFIG_H) */
diff --git a/include/ntp_control.h b/include/ntp_control.h
new file mode 100644
index 0000000..be5b16d
--- /dev/null
+++ b/include/ntp_control.h
@@ -0,0 +1,192 @@
+/*
+ * ntp_control.h - definitions related to NTP mode 6 control messages
+ */
+
+#include "ntp_types.h"
+
+typedef union ctl_pkt_u_tag {
+ u_char data[480 + MAX_MAC_LEN]; /* data + auth */
+ u_int32 u32[(480 + MAX_MAC_LEN) / sizeof(u_int32)];
+} ctl_pkt_u;
+
+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 */
+ associd_t associd; /* association ID */
+ u_short offset; /* offset of this batch of data */
+ u_short count; /* count of data in this packet */
+ ctl_pkt_u u;
+};
+
+/*
+ * Length of the control header, in octets
+ */
+#define CTL_HEADER_LEN (offsetof(struct ntp_control, u))
+#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) ((CTL_RESPONSE & (r_m_e_op)) != 0)
+#define CTL_ISMORE(r_m_e_op) ((CTL_MORE & (r_m_e_op)) != 0)
+#define CTL_ISERROR(r_m_e_op) ((CTL_ERROR & (r_m_e_op)) != 0)
+#define CTL_OP(r_m_e_op) (CTL_OP_MASK & (r_m_e_op))
+
+/*
+ * Opcodes
+ */
+#define CTL_OP_UNSPEC 0 /* unspeciffied */
+#define CTL_OP_READSTAT 1 /* read status */
+#define CTL_OP_READVAR 2 /* read variables */
+#define CTL_OP_WRITEVAR 3 /* write variables */
+#define CTL_OP_READCLOCK 4 /* read clock variables */
+#define CTL_OP_WRITECLOCK 5 /* write clock variables */
+#define CTL_OP_SETTRAP 6 /* set trap address */
+#define CTL_OP_ASYNCMSG 7 /* asynchronous message */
+#define CTL_OP_CONFIGURE 8 /* runtime configuration */
+#define CTL_OP_SAVECONFIG 9 /* save config to file */
+#define CTL_OP_READ_MRU 10 /* retrieve MRU (mrulist) */
+#define CTL_OP_READ_ORDLIST_A 11 /* ordered list req. auth. */
+#define CTL_OP_REQ_NONCE 12 /* request a client nonce */
+#define CTL_OP_UNSETTRAP 31 /* unset trap */
+
+/*
+ * {En,De}coding of the system status word
+ */
+#define CTL_SST_TS_UNSPEC 0 /* unspec */
+#define CTL_SST_TS_ATOM 1 /* pps */
+#define CTL_SST_TS_LF 2 /* lf radio */
+#define CTL_SST_TS_HF 3 /* hf radio */
+#define CTL_SST_TS_UHF 4 /* uhf radio */
+#define CTL_SST_TS_LOCAL 5 /* local */
+#define CTL_SST_TS_NTP 6 /* ntp */
+#define CTL_SST_TS_UDPTIME 7 /* other */
+#define CTL_SST_TS_WRSTWTCH 8 /* wristwatch */
+#define CTL_SST_TS_TELEPHONE 9 /* telephone */
+
+#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_BCAST 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 /* + candidate */
+#define CTL_PST_SEL_EXCESS 5 /* # backup */
+#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 */
+
+
+/*
+ * Definition of the structure used internally to hold trap information.
+ * ntp_request.c wants to see this.
+ */
+struct ctl_trap {
+ sockaddr_u 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 */
+};
+extern struct ctl_trap ctl_traps[CTL_MAXTRAPS];
+
+/*
+ * 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
+
+/*
+ * IFSTATS_FIELDS is the number of fields ntpd supplies for each ifstats
+ * row. Similarly RESLIST_FIELDS for reslist.
+ */
+#define IFSTATS_FIELDS 12
+#define RESLIST_FIELDS 4
+
diff --git a/include/ntp_crypto.h b/include/ntp_crypto.h
new file mode 100644
index 0000000..b801006
--- /dev/null
+++ b/include/ntp_crypto.h
@@ -0,0 +1,190 @@
+/*
+ * ntp_crypto.h - definitions for cryptographic operations
+ */
+#ifndef NTP_CRYPTO_H
+#define NTP_CRYPTO_H
+
+/*
+ * Configuration codes (also needed for parser without AUTOKEY)
+ */
+#define CRYPTO_CONF_NONE 0 /* nothing doing */
+#define CRYPTO_CONF_PRIV 1 /* host name */
+#define CRYPTO_CONF_IDENT 2 /* group name */
+#define CRYPTO_CONF_CERT 3 /* certificate file name */
+#define CRYPTO_CONF_RAND 4 /* random seed file name */
+#define CRYPTO_CONF_IFFPAR 5 /* IFF parameters file name */
+#define CRYPTO_CONF_GQPAR 6 /* GQ parameters file name */
+#define CRYPTO_CONF_MVPAR 7 /* MV parameters file name */
+#define CRYPTO_CONF_PW 8 /* private key password */
+#define CRYPTO_CONF_NID 9 /* specify digest name */
+
+#ifdef AUTOKEY
+#ifndef OPENSSL
+#error AUTOKEY should be defined only if OPENSSL is.
+invalidsyntax: AUTOKEY should be defined only if OPENSSL is.
+#endif
+
+#include "openssl/evp.h"
+#include "ntp_calendar.h" /* for fields in the cert_info structure */
+
+
+/*
+ * The following bits are set by the CRYPTO_ASSOC message from
+ * the server and are not modified by the client.
+ */
+#define CRYPTO_FLAG_ENAB 0x0001 /* crypto enable */
+#define CRYPTO_FLAG_TAI 0x0002 /* leapseconds table */
+
+#define CRYPTO_FLAG_PRIV 0x0010 /* PC identity scheme */
+#define CRYPTO_FLAG_IFF 0x0020 /* IFF identity scheme */
+#define CRYPTO_FLAG_GQ 0x0040 /* GQ identity scheme */
+#define CRYPTO_FLAG_MV 0x0080 /* MV identity scheme */
+#define CRYPTO_FLAG_MASK 0x00f0 /* identity scheme mask */
+
+/*
+ * The following bits are used by the client during the protocol
+ * exchange.
+ */
+#define CRYPTO_FLAG_CERT 0x0100 /* public key verified */
+#define CRYPTO_FLAG_VRFY 0x0200 /* identity verified */
+#define CRYPTO_FLAG_PROV 0x0400 /* signature verified */
+#define CRYPTO_FLAG_COOK 0x0800 /* cookie verifed */
+#define CRYPTO_FLAG_AUTO 0x1000 /* autokey verified */
+#define CRYPTO_FLAG_SIGN 0x2000 /* certificate signed */
+#define CRYPTO_FLAG_LEAP 0x4000 /* leapsecond values verified */
+#define CRYPTO_FLAG_ALL 0x7f00 /* all mask */
+
+/*
+ * Flags used for certificate management
+ */
+#define CERT_TRUST 0x01 /* certificate is trusted */
+#define CERT_SIGN 0x02 /* certificate is signed */
+#define CERT_VALID 0x04 /* certificate is valid */
+#define CERT_PRIV 0x08 /* certificate is private */
+#define CERT_ERROR 0x80 /* certificate has errors */
+
+/*
+ * Extension field definitions
+ */
+#define CRYPTO_MAXLEN 1024 /* max extension field length */
+#define CRYPTO_VN 2 /* current protocol version number */
+#define CRYPTO_CMD(x) (((CRYPTO_VN << 8) | (x)) << 16)
+#define CRYPTO_NULL CRYPTO_CMD(0) /* no operation */
+#define CRYPTO_ASSOC CRYPTO_CMD(1) /* association */
+#define CRYPTO_CERT CRYPTO_CMD(2) /* certificate */
+#define CRYPTO_COOK CRYPTO_CMD(3) /* cookie value */
+#define CRYPTO_AUTO CRYPTO_CMD(4) /* autokey values */
+#define CRYPTO_LEAP CRYPTO_CMD(5) /* leapsecond values */
+#define CRYPTO_SIGN CRYPTO_CMD(6) /* certificate sign */
+#define CRYPTO_IFF CRYPTO_CMD(7) /* IFF identity scheme */
+#define CRYPTO_GQ CRYPTO_CMD(8) /* GQ identity scheme */
+#define CRYPTO_MV CRYPTO_CMD(9) /* MV identity scheme */
+#define CRYPTO_RESP 0x80000000 /* response */
+#define CRYPTO_ERROR 0x40000000 /* error */
+
+/*
+ * Autokey event codes
+ */
+#define XEVNT_CMD(x) (CRPT_EVENT | (x))
+#define XEVNT_OK XEVNT_CMD(0) /* success */
+#define XEVNT_LEN XEVNT_CMD(1) /* bad field format or length */
+#define XEVNT_TSP XEVNT_CMD(2) /* bad timestamp */
+#define XEVNT_FSP XEVNT_CMD(3) /* bad filestamp */
+#define XEVNT_PUB XEVNT_CMD(4) /* bad or missing public key */
+#define XEVNT_MD XEVNT_CMD(5) /* unsupported digest type */
+#define XEVNT_KEY XEVNT_CMD(6) /* unsupported identity type */
+#define XEVNT_SGL XEVNT_CMD(7) /* bad signature length */
+#define XEVNT_SIG XEVNT_CMD(8) /* signature not verified */
+#define XEVNT_VFY XEVNT_CMD(9) /* certificate not verified */
+#define XEVNT_PER XEVNT_CMD(10) /* host certificate expired */
+#define XEVNT_CKY XEVNT_CMD(11) /* bad or missing cookie */
+#define XEVNT_DAT XEVNT_CMD(12) /* bad or missing leapseconds */
+#define XEVNT_CRT XEVNT_CMD(13) /* bad or missing certificate */
+#define XEVNT_ID XEVNT_CMD(14) /* bad or missing group key */
+#define XEVNT_ERR XEVNT_CMD(15) /* protocol error */
+
+/*
+ * Miscellaneous crypto stuff
+ */
+#define NTP_MAXSESSION 100 /* maximum session key list entries */
+#define NTP_MAXEXTEN 2048 /* maximum extension field size */
+#define NTP_AUTOMAX 12 /* default key list timeout (log2 s) */
+#define KEY_REVOKE 17 /* default key revoke timeout (log2 s) */
+#define NTP_REFRESH 19 /* default restart timeout (log2 s) */
+#define NTP_MAXKEY 65535 /* maximum symmetric key ID */
+
+/*
+ * The autokey structure holds the values used to authenticate key IDs.
+ */
+struct autokey { /* network byte order */
+ keyid_t key; /* key ID */
+ int32 seq; /* key number */
+};
+
+/*
+ * The value structure holds variable length data such as public
+ * key, agreement parameters, public valule and leapsecond table.
+ * They are in network byte order.
+ */
+struct value { /* network byte order */
+ tstamp_t tstamp; /* timestamp */
+ tstamp_t fstamp; /* filestamp */
+ u_int32 vallen; /* value length */
+ void *ptr; /* data pointer (various) */
+ u_int32 siglen; /* signature length */
+ u_char *sig; /* signature */
+};
+
+/*
+ * The packet extension field structures are used to hold values
+ * and signatures in network byte order.
+ */
+struct exten {
+ u_int32 opcode; /* opcode */
+ u_int32 associd; /* association ID */
+ u_int32 tstamp; /* timestamp */
+ u_int32 fstamp; /* filestamp */
+ u_int32 vallen; /* value length */
+ u_int32 pkt[1]; /* start of value field */
+};
+
+
+/*
+ * The certificate info/value structure
+ */
+struct cert_info {
+ struct cert_info *link; /* forward link */
+ u_int flags; /* flags that wave */
+ EVP_PKEY *pkey; /* generic key */
+ long version; /* X509 version */
+ int nid; /* signature/digest ID */
+ const EVP_MD *digest; /* message digest algorithm */
+ u_long serial; /* serial number */
+ struct calendar first; /* not valid before */
+ struct calendar last; /* not valid after */
+ char *subject; /* subject common name */
+ char *issuer; /* issuer common name */
+ BIGNUM *grpkey; /* GQ group key */
+ struct value cert; /* certificate/value */
+};
+
+/*
+ * The keys info/value structure
+ */
+struct pkey_info {
+ struct pkey_info *link; /* forward link */
+ EVP_PKEY *pkey; /* generic key */
+ char *name; /* file name */
+ tstamp_t fstamp; /* filestamp */
+};
+
+/*
+ * Cryptographic values
+ */
+extern u_int crypto_flags; /* status word */
+extern int crypto_nid; /* digest nid */
+extern struct value hostval; /* host name/value */
+extern struct cert_info *cinfo; /* host certificate information */
+extern struct value tai_leap; /* leapseconds table */
+#endif /* AUTOKEY */
+#endif /* NTP_CRYPTO_H */
diff --git a/include/ntp_datum.h b/include/ntp_datum.h
new file mode 100644
index 0000000..2aa2cb7
--- /dev/null
+++ b/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/include/ntp_debug.h b/include/ntp_debug.h
new file mode 100644
index 0000000..b0e846e
--- /dev/null
+++ b/include/ntp_debug.h
@@ -0,0 +1,27 @@
+/*
+ * $Header$
+ *
+ * $Created: Sat Aug 20 14:23:01 2005 $
+ *
+ * Copyright (C) 2005 by Frank Kardel
+ */
+#ifndef NTP_DEBUG_H
+#define NTP_DEBUG_H
+
+/*
+ * macro for debugging output - cut down on #ifdef pollution.
+ *
+ * TRACE() is similar to ntpd's DPRINTF() for utilities and libntp.
+ * Uses mprintf() and so supports %m, replaced by strerror(errno).
+ *
+ * The calling convention is not attractive:
+ * TRACE(debuglevel, (fmt, ...));
+ * TRACE(2, ("this will appear on stdout if debug >= %d\n", 2));
+ */
+#define TRACE(lvl, arg) \
+ do { \
+ if (debug >= (lvl)) \
+ mprintf arg; \
+ } while (0)
+
+#endif /* NTP_DEBUG_H */
diff --git a/include/ntp_filegen.h b/include/ntp_filegen.h
new file mode 100644
index 0000000..f5ba8af
--- /dev/null
+++ b/include/ntp_filegen.h
@@ -0,0 +1,56 @@
+/*
+ * 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 Universitaet Erlangen-Nuernberg, 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_tag {
+ FILE * fp; /* file referring to current generation */
+ char * dir; /* currently always statsdir */
+ char * fname; /* filename prefix of generation file */
+ /* must be malloced, will be fed to free() */
+ u_long id_lo; /* lower bound of ident value */
+ u_long id_hi; /* upper bound of ident value */
+ u_char type; /* type of file generation */
+ u_char flag; /* flags modifying processing of file generation */
+} FILEGEN;
+
+extern void filegen_setup (FILEGEN *, u_int32);
+extern void filegen_config (FILEGEN *, const char *, const char *,
+ u_int, u_int);
+extern void filegen_statsdir(void);
+extern FILEGEN *filegen_get (const char *);
+extern void filegen_register (const char *, const char *, FILEGEN *);
+#ifdef DEBUG
+extern void filegen_unregister(char *);
+#endif
diff --git a/include/ntp_fp.h b/include/ntp_fp.h
new file mode 100644
index 0000000..1b97e8b
--- /dev/null
+++ b/include/ntp_fp.h
@@ -0,0 +1,420 @@
+/*
+ * ntp_fp.h - definitions for NTP fixed/floating-point arithmetic
+ */
+
+#ifndef NTP_FP_H
+#define NTP_FP_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;
+ u_int32 l_uf;
+} l_fp;
+
+#define l_ui Ul_i.Xl_ui /* unsigned integral part */
+#define l_i Ul_i.Xl_i /* signed integral 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 NTOHS_FP(x) (ntohl(x))
+
+#define NTOHL_MFP(ni, nf, hi, hf) \
+ do { \
+ (hi) = ntohl(ni); \
+ (hf) = ntohl(nf); \
+ } while (FALSE)
+
+#define HTONL_MFP(hi, hf, ni, nf) \
+ do { \
+ (ni) = htonl(hi); \
+ (nf) = htonl(hf); \
+ } while (FALSE)
+
+#define HTONL_FP(h, n) \
+ HTONL_MFP((h)->l_ui, (h)->l_uf, (n)->l_ui, (n)->l_uf)
+
+#define NTOHL_FP(n, h) \
+ NTOHL_MFP((n)->l_ui, (n)->l_uf, (h)->l_ui, (h)->l_uf)
+
+/* Convert unsigned ts fraction to net order ts */
+#define HTONL_UF(uf, nts) \
+ do { \
+ (nts)->l_ui = 0; \
+ (nts)->l_uf = htonl(uf); \
+ } while (FALSE)
+
+/*
+ * 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_uf)
+
+#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 = 0x7fffffffu, (v)->l_uf = 0xffffffffu)
+#define MINLFP(v) ((v)->l_ui = 0x80000000u, (v)->l_uf = 0u)
+
+/*
+ * 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 { \
+ (v_f) = ~(v_f) + 1u; \
+ (v_i) = ~(v_i) + ((v_f) == 0); \
+ } while (FALSE)
+
+#define M_NEGM(r_i, r_f, a_i, a_f) /* r = -a */ \
+ do { \
+ (r_f) = ~(a_f) + 1u; \
+ (r_i) = ~(a_i) + ((r_f) == 0); \
+ } while (FALSE)
+
+#define M_ADD(r_i, r_f, a_i, a_f) /* r += a */ \
+ do { \
+ u_int32 add_t = (r_f); \
+ (r_f) += (a_f); \
+ (r_i) += (a_i) + ((u_int32)(r_f) < add_t); \
+ } while (FALSE)
+
+#define M_ADD3(r_o, r_i, r_f, a_o, a_i, a_f) /* r += a, three word */ \
+ do { \
+ u_int32 add_t, add_c; \
+ add_t = (r_f); \
+ (r_f) += (a_f); \
+ add_c = ((u_int32)(r_f) < add_t); \
+ (r_i) += add_c; \
+ add_c = ((u_int32)(r_i) < add_c); \
+ add_t = (r_i); \
+ (r_i) += (a_i); \
+ add_c |= ((u_int32)(r_i) < add_t); \
+ (r_o) += (a_o) + add_c; \
+ } while (FALSE)
+
+#define M_SUB(r_i, r_f, a_i, a_f) /* r -= a */ \
+ do { \
+ u_int32 sub_t = (r_f); \
+ (r_f) -= (a_f); \
+ (r_i) -= (a_i) + ((u_int32)(r_f) > sub_t); \
+ } while (FALSE)
+
+#define M_RSHIFTU(v_i, v_f) /* v >>= 1, v is unsigned */ \
+ do { \
+ (v_f) = ((u_int32)(v_f) >> 1) | ((u_int32)(v_i) << 31); \
+ (v_i) = ((u_int32)(v_i) >> 1); \
+ } while (FALSE)
+
+#define M_RSHIFT(v_i, v_f) /* v >>= 1, v is signed */ \
+ do { \
+ (v_f) = ((u_int32)(v_f) >> 1) | ((u_int32)(v_i) << 31); \
+ (v_i) = ((u_int32)(v_i) >> 1) | ((u_int32)(v_i) & 0x80000000); \
+ } while (FALSE)
+
+#define M_LSHIFT(v_i, v_f) /* v <<= 1 */ \
+ do { \
+ (v_i) = ((u_int32)(v_i) << 1) | ((u_int32)(v_f) >> 31); \
+ (v_f) = ((u_int32)(v_f) << 1); \
+ } while (FALSE)
+
+#define M_LSHIFT3(v_o, v_i, v_f) /* v <<= 1, with overflow */ \
+ do { \
+ (v_o) = ((u_int32)(v_o) << 1) | ((u_int32)(v_i) >> 31); \
+ (v_i) = ((u_int32)(v_i) << 1) | ((u_int32)(v_f) >> 31); \
+ (v_f) = ((u_int32)(v_f) << 1); \
+ } while (FALSE)
+
+#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 { \
+ int32 add_f = (int32)(f); \
+ if (add_f >= 0) \
+ M_ADD((r_i), (r_f), 0, (uint32)( add_f)); \
+ else \
+ M_SUB((r_i), (r_f), 0, (uint32)(-add_f)); \
+ } while(0)
+
+#define M_ISNEG(v_i) /* v < 0 */ \
+ (((v_i) & 0x80000000) != 0)
+
+#define M_ISGT(a_i, a_f, b_i, b_f) /* a > b signed */ \
+ (((u_int32)((a_i) ^ 0x80000000) > (u_int32)((b_i) ^ 0x80000000)) || \
+ ((a_i) == (b_i) && ((u_int32)(a_f)) > ((u_int32)(b_f))))
+
+#define M_ISGTU(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_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 */ \
+ (((u_int32)((a_i) ^ 0x80000000) > (u_int32)((b_i) ^ 0x80000000)) || \
+ ((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 */ \
+ ((u_int32)(a_i) == (u_int32)(b_i) && (u_int32)(a_f) == (u_int32)(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_RSHIFTU((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) M_ISNEG((v)->l_ui)
+#define L_ISZERO(v) (((v)->l_ui | (v)->l_uf) == 0)
+#define L_ISGT(a, b) M_ISGT((a)->l_i, (a)->l_uf, (b)->l_i, (b)->l_uf)
+#define L_ISGTU(a, b) M_ISGTU((a)->l_ui, (a)->l_uf, (b)->l_ui, (b)->l_uf)
+#define L_ISHIS(a, b) M_ISHIS((a)->l_ui, (a)->l_uf, (b)->l_ui, (b)->l_uf)
+#define L_ISGEQ(a, b) M_ISGEQ((a)->l_ui, (a)->l_uf, (b)->l_ui, (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.0 /* 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.0 /* 2^32 as a double */
+
+/*
+ * Use 64 bit integers if available. Solaris on SPARC has a problem
+ * compiling parsesolaris.c if ntp_fp.h includes math.h, due to
+ * archaic gets() and printf() prototypes used in Solaris kernel
+ * headers. So far the problem has only been seen with gcc, but it
+ * may also affect Sun compilers, in which case the defined(__GNUC__)
+ * term should be removed.
+ */
+#if defined(HAVE_U_INT64) && \
+ !(defined(__SVR4) && defined(__sun) && \
+ defined(sparc) && defined(__GNUC__))
+
+#include <math.h> /* ldexp() */
+
+#define M_DTOLFP(d, r_ui, r_uf) /* double to l_fp */ \
+ do { \
+ double d_tmp; \
+ u_int64 q_tmp; \
+ int M_isneg; \
+ \
+ d_tmp = (d); \
+ M_isneg = (d_tmp < 0.); \
+ if (M_isneg) { \
+ d_tmp = -d_tmp; \
+ } \
+ q_tmp = (u_int64)ldexp(d_tmp, 32); \
+ if (M_isneg) { \
+ q_tmp = ~q_tmp + 1; \
+ } \
+ (r_uf) = (u_int32)q_tmp; \
+ (r_ui) = (u_int32)(q_tmp >> 32); \
+ } while (FALSE)
+
+#define M_LFPTOD(r_ui, r_uf, d) /* l_fp to double */ \
+ do { \
+ double d_tmp; \
+ u_int64 q_tmp; \
+ int M_isneg; \
+ \
+ q_tmp = ((u_int64)(r_ui) << 32) + (r_uf); \
+ M_isneg = M_ISNEG(r_ui); \
+ if (M_isneg) { \
+ q_tmp = ~q_tmp + 1; \
+ } \
+ d_tmp = ldexp((double)q_tmp, -32); \
+ if (M_isneg) { \
+ d_tmp = -d_tmp; \
+ } \
+ (d) = d_tmp; \
+ } while (FALSE)
+
+#else /* use only 32 bit unsigned values */
+
+#define M_DTOLFP(d, r_ui, r_uf) /* double to l_fp */ \
+ do { \
+ double d_tmp; \
+ if ((d_tmp = (d)) < 0) { \
+ (r_ui) = (u_int32)(-d_tmp); \
+ (r_uf) = (u_int32)(-(d_tmp + (double)(r_ui)) * FRAC); \
+ M_NEG((r_ui), (r_uf)); \
+ } else { \
+ (r_ui) = (u_int32)d_tmp; \
+ (r_uf) = (u_int32)((d_tmp - (double)(r_ui)) * FRAC); \
+ } \
+ } while (0)
+#define M_LFPTOD(r_ui, r_uf, d) /* l_fp to double */ \
+ do { \
+ u_int32 l_thi, l_tlo; \
+ l_thi = (r_ui); l_tlo = (r_uf); \
+ if (M_ISNEG(l_thi)) { \
+ M_NEG(l_thi, l_tlo); \
+ (d) = -((double)l_thi + (double)l_tlo / FRAC); \
+ } else { \
+ (d) = (double)l_thi + (double)l_tlo / FRAC; \
+ } \
+ } while (0)
+#endif
+
+#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 (u_fp, int, short, int);
+extern char * dolfptoa (u_int32, u_int32, int, short, int);
+
+extern int atolfp (const char *, l_fp *);
+extern int buftvtots (const char *, l_fp *);
+extern char * fptoa (s_fp, short);
+extern char * fptoms (s_fp, short);
+extern int hextolfp (const char *, l_fp *);
+extern void gpstolfp (int, int, unsigned long, l_fp *);
+extern int mstolfp (const char *, l_fp *);
+extern char * prettydate (l_fp *);
+extern char * gmprettydate (l_fp *);
+extern char * uglydate (l_fp *);
+extern void mfp_mul (int32 *, u_int32 *, int32, u_int32, int32, u_int32);
+
+extern void set_sys_fuzz (double);
+extern void init_systime (void);
+extern void get_systime (l_fp *);
+extern int step_systime (double);
+extern int adj_systime (double);
+
+extern struct tm * ntp2unix_tm (u_int32 ntp, int local);
+
+#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 stoa(addr) socktoa(addr)
+#define ntoa(addr) stoa(addr)
+#define sptoa(addr) sockporttoa(addr)
+#define stohost(addr) socktohost(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)
+
+/*
+ * Optional callback from libntp step_systime() to ntpd. Optional
+* because other libntp clients like ntpdate don't use it.
+ */
+typedef void (*time_stepped_callback)(void);
+extern time_stepped_callback step_callback;
+
+/*
+ * Multi-thread locking for get_systime()
+ *
+ * On most systems, get_systime() is used solely by the main ntpd
+ * thread, but on Windows it's also used by the dedicated I/O thread.
+ * The [Bug 2037] changes to get_systime() have it keep state between
+ * calls to ensure time moves in only one direction, which means its
+ * use on Windows needs to be protected against simultaneous execution
+ * to avoid falsely detecting Lamport violations by ensuring only one
+ * thread at a time is in get_systime().
+ */
+#ifdef SYS_WINNT
+extern CRITICAL_SECTION get_systime_cs;
+# define INIT_GET_SYSTIME_CRITSEC() \
+ InitializeCriticalSection(&get_systime_cs)
+# define ENTER_GET_SYSTIME_CRITSEC() \
+ EnterCriticalSection(&get_systime_cs)
+# define LEAVE_GET_SYSTIME_CRITSEC() \
+ LeaveCriticalSection(&get_systime_cs)
+# define INIT_WIN_PRECISE_TIME() \
+ init_win_precise_time()
+#else /* !SYS_WINNT follows */
+# define INIT_GET_SYSTIME_CRITSEC() \
+ do {} while (FALSE)
+# define ENTER_GET_SYSTIME_CRITSEC() \
+ do {} while (FALSE)
+# define LEAVE_GET_SYSTIME_CRITSEC() \
+ do {} while (FALSE)
+# define INIT_WIN_PRECISE_TIME() \
+ do {} while (FALSE)
+#endif
+
+#endif /* NTP_FP_H */
diff --git a/include/ntp_if.h b/include/ntp_if.h
new file mode 100644
index 0000000..3af5865
--- /dev/null
+++ b/include/ntp_if.h
@@ -0,0 +1,27 @@
+/*
+ * 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_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
+
+#ifdef HAVE_NET_IF_H
+# include <net/if.h>
+#endif /* HAVE_NET_IF_H */
diff --git a/include/ntp_intres.h b/include/ntp_intres.h
new file mode 100644
index 0000000..1b6bd66
--- /dev/null
+++ b/include/ntp_intres.h
@@ -0,0 +1,45 @@
+/*
+ * ntp_intres.h - client interface to blocking-worker name resolution.
+ */
+#ifndef NTP_INTRES_H
+#define NTP_INTRES_H
+
+#include <ntp_worker.h>
+
+#ifdef WORKER
+#define INITIAL_DNS_RETRY 2 /* seconds between queries */
+
+/*
+ * you call getaddrinfo_sometime(name, service, &hints, retry, callback_func, context);
+ * later (*callback_func)(rescode, gai_errno, context, name, service, hints, ai_result) is called.
+ */
+typedef void (*gai_sometime_callback)
+ (int, int, void *, const char *, const char *,
+ const struct addrinfo *, const struct addrinfo *);
+extern int getaddrinfo_sometime(const char *, const char *,
+ const struct addrinfo *, int,
+ gai_sometime_callback, void *);
+/*
+ * In gai_sometime_callback routines, the resulting addrinfo list is
+ * only available until the callback returns. To hold on to the list
+ * of addresses after the callback returns, use copy_addrinfo_list():
+ *
+ * struct addrinfo *copy_addrinfo_list(const struct addrinfo *);
+ */
+
+
+/*
+ * you call getnameinfo_sometime(sockaddr, namelen, servlen, flags, callback_func, context);
+ * later (*callback_func)(rescode, gni_errno, sockaddr, flags, name, service, context) is called.
+ */
+typedef void (*gni_sometime_callback)
+ (int, int, sockaddr_u *, int, const char *,
+ const char *, void *);
+extern int getnameinfo_sometime(sockaddr_u *, size_t, size_t, int,
+ gni_sometime_callback, void *);
+#endif /* WORKER */
+
+/* intres_timeout_req() is provided by the client, ntpd or sntp. */
+extern void intres_timeout_req(u_int);
+
+#endif /* NTP_INTRES_H */
diff --git a/include/ntp_io.h b/include/ntp_io.h
new file mode 100644
index 0000000..2cdca71
--- /dev/null
+++ b/include/ntp_io.h
@@ -0,0 +1,97 @@
+#ifndef NTP_IO_H
+#define NTP_IO_H
+
+#include "ntp_workimpl.h"
+
+/*
+ * POSIX says use <fnct.h> to get O_* symbols and
+ * SEEK_SET symbol form <unistd.h>.
+ */
+#include <sys/types.h>
+#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
+
+#include <isc/boolean.h>
+#include <isc/netaddr.h>
+
+#if defined(HAVE_NETINET_IN_H) && defined(HAVE_NETINET_IP_H)
+# include <netinet/in.h>
+# ifdef HAVE_NETINET_IN_SYSTM_H
+# include <netinet/in_systm.h>
+# endif
+# include <netinet/ip.h>
+#endif
+
+#include "libntp.h" /* This needs Something above for GETDTABLESIZE */
+
+/*
+ * Define FNDELAY and FASYNC using O_NONBLOCK and O_ASYNC if we need
+ * to (and can). This is here initially for QNX, but may help for
+ * others as well...
+ */
+#ifndef FNDELAY
+# ifdef O_NONBLOCK
+# define FNDELAY O_NONBLOCK
+# endif
+#endif
+
+#ifndef FASYNC
+# ifdef O_ASYNC
+# define FASYNC O_ASYNC
+# endif
+#endif
+
+
+/*
+ * NIC rule match types
+ */
+typedef enum {
+ MATCH_ALL,
+ MATCH_IPV4,
+ MATCH_IPV6,
+ MATCH_WILDCARD,
+ MATCH_IFNAME,
+ MATCH_IFADDR
+} nic_rule_match;
+
+/*
+ * NIC rule actions
+ */
+typedef enum {
+ ACTION_LISTEN,
+ ACTION_IGNORE,
+ ACTION_DROP
+} nic_rule_action;
+
+
+SOCKET move_fd(SOCKET fd);
+isc_boolean_t get_broadcastclient_flag(void);
+extern int is_ip_address(const char *, u_short, sockaddr_u *);
+extern void sau_from_netaddr(sockaddr_u *, const isc_netaddr_t *);
+extern void add_nic_rule(nic_rule_match match_type,
+ const char *if_name, int prefixlen,
+ nic_rule_action action);
+#ifndef HAVE_IO_COMPLETION_PORT
+extern void maintain_activefds(int fd, int closing);
+#else
+#define maintain_activefds(f, c) do {} while (0)
+#endif
+
+
+#endif /* NTP_IO_H */
diff --git a/include/ntp_libopts.h b/include/ntp_libopts.h
new file mode 100644
index 0000000..b03b2f6
--- /dev/null
+++ b/include/ntp_libopts.h
@@ -0,0 +1,14 @@
+/*
+ * ntp_libopts.h
+ *
+ * Common code interfacing with Autogen's libopts command-line option
+ * processing.
+ */
+#ifndef NTP_LIBOPTS_H
+# define NTP_LIBOPTS_H
+# include "autoopts/options.h"
+
+extern int ntpOptionProcess(tOptions *pOpts, int argc,
+ char ** argv);
+extern void ntpOptionPrintVersion(tOptions *, tOptDesc *);
+#endif
diff --git a/include/ntp_lineedit.h b/include/ntp_lineedit.h
new file mode 100644
index 0000000..623c6f4
--- /dev/null
+++ b/include/ntp_lineedit.h
@@ -0,0 +1,13 @@
+
+/*
+ * ntp_lineedit.h - generic interface to various line editing libs
+ */
+
+int ntp_readline_init(const char *prompt);
+void ntp_readline_uninit(void);
+
+/*
+ * strings returned by ntp_readline go home to free()
+ */
+char * ntp_readline(int *pcount);
+
diff --git a/include/ntp_lists.h b/include/ntp_lists.h
new file mode 100644
index 0000000..2b6e616
--- /dev/null
+++ b/include/ntp_lists.h
@@ -0,0 +1,443 @@
+/*
+ * ntp_lists.h - linked lists common code
+ *
+ * SLIST: singly-linked lists
+ * ==========================
+ *
+ * These macros implement a simple singly-linked list template. Both
+ * the listhead and per-entry next fields are declared as pointers to
+ * the list entry struct type. Initialization to NULL is typically
+ * implicit (for globals and statics) or handled by zeroing of the
+ * containing structure.
+ *
+ * The name of the next link field is passed as an argument to allow
+ * membership in several lists at once using multiple next link fields.
+ *
+ * When possible, placing the link field first in the entry structure
+ * allows slightly smaller code to be generated on some platforms.
+ *
+ * LINK_SLIST(listhead, pentry, nextlink)
+ * add entry at head
+ *
+ * LINK_TAIL_SLIST(listhead, pentry, nextlink, entrytype)
+ * add entry at tail. This is O(n), if this is a common
+ * operation the FIFO template may be more appropriate.
+ *
+ * LINK_SORT_SLIST(listhead, pentry, beforecur, nextlink, entrytype)
+ * add entry in sorted order. beforecur is an expression comparing
+ * pentry with the current list entry. The current entry can be
+ * referenced within beforecur as L_S_S_CUR(), which is short for
+ * LINK_SORT_SLIST_CUR(). beforecur is nonzero if pentry sorts
+ * before L_S_S_CUR().
+ *
+ * UNLINK_HEAD_SLIST(punlinked, listhead, nextlink)
+ * unlink first entry and point punlinked to it, or set punlinked
+ * to NULL if the list is empty.
+ *
+ * UNLINK_SLIST(punlinked, listhead, ptounlink, nextlink, entrytype)
+ * unlink entry pointed to by ptounlink. punlinked is set to NULL
+ * if the entry is not found on the list, otherwise it is set to
+ * ptounlink.
+ *
+ * UNLINK_EXPR_SLIST(punlinked, listhead, expr, nextlink, entrytype)
+ * unlink entry where expression expr is nonzero. expr can refer
+ * to the entry being tested using UNLINK_EXPR_SLIST_CURRENT(),
+ * alias U_E_S_CUR(). See the implementation of UNLINK_SLIST()
+ * below for an example. U_E_S_CUR() is NULL iff the list is empty.
+ * punlinked is pointed to the removed entry or NULL if none
+ * satisfy expr.
+ *
+ * FIFO: singly-linked lists plus tail pointer
+ * ===========================================
+ *
+ * This is the same as FreeBSD's sys/queue.h STAILQ -- a singly-linked
+ * list implementation with tail-pointer maintenance, so that adding
+ * at the tail for first-in, first-out access is O(1).
+ *
+ * DECL_FIFO_ANCHOR(entrytype)
+ * provides the type specification portion of the declaration for
+ * a variable to refer to a FIFO queue (similar to listhead). The
+ * anchor contains the head and indirect tail pointers. Example:
+ *
+ * #include "ntp_lists.h"
+ *
+ * typedef struct myentry_tag myentry;
+ * struct myentry_tag {
+ * myentry *next_link;
+ * ...
+ * };
+ *
+ * DECL_FIFO_ANCHOR(myentry) my_fifo;
+ *
+ * void somefunc(myentry *pentry)
+ * {
+ * LINK_FIFO(my_fifo, pentry, next_link);
+ * }
+ *
+ * If DECL_FIFO_ANCHOR is used with stack or heap storage, it
+ * should be initialized to NULL pointers using a = { NULL };
+ * initializer or memset.
+ *
+ * HEAD_FIFO(anchor)
+ * TAIL_FIFO(anchor)
+ * Pointer to first/last entry, NULL if FIFO is empty.
+ *
+ * LINK_FIFO(anchor, pentry, nextlink)
+ * add entry at tail.
+ *
+ * UNLINK_FIFO(punlinked, anchor, nextlink)
+ * unlink head entry and point punlinked to it, or set punlinked
+ * to NULL if the list is empty.
+ *
+ * CONCAT_FIFO(q1, q2, nextlink)
+ * empty fifoq q2 moving its nodes to q1 following q1's existing
+ * nodes.
+ *
+ * DLIST: doubly-linked lists
+ * ==========================
+ *
+ * Elements on DLISTs always have non-NULL forward and back links,
+ * because both link chains are circular. The beginning/end is marked
+ * by the listhead, which is the same type as elements for simplicity.
+ * An empty list's listhead has both links set to its own address.
+ *
+ *
+ */
+#ifndef NTP_LISTS_H
+#define NTP_LISTS_H
+
+#include "ntp_types.h" /* TRUE and FALSE */
+#include "ntp_assert.h"
+
+#ifdef DEBUG
+# define NTP_DEBUG_LISTS_H
+#endif
+
+/*
+ * If list debugging is not enabled, save a little time by not clearing
+ * an entry's link pointer when it is unlinked, as the stale pointer
+ * is harmless as long as it is ignored when the entry is not in a
+ * list.
+ */
+#ifndef NTP_DEBUG_LISTS_H
+#define MAYBE_Z_LISTS(p) do { } while (FALSE)
+#else
+#define MAYBE_Z_LISTS(p) (p) = NULL
+#endif
+
+#define LINK_SLIST(listhead, pentry, nextlink) \
+do { \
+ (pentry)->nextlink = (listhead); \
+ (listhead) = (pentry); \
+} while (FALSE)
+
+#define LINK_TAIL_SLIST(listhead, pentry, nextlink, entrytype) \
+do { \
+ entrytype **pptail; \
+ \
+ pptail = &(listhead); \
+ while (*pptail != NULL) \
+ pptail = &((*pptail)->nextlink); \
+ \
+ (pentry)->nextlink = NULL; \
+ *pptail = (pentry); \
+} while (FALSE)
+
+#define LINK_SORT_SLIST_CURRENT() (*ppentry)
+#define L_S_S_CUR() LINK_SORT_SLIST_CURRENT()
+
+#define LINK_SORT_SLIST(listhead, pentry, beforecur, nextlink, \
+ entrytype) \
+do { \
+ entrytype **ppentry; \
+ \
+ ppentry = &(listhead); \
+ while (TRUE) { \
+ if (NULL == *ppentry || (beforecur)) { \
+ (pentry)->nextlink = *ppentry; \
+ *ppentry = (pentry); \
+ break; \
+ } \
+ ppentry = &((*ppentry)->nextlink); \
+ if (NULL == *ppentry) { \
+ (pentry)->nextlink = NULL; \
+ *ppentry = (pentry); \
+ break; \
+ } \
+ } \
+} while (FALSE)
+
+#define UNLINK_HEAD_SLIST(punlinked, listhead, nextlink) \
+do { \
+ (punlinked) = (listhead); \
+ if (NULL != (punlinked)) { \
+ (listhead) = (punlinked)->nextlink; \
+ MAYBE_Z_LISTS((punlinked)->nextlink); \
+ } \
+} while (FALSE)
+
+#define UNLINK_EXPR_SLIST_CURRENT() (*ppentry)
+#define U_E_S_CUR() UNLINK_EXPR_SLIST_CURRENT()
+
+#define UNLINK_EXPR_SLIST(punlinked, listhead, expr, nextlink, \
+ entrytype) \
+do { \
+ entrytype **ppentry; \
+ \
+ ppentry = &(listhead); \
+ \
+ while (!(expr)) \
+ if (*ppentry != NULL && \
+ (*ppentry)->nextlink != NULL) { \
+ ppentry = &((*ppentry)->nextlink); \
+ } else { \
+ ppentry = NULL; \
+ break; \
+ } \
+ \
+ if (ppentry != NULL) { \
+ (punlinked) = *ppentry; \
+ *ppentry = (punlinked)->nextlink; \
+ MAYBE_Z_LISTS((punlinked)->nextlink); \
+ } else { \
+ (punlinked) = NULL; \
+ } \
+} while (FALSE)
+
+#define UNLINK_SLIST(punlinked, listhead, ptounlink, nextlink, \
+ entrytype) \
+ UNLINK_EXPR_SLIST(punlinked, listhead, (ptounlink) == \
+ U_E_S_CUR(), nextlink, entrytype)
+
+#define CHECK_SLIST(listhead, nextlink, entrytype) \
+do { \
+ entrytype *pentry; \
+ \
+ for (pentry = (listhead); \
+ pentry != NULL; \
+ pentry = pentry->nextlink){ \
+ NTP_INSIST(pentry != pentry->nextlink); \
+ NTP_INSIST((listhead) != pentry->nextlink); \
+ } \
+} while (FALSE)
+
+/*
+ * FIFO
+ */
+
+#define DECL_FIFO_ANCHOR(entrytype) \
+struct { \
+ entrytype * phead; /* NULL if list empty */ \
+ entrytype ** pptail; /* NULL if list empty */ \
+}
+
+#define HEAD_FIFO(anchor) ((anchor).phead)
+#define TAIL_FIFO(anchor) ((NULL == (anchor).pptail) \
+ ? NULL \
+ : *((anchor).pptail))
+
+/*
+ * For DEBUG builds only, verify both or neither of the anchor pointers
+ * are NULL with each operation.
+ */
+#if !defined(NTP_DEBUG_LISTS_H)
+#define CHECK_FIFO_CONSISTENCY(anchor) do { } while (FALSE)
+#else
+#define CHECK_FIFO_CONSISTENCY(anchor) \
+ check_gen_fifo_consistency(&(anchor))
+void check_gen_fifo_consistency(void *fifo);
+#endif
+
+/*
+ * generic FIFO element used to access any FIFO where each element
+ * begins with the link pointer
+ */
+typedef struct gen_node_tag gen_node;
+struct gen_node_tag {
+ gen_node * link;
+};
+
+/* generic FIFO */
+typedef DECL_FIFO_ANCHOR(gen_node) gen_fifo;
+
+
+#define LINK_FIFO(anchor, pentry, nextlink) \
+do { \
+ CHECK_FIFO_CONSISTENCY(anchor); \
+ \
+ (pentry)->nextlink = NULL; \
+ if (NULL != (anchor).pptail) { \
+ (*((anchor).pptail))->nextlink = (pentry); \
+ (anchor).pptail = \
+ &(*((anchor).pptail))->nextlink; \
+ } else { \
+ (anchor).phead = (pentry); \
+ (anchor).pptail = &(anchor).phead; \
+ } \
+ \
+ CHECK_FIFO_CONSISTENCY(anchor); \
+} while (FALSE)
+
+#define UNLINK_FIFO(punlinked, anchor, nextlink) \
+do { \
+ CHECK_FIFO_CONSISTENCY(anchor); \
+ \
+ (punlinked) = (anchor).phead; \
+ if (NULL != (punlinked)) { \
+ (anchor).phead = (punlinked)->nextlink; \
+ if (NULL == (anchor).phead) \
+ (anchor).pptail = NULL; \
+ else if ((anchor).pptail == \
+ &(punlinked)->nextlink) \
+ (anchor).pptail = &(anchor).phead; \
+ MAYBE_Z_LISTS((punlinked)->nextlink); \
+ CHECK_FIFO_CONSISTENCY(anchor); \
+ } \
+} while (FALSE)
+
+#define UNLINK_MID_FIFO(punlinked, anchor, tounlink, nextlink, \
+ entrytype) \
+do { \
+ entrytype **ppentry; \
+ \
+ CHECK_FIFO_CONSISTENCY(anchor); \
+ \
+ ppentry = &(anchor).phead; \
+ \
+ while ((tounlink) != *ppentry) \
+ if ((*ppentry)->nextlink != NULL) { \
+ ppentry = &((*ppentry)->nextlink); \
+ } else { \
+ ppentry = NULL; \
+ break; \
+ } \
+ \
+ if (ppentry != NULL) { \
+ (punlinked) = *ppentry; \
+ *ppentry = (punlinked)->nextlink; \
+ if (NULL == *ppentry) \
+ (anchor).pptail = NULL; \
+ else if ((anchor).pptail == \
+ &(punlinked)->nextlink) \
+ (anchor).pptail = &(anchor).phead; \
+ MAYBE_Z_LISTS((punlinked)->nextlink); \
+ CHECK_FIFO_CONSISTENCY(anchor); \
+ } else { \
+ (punlinked) = NULL; \
+ } \
+} while (FALSE)
+
+#define CONCAT_FIFO(f1, f2, nextlink) \
+do { \
+ CHECK_FIFO_CONSISTENCY(f1); \
+ CHECK_FIFO_CONSISTENCY(f2); \
+ \
+ if ((f2).pptail != NULL) { \
+ if ((f1).pptail != NULL) { \
+ (*(f1).pptail)->nextlink = (f2).phead; \
+ if ((f2).pptail == &(f2).phead) \
+ (f1).pptail = \
+ &(*(f1).pptail)->nextlink; \
+ else \
+ (f1).pptail = (f2).pptail; \
+ CHECK_FIFO_CONSISTENCY(f1); \
+ } else { \
+ (f1) = (f2); \
+ } \
+ MAYBE_Z_LISTS((f2).phead); \
+ MAYBE_Z_LISTS((f2).pptail); \
+ } \
+} while (FALSE)
+
+/*
+ * DLIST
+ */
+#define DECL_DLIST_LINK(entrytype, link) \
+struct { \
+ entrytype * b; \
+ entrytype * f; \
+} link
+
+#define INIT_DLIST(listhead, link) \
+do { \
+ (listhead).link.f = &(listhead); \
+ (listhead).link.b = &(listhead); \
+} while (FALSE)
+
+#define HEAD_DLIST(listhead, link) \
+ ( \
+ (&(listhead) != (listhead).link.f) \
+ ? (listhead).link.f \
+ : NULL \
+ )
+
+#define TAIL_DLIST(listhead, link) \
+ ( \
+ (&(listhead) != (listhead).link.b) \
+ ? (listhead).link.b \
+ : NULL \
+ )
+
+#define NEXT_DLIST(listhead, entry, link) \
+ ( \
+ (&(listhead) != (entry)->link.f) \
+ ? (entry)->link.f \
+ : NULL \
+ )
+
+#define PREV_DLIST(listhead, entry, link) \
+ ( \
+ (&(listhead) != (entry)->link.b) \
+ ? (entry)->link.b \
+ : NULL \
+ )
+
+#define LINK_DLIST(listhead, pentry, link) \
+do { \
+ (pentry)->link.f = (listhead).link.f; \
+ (pentry)->link.b = &(listhead); \
+ (listhead).link.f->link.b = (pentry); \
+ (listhead).link.f = (pentry); \
+} while (FALSE)
+
+#define LINK_TAIL_DLIST(listhead, pentry, link) \
+do { \
+ (pentry)->link.b = (listhead).link.b; \
+ (pentry)->link.f = &(listhead); \
+ (listhead).link.b->link.f = (pentry); \
+ (listhead).link.b = (pentry); \
+} while (FALSE)
+
+#define UNLINK_DLIST(ptounlink, link) \
+do { \
+ (ptounlink)->link.b->link.f = (ptounlink)->link.f; \
+ (ptounlink)->link.f->link.b = (ptounlink)->link.b; \
+ MAYBE_Z_LISTS((ptounlink)->link.b); \
+ MAYBE_Z_LISTS((ptounlink)->link.f); \
+} while (FALSE)
+
+#define ITER_DLIST_BEGIN(listhead, iter, link, entrytype) \
+{ \
+ entrytype *i_dl_nextiter; \
+ \
+ for ((iter) = (listhead).link.f; \
+ (iter) != &(listhead) \
+ && ((i_dl_nextiter = (iter)->link.f), TRUE); \
+ (iter) = i_dl_nextiter) {
+#define ITER_DLIST_END() \
+ } \
+}
+
+#define REV_ITER_DLIST_BEGIN(listhead, iter, link, entrytype) \
+{ \
+ entrytype *i_dl_nextiter; \
+ \
+ for ((iter) = (listhead).link.b; \
+ (iter) != &(listhead) \
+ && ((i_dl_nextiter = (iter)->link.b), TRUE); \
+ (iter) = i_dl_nextiter) {
+#define REV_ITER_DLIST_END() \
+ } \
+}
+
+#endif /* NTP_LISTS_H */
diff --git a/include/ntp_machine.h b/include/ntp_machine.h
new file mode 100644
index 0000000..c5e7248
--- /dev/null
+++ b/include/ntp_machine.h
@@ -0,0 +1,297 @@
+/*
+ * ntp_machine.h
+ *
+ * Collect all machine dependent idiosyncrasies in one place.
+ *
+ * The functionality formerly in this file is mostly handled by
+ * Autoconf these days.
+ */
+
+#ifndef NTP_MACHINE_H
+#define NTP_MACHINE_H
+
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+#include <time.h>
+
+#include "ntp_proto.h"
+
+/*
+
+ HEY! CHECK THIS OUT!
+
+ 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.
+
+*/
+
+/*
+
+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.
+
+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
+
+ 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.
+*/
+
+int ntp_set_tod (struct timeval *tvp, void *tzp);
+
+/*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 ... */
+
+/* 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 ();
+
+/* 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 ( struct timeval *tp, struct timezone *tzp );
+extern int settimeofday (struct timeval *, struct timezone *);
+extern int adjtime ( struct timeval *delta, struct timeval *olddelta );
+ */
+
+/* in machines.c */
+extern void sleep (int seconds);
+extern void alarm (int seconds);
+/* machines.c */
+
+
+/* this is really this */
+#define getpid taskIdSelf
+#define getclock clock_gettime
+#define fcntl ioctl
+#define _getch getchar
+
+/* 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 (char * netnum);
+struct hostent *gethostbyaddr (char * netnum, int size, int addr_type);
+/* type is the protocol */
+struct servent *getservbyname (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 MPE
+# include <sys/types.h>
+# include <netinet/in.h>
+# include <stdio.h>
+# include <time.h>
+
+/* missing functions that are easily renamed */
+
+# define _getch getchar
+
+/* special functions that require MPE-specific wrappers */
+
+# define bind __ntp_mpe_bind
+# define fcntl __ntp_mpe_fcntl
+
+/* standard macros missing from MPE include files */
+
+# define IN_CLASSD(i) ((((long)(i))&0xf0000000)==0xe0000000)
+# define IN_MULTICAST IN_CLASSD
+# define ITIMER_REAL 0
+
+/* standard structures missing from MPE include files */
+
+struct itimerval {
+ struct timeval it_interval; /* timer interval */
+ struct timeval it_value; /* current value */
+};
+
+/* various declarations to make gcc stop complaining */
+
+extern int __filbuf(FILE *);
+extern int __flsbuf(int, FILE *);
+extern int gethostname(char *, int);
+extern unsigned long inet_addr(char *);
+extern char *strdup(const char *);
+
+/* miscellaneous NTP macros */
+
+# define HAVE_NO_NICE
+#endif /* MPE */
+
+#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)
+#include "ERROR: You must define one of the HAVE_xx_NICE defines!"
+#endif
+
+#ifndef HAVE_TIMEGM
+extern time_t timegm (struct tm *);
+#endif
+
+
+#endif /* NTP_MACHINE_H */
diff --git a/include/ntp_malloc.h b/include/ntp_malloc.h
new file mode 100644
index 0000000..4cde62e
--- /dev/null
+++ b/include/ntp_malloc.h
@@ -0,0 +1,61 @@
+/*
+ * Define malloc and friends.
+ */
+#ifndef NTP_MALLOC_H
+#define NTP_MALLOC_H
+
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#else
+# ifdef HAVE_MALLOC_H
+# include <malloc.h>
+# endif
+#endif
+
+/*
+ * Deal with platform differences declaring alloca()
+ * This comes nearly verbatim from:
+ *
+ * http://www.gnu.org/software/autoconf/manual/autoconf.html#Particular-Functions
+ *
+ * The only modifications were to remove C++ support and guard against
+ * redefining alloca.
+ */
+#ifdef HAVE_ALLOCA_H
+# include <alloca.h>
+#elif defined __GNUC__
+# ifndef alloca
+# define alloca __builtin_alloca
+# endif
+#elif defined _AIX
+# ifndef alloca
+# define alloca __alloca
+# endif
+#elif defined _MSC_VER
+# include <malloc.h>
+# ifndef alloca
+# define alloca _alloca
+# endif
+#else
+# include <stddef.h>
+void * alloca(size_t);
+#endif
+
+#ifdef EREALLOC_IMPL
+# define EREALLOC_CALLSITE /* preserve __FILE__ and __LINE__ */
+#else
+# define EREALLOC_IMPL(ptr, newsz, filenm, loc) \
+ realloc(ptr, (newsz))
+#endif
+
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+# define zero_mem(p, s) bzero(p, s)
+#endif
+
+#ifndef zero_mem
+# define zero_mem(p, s) memset(p, 0, s)
+#endif
+#define ZERO(var) zero_mem(&(var), sizeof(var))
+
+#endif /* NTP_MALLOC_H */
diff --git a/include/ntp_md5.h b/include/ntp_md5.h
new file mode 100644
index 0000000..9f43378
--- /dev/null
+++ b/include/ntp_md5.h
@@ -0,0 +1,40 @@
+/*
+ * ntp_md5.h: deal with md5.h headers
+ *
+ * Use the system MD5 if available, otherwise libisc's.
+ */
+#ifndef NTP_MD5_H
+#define NTP_MD5_H
+
+#ifdef OPENSSL
+# include "openssl/evp.h"
+#else /* !OPENSSL follows */
+/*
+ * Provide OpenSSL-alike MD5 API if we're not using OpenSSL
+ */
+# if defined HAVE_MD5_H && defined HAVE_MD5INIT
+# include <md5.h>
+# else
+# include "isc/md5.h"
+ typedef isc_md5_t MD5_CTX;
+# define MD5Init(c) isc_md5_init(c)
+# define MD5Update(c, p, s) isc_md5_update(c, p, s)
+# define MD5Final(d, c) isc_md5_final((c), (d)) /* swapped */
+# endif
+
+ typedef MD5_CTX EVP_MD_CTX;
+# define EVP_get_digestbynid(t) NULL
+# define EVP_md5(v) NULL
+# define EVP_MD_CTX_init(c)
+# define EVP_MD_CTX_set_flags(c, f)
+# define EVP_DigestInit(c, dt) (MD5Init(c), 1)
+# define EVP_DigestInit_ex(c, dt, i) (MD5Init(c), 1)
+# define EVP_DigestUpdate(c, p, s) MD5Update(c, (const void *)(p), \
+ s)
+# define EVP_DigestFinal(c, d, pdl) \
+ do { \
+ MD5Final((d), (c)); \
+ *(pdl) = 16; \
+ } while (0)
+# endif /* !OPENSSL */
+#endif /* NTP_MD5_H */
diff --git a/include/ntp_net.h b/include/ntp_net.h
new file mode 100644
index 0000000..0577402
--- /dev/null
+++ b/include/ntp_net.h
@@ -0,0 +1,238 @@
+/*
+ * ntp_net.h - definitions for NTP network stuff
+ */
+
+#ifndef NTP_NET_H
+#define NTP_NET_H
+
+#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_NET_IF_VAR_H
+#include <net/if_var.h>
+#endif
+#ifdef HAVE_NETINET_IN_VAR_H
+#include <netinet/in_var.h>
+#endif
+
+#include "ntp_rfc2553.h"
+#include "ntp_malloc.h"
+
+typedef union {
+ struct sockaddr sa;
+ struct sockaddr_in sa4;
+ struct sockaddr_in6 sa6;
+} sockaddr_u;
+
+/*
+ * Utilities for manipulating sockaddr_u v4/v6 unions
+ */
+#define SOCK_ADDR4(psau) ((psau)->sa4.sin_addr)
+#define SOCK_ADDR6(psau) ((psau)->sa6.sin6_addr)
+
+#define PSOCK_ADDR4(psau) (&SOCK_ADDR4(psau))
+#define PSOCK_ADDR6(psau) (&SOCK_ADDR6(psau))
+
+#define AF(psau) ((psau)->sa.sa_family)
+
+#define IS_IPV4(psau) (AF_INET == AF(psau))
+#define IS_IPV6(psau) (AF_INET6 == AF(psau))
+
+/* sockaddr_u v4 address in network byte order */
+#define NSRCADR(psau) (SOCK_ADDR4(psau).s_addr)
+
+/* sockaddr_u v4 address in host byte order */
+#define SRCADR(psau) (ntohl(NSRCADR(psau)))
+
+/* sockaddr_u v6 address in network byte order */
+#define NSRCADR6(psau) (SOCK_ADDR6(psau).s6_addr)
+
+/* assign sockaddr_u v4 address from host byte order */
+#define SET_ADDR4(psau, addr4) (NSRCADR(psau) = htonl(addr4))
+
+/* assign sockaddr_u v4 address from network byte order */
+#define SET_ADDR4N(psau, addr4n) (NSRCADR(psau) = (addr4n));
+
+/* assign sockaddr_u v6 address from network byte order */
+#define SET_ADDR6N(psau, s6_addr) \
+ (SOCK_ADDR6(psau) = (s6_addr))
+
+/* sockaddr_u v4/v6 port in network byte order */
+#define NSRCPORT(psau) ((psau)->sa4.sin_port)
+
+/* sockaddr_u v4/v6 port in host byte order */
+#define SRCPORT(psau) (ntohs(NSRCPORT(psau)))
+
+/* assign sockaddr_u v4/v6 port from host byte order */
+#define SET_PORT(psau, port) (NSRCPORT(psau) = htons(port))
+
+/* sockaddr_u v6 scope */
+#define SCOPE_VAR(psau) ((psau)->sa6.sin6_scope_id)
+
+#ifdef ISC_PLATFORM_HAVESCOPEID
+/* v4/v6 scope (always zero for v4) */
+# define SCOPE(psau) (IS_IPV4(psau) \
+ ? 0 \
+ : SCOPE_VAR(psau))
+
+/* are two v6 sockaddr_u scopes equal? */
+# define SCOPE_EQ(psau1, psau2) \
+ (SCOPE_VAR(psau1) == SCOPE_VAR(psau2))
+
+/* assign scope if supported */
+# define SET_SCOPE(psau, s) \
+ do \
+ if (IS_IPV6(psau)) \
+ SCOPE_VAR(psau) = (s); \
+ while (0)
+#else /* ISC_PLATFORM_HAVESCOPEID not defined */
+# define SCOPE(psau) (0)
+# define SCOPE_EQ(psau1, psau2) (1)
+# define SET_SCOPE(psau, s) do { } while (0)
+#endif /* ISC_PLATFORM_HAVESCOPEID */
+
+/* v4/v6 is multicast address */
+#define IS_MCAST(psau) \
+ (IS_IPV4(psau) \
+ ? IN_CLASSD(SRCADR(psau)) \
+ : IN6_IS_ADDR_MULTICAST(PSOCK_ADDR6(psau)))
+
+/* v6 is interface ID scope universal, as with MAC-derived addresses */
+#define IS_IID_UNIV(psau) \
+ (!!(0x02 & NSRCADR6(psau)[8]))
+
+#define SIZEOF_INADDR(fam) \
+ ((AF_INET == (fam)) \
+ ? sizeof(struct in_addr) \
+ : sizeof(struct in6_addr))
+
+#define SIZEOF_SOCKADDR(fam) \
+ ((AF_INET == (fam)) \
+ ? sizeof(struct sockaddr_in) \
+ : sizeof(struct sockaddr_in6))
+
+#define SOCKLEN(psau) \
+ (IS_IPV4(psau) \
+ ? sizeof((psau)->sa4) \
+ : sizeof((psau)->sa6))
+
+#define ZERO_SOCK(psau) \
+ ZERO(*(psau))
+
+/* blast a byte value across sockaddr_u v6 address */
+#define MEMSET_ADDR6(psau, v) \
+ memset((psau)->sa6.sin6_addr.s6_addr, (v), \
+ sizeof((psau)->sa6.sin6_addr.s6_addr))
+
+#define SET_ONESMASK(psau) \
+ do { \
+ if (IS_IPV6(psau)) \
+ MEMSET_ADDR6((psau), 0xff); \
+ else \
+ NSRCADR(psau) = 0xffffffff; \
+ } while(0)
+
+/* zero sockaddr_u, fill in family and all-ones (host) mask */
+#define SET_HOSTMASK(psau, family) \
+ do { \
+ ZERO_SOCK(psau); \
+ AF(psau) = (family); \
+ SET_ONESMASK(psau); \
+ } while (0)
+
+/*
+ * compare two in6_addr returning negative, 0, or positive.
+ * ADDR6_CMP is negative if *pin6A is lower than *pin6B, zero if they
+ * are equal, positive if *pin6A is higher than *pin6B. IN6ADDR_ANY
+ * is the lowest address (128 zero bits).
+ */
+#define ADDR6_CMP(pin6A, pin6B) \
+ memcmp((pin6A)->s6_addr, (pin6B)->s6_addr, \
+ sizeof(pin6A)->s6_addr)
+
+/* compare two in6_addr for equality only */
+#if !defined(SYS_WINNT) || !defined(in_addr6)
+#define ADDR6_EQ(pin6A, pin6B) \
+ (!ADDR6_CMP(pin6A, pin6B))
+#else
+#define ADDR6_EQ(pin6A, pin6B) \
+ IN6_ADDR_EQUAL(pin6A, pin6B)
+#endif
+
+/* compare a in6_addr with socket address */
+#define S_ADDR6_EQ(psau, pin6) \
+ ADDR6_EQ(&(psau)->sa6.sin6_addr, pin6)
+
+/* are two sockaddr_u's addresses equal? (port excluded) */
+#define SOCK_EQ(psau1, psau2) \
+ ((AF(psau1) != AF(psau2)) \
+ ? 0 \
+ : IS_IPV4(psau1) \
+ ? (NSRCADR(psau1) == NSRCADR(psau2)) \
+ : (S_ADDR6_EQ((psau1), PSOCK_ADDR6(psau2)) \
+ && SCOPE_EQ((psau1), (psau2))))
+
+/* are two sockaddr_u's addresses and ports equal? */
+#define ADDR_PORT_EQ(psau1, psau2) \
+ ((NSRCPORT(psau1) != NSRCPORT(psau2) \
+ ? 0 \
+ : SOCK_EQ((psau1), (psau2))))
+
+/* is sockaddr_u address unspecified? */
+#define SOCK_UNSPEC(psau) \
+ (IS_IPV4(psau) \
+ ? !NSRCADR(psau) \
+ : IN6_IS_ADDR_UNSPECIFIED(PSOCK_ADDR6(psau)))
+
+/* just how unspecified do you mean? (scope 0/unspec too) */
+#define SOCK_UNSPEC_S(psau) \
+ (SOCK_UNSPEC(psau) && !SCOPE(psau))
+
+/* choose a default net interface (struct interface) for v4 or v6 */
+#define ANY_INTERFACE_BYFAM(family) \
+ ((AF_INET == family) \
+ ? any_interface \
+ : any6_interface)
+
+/* choose a default interface for addresses' protocol (addr family) */
+#define ANY_INTERFACE_CHOOSE(psau) \
+ ANY_INTERFACE_BYFAM(AF(psau))
+
+
+/*
+ * 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) \
+ (IS_IPV4(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) \
+ (IS_IPV4(srcadr) \
+ && ((SRCADR(srcadr) & LOOPNETMASK) \
+ == (LOOPBACKADR & LOOPNETMASK)) \
+ && SRCADR(srcadr) != LOOPBACKADR)
+
+
+#endif /* NTP_NET_H */
diff --git a/include/ntp_prio_q.h b/include/ntp_prio_q.h
new file mode 100644
index 0000000..4b5ffca
--- /dev/null
+++ b/include/ntp_prio_q.h
@@ -0,0 +1,83 @@
+/* ntp_prio_q.h
+ *
+ * This file contains the structures and function prototypes for the
+ * priority queue implementation used by the discrete event simulator.
+ *
+ * Written By: Sachin Kamboj
+ * University of Delaware
+ * Newark, DE 19711
+ * Copyright (c) 2006
+ */
+
+#ifndef NTP_PRIO_Q_H
+#define NTP_PRIO_Q_H
+
+#include <stddef.h> /* size_t */
+
+/* Structures for storing a priority queue
+ * ---------------------------------------
+ */
+
+typedef struct node {
+ union {
+ struct node *next;
+ double d;
+ } nodeu;
+} node;
+#define node_next nodeu.next
+
+typedef int (*q_order_func)(const void *, const void *);
+
+typedef struct Queue {
+ q_order_func get_order;
+ node * front;
+ int no_of_elements;
+} queue;
+
+
+/* FUNCTION PROTOTYPES
+ * -------------------
+ */
+/* Define a function to create a FIFO queue */
+#define create_queue() create_priority_queue(&get_fifo_order)
+
+void destroy_queue(queue *my_queue);
+void free_node(void *my_node);
+void *next_node(void *my_node);
+int empty(queue *my_queue);
+void *queue_head(queue *my_queue);
+queue *enqueue(queue *my_queue, void *my_node);
+void append_queue(queue *q1, queue *q2);
+void *dequeue(queue *my_queue);
+int get_no_of_elements(queue *my_queue);
+int get_fifo_order(const void *el1, const void *el2);
+
+/*
+ * Preserve original callsite __FILE__ and __LINE__ for these
+ * malloc-like funcs when using MS C runtime debug heap.
+ */
+#ifdef _CRTDBG_MAP_ALLOC
+# define create_priority_queue(order) debug_create_priority_queue(order, __FILE__, __LINE__)
+# define get_node(size) debug_get_node(size, __FILE__, __LINE__)
+#else
+# define create_priority_queue(order) debug_create_priority_queue(order)
+# define get_node(size) debug_get_node(size)
+#endif
+
+queue *debug_create_priority_queue(
+ q_order_func get_order
+#ifdef _CRTDBG_MAP_ALLOC
+ , const char * sourcefile
+ , int line_num
+#endif
+ );
+
+void *debug_get_node(
+ size_t size
+#ifdef _CRTDBG_MAP_ALLOC
+ , const char * sourcefile
+ , int line_num
+#endif
+ );
+
+#endif /* NTP_PRIO_Q_H */
diff --git a/include/ntp_proto.h b/include/ntp_proto.h
new file mode 100644
index 0000000..1d04b78
--- /dev/null
+++ b/include/ntp_proto.h
@@ -0,0 +1,6 @@
+#ifndef NTP_PROTO_H
+#define NTP_PROTO_H
+
+#define NTP_MAXFREQ 500e-6
+
+#endif /* NTP_PROTO_H */
diff --git a/include/ntp_random.h b/include/ntp_random.h
new file mode 100644
index 0000000..3f89831
--- /dev/null
+++ b/include/ntp_random.h
@@ -0,0 +1,14 @@
+
+#include <ntp_types.h>
+
+long ntp_random (void);
+void ntp_srandom (unsigned long);
+void ntp_srandomdev (void);
+char * ntp_initstate (unsigned long, /* seed for R.N.G. */
+ char *, /* pointer to state array */
+ long /* # bytes of state info */
+ );
+char * ntp_setstate (char *); /* pointer to state array */
+
+
+
diff --git a/include/ntp_refclock.h b/include/ntp_refclock.h
new file mode 100644
index 0000000..f92d14c
--- /dev/null
+++ b/include/ntp_refclock.h
@@ -0,0 +1,239 @@
+/*
+ * ntp_refclock.h - definitions for reference clock support
+ */
+
+#ifndef NTP_REFCLOCK_H
+#define NTP_REFCLOCK_H
+
+#if defined(HAVE_SYS_MODEM_H)
+#include <sys/modem.h>
+#endif
+
+#include "ntp_types.h"
+#include "ntp_tty.h"
+#include "recvbuff.h"
+
+
+#define SAMPLE(x) pp->coderecv = (pp->coderecv + 1) % MAXSTAGE; \
+ pp->filter[pp->coderecv] = (x); \
+ if (pp->coderecv == pp->codeproc) \
+ pp->codeproc = (pp->codeproc + 1) % MAXSTAGE;
+
+/*
+ * 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 */
+};
+extern struct clktype clktypes[];
+
+/*
+ * 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 */
+ u_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) (struct recvbuf *); /* completion routine */
+ int (*io_input) (struct recvbuf *); /* input routine -
+ to avoid excessive buffer use
+ due to small bursts
+ of refclock input data */
+ struct peer *srcclock; /* refclock peer */
+ int datalen; /* length of data */
+ int fd; /* file descriptor */
+ u_long recvcount; /* count of receive completions */
+ int active; /* nonzero when in use */
+
+#ifdef HAVE_IO_COMPLETION_PORT
+ void * device_context; /* device-related data for i/o subsystem */
+#endif
+};
+
+/*
+ * 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 */
+};
+
+#ifdef HAVE_IO_COMPLETION_PORT
+extern HANDLE WaitableIoEventHandle;
+#endif
+
+/*
+ * 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 */
+
+
+struct refclockproc {
+ void * unitptr; /* pointer to unit structure */
+ struct refclock * conf; /* refclock_conf[type] */
+ struct refclockio io; /* I/O handler 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 */
+ u_long nextaction; /* local activity timeout */
+ void (*action)(struct peer *); /* timeout callback */
+
+ char a_lastcode[BMAX]; /* last timecode received */
+ int 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 */
+ long nsec; /* nanosecond of second */
+ u_long yearstart; /* beginning of year */
+ int coderecv; /* put pointer */
+ int codeproc; /* get pointer */
+ l_fp lastref; /* reference timestamp */
+ l_fp lastrec; /* receive timestamp */
+ double offset; /* mean offset */
+ double disp; /* sample dispersion */
+ double jitter; /* jitter (mean squares) */
+ double filter[MAXSTAGE]; /* median filter */
+
+ /*
+ * Configuration data
+ */
+ double fudgetime1; /* fudge time1 */
+ double fudgetime2; /* fudge time2 */
+ u_char stratum; /* server stratum */
+ 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) (int, struct peer *);
+ void (*clock_shutdown) (int, struct peer *);
+ void (*clock_poll) (int, struct peer *);
+ void (*clock_control) (int, const struct refclockstat *,
+ struct refclockstat *, struct peer *);
+ void (*clock_init) (void);
+ void (*clock_buginfo) (int, struct refclockbug *, struct peer *);
+ void (*clock_timer) (int, struct peer *);
+};
+
+/*
+ * Function prototypes
+ */
+extern int io_addclock (struct refclockio *);
+extern void io_closeclock (struct refclockio *);
+
+#ifdef REFCLOCK
+extern void refclock_buginfo(sockaddr_u *,
+ struct refclockbug *);
+extern void refclock_control(sockaddr_u *,
+ const struct refclockstat *,
+ struct refclockstat *);
+extern int refclock_open (char *, u_int, u_int);
+extern int refclock_setup (int, u_int, u_int);
+extern void refclock_timer (struct peer *);
+extern void refclock_transmit(struct peer *);
+extern int refclock_process(struct refclockproc *);
+extern int refclock_process_f(struct refclockproc *, double);
+extern void refclock_process_offset(struct refclockproc *, l_fp,
+ l_fp, double);
+extern void refclock_report (struct peer *, int);
+extern int refclock_gtlin (struct recvbuf *, char *, int, l_fp *);
+extern int refclock_gtraw (struct recvbuf *, char *, int, l_fp *);
+extern int indicate_refclock_packet(struct refclockio *,
+ struct recvbuf *);
+extern void process_refclock_packet(struct recvbuf *);
+#endif /* REFCLOCK */
+
+#endif /* NTP_REFCLOCK_H */
diff --git a/include/ntp_request.h b/include/ntp_request.h
new file mode 100644
index 0000000..c750b77
--- /dev/null
+++ b/include/ntp_request.h
@@ -0,0 +1,952 @@
+/*
+ * ntp_request.h - definitions for the ntpd remote query facility
+ */
+
+#ifndef NTP_REQUEST_H
+#define NTP_REQUEST_H
+
+#include "stddef.h"
+#include "ntp_types.h"
+#include "recvbuff.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 - incompatible 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.
+ */
+
+/*
+ * union of raw addresses to save space
+ */
+union addrun {
+ struct in6_addr addr6;
+ struct in_addr addr;
+};
+
+#define MODE7_PAYLOAD_LIM 176
+
+typedef union req_data_u_tag {
+ u_int32 u32[MODE7_PAYLOAD_LIM / sizeof(u_int32)];
+ char data[MODE7_PAYLOAD_LIM]; /* data area (176 byte max) */
+} req_data_u; /* struct conf_peer must fit */
+
+/*
+ * 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 */
+ req_data_u u; /* data area */
+ l_fp tstamp; /* time stamp, for authentication */
+ keyid_t keyid; /* (optional) encryption key */
+ char mac[MAX_MAC_LEN-sizeof(keyid_t)]; /* (optional) auth code */
+};
+
+/*
+ * The req_pkt_tail structure is used by ntpd to adjust for different
+ * packet sizes that may arrive.
+ */
+struct req_pkt_tail {
+ l_fp tstamp; /* time stamp, for authentication */
+ keyid_t keyid; /* (optional) encryption key */
+ char mac[MAX_MAC_LEN-sizeof(keyid_t)]; /* (optional) auth code */
+};
+
+/* MODE_PRIVATE request packet header length before optional items. */
+#define REQ_LEN_HDR (offsetof(struct req_pkt, u))
+/* MODE_PRIVATE request packet fixed length without MAC. */
+#define REQ_LEN_NOMAC (offsetof(struct req_pkt, keyid))
+/* MODE_PRIVATE req_pkt_tail minimum size (16 octet digest) */
+#define REQ_TAIL_MIN \
+ (sizeof(struct req_pkt_tail) - (MAX_MAC_LEN - MAX_MD5_LEN))
+
+/*
+ * A MODE_PRIVATE 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 (offsetof(struct resp_pkt, u))
+#define RESP_DATA_SIZE 500
+
+typedef union resp_pkt_u_tag {
+ char data[RESP_DATA_SIZE];
+ u_int32 u32[RESP_DATA_SIZE / sizeof(u_int32)];
+} resp_pkt_u;
+
+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 */
+ resp_pkt_u u; /* data area */
+};
+
+
+/*
+ * Information error codes
+ */
+#define INFO_OKAY 0
+#define INFO_ERR_IMPL 1 /* incompatible 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 */
+#define MAX_INFO_ERR INFO_ERR_AUTH
+
+/*
+ * 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) ((u_short)(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_OLD 2 /* Used by pre ipv6 ntpdc */
+#define IMPL_XNTPD 3 /* Used by post ipv6 ntpdc */
+
+/*
+ * 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.
+ */
+
+/*
+ * ntpdc -> 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 collected v1 monitor data */
+#define REQ_HOSTNAME_ASSOCID 43 /* Here is a hostname + assoc_id */
+#define REQ_IF_STATS 44 /* get interface statistics */
+#define REQ_IF_RELOAD 45 /* reload interface list */
+
+/* Determine size of pre-v6 version of structures */
+#define v4sizeof(type) offsetof(type, v6_flag)
+
+/*
+ * 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
+#define INFO_FLAG_IBURST 0x100
+
+/*
+ * 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_CAL 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.
+ * Well, it *would* have gone without saying, but somebody said it.
+ */
+struct info_peer_list {
+ u_int32 addr; /* address of peer */
+ u_short port; /* port number of peer */
+ u_char hmode; /* mode for this peer */
+ u_char flags; /* flags (from above) */
+ u_int v6_flag; /* is this v6 or not */
+ u_int unused1; /* (unused) padding for addr6 */
+ struct in6_addr addr6; /* v6 address of peer */
+};
+
+
+/*
+ * 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 */
+ u_int v6_flag; /* is this v6 or not */
+ u_int unused1; /* (unused) padding for dstadr6 */
+ struct in6_addr dstadr6; /* local address (v6) */
+ struct in6_addr srcadr6; /* source address (v6) */
+};
+
+
+/*
+ * Peer information structure.
+ */
+struct info_peer {
+ u_int32 dstadr; /* local address */
+ u_int32 srcadr; /* source 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 unused8;
+ 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 */
+ associd_t associd; /* association ID */
+ keyid_t keyid; /* peer.keyid */
+ u_int32 pkeyid; /* unused */
+ u_int32 refid; /* peer.refid */
+ u_int32 timer; /* peer.timer */
+ s_fp rootdelay; /* peer.delay */
+ 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 */
+ u_int v6_flag; /* is this v6 or not */
+ u_int unused9; /* (unused) padding for dstadr6 */
+ struct in6_addr dstadr6; /* local address (v6-like) */
+ struct in6_addr srcadr6; /* sources address (v6-like) */
+};
+
+
+/*
+ * 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) */
+ u_int v6_flag; /* is this v6 or not */
+ u_int unused9; /* (unused) padding for dstadr6 */
+ struct in6_addr dstadr6; /* local address */
+ struct in6_addr srcadr6; /* remote address */
+};
+
+
+/*
+ * 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 (v4) */
+ 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; /* delay 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) */
+ u_int v6_flag; /* is this v6 or not */
+ u_int unused4; /* unused, padding for peer6 */
+ struct in6_addr peer6; /* system peer address (v6) */
+};
+
+
+/*
+ * System stats. These are collected in the protocol module
+ */
+struct info_sys_stats {
+ u_int32 timeup; /* time since restart */
+ u_int32 timereset; /* time since reset */
+ u_int32 denied; /* access denied */
+ u_int32 oldversionpkt; /* recent version */
+ u_int32 newversionpkt; /* current version */
+ u_int32 unknownversion; /* bad version */
+ u_int32 badlength; /* bad length or format */
+ u_int32 processed; /* packets processed */
+ u_int32 badauth; /* bad authentication */
+ u_int32 received; /* packets received */
+ u_int32 limitrejected; /* rate exceeded */
+};
+
+
+/*
+ * System stats - old version
+ */
+struct old_info_sys_stats {
+ u_int32 timeup; /* time since restart */
+ u_int32 timereset; /* time since reset */
+ u_int32 denied; /* access denied */
+ u_int32 oldversionpkt; /* recent version */
+ u_int32 newversionpkt; /* current version */
+ u_int32 unknownversion; /* bad version */
+ u_int32 badlength; /* bad length or format */
+ u_int32 processed; /* packets processed */
+ u_int32 badauth; /* bad authentication */
+ u_int32 wanderhold; /* (not used) */
+};
+
+
+/*
+ * 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[NTP_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 old_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 */
+ keyid_t keyid; /* key to use for this association */
+};
+
+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 unused1; /* unused */
+ keyid_t keyid; /* key to use for this association */
+ char keystr[128]; /* public key file name */
+ u_int v6_flag; /* is this v6 or not */
+ u_int unused2; /* unused, padding for peeraddr6 */
+ struct in6_addr peeraddr6; /* ipv6 address to poll */
+};
+
+#define CONF_FLAG_AUTHENABLE 0x01
+#define CONF_FLAG_PREFER 0x02
+#define CONF_FLAG_BURST 0x04
+#define CONF_FLAG_IBURST 0x08
+#define CONF_FLAG_NOSELECT 0x10
+#define CONF_FLAG_SKEY 0x20
+
+/*
+ * 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 */
+ u_int v6_flag; /* is this v6 or not */
+ struct in6_addr peeraddr6; /* address of peer (v6) */
+};
+
+/*
+ * Structure for carrying system flags.
+ */
+struct conf_sys_flags {
+ u_int32 flags;
+};
+
+/*
+ * System flags we can set/clear
+ */
+#define SYS_FLAG_BCLIENT 0x01
+#define SYS_FLAG_PPS 0x02
+#define SYS_FLAG_NTP 0x04
+#define SYS_FLAG_KERNEL 0x08
+#define SYS_FLAG_MONITOR 0x10
+#define SYS_FLAG_FILEGEN 0x20
+#define SYS_FLAG_AUTH 0x40
+#define SYS_FLAG_CAL 0x80
+
+/*
+ * 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 */
+ u_int v6_flag; /* is this v6 or not */
+ u_int unused1; /* unused, padding for addr6 */
+ struct in6_addr addr6; /* match address (v6) */
+ struct in6_addr mask6; /* match mask (v6) */
+};
+
+
+/*
+ * 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 */
+ u_int v6_flag; /* is this v6 or not */
+ struct in6_addr addr6; /* match address (v6) */
+ struct in6_addr mask6; /* match mask (v6) */
+};
+
+
+/*
+ * Structure used for returning monitor data
+ */
+struct info_monitor_1 {
+ u_int32 avg_int; /* avg s between packets from this host */
+ u_int32 last_int; /* s since we last received a packet */
+ u_int32 restr; /* restrict bits (was named lastdrop) */
+ u_int32 count; /* count of packets received */
+ u_int32 addr; /* host address V4 style */
+ 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 */
+ u_int v6_flag; /* is this v6 or not */
+ u_int unused1; /* unused, padding for addr6 */
+ struct in6_addr addr6; /* host address V6 style */
+ struct in6_addr daddr6; /* host address V6 style */
+};
+
+
+/*
+ * Structure used for returning monitor data
+ */
+struct info_monitor {
+ u_int32 avg_int; /* avg s between packets from this host */
+ u_int32 last_int; /* s since we last received a packet */
+ u_int32 restr; /* restrict bits (was named lastdrop) */
+ 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 */
+ u_int v6_flag; /* is this v6 or not */
+ u_int unused1; /* unused, padding for addr6 */
+ struct in6_addr addr6; /* host v6 address */
+};
+
+/*
+ * 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 */
+ u_int v6_flag; /* is this v6 or not */
+ struct in6_addr addr6; /* host address (v6)*/
+};
+
+/*
+ * 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 addres (v4) */
+ u_int32 trap_address; /* remote client's addres (v4) */
+ 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 */
+ u_int v6_flag; /* is this v6 or not */
+ struct in6_addr local_address6; /* local interface address (v6) */
+ struct in6_addr trap_address6; /* remote client's address (v6) */
+};
+
+/*
+ * Structure used to pass add/clear trap information to the client
+ */
+struct conf_trap {
+ u_int32 local_address; /* remote client's address */
+ u_int32 trap_address; /* local interface address */
+ u_short trap_port; /* remote client's port */
+ u_short unused; /* (unused) */
+ u_int v6_flag; /* is this v6 or not */
+ struct in6_addr local_address6; /* local interface address (v6) */
+ struct in6_addr trap_address6; /* remote client's address (v6) */
+};
+
+
+/*
+ * 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;
+ u_int32 fudgeval2;
+};
+
+
+/*
+ * Structure used for setting clock fudge factors
+ */
+struct conf_fudge {
+ u_int32 clockadr;
+ u_int32 which;
+ l_fp fudgetime;
+ u_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;
+};
+
+/*
+ * interface statistics
+ */
+struct info_if_stats {
+ union addrun unaddr; /* address */
+ union addrun unbcast; /* broadcast */
+ union addrun unmask; /* mask */
+ u_int32 v6_flag; /* is this v6 */
+ char name[32]; /* name of interface */
+ int32 flags; /* interface flags */
+ int32 last_ttl; /* last TTL specified */
+ int32 num_mcast; /* No. of IP addresses in multicast socket */
+ int32 received; /* number of incoming packets */
+ int32 sent; /* number of outgoing packets */
+ int32 notsent; /* number of send failures */
+ int32 uptime; /* number of seconds this interface was active */
+ u_int32 scopeid; /* Scope used for Multicasting */
+ u_int32 ifindex; /* interface index - from system */
+ u_int32 ifnum; /* sequential interface number */
+ u_int32 peercnt; /* number of peers referencinf this interface - informational only */
+ u_short family; /* Address family */
+ u_char ignore_packets; /* Specify whether the packet should be ignored */
+ u_char action; /* reason the item is listed */
+ int32 _filler0; /* pad to a 64 bit size boundary */
+};
+
+#define IFS_EXISTS 1 /* just exists */
+#define IFS_CREATED 2 /* was just created */
+#define IFS_DELETED 3 /* was just delete */
+
+/*
+ * Info returned with IP -> hostname lookup
+ */
+/* 144 might need to become 32, matching data[] member of req_pkt */
+#define NTP_MAXHOSTNAME (32 - sizeof(u_int32) - sizeof(u_short))
+struct info_dns_assoc {
+ u_int32 peeraddr; /* peer address (HMS: being careful...) */
+ associd_t associd; /* association ID */
+ char hostname[NTP_MAXHOSTNAME]; /* hostname */
+};
+
+/*
+ * function declarations
+ */
+int get_packet_mode(struct recvbuf *rbufp); /* Return packet mode */
+
+#endif /* NTP_REQUEST_H */
diff --git a/include/ntp_rfc2553.h b/include/ntp_rfc2553.h
new file mode 100644
index 0000000..08ccbc4
--- /dev/null
+++ b/include/ntp_rfc2553.h
@@ -0,0 +1,253 @@
+/*
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1982, 1986, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)in.h 8.3 (Berkeley) 1/3/94
+ */
+
+/*
+ * Compatability shims with the rfc2553 API to simplify ntp.
+ */
+#ifndef NTP_RFC2553_H
+#define NTP_RFC2553_H
+
+#include <netdb.h>
+#include <isc/net.h>
+
+#include "ntp_types.h"
+#include "ntp_malloc.h"
+
+struct addrinfo *copy_addrinfo_impl(const struct addrinfo *
+#ifdef EREALLOC_CALLSITE /* from ntp_malloc.h */
+ ,
+ const char *, int
+#endif
+ );
+struct addrinfo *copy_addrinfo_list_impl(const struct addrinfo *
+#ifdef EREALLOC_CALLSITE /* from ntp_malloc.h */
+ ,
+ const char *, int
+#endif
+ );
+#ifdef EREALLOC_CALLSITE
+# define copy_addrinfo(l) \
+ copy_addrinfo_impl((l), __FILE__, __LINE__)
+# define copy_addrinfo_list(l) \
+ copy_addrinfo_list_impl((l), __FILE__, __LINE__)
+#else
+# define copy_addrinfo(l) copy_addrinfo_impl(l)
+# define copy_addrinfo_list(l) copy_addrinfo_list_impl(l)
+#endif
+
+/*
+ * If various macros are not defined we need to define them
+ */
+
+#ifndef AF_INET6
+# define AF_INET6 AF_MAX
+# define PF_INET6 AF_INET6
+#endif
+
+#if !defined(_SS_MAXSIZE) && !defined(_SS_ALIGNSIZE)
+
+# define _SS_MAXSIZE 128
+# define _SS_ALIGNSIZE (sizeof(ntp_uint64_t))
+# ifdef ISC_PLATFORM_HAVESALEN
+# define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t))
+# define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t) - \
+ _SS_PAD1SIZE - _SS_ALIGNSIZE)
+# else
+# define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(short))
+# define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(short) - \
+ _SS_PAD1SIZE - _SS_ALIGNSIZE)
+# endif /* ISC_PLATFORM_HAVESALEN */
+#endif
+
+#ifndef INET6_ADDRSTRLEN
+# define INET6_ADDRSTRLEN 46 /* max len of IPv6 addr in ascii */
+#endif
+
+/*
+ * If we don't have the sockaddr_storage structure
+ * we need to define it
+ */
+
+#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
+struct sockaddr_storage {
+#ifdef ISC_PLATFORM_HAVESALEN
+ ntp_u_int8_t ss_len; /* address length */
+ ntp_u_int8_t ss_family; /* address family */
+#else
+ short ss_family; /* address family */
+#endif
+ char __ss_pad1[_SS_PAD1SIZE];
+ ntp_uint64_t __ss_align; /* force desired structure storage alignment */
+ char __ss_pad2[_SS_PAD2SIZE];
+};
+#endif
+
+/*
+ * Finally if the platform doesn't support IPv6 we need some
+ * additional definitions
+ */
+
+/*
+ * Flag values for getaddrinfo()
+ */
+#ifndef AI_PASSIVE
+#define AI_PASSIVE 0x00000001 /* get address to use bind() */
+#define AI_CANONNAME 0x00000002 /* fill ai_canonname */
+#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
+/* valid flags for addrinfo */
+#define AI_MASK \
+ (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG)
+
+#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
+#endif /* !AI_PASSIVE */
+
+#ifndef AI_NUMERICHOST /* such as AIX 4.3 */
+# define Z_AI_NUMERICHOST 0
+#else
+# define Z_AI_NUMERICHOST AI_NUMERICHOST
+#endif
+
+#ifndef AI_NUMERICSERV /* not in RFC 2553 */
+# define Z_AI_NUMERICSERV 0
+#else
+# define Z_AI_NUMERICSERV AI_NUMERICSERV
+#endif
+
+#ifndef ISC_PLATFORM_HAVEIPV6
+
+#ifdef SYS_WINNT
+# define in6_addr in_addr6
+#endif
+
+struct addrinfo {
+ int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
+ int ai_family; /* PF_xxx */
+ int ai_socktype; /* SOCK_xxx */
+ int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
+ size_t ai_addrlen; /* length of ai_addr */
+ char *ai_canonname; /* canonical name for hostname */
+ struct sockaddr *ai_addr; /* binary address */
+ struct addrinfo *ai_next; /* next structure in linked list */
+};
+
+/*
+ * Error return codes from getaddrinfo()
+ */
+#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
+#define EAI_AGAIN 2 /* temporary failure in name resolution */
+#define EAI_BADFLAGS 3 /* invalid value for ai_flags */
+#define EAI_FAIL 4 /* non-recoverable failure in name resolution */
+#define EAI_FAMILY 5 /* ai_family not supported */
+#define EAI_MEMORY 6 /* memory allocation failure */
+#define EAI_NODATA 7 /* no address associated with hostname */
+#define EAI_NONAME 8 /* hostname nor servname provided, or not known */
+#define EAI_SERVICE 9 /* servname not supported for ai_socktype */
+#define EAI_SOCKTYPE 10 /* ai_socktype not supported */
+#define EAI_SYSTEM 11 /* system error returned in errno */
+#define EAI_BADHINTS 12
+#define EAI_PROTOCOL 13
+#define EAI_MAX 14
+
+
+int getaddrinfo (const char *, const char *,
+ const struct addrinfo *, struct addrinfo **);
+int getnameinfo (const struct sockaddr *, u_int, char *,
+ size_t, char *, size_t, int);
+void freeaddrinfo (struct addrinfo *);
+char *gai_strerror (int);
+
+/*
+ * Constants for getnameinfo()
+ */
+#ifndef NI_MAXHOST
+#define NI_MAXHOST 1025
+#define NI_MAXSERV 32
+#endif
+
+/*
+ * Flag values for getnameinfo()
+ */
+#ifndef NI_NUMERICHOST
+#define NI_NOFQDN 0x00000001
+#define NI_NUMERICHOST 0x00000002
+#define NI_NAMEREQD 0x00000004
+#define NI_NUMERICSERV 0x00000008
+#define NI_DGRAM 0x00000010
+#define NI_WITHSCOPEID 0x00000020
+#endif
+
+#endif /* !ISC_PLATFORM_HAVEIPV6 */
+
+/*
+ * Set up some macros to look for IPv6 and IPv6 multicast
+ */
+
+#if defined(ISC_PLATFORM_HAVEIPV6) && defined(WANT_IPV6)
+# define INCLUDE_IPV6_SUPPORT
+# if defined(IPV6_JOIN_GROUP) && defined(IPV6_LEAVE_GROUP)
+# define INCLUDE_IPV6_MULTICAST_SUPPORT
+# endif /* IPV6 Multicast Support */
+#endif /* IPv6 Support */
+
+#endif /* !NTP_RFC2553_H */
diff --git a/include/ntp_select.h b/include/ntp_select.h
new file mode 100644
index 0000000..2c0fbee
--- /dev/null
+++ b/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 /* note: tested by include/l_stdlib.h */
+
+/* Was: (defined(RS6000)||defined(SYS_PTX))&&!defined(_BSD) */
+/* Could say: !defined(FD_SET) && defined(HAVE_SYS_SELECT_H) */
+/* except FD_SET can legitimately be a typedef... */
+#if defined(HAVE_SYS_SELECT_H) && !defined(_BSD)
+# ifndef SYS_VXWORKS
+# include <sys/select.h>
+# else
+# include <sockLib.h>
+extern int select(int width, fd_set *pReadFds, fd_set *pWriteFds,
+ fd_set *pExceptFds, struct timeval *pTimeOut);
+# endif
+#endif
+
+#if !defined(FD_SET)
+# 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((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/include/ntp_stdlib.h b/include/ntp_stdlib.h
new file mode 100644
index 0000000..7c884fc
--- /dev/null
+++ b/include/ntp_stdlib.h
@@ -0,0 +1,267 @@
+/*
+ * ntp_stdlib.h - Prototypes for NTP lib.
+ */
+#ifndef NTP_STDLIB_H
+#define NTP_STDLIB_H
+
+#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+#include "declcond.h" /* ntpd uses ntpd/declcond.h, others include/ */
+#include "l_stdlib.h"
+#include "ntp_net.h"
+#include "ntp_debug.h"
+#include "ntp_malloc.h"
+#include "ntp_string.h"
+#include "ntp_syslog.h"
+
+#ifdef __GNUC__
+#define NTP_PRINTF(fmt, args) __attribute__((__format__(__printf__, fmt, args)))
+#else
+#define NTP_PRINTF(fmt, args)
+#endif
+
+extern int mprintf(const char *, ...) NTP_PRINTF(1, 2);
+extern int mfprintf(FILE *, const char *, ...) NTP_PRINTF(2, 3);
+extern int mvfprintf(FILE *, const char *, va_list) NTP_PRINTF(2, 0);
+extern int mvsnprintf(char *, size_t, const char *, va_list)
+ NTP_PRINTF(3, 0);
+extern int msnprintf(char *, size_t, const char *, ...)
+ NTP_PRINTF(3, 4);
+extern void msyslog(int, const char *, ...) NTP_PRINTF(2, 3);
+extern void init_logging (const char *, u_int32, int);
+extern int change_logfile (const char *, int);
+extern void setup_logfile (const char *);
+#ifndef errno_to_str
+extern void errno_to_str(int, char *, size_t);
+#endif
+
+/*
+ * When building without OpenSSL, use a few macros of theirs to
+ * minimize source differences in NTP.
+ */
+#ifndef OPENSSL
+#define NID_md5 4 /* from openssl/objects.h */
+/* from openssl/evp.h */
+#define EVP_MAX_MD_SIZE 64 /* longest known is SHA512 */
+#endif
+
+#define SAVE_ERRNO(stmt) \
+ { \
+ int preserved_errno; \
+ \
+ preserved_errno = socket_errno(); \
+ { \
+ stmt \
+ } \
+ errno = preserved_errno; \
+ }
+
+typedef void (*ctrl_c_fn)(void);
+
+/* authkeys.c */
+extern void auth_delkeys (void);
+extern int auth_havekey (keyid_t);
+extern int authdecrypt (keyid_t, u_int32 *, int, int);
+extern int authencrypt (keyid_t, u_int32 *, int);
+extern int authhavekey (keyid_t);
+extern int authistrusted (keyid_t);
+extern int authreadkeys (const char *);
+extern void authtrust (keyid_t, u_long);
+extern int authusekey (keyid_t, int, const u_char *);
+
+/*
+ * Based on the NTP timestamp, calculate the NTP timestamp of
+ * the corresponding calendar unit. Use the pivot time to unfold
+ * the NTP timestamp properly, or the current system time if the
+ * pivot pointer is NULL.
+ */
+extern u_int32 calyearstart (u_int32 ntptime, const time_t *pivot);
+extern u_int32 calmonthstart (u_int32 ntptime, const time_t *pivot);
+extern u_int32 calweekstart (u_int32 ntptime, const time_t *pivot);
+extern u_int32 caldaystart (u_int32 ntptime, const time_t *pivot);
+
+extern const char *clockname (int);
+extern int clocktime (int, int, int, int, int, u_int32, u_long *, u_int32 *);
+extern int ntp_getopt (int, char **, const char *);
+extern void init_auth (void);
+extern void init_lib (void);
+extern struct savekey *auth_findkey (keyid_t);
+extern void auth_moremem (int);
+extern void auth_prealloc_symkeys(int);
+extern int ymd2yd (int, int, int);
+
+/* a_md5encrypt.c */
+extern int MD5authdecrypt (int, u_char *, u_int32 *, int, int);
+extern int MD5authencrypt (int, u_char *, u_int32 *, int);
+extern void MD5auth_setkey (keyid_t, int, const u_char *, int);
+extern u_int32 addr2refid (sockaddr_u *);
+
+/* emalloc.c */
+#ifndef EREALLOC_CALLSITE /* ntp_malloc.h defines */
+extern void * ereallocz (void *, size_t, size_t, int);
+#define erealloczsite(p, n, o, z, f, l) ereallocz(p, n, o, (z))
+extern void * emalloc (size_t);
+#define emalloc_zero(c) ereallocz(NULL, (c), 0, TRUE)
+#define erealloc(p, c) ereallocz(p, (c), 0, FALSE)
+#define erealloc_zero(p, n, o) ereallocz(p, n, (o), TRUE)
+extern char * estrdup_impl (const char *);
+#define estrdup(s) estrdup_impl(s)
+#else
+extern void * ereallocz (void *, size_t, size_t, int,
+ const char *, int);
+#define erealloczsite ereallocz
+#define emalloc(c) ereallocz(NULL, (c), 0, FALSE, \
+ __FILE__, __LINE__)
+#define emalloc_zero(c) ereallocz(NULL, (c), 0, TRUE, \
+ __FILE__, __LINE__)
+#define erealloc(p, c) ereallocz(p, (c), 0, FALSE, \
+ __FILE__, __LINE__)
+#define erealloc_zero(p, n, o) ereallocz(p, n, (o), TRUE, \
+ __FILE__, __LINE__)
+extern char * estrdup_impl (const char *, const char *, int);
+#define estrdup(s) estrdup_impl((s), __FILE__, __LINE__)
+#endif
+
+
+extern int atoint (const char *, long *);
+extern int atouint (const char *, u_long *);
+extern int hextoint (const char *, u_long *);
+extern char * humanlogtime (void);
+extern char * humantime (time_t);
+extern char * mfptoa (u_int32, u_int32, short);
+extern char * mfptoms (u_int32, u_int32, short);
+extern const char * modetoa (int);
+extern const char * eventstr (int);
+extern const char * ceventstr (int);
+extern const char * res_match_flags(u_short);
+extern const char * res_access_flags(u_short);
+#ifdef KERNEL_PLL
+extern const char * k_st_flags (u_int32);
+#endif
+extern char * statustoa (int, int);
+extern sockaddr_u * netof (sockaddr_u *);
+extern char * numtoa (u_int32);
+extern char * numtohost (u_int32);
+extern const char * socktoa (const sockaddr_u *);
+extern const char * sockporttoa(const sockaddr_u *);
+extern u_short sock_hash (const sockaddr_u *);
+extern int sockaddr_masktoprefixlen(const sockaddr_u *);
+extern const char * socktohost (const sockaddr_u *);
+extern int octtoint (const char *, u_long *);
+extern u_long ranp2 (int);
+extern const char *refnumtoa (sockaddr_u *);
+extern const char *refid_str (u_int32, int);
+
+extern int decodenetnum (const char *, sockaddr_u *);
+
+extern const char * FindConfig (const char *);
+
+extern void signal_no_reset (int, RETSIGTYPE (*func)(int));
+extern void set_ctrl_c_hook (ctrl_c_fn);
+
+extern void getauthkeys (const char *);
+extern void auth_agekeys (void);
+extern void rereadkeys (void);
+
+/*
+ * Variable declarations for libntp.
+ */
+
+/* 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 keyid_t cache_keyid; /* key identifier */
+extern int cache_type; /* key type */
+extern u_char * cache_secret; /* secret */
+extern u_short cache_secretsize; /* secret octets */
+extern u_short cache_flags; /* KEY_ bit flags */
+
+/* getopt.c */
+extern char * ntp_optarg; /* global argument pointer */
+extern int ntp_optind; /* global argv index */
+
+/* lib_strbuf.c */
+extern int ipv4_works;
+extern int ipv6_works;
+
+/* machines.c */
+typedef void (*pset_tod_using)(const char *);
+extern pset_tod_using set_tod_using;
+
+/* ssl_init.c */
+#ifdef OPENSSL
+extern void ssl_init (void);
+extern void ssl_check_version (void);
+extern int ssl_init_done;
+#define INIT_SSL() \
+ do { \
+ if (!ssl_init_done) \
+ ssl_init(); \
+ } while (0)
+#else /* !OPENSSL follows */
+#define INIT_SSL() do {} while (0)
+#endif
+extern int keytype_from_text (const char *, size_t *);
+extern const char *keytype_name (int);
+extern char * getpass_keytype (int);
+
+/* strl-obsd.c */
+#ifndef HAVE_STRLCPY /* + */
+/*
+ * Copy src to string dst of size siz. At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz == 0).
+ * Returns strlen(src); if retval >= siz, truncation occurred.
+ */
+extern size_t strlcpy(char *dst, const char *src, size_t siz);
+#endif
+#ifndef HAVE_STRLCAT /* + */
+/*
+ * Appends src to string dst of size siz (unlike strncat, siz is the
+ * full size of dst, not space left). At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
+ * Returns strlen(src) + MIN(siz, strlen(initial dst)).
+ * If retval >= siz, truncation occurred.
+ */
+extern size_t strlcat(char *dst, const char *src, size_t siz);
+#endif
+
+
+
+/* lib/isc/win32/strerror.c
+ *
+ * To minimize Windows-specific changes to the rest of the NTP code,
+ * particularly reference clocks, we hijack calls to strerror() to deal
+ * with our mixture of error codes from the C runtime (open, write)
+ * and Windows (sockets, serial ports). This is an ugly hack because
+ * both use the lowest values differently, but particularly for ntpd,
+ * it's not a problem.
+ */
+#ifdef NTP_REDEFINE_STRERROR
+#define strerror(e) ntp_strerror(e)
+extern char * ntp_strerror (int e);
+#endif
+
+/* systime.c */
+extern double sys_tick; /* tick size or time to read */
+extern double measured_tick; /* non-overridable sys_tick */
+extern double sys_fuzz; /* min clock read latency */
+extern int trunc_os_clock; /* sys_tick > measured_tick */
+
+/* version.c */
+extern const char *Version; /* version declaration */
+
+#endif /* NTP_STDLIB_H */
diff --git a/include/ntp_string.h b/include/ntp_string.h
new file mode 100644
index 0000000..9b62ec2
--- /dev/null
+++ b/include/ntp_string.h
@@ -0,0 +1,37 @@
+/*
+ * Define string ops: strchr strrchr memcmp memmove memset
+ */
+
+#ifndef NTP_STRING_H
+#define NTP_STRING_H
+
+#ifdef HAVE_MEMORY_H
+# include <memory.h>
+#endif
+
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+#ifdef HAVE_BSTRING_H
+# include <bstring.h>
+#endif
+
+#ifdef NTP_NEED_BOPS
+
+#ifdef HAVE_STRINGS_H
+# include <strings.h> /* bcmp, bcopy, bzero */
+#endif
+
+void ntp_memset (char *, int, int);
+
+#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 (0 == (x)) \
+ bzero(a, (int)(c)); \
+ else \
+ ntp_memset((char *)(a), x, c)
+#endif /* NTP_NEED_BOPS */
+
+#endif /* NTP_STRING_H */
diff --git a/include/ntp_syscall.h b/include/ntp_syscall.h
new file mode 100644
index 0000000..d1ce03e
--- /dev/null
+++ b/include/ntp_syscall.h
@@ -0,0 +1,56 @@
+/*
+ * 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_SYS_TIMEX_H
+# include <sys/timex.h>
+#endif
+
+#ifndef NTP_SYSCALLS_LIBC
+# 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_NTP_ADJTIME
+extern int ntp_adjtime (struct timex *);
+
+# ifndef HAVE_STRUCT_NTPTIMEVAL
+struct ntptimeval
+{
+ struct timeval time; /* current time (ro) */
+ long int maxerror; /* maximum error (us) (ro) */
+ long int esterror; /* estimated error (us) (ro) */
+};
+# endif
+
+# ifndef HAVE_NTP_GETTIME
+static inline int
+ntp_gettime(
+ struct ntptimeval *ntv
+ )
+{
+ struct timex tntx;
+ int result;
+
+ ZERO(tntx);
+ result = ntp_adjtime(&tntx);
+ ntv->time = tntx.time;
+ ntv->maxerror = tntx.maxerror;
+ ntv->esterror = tntx.esterror;
+# ifdef NTP_API
+# if NTP_API > 3
+ ntv->tai = tntx.tai;
+# endif
+# endif
+ return result;
+}
+# endif /* !HAVE_NTP_GETTIME */
+# endif /* !HAVE_NTP_ADJTIME */
+# endif /* !NTP_SYSCALLS_STD */
+#endif /* !NTP_SYSCALLS_LIBC */
+
+#endif /* NTP_SYSCALL_H */
diff --git a/include/ntp_syslog.h b/include/ntp_syslog.h
new file mode 100644
index 0000000..a0152b5
--- /dev/null
+++ b/include/ntp_syslog.h
@@ -0,0 +1,85 @@
+/*
+ * A hack for platforms which require specially built syslog facilities
+ */
+
+#ifndef NTP_SYSLOG_H
+#define NTP_SYSLOG_H
+
+#include <ntp_types.h> /* u_int32 type */
+
+#ifdef VMS
+extern void msyslog();
+#else
+# ifndef SYS_VXWORKS
+# include <syslog.h>
+# endif
+#endif /* VMS */
+#include <stdio.h>
+
+extern int syslogit;
+extern int msyslog_term; /* duplicate to stdout/err */
+extern int msyslog_term_pid;
+extern int msyslog_include_timestamp;
+extern FILE * syslog_file; /* if syslogit is FALSE, log to
+ this file and not syslog */
+extern char * syslog_fname;
+extern char * syslog_abs_fname;
+
+#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 u_int32 ntp_syslogmask;
+
+#define NLOG(bits) if (ntp_syslogmask & (bits))
+
+#define LOGIF(nlog_suffix, msl_args) \
+do { \
+ NLOG(NLOG_##nlog_suffix) /* like "if (...) */ \
+ msyslog msl_args; \
+} while (FALSE)
+
+#endif /* NTP_SYSLOG_H */
diff --git a/include/ntp_tty.h b/include/ntp_tty.h
new file mode 100644
index 0000000..6dc48b6
--- /dev/null
+++ b/include/ntp_tty.h
@@ -0,0 +1,103 @@
+/*
+ * ntp_tty.h - header file for serial lines handling
+ */
+#ifndef NTP_TTY_H
+#define NTP_TTY_H
+
+/*
+ * 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
+ */
+
+#if defined(HAVE_TERMIOS_H) || defined(HAVE_SYS_TERMIOS_H)
+# define HAVE_TERMIOS
+#elif defined(HAVE_TERMIO_H)
+# define HAVE_SYSV_TTYS
+#elif defined(HAVE_SGTTY_H)
+# define HAVE_BSD_TTYS
+#endif
+
+#if !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 /* !VMS && !SYS_VXWORKS*/
+
+#if defined(HAVE_BSD_TTYS)
+#include <sgtty.h>
+#define TTY struct sgttyb
+#endif /* HAVE_BSD_TTYS */
+
+#if defined(HAVE_SYSV_TTYS)
+#include <termio.h>
+#define TTY struct termio
+#ifndef tcsetattr
+#define tcsetattr(fd, cmd, arg) ioctl(fd, cmd, arg)
+#endif
+#ifndef TCSANOW
+#define TCSANOW TCSETA
+#endif
+#ifndef TCIFLUSH
+#define TCIFLUSH 0
+#endif
+#ifndef TCOFLUSH
+#define TCOFLUSH 1
+#endif
+#ifndef TCIOFLUSH
+#define TCIOFLUSH 2
+#endif
+#ifndef tcflush
+#define tcflush(fd, arg) ioctl(fd, TCFLSH, arg)
+#endif
+#endif /* HAVE_SYSV_TTYS */
+
+#if defined(HAVE_TERMIOS)
+# if defined(HAVE_TERMIOS_H)
+# ifdef TERMIOS_NEEDS__SVID3
+# define _SVID3
+# endif
+# include <termios.h>
+# ifdef TERMIOS_NEEDS__SVID3
+# undef _SVID3
+# endif
+# elif defined(HAVE_SYS_TERMIOS_H)
+# include <sys/termios.h>
+# endif
+# define TTY struct termios
+#endif
+
+#if defined(HAVE_SYS_MODEM_H)
+#include <sys/modem.h>
+#endif
+
+/*
+ * Line discipline flags. The depredated ones required line discipline
+ * or streams modules to be installed/loaded in the kernel and are now
+ * ignored. Leave the LDISC_CLK and other deprecated symbols defined
+ * until 2013 or 2014 to avoid complicating the use of newer drivers on
+ * older ntpd, which is often as easy as dropping in the refclock *.c.
+ */
+#define LDISC_STD 0x000 /* standard */
+#define LDISC_CLK 0x001 /* depredated tty_clk \n */
+#define LDISC_CLKPPS 0x002 /* depredated tty_clk \377 */
+#define LDISC_ACTS 0x004 /* depredated tty_clk #* */
+#define LDISC_CHU 0x008 /* depredated */
+#define LDISC_PPS 0x010 /* depredated */
+#define LDISC_RAW 0x020 /* raw binary */
+#define LDISC_ECHO 0x040 /* enable echo */
+#define LDISC_REMOTE 0x080 /* remote mode */
+#define LDISC_7O1 0x100 /* 7-bit, odd parity for Z3801A */
+
+/* function prototypes for ntp_tty.c */
+#if !defined(SYS_VXWORKS) && !defined(SYS_WINNT)
+# if defined(HAVE_TERMIOS) || defined(HAVE_SYSV_TTYS) || \
+ defined(HAVE_BSD_TTYS)
+extern int ntp_tty_setup(int, u_int, u_int);
+extern int ntp_tty_ioctl(int, u_int);
+# endif
+#endif
+
+#endif /* NTP_TTY_H */
diff --git a/include/ntp_types.h b/include/ntp_types.h
new file mode 100644
index 0000000..1beb166
--- /dev/null
+++ b/include/ntp_types.h
@@ -0,0 +1,288 @@
+/*
+ * ntp_types.h - defines how int32 and u_int32 are treated.
+ *
+ * New style: Make sure C99 fixed width integer types are available:
+ * intN_t and uintN_t
+
+ * Old style: 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
+ */
+#ifndef NTP_TYPES_H
+#define NTP_TYPES_H
+
+#include <sys/types.h>
+#if defined(HAVE_INTTYPES_H)
+# include <inttypes.h>
+#elif defined(HAVE_STDINT_H)
+# include <stdint.h>
+#endif
+
+#include "ntp_machine.h"
+
+
+#ifndef TRUE
+# define TRUE 1
+#endif
+#ifndef FALSE
+# define FALSE 0
+#endif
+
+/*
+ * 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
+
+/*
+ * used to quiet compiler warnings
+ */
+#ifndef UNUSED_ARG
+#define UNUSED_ARG(arg) ((void)(arg))
+#endif
+#ifndef UNUSED_LOCAL
+#define UNUSED_LOCAL(arg) ((void)(arg))
+#endif
+
+/*
+ * COUNTOF(array) - size of array in elements
+ */
+#define COUNTOF(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+/*
+ * 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;
+#endif /* VMS */
+
+#ifdef HAVE_UINT32_T
+# ifndef HAVE_INT32
+ typedef int32_t int32;
+# endif
+# ifndef HAVE_U_INT32
+ typedef uint32_t u_int32;
+# if defined(UINT32_MAX) && !defined(U_INT32_MAX)
+# define U_INT32_MAX UINT32_MAX
+# endif
+# endif
+#elif (SIZEOF_INT == 4)
+# if !defined(HAVE_INT32) && !defined(int32)
+ typedef int int32;
+# ifndef INT32_MIN
+# define INT32_MIN INT_MIN
+# endif
+# ifndef INT32_MAX
+# define INT32_MAX INT_MAX
+# endif
+# endif
+# if !defined(HAVE_U_INT32) && !defined(u_int32)
+ typedef unsigned u_int32;
+# if defined(UINT_MAX) && !defined(U_INT32_MAX)
+# define U_INT32_MAX UINT_MAX
+# endif
+# endif
+#else /* SIZEOF_INT != 4 */
+# if (SIZEOF_LONG == 4)
+# if !defined(HAVE_INT32) && !defined(int32)
+ typedef long int32;
+# ifndef INT32_MIN
+# define INT32_MIN LONG_MIN
+# endif
+# ifndef INT32_MAX
+# define INT32_MAX LONG_MAX
+# endif
+# endif
+# if !defined(HAVE_U_INT32) && !defined(u_int32)
+ typedef unsigned long u_int32;
+# if defined(ULONG_MAX) && !defined(U_INT32_MAX)
+# define U_INT32_MAX ULONG_MAX
+# endif
+# endif
+# else /* SIZEOF_LONG != 4 */
+# include "Bletch: what's 32 bits on this machine?"
+# endif
+#endif /* !HAVE_UINT32_T && SIZEOF_INT != 4 */
+
+#ifndef U_INT32_MAX
+# define U_INT32_MAX 0xffffffff
+#endif
+
+
+/*
+ * Ugly dance to find out if we have 64bit integer type.
+ */
+#if !defined(HAVE_INT64)
+
+/* assume best for now, fix if frustrated later. */
+# define HAVE_INT64
+# define HAVE_U_INT64
+
+/* now check the cascade. Feel free to add things. */
+# ifdef INT64_MAX
+
+typedef int64_t int64;
+typedef uint64_t u_int64;
+
+# elif SIZEOF_LONG == 8
+
+typedef long int64;
+typedef unsigned long u_int64;
+
+# elif SIZEOF_LONG_LONG == 8
+
+typedef long long int64;
+typedef unsigned long long u_int64;
+
+# else
+
+/* no 64bit scalar, give it up. */
+# undef HAVE_INT64
+# undef HAVE_U_INT64
+
+# endif
+
+#endif
+
+/*
+ * and here the trouble starts: We need a representation with more than
+ * 64 bits. If a scalar of that size is not available, we need a struct
+ * that holds the value in split representation.
+ *
+ * To ease the usage a bit, we alwys use a union that is in processor
+ * byte order and might or might not contain a 64bit scalar.
+ */
+
+#if SIZEOF_SHORT != 2
+# error short is not 2 bytes -- what is 16 bit integer on this target?
+#endif
+
+typedef union {
+# ifdef WORDS_BIGENDIAN
+ struct {
+ int16_t hh; uint16_t hl; uint16_t lh; uint16_t ll;
+ } w_s;
+ struct {
+ uint16_t hh; uint16_t hl; uint16_t lh; uint16_t ll;
+ } W_s;
+ struct {
+ int32 hi; u_int32 lo;
+ } d_s;
+ struct {
+ u_int32 hi; u_int32 lo;
+ } D_s;
+# else
+ struct {
+ uint16_t ll; uint16_t lh; uint16_t hl; int16_t hh;
+ } w_s;
+ struct {
+ uint16_t ll; uint16_t lh; uint16_t hl; uint16_t hh;
+ } W_s;
+ struct {
+ u_int32 lo; int32 hi;
+ } d_s;
+ struct {
+ u_int32 lo; u_int32 hi;
+ } D_s;
+# endif
+
+# ifdef HAVE_INT64
+ int64 q_s; /* signed quad scalar */
+ u_int64 Q_s; /* unsigned quad scalar */
+# endif
+} vint64; /* variant int 64 */
+
+
+typedef uint8_t ntp_u_int8_t;
+typedef uint16_t ntp_u_int16_t;
+typedef uint32_t ntp_u_int32_t;
+
+typedef struct ntp_uint64_t { u_int32 val[2]; } ntp_uint64_t;
+
+typedef uint16_t associd_t; /* association ID */
+#define ASSOCID_MAX USHRT_MAX
+typedef u_int32 keyid_t; /* cryptographic key ID */
+#define KEYID_T_MAX (0xffffffff)
+typedef u_int32 tstamp_t; /* NTP seconds timestamp */
+
+/*
+ * Cloning malloc()'s behavior of always returning pointers suitably
+ * aligned for the strictest alignment requirement of any type is not
+ * easy to do portably, as the maximum alignment required is not
+ * exposed. Use the size of a union of the types known to represent the
+ * strictest alignment on some platform.
+ */
+typedef union max_alignment_tag {
+ double d;
+} max_alignment;
+
+#define MAXALIGN sizeof(max_alignment)
+#define ALIGN_UNITS(sz) (((sz) + MAXALIGN - 1) / MAXALIGN)
+#define ALIGNED_SIZE(sz) (MAXALIGN * ALIGN_UNITS(sz))
+#define INC_ALIGNED_PTR(b, m) ((void *)aligned_ptr((void *)(b), m))
+
+static inline
+max_alignment *
+aligned_ptr(
+ max_alignment * base,
+ size_t minsize
+ )
+{
+ return base + ALIGN_UNITS((minsize < 1) ? 1 : minsize);
+}
+
+/*
+ * Macro to use in otherwise-empty source files to comply with ANSI C
+ * requirement that each translation unit (source file) contain some
+ * declaration. This has commonly been done by declaring an unused
+ * global variable of type int or char. An extern reference to exit()
+ * serves the same purpose without bloat.
+ */
+#define NONEMPTY_TRANSLATION_UNIT extern void exit(int);
+
+/*
+ * On Unix struct sock_timeval is equivalent to struct timeval.
+ * On Windows built with 64-bit time_t, sock_timeval.tv_sec is a long
+ * as required by Windows' socket() interface timeout argument, while
+ * timeval.tv_sec is time_t for the more common use as a UTC time
+ * within NTP.
+ */
+#ifndef SYS_WINNT
+#define sock_timeval timeval
+#endif
+
+/*
+ * On Unix open() works for tty (serial) devices just fine, while on
+ * Windows refclock serial devices are opened using CreateFile, a lower
+ * level than the CRT-provided descriptors, because the C runtime lacks
+ * tty APIs. For refclocks which wish to use open() as well as or
+ * instead of refclock_open(), tty_open() is equivalent to open() on
+ * Unix and implemented in the Windows port similarly to
+ * refclock_open().
+ * Similarly, the termios emulation in the Windows code needs to know
+ * about serial ports being closed, while the Posix systems do not.
+ */
+#ifndef SYS_WINNT
+# define tty_open(f, a, m) open(f, a, m)
+# define closeserial(fd) close(fd)
+# define closesocket(fd) close(fd)
+typedef int SOCKET;
+# define INVALID_SOCKET (-1)
+# define SOCKET_ERROR (-1)
+# define socket_errno() (errno)
+#else /* SYS_WINNT follows */
+# define socket_errno() (errno = WSAGetLastError())
+#endif
+
+
+
+#endif /* NTP_TYPES_H */
diff --git a/include/ntp_unixtime.h b/include/ntp_unixtime.h
new file mode 100644
index 0000000..eaa8b1e
--- /dev/null
+++ b/include/ntp_unixtime.h
@@ -0,0 +1,47 @@
+/*
+ * ntp_unixtime.h - much of what was here is now in timevalops.h
+ */
+
+#ifndef NTP_UNIXTIME_H
+#define NTP_UNIXTIME_H
+
+#include "ntp_types.h" /* picks up time.h via ntp_machine.h */
+#include "ntp_calendar.h"
+
+#ifdef SIM
+# define GETTIMEOFDAY(a, b) (node_gettime(&ntp_node, a))
+# define SETTIMEOFDAY(a, b) (node_settime(&ntp_node, a))
+# define ADJTIMEOFDAY(a, b) (node_adjtime(&ntp_node, a, b))
+#else
+# define ADJTIMEOFDAY(a, b) (adjtime(a, b))
+/* 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);
+# define GETTIMEOFDAY(a, b) (gettimeofday(a, b))
+# 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) */
+#endif /* SIM */
+
+/*
+ * Time of day conversion constant. Ntp's time scale starts in 1900,
+ * Unix in 1970. The value is 1970 - 1900 in seconds, 0x83aa7e80 or
+ * 2208988800. This is larger than 32-bit INT_MAX, so unsigned
+ * type is forced.
+ */
+#define JAN_1970 ((u_int)NTP_TO_UNIX_DAYS * (u_int)SECSPERDAY)
+
+#endif /* !defined(NTP_UNIXTIME_H) */
diff --git a/include/ntp_worker.h b/include/ntp_worker.h
new file mode 100644
index 0000000..f7e8d5b
--- /dev/null
+++ b/include/ntp_worker.h
@@ -0,0 +1,162 @@
+/*
+ * ntp_worker.h
+ */
+
+#ifndef NTP_WORKER_H
+#define NTP_WORKER_H
+
+#include "ntp_workimpl.h"
+
+#ifdef WORKER
+# if defined(WORK_THREAD) && defined(WORK_PIPE)
+# ifdef HAVE_SEMAPHORE_H
+# include <semaphore.h>
+# endif
+# endif
+#include "ntp_stdlib.h"
+
+/* #define TEST_BLOCKING_WORKER */ /* ntp_config.c ntp_intres.c */
+
+typedef enum blocking_work_req_tag {
+ BLOCKING_GETNAMEINFO,
+ BLOCKING_GETADDRINFO,
+} blocking_work_req;
+
+typedef void (*blocking_work_callback)(blocking_work_req, void *, size_t, void *);
+
+typedef enum blocking_magic_sig_e {
+ BLOCKING_REQ_MAGIC = 0x510c7ecf,
+ BLOCKING_RESP_MAGIC = 0x510c7e54,
+} blocking_magic_sig;
+
+/*
+ * The same header is used for both requests to and responses from
+ * the child. In the child, done_func and context are opaque.
+ */
+typedef struct blocking_pipe_header_tag {
+ size_t octets;
+ blocking_magic_sig magic_sig;
+ blocking_work_req rtype;
+ u_int child_idx;
+ blocking_work_callback done_func;
+ void * context;
+} blocking_pipe_header;
+
+# ifdef WORK_THREAD
+# ifdef WORK_PIPE
+typedef pthread_t * thr_ref;
+typedef sem_t * sem_ref;
+# else
+typedef HANDLE thr_ref;
+typedef HANDLE sem_ref;
+# endif
+# endif
+
+/*
+ *
+ */
+#ifdef WORK_FORK
+typedef struct blocking_child_tag {
+ int reusable;
+ int pid;
+ int req_write_pipe; /* parent */
+ int resp_read_pipe;
+ void * resp_read_ctx;
+ int req_read_pipe; /* child */
+ int resp_write_pipe;
+ int ispipe;
+} blocking_child;
+#elif defined(WORK_THREAD)
+typedef struct blocking_child_tag {
+/*
+ * blocking workitems and blocking_responses are dynamically-sized
+ * one-dimensional arrays of pointers to blocking worker requests and
+ * responses.
+ */
+ int reusable;
+ thr_ref thread_ref;
+ u_int thread_id;
+ blocking_pipe_header * volatile * volatile
+ workitems;
+ volatile size_t workitems_alloc;
+ size_t next_workitem; /* parent */
+ size_t next_workeritem; /* child */
+ blocking_pipe_header * volatile * volatile
+ responses;
+ volatile size_t responses_alloc;
+ size_t next_response; /* child */
+ size_t next_workresp; /* parent */
+ /* event handles / sem_t pointers */
+ /* sem_ref child_is_blocking; */
+ sem_ref blocking_req_ready;
+ sem_ref wake_scheduled_sleep;
+#ifdef WORK_PIPE
+ int resp_read_pipe; /* parent */
+ int resp_write_pipe;/* child */
+ int ispipe;
+ void * resp_read_ctx; /* child */
+#else
+ sem_ref blocking_response_ready;
+#endif
+} blocking_child;
+
+#endif /* WORK_THREAD */
+
+extern blocking_child ** blocking_children;
+extern size_t blocking_children_alloc;
+extern int worker_per_query; /* boolean */
+extern int intres_req_pending;
+
+extern u_int available_blocking_child_slot(void);
+extern int queue_blocking_request(blocking_work_req, void *,
+ size_t, blocking_work_callback,
+ void *);
+extern int queue_blocking_response(blocking_child *,
+ blocking_pipe_header *, size_t,
+ const blocking_pipe_header *);
+extern void process_blocking_resp(blocking_child *);
+extern int send_blocking_req_internal(blocking_child *,
+ blocking_pipe_header *,
+ void *);
+extern int send_blocking_resp_internal(blocking_child *,
+ blocking_pipe_header *);
+extern blocking_pipe_header *
+ receive_blocking_req_internal(blocking_child *);
+extern blocking_pipe_header *
+ receive_blocking_resp_internal(blocking_child *);
+extern int blocking_child_common(blocking_child *);
+extern void exit_worker(int)
+ __attribute__ ((__noreturn__));
+extern int worker_sleep(blocking_child *, time_t);
+extern void worker_idle_timer_fired(void);
+extern void interrupt_worker_sleep(void);
+extern int req_child_exit(blocking_child *);
+#ifndef HAVE_IO_COMPLETION_PORT
+extern int pipe_socketpair(int fds[2], int *is_pipe);
+extern void close_all_beyond(int);
+extern void close_all_except(int);
+extern void kill_asyncio (int);
+#endif
+
+# ifdef WORK_PIPE
+typedef void (*addremove_io_fd_func)(int, int, int);
+extern addremove_io_fd_func addremove_io_fd;
+# else
+extern void handle_blocking_resp_sem(void *);
+typedef void (*addremove_io_semaphore_func)(sem_ref, int);
+extern addremove_io_semaphore_func addremove_io_semaphore;
+# endif
+
+# ifdef WORK_FORK
+extern int worker_process;
+# endif
+
+#endif /* WORKER */
+
+#if defined(HAVE_DROPROOT) && defined(WORK_FORK)
+extern void fork_deferred_worker(void);
+#else
+# define fork_deferred_worker() do {} while (0)
+#endif
+
+#endif /* !NTP_WORKER_H */
diff --git a/include/ntp_workimpl.h b/include/ntp_workimpl.h
new file mode 100644
index 0000000..a86c2cd
--- /dev/null
+++ b/include/ntp_workimpl.h
@@ -0,0 +1,30 @@
+/*
+ * ntp_workimpl.h - selects worker child implementation
+ */
+#ifndef NTP_WORKIMPL_H
+#define NTP_WORKIMPL_H
+
+/*
+ * Some systems do not support fork() and don't have an alternate
+ * threads implementation of ntp_intres. Such systems are limited
+ * to using numeric IP addresses.
+ */
+#if defined(SYS_WINNT)
+# define WORK_THREAD
+#elif defined(ISC_PLATFORM_USETHREADS) && \
+ defined(HAVE_SEM_TIMEDWAIT) && \
+ (defined(HAVE_GETCLOCK) || defined(HAVE_CLOCK_GETTIME))
+# define WORK_THREAD
+# define WORK_PIPE
+#elif defined(VMS) || defined(SYS_VXWORKS)
+ /* empty */
+#elif defined(HAVE_WORKING_FORK)
+# define WORK_FORK
+# define WORK_PIPE
+#endif
+
+#if defined(WORK_FORK) || defined(WORK_THREAD)
+# define WORKER
+#endif
+
+#endif /* !NTP_WORKIMPL_H */
diff --git a/include/ntpd.h b/include/ntpd.h
new file mode 100644
index 0000000..51d8f2a
--- /dev/null
+++ b/include/ntpd.h
@@ -0,0 +1,568 @@
+/*
+ * ntpd.h - Prototypes and external variables for ntpd.
+ *
+ * Note the first half is primarily function prototypes, type
+ * declarations, and preprocessor macros, with variables declared
+ * primarily in the second half.
+ *
+ * Each half is further divided into sections for each source file.
+ */
+
+#include "ntp.h"
+#include "ntp_stdlib.h"
+#include "ntp_syslog.h"
+#include "ntp_debug.h"
+#include "ntp_syslog.h"
+#include "ntp_select.h"
+#include "ntp_malloc.h"
+#include "ntp_refclock.h"
+#include "ntp_intres.h"
+#include "recvbuff.h"
+
+/*
+ * First half: ntpd types, functions, macros
+ * -----------------------------------------
+ */
+
+/*
+ * macro for debugging output - cut down on #ifdef pollution.
+ *
+ * DPRINTF() is for use by ntpd only, and compiles away to nothing
+ * without DEBUG (configure --disable-debugging).
+ *
+ * TRACE() is similar for libntp and utilities, which retain full
+ * debug capability even when compiled without DEBUG.
+ *
+ * The calling convention is not attractive:
+ * DPRINTF(debuglevel, (fmt, ...));
+ * DPRINTF(2, ("shows #ifdef DEBUG and if debug >= %d\n", 2));
+ */
+#ifdef DEBUG
+# define DPRINTF(lvl, arg) \
+ do { \
+ if (debug >= (lvl)) \
+ mprintf arg; \
+ } while (0)
+#else
+# define DPRINTF(lvl, arg) do {} while (0)
+#endif
+
+
+/* nt_clockstuff.c */
+#ifdef SYS_WINNT
+extern void win_time_stepped(void);
+#endif
+
+/* ntp_config.c */
+#define TAI_1972 10 /* initial TAI offset (s) */
+extern char *keysdir; /* crypto keys and leaptable directory */
+extern char * saveconfigdir; /* ntpq saveconfig output directory */
+
+extern void getconfig (int, char **);
+extern void ctl_clr_stats (void);
+extern int ctlclrtrap (sockaddr_u *, struct interface *, int);
+extern u_short ctlpeerstatus (struct peer *);
+extern int ctlsettrap (sockaddr_u *, struct interface *, int, int);
+extern u_short ctlsysstatus (void);
+extern void init_control (void);
+extern void process_control (struct recvbuf *, int);
+extern void report_event (int, struct peer *, const char *);
+extern int mprintf_event (int, struct peer *, const char *, ...)
+ NTP_PRINTF(3, 4);
+
+/* 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 (struct ctl_var **, u_long, u_short);
+extern void free_varlist (struct ctl_var *);
+extern void set_var (struct ctl_var **, const char *, u_long, u_short);
+extern void set_sys_var (const char *, u_long, u_short);
+extern const char * get_ext_sys_var(const char *tag);
+
+/* ntp_io.c */
+typedef struct interface_info {
+ endpt * ep;
+ u_char action;
+} interface_info_t;
+
+typedef void (*interface_receiver_t) (void *, interface_info_t *);
+
+extern void interface_enumerate (interface_receiver_t, void *);
+extern endpt * getinterface (sockaddr_u *, u_int32);
+extern endpt * select_peerinterface (struct peer *, sockaddr_u *,
+ endpt *);
+extern endpt * findinterface (sockaddr_u *);
+extern endpt * findbcastinter (sockaddr_u *);
+extern void enable_broadcast (endpt *, sockaddr_u *);
+extern void enable_multicast_if (endpt *, sockaddr_u *);
+extern void interface_update (interface_receiver_t, void *);
+#ifndef HAVE_IO_COMPLETION_PORT
+extern void io_handler (void);
+#endif
+extern void init_io (void);
+extern void io_open_sockets (void);
+extern void io_clr_stats (void);
+extern void io_setbclient (void);
+extern void io_unsetbclient (void);
+extern void io_multicast_add(sockaddr_u *);
+extern void io_multicast_del(sockaddr_u *);
+extern void sendpkt (sockaddr_u *, struct interface *, int, struct pkt *, int);
+#ifdef DEBUG
+extern void collect_timing (struct recvbuf *, const char *, int, l_fp *);
+#endif
+#ifdef HAVE_SIGNALED_IO
+extern void wait_for_signal (void);
+extern void unblock_io_and_alarm (void);
+extern void block_io_and_alarm (void);
+# define UNBLOCK_IO_AND_ALARM() unblock_io_and_alarm()
+# define BLOCK_IO_AND_ALARM() block_io_and_alarm()
+#else
+# define UNBLOCK_IO_AND_ALARM() do {} while (0)
+# define BLOCK_IO_AND_ALARM() do {} while (0)
+#endif
+#define latoa(pif) localaddrtoa(pif)
+extern const char * localaddrtoa(endpt *);
+
+/* ntp_loopfilter.c */
+extern void init_loopfilter(void);
+extern int local_clock(struct peer *, double);
+extern void adj_host_clock(void);
+extern void loop_config(int, double);
+extern void select_loop(int);
+extern void huffpuff(void);
+extern u_long sys_clocktime;
+extern u_int sys_tai;
+extern int freq_cnt;
+
+/* ntp_monitor.c */
+#define MON_HASH_SIZE (1U << mon_hash_bits)
+#define MON_HASH_MASK (MON_HASH_SIZE - 1)
+#define MON_HASH(addr) (sock_hash(addr) & MON_HASH_MASK)
+extern void init_mon (void);
+extern void mon_start (int);
+extern void mon_stop (int);
+extern u_short ntp_monitor (struct recvbuf *, u_short);
+extern void mon_clearinterface(endpt *interface);
+
+/* ntp_peer.c */
+extern void init_peer (void);
+extern struct peer *findexistingpeer(sockaddr_u *, const char *,
+ struct peer *, int, u_char);
+extern struct peer *findpeer (struct recvbuf *, int, int *);
+extern struct peer *findpeerbyassoc(associd_t);
+extern void set_peerdstadr (struct peer *, endpt *);
+extern struct peer *newpeer (sockaddr_u *, const char *,
+ endpt *, u_char, u_char,
+ u_char, u_char, u_int, u_char, u_int32,
+ keyid_t, const char *);
+extern void peer_all_reset (void);
+extern void peer_clr_stats (void);
+extern struct peer *peer_config(sockaddr_u *, const char *,
+ endpt *, u_char, u_char,
+ u_char, u_char, u_int, u_int32,
+ keyid_t, const char *);
+extern void peer_reset (struct peer *);
+extern void refresh_all_peerinterfaces(void);
+extern void unpeer (struct peer *);
+extern void clear_all (void);
+extern int score_all (struct peer *);
+extern struct peer *findmanycastpeer(struct recvbuf *);
+
+/* ntp_crypto.c */
+#ifdef AUTOKEY
+extern int crypto_recv (struct peer *, struct recvbuf *);
+extern int crypto_xmit (struct peer *, struct pkt *,
+ struct recvbuf *, int,
+ struct exten *, keyid_t);
+extern keyid_t session_key (sockaddr_u *, sockaddr_u *, keyid_t,
+ keyid_t, u_long);
+extern int make_keylist (struct peer *, struct interface *);
+extern void key_expire (struct peer *);
+extern void crypto_update (void);
+extern void crypto_config (int, char *);
+extern void crypto_setup (void);
+extern u_int crypto_ident (struct peer *);
+extern struct exten *crypto_args (struct peer *, u_int, associd_t, char *);
+extern int crypto_public (struct peer *, u_char *, u_int);
+extern void value_free (struct value *);
+extern char *iffpar_file;
+extern EVP_PKEY *iffpar_pkey;
+extern char *gqpar_file;
+extern EVP_PKEY *gqpar_pkey;
+extern char *mvpar_file;
+extern EVP_PKEY *mvpar_pkey;
+extern struct value tai_leap;
+#endif /* AUTOKEY */
+
+/* ntp_proto.c */
+extern void transmit (struct peer *);
+extern void receive (struct recvbuf *);
+extern void peer_clear (struct peer *, char *);
+extern void process_packet (struct peer *, struct pkt *, u_int);
+extern void clock_select (void);
+
+extern u_long leapsec; /* seconds to next leap (proximity class) */
+extern int leapdif; /* TAI difference step at next leap second*/
+extern int sys_orphan;
+extern double sys_mindisp;
+extern double sys_maxdist;
+
+extern char *sys_ident; /* identity scheme */
+extern void poll_update (struct peer *, u_char);
+
+extern void clear (struct peer *);
+extern void clock_filter (struct peer *, double, double, double);
+extern void init_proto (void);
+extern void set_sys_tick_precision(double);
+extern void proto_config (int, u_long, double, sockaddr_u *);
+extern void proto_clr_stats (void);
+
+/* ntp_refclock.c */
+#ifdef REFCLOCK
+extern int refclock_newpeer (struct peer *);
+extern void refclock_unpeer (struct peer *);
+extern void refclock_receive (struct peer *);
+extern void refclock_transmit (struct peer *);
+extern void init_refclock (void);
+#endif /* REFCLOCK */
+
+/* ntp_request.c */
+extern void init_request (void);
+extern void process_private (struct recvbuf *, int);
+extern void reset_auth_stats(void);
+
+/* ntp_restrict.c */
+extern void init_restrict (void);
+extern u_short restrictions (sockaddr_u *);
+extern void hack_restrict (int, sockaddr_u *, sockaddr_u *,
+ u_short, u_short, u_long);
+extern void restrict_source (sockaddr_u *, int, u_long);
+
+/* ntp_timer.c */
+extern void init_timer (void);
+extern void reinit_timer (void);
+extern void timer (void);
+extern void timer_clr_stats (void);
+extern void timer_interfacetimeout (u_long);
+extern volatile int interface_interval;
+extern u_long orphwait; /* orphan wait time */
+#ifdef AUTOKEY
+extern char *sys_hostname; /* host name */
+extern char *sys_groupname; /* group name */
+extern char *group_name; /* group name */
+extern u_long sys_revoke; /* keys revoke timeout */
+extern u_long sys_automax; /* session key timeout */
+#endif /* AUTOKEY */
+
+/* ntp_util.c */
+extern void init_util (void);
+extern void write_stats (void);
+extern void stats_config (int, const char *);
+extern void record_peer_stats (sockaddr_u *, int, double, double, double, double);
+extern void record_proto_stats (char *);
+extern void record_loop_stats (double, double, double, double, int);
+extern void record_clock_stats (sockaddr_u *, const char *);
+extern int mprintf_clock_stats(sockaddr_u *, const char *, ...)
+ NTP_PRINTF(2, 3);
+extern void record_raw_stats (sockaddr_u *srcadr, sockaddr_u *dstadr, l_fp *t1, l_fp *t2, l_fp *t3, l_fp *t4, int leap, int version, int mode, int stratum, int poll, int precision, double root_delay, double root_dispersion, u_int32 refid);
+extern void check_leap_file (int is_daily_check, u_int32 ntptime, const time_t * systime);
+extern void record_crypto_stats (sockaddr_u *, const char *);
+#ifdef DEBUG
+extern void record_timing_stats (const char *);
+#endif
+extern char * fstostr(time_t); /* NTP timescale seconds */
+
+/* ntpd.c */
+extern void parse_cmdline_opts(int *, char ***);
+/*
+ * Signals we catch for debugging.
+ */
+#define MOREDEBUGSIG SIGUSR1
+#define LESSDEBUGSIG SIGUSR2
+/*
+ * Signals which terminate us gracefully.
+ */
+#ifndef SYS_WINNT
+# define SIGDIE1 SIGHUP
+# define SIGDIE2 SIGINT
+# define SIGDIE3 SIGQUIT
+# define SIGDIE4 SIGTERM
+#endif /* SYS_WINNT */
+
+
+/*
+ * Last half: ntpd variables
+ * -------------------------
+ */
+
+/* ntp_config.c */
+extern char const * progname;
+extern char *sys_phone[]; /* ACTS phone numbers */
+#if defined(HAVE_SCHED_SETSCHEDULER)
+extern int config_priority_override;
+extern int config_priority;
+#endif
+extern char *ntp_signd_socket;
+extern struct config_tree_tag *cfg_tree_history;
+
+#ifdef BC_LIST_FRAMEWORK_NOT_YET_USED
+/*
+ * backwards compatibility flags
+ */
+typedef struct bc_entry_tag {
+ int token;
+ int enabled;
+} bc_entry;
+
+extern bc_entry bc_list[];
+#endif
+
+/* ntp_control.c */
+extern int num_ctl_traps;
+extern keyid_t 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 */
+
+/*
+ * 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 */
+
+/* ntp_io.c */
+extern int disable_dynamic_updates;
+extern u_int sys_ifnum; /* next .ifnum to assign */
+extern endpt * any_interface; /* IPv4 wildcard */
+extern endpt * any6_interface; /* IPv6 wildcard */
+extern endpt * loopback_interface; /* IPv4 loopback for refclocks */
+extern endpt * ep_list; /* linked list */
+
+/* ntp_loopfilter.c */
+extern double drift_comp; /* clock frequency (s/s) */
+extern double clock_stability; /* clock stability (s/s) */
+extern double clock_max; /* max offset before step (s) */
+extern double clock_panic; /* max offset before panic (s) */
+extern double clock_phi; /* dispersion rate (s/s) */
+extern double clock_minstep; /* step timeout (s) */
+extern double clock_codec; /* codec frequency */
+#ifdef KERNEL_PLL
+extern int pll_status; /* status bits for kernel pll */
+#endif /* KERNEL_PLL */
+
+/*
+ * 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 hardpps_enable; /* kernel PPS discipline enabled */
+extern int ext_enable; /* external clock enabled */
+extern int cal_enable; /* refclock calibrate enable */
+extern int allow_panic; /* allow panic correction */
+extern int mode_ntpdate; /* exit on first clock set */
+extern int peer_ntpdate; /* count of ntpdate peers */
+
+/*
+ * Clock state machine variables
+ */
+extern u_char sys_poll; /* system poll interval (log2 s) */
+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 u_char allan_xpt; /* Allan intercept (log2 s) */
+extern double clock_jitter; /* clock jitter (s) */
+extern double sys_offset; /* system offset (s) */
+extern double sys_jitter; /* system jitter (s) */
+
+/* ntp_monitor.c */
+extern u_char mon_hash_bits; /* log2 size of hash table */
+extern mon_entry ** mon_hash; /* MRU hash table */
+extern mon_entry mon_mru_list; /* mru listhead */
+extern u_int mon_enabled; /* MON_OFF (0) or other MON_* */
+extern u_int mru_alloc; /* mru list + free list count */
+extern u_int mru_entries; /* mru list count */
+extern u_int mru_peakentries; /* highest mru_entries */
+extern u_int mru_initalloc; /* entries to preallocate */
+extern u_int mru_incalloc; /* allocation batch factor */
+extern u_int mru_mindepth; /* preempt above this */
+extern int mru_maxage; /* for entries older than */
+extern u_int mru_maxdepth; /* MRU size hard limit */
+extern int mon_age; /* preemption limit */
+
+/* ntp_peer.c */
+extern struct peer *peer_hash[NTP_HASH_SIZE]; /* peer hash table */
+extern int peer_hash_count[NTP_HASH_SIZE]; /* count of in each bucket */
+extern struct peer *assoc_hash[NTP_HASH_SIZE]; /* association ID hash table */
+extern int assoc_hash_count[NTP_HASH_SIZE];/* count of in each bucket */
+extern struct peer *peer_list; /* peer structures list */
+extern int peer_count; /* count in peer_list */
+extern int peer_free_count; /* count in peer_free */
+
+/*
+ * 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; /* mobilized associations */
+extern int peer_preempt; /* preemptable 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; /* system stratum */
+extern s_char sys_precision; /* local clock precision */
+extern double sys_rootdelay; /* roundtrip delay to primary source */
+extern double sys_rootdisp; /* dispersion to primary source */
+extern u_int32 sys_refid; /* reference id */
+extern l_fp sys_reftime; /* last update time */
+extern struct peer *sys_peer; /* current peer */
+
+/*
+ * 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_epoch; /* last clock update time */
+extern keyid_t sys_private; /* private value for session seed */
+extern int sys_manycastserver; /* respond to manycast client pkts */
+extern int sys_minclock; /* minimum survivors */
+extern int sys_minsane; /* minimum candidates */
+extern int sys_floor; /* cluster stratum floor */
+extern int sys_ceiling; /* cluster stratum ceiling */
+extern u_char sys_ttl[MAX_TTL]; /* ttl mapping vector */
+extern int sys_ttlmax; /* max ttl mapping vector index */
+
+/*
+ * Statistics counters
+ */
+extern u_long sys_stattime; /* time since reset */
+extern u_long sys_received; /* packets received */
+extern u_long sys_processed; /* packets for this host */
+extern u_long sys_restricted; /* restricted packets */
+extern u_long sys_newversion; /* current version */
+extern u_long sys_oldversion; /* old version */
+extern u_long sys_restricted; /* access denied */
+extern u_long sys_badlength; /* bad length or format */
+extern u_long sys_badauth; /* bad authentication */
+extern u_long sys_declined; /* declined */
+extern u_long sys_limitrejected; /* rate exceeded */
+extern u_long sys_kodsent; /* KoD sent */
+
+/* ntp_request.c */
+extern keyid_t info_auth_keyid; /* keyid used to authenticate requests */
+extern u_long auth_timereset;
+
+/* ntp_restrict.c */
+extern restrict_u * restrictlist4; /* IPv4 restriction list */
+extern restrict_u * restrictlist6; /* IPv6 restriction list */
+extern int ntp_minpkt;
+extern u_char ntp_minpoll;
+
+/* ntp_scanner.c */
+extern u_int32 conf_file_sum; /* Simple sum of characters */
+
+/* ntp_signd.c */
+#ifdef HAVE_NTP_SIGND
+extern void send_via_ntp_signd(struct recvbuf *, int, keyid_t, int,
+ struct pkt *);
+#endif
+
+/* ntp_timer.c */
+extern volatile int alarm_flag; /* alarm flag */
+extern volatile u_long alarm_overflow;
+extern u_long current_time; /* seconds since startup */
+extern u_long timer_timereset;
+extern u_long timer_overflows;
+extern u_long timer_xmtcalls;
+#ifdef SYS_WINNT
+HANDLE WaitableTimerHandle;
+#endif
+
+/* ntp_util.c */
+extern char statsdir[MAXFILENAME];
+extern int stats_control; /* write stats to fileset? */
+extern int stats_write_period; /* # of seconds between writes. */
+extern double stats_write_tolerance;
+extern double wander_threshold;
+
+/* ntpd.c */
+extern int nofork; /* no-fork flag */
+extern int initializing; /* initializing flag */
+#ifdef HAVE_DROPROOT
+extern int droproot; /* flag: try to drop root privileges after startup */
+extern int root_dropped; /* root has been dropped */
+extern char *user; /* user to switch to */
+extern char *group; /* group to switch to */
+extern const char *chrootdir; /* directory to chroot() to */
+#endif
+#ifdef HAVE_WORKING_FORK
+extern int waitsync_fd_to_close; /* -w/--wait-sync */
+#endif
+
+/* ntservice.c */
+#ifdef SYS_WINNT
+extern int accept_wildcard_if_for_winnt;
+#endif
+
+/* refclock_conf.c */
+#ifdef REFCLOCK
+/* refclock configuration table */
+extern struct refclock * const refclock_conf[];
+extern u_char num_refclock_conf;
+#endif
+
diff --git a/include/ntpsim.h b/include/ntpsim.h
new file mode 100644
index 0000000..b270ce6
--- /dev/null
+++ b/include/ntpsim.h
@@ -0,0 +1,146 @@
+/* ntpsim.h
+ *
+ * The header file for the ntp discrete event simulator.
+ *
+ * Written By: Sachin Kamboj
+ * University of Delaware
+ * Newark, DE 19711
+ * Copyright (c) 2006
+ */
+
+#ifndef NTPSIM_H
+#define NTPSIM_H
+
+#include <stdio.h>
+#include <math.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#include <arpa/inet.h>
+#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"
+#include "ntp_io.h"
+#include "ntp_stdlib.h"
+#include "ntp_prio_q.h"
+
+/* CONSTANTS */
+
+#ifdef PI
+# undef PI
+#endif
+#define PI 3.1415926535 /* The world's most famous constant */
+#define SIM_TIME 86400 /* end simulation time */
+#define NET_DLY .001 /* network delay */
+#define PROC_DLY .001 /* processing delay */
+#define BEEP_DLY 3600 /* beep interval (s) */
+
+
+/* Discrete Event Queue
+ * --------------------
+ * The NTP simulator is a discrete event simulator.
+ *
+ * Central to this simulator is an event queue which is a priority queue
+ * in which the "priority" is given by the time of arrival of the event.
+ *
+ * A discrete set of events can happen and are stored in the queue to arrive
+ * at a particular time.
+ */
+
+/* Possible Discrete Events */
+
+typedef enum {
+ BEEP, /* Event to record simulator stats */
+ CLOCK, /* Event to advance the clock to the specified time */
+ TIMER, /* Event that designates a timer interrupt. */
+ PACKET /* Event that designates arrival of a packet */
+} funcTkn;
+
+
+/* Event information */
+
+typedef struct {
+ double time; /* Time at which event occurred */
+ funcTkn function; /* Type of event that occured */
+ union {
+ struct pkt evnt_pkt;
+ struct recvbuf evnt_buf;
+ } buffer; /* Other data associated with the event */
+#define ntp_pkt buffer.evnt_pkt
+#define rcv_buf buffer.evnt_buf
+} Event;
+
+
+/* Server Script Information */
+typedef struct script_info_tag script_info;
+struct script_info_tag {
+ script_info * link;
+ double duration;
+ double freq_offset;
+ double wander;
+ double jitter;
+ double prop_delay;
+ double proc_delay;
+};
+
+typedef DECL_FIFO_ANCHOR(script_info) script_info_fifo;
+
+
+/* Server Structures */
+
+typedef struct server_info_tag server_info;
+struct server_info_tag {
+ server_info * link;
+ double server_time;
+ sockaddr_u * addr;
+ script_info_fifo * script;
+ script_info * curr_script;
+};
+
+typedef DECL_FIFO_ANCHOR(server_info) server_info_fifo;
+
+
+/* Simulation control information */
+
+typedef struct Sim_Info {
+ double sim_time; /* Time in the simulation */
+ double end_time; /* Time at which simulation needs to be ended */
+ double beep_delay; /* Delay between simulation "beeps" at which
+ simulation stats are recorded. */
+ int num_of_servers; /* Number of servers in the simulation */
+ server_info *servers; /* Pointer to array of servers */
+} sim_info;
+
+
+/* Local Clock (Client) Variables */
+
+typedef struct Local_Clock_Info {
+ double local_time; /* Client disciplined time */
+ double adj; /* Remaining time correction */
+ double slew; /* Correction Slew Rate */
+ double last_read_time; /* Last time the clock was read */
+} local_clock_info;
+
+extern local_clock_info simclock; /* Local Clock Variables */
+extern sim_info simulation; /* Simulation Control Variables */
+
+/* Function Prototypes */
+
+int ntpsim (int argc, char *argv[]);
+Event *event (double t, funcTkn f);
+void sim_event_timer (Event *e);
+int simulate_server (sockaddr_u *serv_addr, endpt *inter,
+ struct pkt *rpkt);
+void sim_update_clocks (Event *e);
+void sim_event_recv_packet (Event *e);
+void sim_event_beep (Event *e);
+void abortsim (char *errmsg);
+double gauss (double, double);
+double poisson (double, double);
+void create_server_associations(void);
+
+#endif /* NTPSIM_H */
diff --git a/include/parse.h b/include/parse.h
new file mode 100644
index 0000000..3a98408
--- /dev/null
+++ b/include/parse.h
@@ -0,0 +1,421 @@
+/*
+ * /src/NTP/REPOSITORY/ntp4-dev/include/parse.h,v 4.12 2007/01/14 08:36:03 kardel RELEASE_20070114_A
+ *
+ * parse.h,v 4.12 2007/01/14 08:36:03 kardel RELEASE_20070114_A
+ *
+ * Copyright (c) 1995-2005 by Frank Kardel <kardel <AT> ntp.org>
+ * Copyright (c) 1989-1994 by Frank Kardel, Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#ifndef __PARSE_H__
+#define __PARSE_H__
+#if !(defined(lint) || defined(__GNUC__))
+ static char parsehrcsid[]="parse.h,v 4.12 2007/01/14 08:36:03 kardel RELEASE_20070114_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 (unsigned int);
+extern caddr_t kmem_free (caddr_t, unsigned int);
+extern unsigned int splx (unsigned int);
+extern unsigned int splhigh (void);
+extern unsigned int splclock (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_TRUSTTIME CLK_FLAG1 /* use flag1 to indicate the time2 references mean the trust time */
+#define PARSE_CLEAR CLK_FLAG2 /* use flag2 to control pps on assert */
+#define PARSE_PPSKERNEL CLK_FLAG3 /* use flag3 to bind PPS to kernel */
+#define PARSE_LEAP_DELETE CLK_FLAG4 /* use flag4 to force leap deletion - only necessary when earth slows down */
+
+#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
+{
+ 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) (parse_t *, unsigned int, timestamp_t *);
+ /* conversion routine */
+ u_long (*convert) (unsigned char *, int, struct format *, clocktime_t *, void *);
+ /* routine for handling RS232 sync events (time stamps) */
+ /* PPS input routine */
+ u_long (*syncpps) (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 (parse_t *);
+extern void parse_ioend (parse_t *);
+extern int parse_ioread (parse_t *, unsigned int, timestamp_t *);
+extern int parse_iopps (parse_t *, int, timestamp_t *);
+extern void parse_iodone (parse_t *);
+extern int parse_timecode (parsectl_t *, parse_t *);
+extern int parse_getfmt (parsectl_t *, parse_t *);
+extern int parse_setfmt (parsectl_t *, parse_t *);
+extern int parse_setcs (parsectl_t *, parse_t *);
+
+extern unsigned int parse_restart (parse_t *, unsigned int);
+extern unsigned int parse_addchar (parse_t *, unsigned int);
+extern unsigned int parse_end (parse_t *);
+
+extern int Strok (const unsigned char *, const unsigned char *);
+extern int Stoi (const unsigned char *, long *, int);
+
+extern time_t parse_to_unixtime (clocktime_t *, u_long *);
+extern u_long updatetimeinfo (parse_t *, u_long);
+extern void syn_simple (parse_t *, timestamp_t *, struct format *, u_long);
+extern u_long pps_simple (parse_t *, int, timestamp_t *);
+extern u_long pps_one (parse_t *, int, timestamp_t *);
+extern u_long pps_zero (parse_t *, int, timestamp_t *);
+extern int parse_timedout (parse_t *, timestamp_t *, struct timeval *);
+
+#endif
+
+/*
+ * History:
+ *
+ * parse.h,v
+ * Revision 4.12 2007/01/14 08:36:03 kardel
+ * make timestamp union anonymous to avoid conflicts with
+ * some OSes that choose to create a nameing conflic here.
+ *
+ * Revision 4.11 2005/06/25 10:58:45 kardel
+ * add missing log keywords
+ *
+ * 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/include/parse_conf.h b/include/parse_conf.h
new file mode 100644
index 0000000..319dd54
--- /dev/null
+++ b/include/parse_conf.h
@@ -0,0 +1,83 @@
+/*
+ * /src/NTP/ntp4-dev/include/parse_conf.h,v 4.7 2005/06/25 10:58:45 kardel RELEASE_20050625_A
+ *
+ * parse_conf.h,v 4.7 2005/06/25 10:58:45 kardel RELEASE_20050625_A
+ *
+ * Copyright (c) 1995-2005 by Frank Kardel <kardel <AT> ntp.org>
+ * Copyright (c) 1989-1994 by Frank Kardel, Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#ifndef __PARSE_CONF_H__
+#define __PARSE_CONF_H__
+#if !(defined(lint) || defined(__GNUC__))
+ static char prshrcsid[] = "parse_conf.h,v 4.7 2005/06/25 10:58:45 kardel RELEASE_20050625_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
+
+/*
+ * History:
+ *
+ * parse_conf.h,v
+ * Revision 4.7 2005/06/25 10:58:45 kardel
+ * add missing log keywords
+ *
+ */
diff --git a/include/recvbuff.h b/include/recvbuff.h
new file mode 100644
index 0000000..92188f5
--- /dev/null
+++ b/include/recvbuff.h
@@ -0,0 +1,123 @@
+#ifndef RECVBUFF_H
+#define RECVBUFF_H
+
+#include "ntp.h"
+#include "ntp_net.h"
+#include "ntp_lists.h"
+
+#include <isc/result.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(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 contains the NTP header, one Autokey
+ * request, one Autokey response and the MAC. Assuming certificates don't
+ * get too big, the maximum packet length is set arbitrarily at 1000.
+ */
+#define RX_BUFF_SIZE 1000 /* hail Mary */
+
+
+typedef struct recvbuf recvbuf_t;
+
+struct recvbuf {
+ recvbuf_t * link; /* next in list */
+ union {
+ sockaddr_u 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
+#ifndef HAVE_IO_COMPLETION_PORT
+ sockaddr_u srcadr; /* where packet came from */
+#else
+ int recv_srcadr_len;/* filled in on completion */
+#endif
+ endpt * dstadr; /* address pkt arrived on */
+ SOCKET fd; /* fd on which it was received */
+ int msg_flags; /* Flags received about the packet */
+ l_fp recv_time; /* time of arrival */
+ void (*receiver)(struct recvbuf *); /* callback */
+ 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
+ int used; /* reference count */
+};
+
+extern void init_recvbuff(int);
+
+/* freerecvbuf - make a single recvbuf available for reuse
+ */
+extern void freerecvbuf(struct recvbuf *);
+
+/* 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
+ */
+
+/* signal safe - no malloc */
+extern struct recvbuf *get_free_recv_buffer(void);
+/* signal unsafe - may malloc */
+extern struct recvbuf *get_free_recv_buffer_alloc(void);
+
+/* Add a buffer to the full list
+ */
+extern void add_full_recv_buffer(struct recvbuf *);
+
+/* number of recvbufs on freelist */
+extern u_long free_recvbuffs(void);
+extern u_long full_recvbuffs(void);
+extern u_long total_recvbuffs(void);
+extern u_long lowater_additions(void);
+
+/* Returns the next buffer in the full list.
+ *
+ */
+extern struct recvbuf *get_full_recv_buffer(void);
+
+/*
+ * purge_recv_buffers_for_fd() - purges any previously-received input
+ * from a given file descriptor.
+ */
+extern void purge_recv_buffers_for_fd(SOCKET);
+
+/*
+ * Checks to see if there are buffers to process
+ */
+extern isc_boolean_t has_full_recv_buffer(void);
+
+#endif /* RECVBUFF_H */
diff --git a/include/refclock_atom.h b/include/refclock_atom.h
new file mode 100644
index 0000000..452e933
--- /dev/null
+++ b/include/refclock_atom.h
@@ -0,0 +1,15 @@
+/*
+ * Definitions for the atom driver and its friends
+ */
+#undef NANOSECOND /* some systems define it differently */
+#define NANOSECOND 1000000000 /* one second (ns) */
+
+struct refclock_atom {
+ pps_handle_t handle;
+ pps_params_t pps_params;
+ struct timespec ts;
+};
+
+extern int refclock_ppsapi(int, struct refclock_atom *);
+extern int refclock_params(int, struct refclock_atom *);
+extern int refclock_pps(struct peer *, struct refclock_atom *, int);
diff --git a/include/ssl_applink.c b/include/ssl_applink.c
new file mode 100644
index 0000000..ba1f4a8
--- /dev/null
+++ b/include/ssl_applink.c
@@ -0,0 +1,74 @@
+/*
+ * include/ssl_applink.c -- common NTP code for openssl/applink.c
+ *
+ * Each program which uses OpenSSL should include this file in _one_
+ * of its source files and call ssl_applink() before any OpenSSL
+ * functions.
+ */
+
+#if defined(OPENSSL) && defined(SYS_WINNT)
+# ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable: 4152)
+# endif
+# include <openssl/applink.c>
+# ifdef _MSC_VER
+# pragma warning(pop)
+# endif
+#endif
+
+#if defined(OPENSSL) && defined(_MSC_VER) && defined(_DEBUG)
+#define WRAP_DBG_MALLOC
+#endif
+
+#ifdef WRAP_DBG_MALLOC
+void *wrap_dbg_malloc(size_t s, const char *f, int l);
+void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l);
+void wrap_dbg_free(void *p);
+#endif
+
+
+#if defined(OPENSSL) && defined(SYS_WINNT)
+void ssl_applink(void);
+
+void
+ssl_applink(void)
+{
+#ifdef WRAP_DBG_MALLOC
+ CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free);
+#else
+ CRYPTO_malloc_init();
+#endif
+}
+#else /* !OPENSSL || !SYS_WINNT */
+#define ssl_applink() do {} while (0)
+#endif
+
+
+#ifdef WRAP_DBG_MALLOC
+/*
+ * OpenSSL malloc overriding uses different parameters
+ * for DEBUG malloc/realloc/free (lacking block type).
+ * Simple wrappers convert.
+ */
+void *wrap_dbg_malloc(size_t s, const char *f, int l)
+{
+ void *ret;
+
+ ret = _malloc_dbg(s, _NORMAL_BLOCK, f, l);
+ return ret;
+}
+
+void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l)
+{
+ void *ret;
+
+ ret = _realloc_dbg(p, s, _NORMAL_BLOCK, f, l);
+ return ret;
+}
+
+void wrap_dbg_free(void *p)
+{
+ _free_dbg(p, _NORMAL_BLOCK);
+}
+#endif /* WRAP_DBG_MALLOC */
diff --git a/include/timepps-SCO.h b/include/timepps-SCO.h
new file mode 100644
index 0000000..ce9052e
--- /dev/null
+++ b/include/timepps-SCO.h
@@ -0,0 +1,503 @@
+/***********************************************************************
+ * *
+ * Copyright (c) David L. Mills 1999-2000 *
+ * *
+ * Permission to use, copy, modify, and distribute this software and *
+ * its documentation for any purpose and with or without fee is hereby *
+ * granted, provided that the above copyright notice appears in all *
+ * copies and that both the copyright notice and this permission *
+ * notice appear in supporting documentation, and that the name *
+ * University of Delaware not be used in advertising or publicity *
+ * pertaining to distribution of the software without specific, *
+ * written prior permission. The University of Delaware makes no *
+ * representations about the suitability this software for any *
+ * purpose. It is provided "as is" without express or implied *
+ * warranty. *
+ * *
+ ***********************************************************************
+ * *
+ * This header file complies with "Pulse-Per-Second API for UNIX-like *
+ * Operating Systems, Version 1.0", rfc2783. Credit is due Jeff Mogul *
+ * and Marc Brett, from whom much of this code was shamelessly stolen. *
+ * *
+ * this modified timepps.h can be used to provide a PPSAPI interface *
+ * to a machine running SCO Unix. *
+ * *
+ ***********************************************************************
+ * *
+ * A full PPSAPI interface to the SCO Unix kernel would be better, but *
+ * this at least removes the necessity for special coding from the NTP *
+ * NTP drivers. *
+ * *
+ ***********************************************************************
+ * *
+ * Some of this include file *
+ * Copyright (c) 1999 by Ulrich Windl, *
+ * based on code by Reg Clemens <reg@dwf.com> *
+ * based on code by Poul-Henning Kamp <phk@FreeBSD.org> *
+ * *
+ ***********************************************************************
+ * *
+ * "THE BEER-WARE LICENSE" (Revision 42): *
+ * <phk@FreeBSD.org> wrote this file. As long as you retain this *
+ * notice you can do whatever you want with this stuff. If we meet some*
+ * day, and you think this stuff is worth it, you can buy me a beer *
+ * in return. Poul-Henning Kamp *
+ * *
+ **********************************************************************/
+
+/*SCO UNIX version, TIOCDCDTIMESTAMP assumed to exist. */
+
+#ifndef _SYS_TIMEPPS_H_
+#define _SYS_TIMEPPS_H_
+
+#include <termios.h> /* to get TIOCDCDTIMESTAMP */
+
+/* Implementation note: the logical states ``assert'' and ``clear''
+ * are implemented in terms of the UART register, i.e. ``assert''
+ * means the bit is set.
+ */
+
+/*
+ * The following definitions are architecture independent
+ */
+
+#define PPS_API_VERS_1 1 /* API version number */
+#define PPS_JAN_1970 2208988800UL /* 1970 - 1900 in seconds */
+#define PPS_NANOSECOND 1000000000L /* one nanosecond in decimal */
+#define PPS_FRAC 4294967296. /* 2^32 as a double */
+
+#define PPS_NORMALIZE(x) /* normalize timespec */ \
+ do { \
+ if ((x).tv_nsec >= PPS_NANOSECOND) { \
+ (x).tv_nsec -= PPS_NANOSECOND; \
+ (x).tv_sec++; \
+ } else if ((x).tv_nsec < 0) { \
+ (x).tv_nsec += PPS_NANOSECOND; \
+ (x).tv_sec--; \
+ } \
+ } while (0)
+
+#define PPS_TSPECTONTP(x) /* convert timespec to l_fp */ \
+ do { \
+ double d_temp; \
+ \
+ (x).integral += (unsigned int)PPS_JAN_1970; \
+ d_temp = (x).fractional * PPS_FRAC / PPS_NANOSECOND; \
+ if (d_temp >= PPS_FRAC) \
+ (x).integral++; \
+ (x).fractional = (unsigned int)d_temp; \
+ } while (0)
+
+/*
+ * Device/implementation parameters (mode)
+ */
+
+#define PPS_CAPTUREASSERT 0x01 /* capture assert events */
+#define PPS_CAPTURECLEAR 0x02 /* capture clear events */
+#define PPS_CAPTUREBOTH 0x03 /* capture assert and clear events */
+
+#define PPS_OFFSETASSERT 0x10 /* apply compensation for assert ev. */
+#define PPS_OFFSETCLEAR 0x20 /* apply compensation for clear ev. */
+#define PPS_OFFSETBOTH 0x30 /* apply compensation for both */
+
+#define PPS_CANWAIT 0x100 /* Can we wait for an event? */
+#define PPS_CANPOLL 0x200 /* "This bit is reserved for */
+
+/*
+ * Kernel actions (mode)
+ */
+
+#define PPS_ECHOASSERT 0x40 /* feed back assert event to output */
+#define PPS_ECHOCLEAR 0x80 /* feed back clear event to output */
+
+/*
+ * Timestamp formats (tsformat)
+ */
+
+#define PPS_TSFMT_TSPEC 0x1000 /* select timespec format */
+#define PPS_TSFMT_NTPFP 0x2000 /* select NTP format */
+
+/*
+ * Kernel discipline actions (not used in Solaris)
+ */
+
+#define PPS_KC_HARDPPS 0 /* enable kernel consumer */
+#define PPS_KC_HARDPPS_PLL 1 /* phase-lock mode */
+#define PPS_KC_HARDPPS_FLL 2 /* frequency-lock mode */
+
+/*
+ * Type definitions
+ */
+
+typedef unsigned long pps_seq_t; /* sequence number */
+
+typedef struct ntp_fp {
+ unsigned int integral;
+ unsigned int fractional;
+} ntp_fp_t; /* NTP-compatible time stamp */
+
+typedef union pps_timeu { /* timestamp format */
+ struct timespec tspec;
+ ntp_fp_t ntpfp;
+ unsigned long longpad[3];
+} pps_timeu_t; /* generic data type to represent time stamps */
+
+/*
+ * Timestamp information structure
+ */
+
+typedef struct pps_info {
+ pps_seq_t assert_sequence; /* seq. num. of assert event */
+ pps_seq_t clear_sequence; /* seq. num. of clear event */
+ pps_timeu_t assert_tu; /* time of assert event */
+ pps_timeu_t clear_tu; /* time of clear event */
+ int current_mode; /* current mode bits */
+} pps_info_t;
+
+#define assert_timestamp assert_tu.tspec
+#define clear_timestamp clear_tu.tspec
+
+#define assert_timestamp_ntpfp assert_tu.ntpfp
+#define clear_timestamp_ntpfp clear_tu.ntpfp
+
+/*
+ * Parameter structure
+ */
+
+typedef struct pps_params {
+ int api_version; /* API version # */
+ int mode; /* mode bits */
+ pps_timeu_t assert_off_tu; /* offset compensation for assert */
+ pps_timeu_t clear_off_tu; /* offset compensation for clear */
+} pps_params_t;
+
+#define assert_offset assert_off_tu.tspec
+#define clear_offset clear_off_tu.tspec
+
+#define assert_offset_ntpfp assert_off_tu.ntpfp
+#define clear_offset_ntpfp clear_off_tu.ntpfp
+
+/*
+ * The following definitions are architecture-dependent
+ */
+
+#define PPS_CAP (PPS_CAPTUREASSERT | PPS_OFFSETASSERT | PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)
+#define PPS_RO (PPS_CANWAIT | PPS_CANPOLL | PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)
+
+typedef struct {
+ int filedes; /* file descriptor */
+ pps_params_t params; /* PPS parameters set by user */
+ struct timeval tv_save;
+ pps_seq_t serial;
+} pps_unit_t;
+
+typedef pps_unit_t* pps_handle_t; /* pps handlebars */
+
+/*
+ *------ Here begins the implementation-specific part! ------
+ */
+
+#include <errno.h>
+
+/*
+ * create PPS handle from file descriptor
+ */
+
+static inline int
+time_pps_create(
+ int filedes, /* file descriptor */
+ pps_handle_t *handle /* returned handle */
+ )
+{
+ int one = 1;
+
+ /*
+ * Check for valid arguments and attach PPS signal.
+ */
+
+ if (!handle) {
+ errno = EFAULT;
+ return (-1); /* null pointer */
+ }
+
+ /*
+ * Allocate and initialize default unit structure.
+ */
+
+ *handle = malloc(sizeof(pps_unit_t));
+ if (!(*handle)) {
+ errno = EBADF;
+ return (-1); /* what, no memory? */
+ }
+
+ memset(*handle, 0, sizeof(pps_unit_t));
+ (*handle)->filedes = filedes;
+ (*handle)->params.api_version = PPS_API_VERS_1;
+ (*handle)->params.mode = PPS_CAPTUREASSERT | PPS_TSFMT_TSPEC;
+ return (0);
+}
+
+/*
+ * release PPS handle
+ */
+
+static inline int
+time_pps_destroy(
+ pps_handle_t handle
+ )
+{
+ /*
+ * Check for valid arguments and detach PPS signal.
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+ free(handle);
+ return (0);
+}
+
+/*
+ * set parameters for handle
+ */
+
+static inline int
+time_pps_setparams(
+ pps_handle_t handle,
+ const pps_params_t *params
+ )
+{
+ int mode, mode_in;
+ /*
+ * Check for valid arguments and set parameters.
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+
+ if (!params) {
+ errno = EFAULT;
+ return (-1); /* bad argument */
+ }
+
+ /*
+ * There was no reasonable consensu in the API working group.
+ * I require `api_version' to be set!
+ */
+
+ if (params->api_version != PPS_API_VERS_1) {
+ errno = EINVAL;
+ return(-1);
+ }
+
+ /*
+ * only settable modes are PPS_CAPTUREASSERT and PPS_OFFSETASSERT
+ */
+
+ mode_in = params->mode;
+
+ /* turn off read-only bits */
+
+ mode_in &= ~PPS_RO;
+
+ /* test remaining bits, should only have captureassert and/or offsetassert */
+
+ if (mode_in & ~(PPS_CAPTUREASSERT | PPS_OFFSETASSERT)) {
+ errno = EOPNOTSUPP;
+ return(-1);
+ }
+
+ /*
+ * ok, ready to go.
+ */
+
+ mode = handle->params.mode;
+ memcpy(&handle->params, params, sizeof(pps_params_t));
+ handle->params.api_version = PPS_API_VERS_1;
+ handle->params.mode = mode | mode_in;
+ return (0);
+}
+
+/*
+ * get parameters for handle
+ */
+
+static inline int
+time_pps_getparams(
+ pps_handle_t handle,
+ pps_params_t *params
+ )
+{
+ /*
+ * Check for valid arguments and get parameters.
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+
+ if (!params) {
+ errno = EFAULT;
+ return (-1); /* bad argument */
+ }
+
+ memcpy(params, &handle->params, sizeof(pps_params_t));
+ return (0);
+}
+
+/* (
+ * get capabilities for handle
+ */
+
+static inline int
+time_pps_getcap(
+ pps_handle_t handle,
+ int *mode
+ )
+{
+ /*
+ * Check for valid arguments and get capabilities.
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+
+ if (!mode) {
+ errno = EFAULT;
+ return (-1); /* bad argument */
+ }
+ *mode = PPS_CAP;
+ return (0);
+}
+
+/*
+ * Fetch timestamps
+ */
+
+static inline int
+time_pps_fetch(
+ pps_handle_t handle,
+ const int tsformat,
+ pps_info_t *ppsinfo,
+ const struct timespec *timeout
+ )
+{
+ struct timeval tv;
+ pps_info_t infobuf;
+
+ /*
+ * Check for valid arguments and fetch timestamps
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+
+ if (!ppsinfo) {
+ errno = EFAULT;
+ return (-1); /* bad argument */
+ }
+
+ /*
+ * nb. PPS_CANWAIT is NOT set by the implementation, we can totally
+ * ignore the timeout variable.
+ */
+
+ memset(&infobuf, 0, sizeof(infobuf));
+
+ /*
+ * if not captureassert, nothing to return.
+ */
+
+ if (!handle->params.mode & PPS_CAPTUREASSERT) {
+ memcpy(ppsinfo, &infobuf, sizeof(pps_info_t));
+ return (0);
+ }
+
+ if (ioctl(instance->filedes, TIOCDCDTIMESTAMP, &tv) < 0) {
+ perror("time_pps_fetch:");
+ errno = EOPNOTSUPP;
+ return(-1);
+ }
+
+ /*
+ * fake serial here
+ */
+
+ if (tv.tv_sec != handle->tv_save.tv_sec || tv.tv_usec != handle->tv_save.tv_usec) {
+ handle->tv_save = tv;
+ handle->serial++;
+ }
+
+ /*
+ * Apply offsets as specified. Note that only assert timestamps
+ * are captured by this interface.
+ */
+
+ infobuf.assert_sequence = handle->serial;
+ infobuf.assert_timestamp.tv_sec = tv.tv_sec;
+ infobuf.assert_timestamp.tv_nsec = tv.tv_usec * 1000;
+
+ if (handle->params.mode & PPS_OFFSETASSERT) {
+ infobuf.assert_timestamp.tv_sec += handle->params.assert_offset.tv_sec;
+ infobuf.assert_timestamp.tv_nsec += handle->params.assert_offset.tv_nsec;
+ PPS_NORMALIZE(infobuf.assert_timestamp);
+ }
+
+ /*
+ * Translate to specified format
+ */
+
+ switch (tsformat) {
+ case PPS_TSFMT_TSPEC:
+ break; /* timespec format requires no translation */
+
+ case PPS_TSFMT_NTPFP: /* NTP format requires conversion to fraction form */
+ PPS_TSPECTONTP(infobuf.assert_timestamp_ntpfp);
+ break;
+
+ default:
+ errno = EINVAL;
+ return (-1);
+ }
+
+ infobuf.current_mode = handle->params.mode;
+ memcpy(ppsinfo, &infobuf, sizeof(pps_info_t));
+ return (0);
+}
+
+/*
+ * specify kernel consumer
+ */
+
+static inline int
+time_pps_kcbind(
+ pps_handle_t handle,
+ const int kernel_consumer,
+ const int edge, const int tsformat
+ )
+{
+ /*
+ * Check for valid arguments and bind kernel consumer
+ */
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+ if (geteuid() != 0) {
+ errno = EPERM;
+ return (-1); /* must be superuser */
+ }
+ errno = EOPNOTSUPP;
+ return(-1);
+}
+
+#endif /* _SYS_TIMEPPS_H_ */
diff --git a/include/timepps-Solaris.h b/include/timepps-Solaris.h
new file mode 100644
index 0000000..a2b1fbe
--- /dev/null
+++ b/include/timepps-Solaris.h
@@ -0,0 +1,569 @@
+/***********************************************************************
+ * *
+ * Copyright (c) David L. Mills 1999-2009 *
+ * *
+ * Permission to use, copy, modify, and distribute this software and *
+ * its documentation for any purpose and with or without fee is hereby *
+ * granted, provided that the above copyright notice appears in all *
+ * copies and that both the copyright notice and this permission *
+ * notice appear in supporting documentation, and that the name *
+ * University of Delaware not be used in advertising or publicity *
+ * pertaining to distribution of the software without specific, *
+ * written prior permission. The University of Delaware makes no *
+ * representations about the suitability this software for any *
+ * purpose. It is provided "as is" without express or implied *
+ * warranty. *
+ * *
+ ***********************************************************************
+ * *
+ * This header file complies with "Pulse-Per-Second API for UNIX-like *
+ * Operating Systems, Version 1.0", rfc2783. Credit is due Jeff Mogul *
+ * and Marc Brett, from whom much of this code was shamelessly stolen. *
+ * *
+ * this modified timepps.h can be used to provide a PPSAPI interface *
+ * to a machine running Solaris (2.6 and above). *
+ * *
+ ***********************************************************************
+ * *
+ * A full PPSAPI interface to the Solaris kernel would be better, but *
+ * this at least removes the necessity for special coding from the NTP *
+ * NTP drivers. *
+ * *
+ ***********************************************************************
+ * *
+ * Some of this include file *
+ * Copyright (c) 1999 by Ulrich Windl, *
+ * based on code by Reg Clemens <reg@dwf.com> *
+ * based on code by Poul-Henning Kamp <phk@FreeBSD.org> *
+ * *
+ ***********************************************************************
+ * *
+ * "THE BEER-WARE LICENSE" (Revision 42): *
+ * <phk@FreeBSD.org> wrote this file. As long as you retain this *
+ * notice you can do whatever you want with this stuff. If we meet some*
+ * day, and you think this stuff is worth it, you can buy me a beer *
+ * in return. Poul-Henning Kamp *
+ * *
+ **********************************************************************/
+
+/* Solaris version, TIOCGPPSEV and TIOCSPPS assumed to exist. */
+
+#ifndef _SYS_TIMEPPS_H_
+#define _SYS_TIMEPPS_H_
+
+#include <termios.h> /* to get TOCGPPSEV and TIOCSPPS */
+
+/* Implementation note: the logical states ``assert'' and ``clear''
+ * are implemented in terms of the UART register, i.e. ``assert''
+ * means the bit is set.
+ */
+
+/*
+ * The following definitions are architecture independent
+ */
+
+#define PPS_API_VERS_1 1 /* API version number */
+#define PPS_JAN_1970 2208988800UL /* 1970 - 1900 in seconds */
+#define PPS_NANOSECOND 1000000000L /* one nanosecond in decimal */
+#define PPS_FRAC 4294967296. /* 2^32 as a double */
+
+#define PPS_NORMALIZE(x) /* normalize timespec */ \
+ do { \
+ if ((x).tv_nsec >= PPS_NANOSECOND) { \
+ (x).tv_nsec -= PPS_NANOSECOND; \
+ (x).tv_sec++; \
+ } else if ((x).tv_nsec < 0) { \
+ (x).tv_nsec += PPS_NANOSECOND; \
+ (x).tv_sec--; \
+ } \
+ } while (0)
+
+#define PPS_TSPECTONTP(x) /* convert timespec to l_fp */ \
+ do { \
+ double d_temp; \
+ \
+ (x).integral += (unsigned int)PPS_JAN_1970; \
+ d_temp = (x).fractional * PPS_FRAC / PPS_NANOSECOND; \
+ if (d_temp >= PPS_FRAC) \
+ (x).integral++; \
+ (x).fractional = (unsigned int)d_temp; \
+ } while (0)
+
+/*
+ * Device/implementation parameters (mode)
+ */
+
+#define PPS_CAPTUREASSERT 0x01 /* capture assert events */
+#define PPS_CAPTURECLEAR 0x02 /* capture clear events */
+#define PPS_CAPTUREBOTH 0x03 /* capture assert and clear events */
+
+#define PPS_OFFSETASSERT 0x10 /* apply compensation for assert ev. */
+#define PPS_OFFSETCLEAR 0x20 /* apply compensation for clear ev. */
+#define PPS_OFFSETBOTH 0x30 /* apply compensation for both */
+
+#define PPS_CANWAIT 0x100 /* Can we wait for an event? */
+#define PPS_CANPOLL 0x200 /* "This bit is reserved for */
+
+/*
+ * Kernel actions (mode)
+ */
+
+#define PPS_ECHOASSERT 0x40 /* feed back assert event to output */
+#define PPS_ECHOCLEAR 0x80 /* feed back clear event to output */
+
+/*
+ * Timestamp formats (tsformat)
+ */
+
+#define PPS_TSFMT_TSPEC 0x1000 /* select timespec format */
+#define PPS_TSFMT_NTPFP 0x2000 /* select NTP format */
+
+/*
+ * Kernel discipline actions (not used in Solaris)
+ */
+
+#define PPS_KC_HARDPPS 0 /* enable kernel consumer */
+#define PPS_KC_HARDPPS_PLL 1 /* phase-lock mode */
+#define PPS_KC_HARDPPS_FLL 2 /* frequency-lock mode */
+
+/*
+ * Type definitions
+ */
+
+typedef unsigned long pps_seq_t; /* sequence number */
+
+typedef struct ntp_fp {
+ unsigned int integral;
+ unsigned int fractional;
+} ntp_fp_t; /* NTP-compatible time stamp */
+
+typedef union pps_timeu { /* timestamp format */
+ struct timespec tspec;
+ ntp_fp_t ntpfp;
+ unsigned long longpad[3];
+} pps_timeu_t; /* generic data type to represent time stamps */
+
+/*
+ * Timestamp information structure
+ */
+
+typedef struct pps_info {
+ pps_seq_t assert_sequence; /* seq. num. of assert event */
+ pps_seq_t clear_sequence; /* seq. num. of clear event */
+ pps_timeu_t assert_tu; /* time of assert event */
+ pps_timeu_t clear_tu; /* time of clear event */
+ int current_mode; /* current mode bits */
+} pps_info_t;
+
+#define assert_timestamp assert_tu.tspec
+#define clear_timestamp clear_tu.tspec
+
+#define assert_timestamp_ntpfp assert_tu.ntpfp
+#define clear_timestamp_ntpfp clear_tu.ntpfp
+
+/*
+ * Parameter structure
+ */
+
+typedef struct pps_params {
+ int api_version; /* API version # */
+ int mode; /* mode bits */
+ pps_timeu_t assert_off_tu; /* offset compensation for assert */
+ pps_timeu_t clear_off_tu; /* offset compensation for clear */
+} pps_params_t;
+
+#define assert_offset assert_off_tu.tspec
+#define clear_offset clear_off_tu.tspec
+
+#define assert_offset_ntpfp assert_off_tu.ntpfp
+#define clear_offset_ntpfp clear_off_tu.ntpfp
+
+/* addition of NTP fixed-point format */
+
+#define NTPFP_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 NTPFP_L_ADDS(r, a) NTPFP_M_ADD((r)->integral, (r)->fractional, \
+ (int)(a)->integral, (a)->fractional)
+
+/*
+ * The following definitions are architecture-dependent
+ */
+
+#define PPS_CAP (PPS_CAPTUREASSERT | PPS_OFFSETASSERT | PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)
+#define PPS_RO (PPS_CANWAIT | PPS_CANPOLL)
+
+typedef struct {
+ int filedes; /* file descriptor */
+ pps_params_t params; /* PPS parameters set by user */
+} pps_unit_t;
+
+/*
+ *------ Here begins the implementation-specific part! ------
+ */
+
+#include <errno.h>
+
+/*
+ * pps handlebars, which are required to be an opaque scalar. This
+ * implementation uses the handle as a pointer so it must be large
+ * enough. uintptr_t is as large as a pointer.
+ */
+typedef uintptr_t pps_handle_t;
+
+/*
+ * create PPS handle from file descriptor
+ */
+
+static inline int
+time_pps_create(
+ int filedes, /* file descriptor */
+ pps_handle_t *handle /* returned handle */
+ )
+{
+ pps_unit_t *punit;
+ int one = 1;
+
+ /*
+ * Check for valid arguments and attach PPS signal.
+ */
+
+ if (!handle) {
+ errno = EFAULT;
+ return (-1); /* null pointer */
+ }
+
+ if (ioctl(filedes, TIOCSPPS, &one) < 0) {
+ perror("refclock_ioctl: TIOCSPPS failed:");
+ return (-1);
+ }
+
+ /*
+ * Allocate and initialize default unit structure.
+ */
+
+ punit = malloc(sizeof(*punit));
+ if (NULL == punit) {
+ errno = ENOMEM;
+ return (-1); /* what, no memory? */
+ }
+
+ memset(punit, 0, sizeof(*punit));
+ punit->filedes = filedes;
+ punit->params.api_version = PPS_API_VERS_1;
+ punit->params.mode = PPS_CAPTUREASSERT | PPS_TSFMT_TSPEC;
+
+ *handle = (pps_handle_t)punit;
+ return (0);
+}
+
+/*
+ * release PPS handle
+ */
+
+static inline int
+time_pps_destroy(
+ pps_handle_t handle
+ )
+{
+ pps_unit_t *punit;
+
+ /*
+ * Check for valid arguments and detach PPS signal.
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+ punit = (pps_unit_t *)handle;
+ free(punit);
+ return (0);
+}
+
+/*
+ * set parameters for handle
+ */
+
+static inline int
+time_pps_setparams(
+ pps_handle_t handle,
+ const pps_params_t *params
+ )
+{
+ pps_unit_t * punit;
+ int mode, mode_in;
+ /*
+ * Check for valid arguments and set parameters.
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+
+ if (!params) {
+ errno = EFAULT;
+ return (-1); /* bad argument */
+ }
+
+ /*
+ * There was no reasonable consensu in the API working group.
+ * I require `api_version' to be set!
+ */
+
+ if (params->api_version != PPS_API_VERS_1) {
+ errno = EINVAL;
+ return(-1);
+ }
+
+ /*
+ * only settable modes are PPS_CAPTUREASSERT and PPS_OFFSETASSERT
+ */
+
+ mode_in = params->mode;
+ punit = (pps_unit_t *)handle;
+
+ /*
+ * Only one of the time formats may be selected
+ * if a nonzero assert offset is supplied.
+ */
+ if ((mode_in & (PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)) ==
+ (PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)) {
+
+ if (punit->params.assert_offset.tv_sec ||
+ punit->params.assert_offset.tv_nsec) {
+
+ errno = EINVAL;
+ return(-1);
+ }
+
+ /*
+ * If no offset was specified but both time
+ * format flags are used consider it harmless
+ * but turn off PPS_TSFMT_NTPFP so getparams
+ * will not show both formats lit.
+ */
+ mode_in &= ~PPS_TSFMT_NTPFP;
+ }
+
+ /* turn off read-only bits */
+
+ mode_in &= ~PPS_RO;
+
+ /*
+ * test remaining bits, should only have captureassert,
+ * offsetassert, and/or timestamp format bits.
+ */
+
+ if (mode_in & ~(PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
+ PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)) {
+ errno = EOPNOTSUPP;
+ return(-1);
+ }
+
+ /*
+ * ok, ready to go.
+ */
+
+ mode = punit->params.mode;
+ memcpy(&punit->params, params, sizeof(punit->params));
+ punit->params.api_version = PPS_API_VERS_1;
+ punit->params.mode = mode | mode_in;
+ return (0);
+}
+
+/*
+ * get parameters for handle
+ */
+
+static inline int
+time_pps_getparams(
+ pps_handle_t handle,
+ pps_params_t *params
+ )
+{
+ pps_unit_t * punit;
+
+ /*
+ * Check for valid arguments and get parameters.
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+
+ if (!params) {
+ errno = EFAULT;
+ return (-1); /* bad argument */
+ }
+
+ punit = (pps_unit_t *)handle;
+ memcpy(params, &punit->params, sizeof(params));
+ return (0);
+}
+
+/*
+ * get capabilities for handle
+ */
+
+static inline int
+time_pps_getcap(
+ pps_handle_t handle,
+ int *mode
+ )
+{
+ /*
+ * Check for valid arguments and get capabilities.
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+
+ if (!mode) {
+ errno = EFAULT;
+ return (-1); /* bad argument */
+ }
+ *mode = PPS_CAP;
+ return (0);
+}
+
+/*
+ * Fetch timestamps
+ */
+
+static inline int
+time_pps_fetch(
+ pps_handle_t handle,
+ const int tsformat,
+ pps_info_t *ppsinfo,
+ const struct timespec *timeout
+ )
+{
+ struct ppsclockev {
+ struct timeval tv;
+ u_int serial;
+ } ev;
+
+ pps_info_t infobuf;
+ pps_unit_t * punit;
+
+ /*
+ * Check for valid arguments and fetch timestamps
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+
+ if (!ppsinfo) {
+ errno = EFAULT;
+ return (-1); /* bad argument */
+ }
+
+ /*
+ * nb. PPS_CANWAIT is NOT set by the implementation, we can totally
+ * ignore the timeout variable.
+ */
+
+ memset(&infobuf, 0, sizeof(infobuf));
+ punit = (pps_unit_t *)handle;
+
+ /*
+ * if not captureassert, nothing to return.
+ */
+
+ if (!punit->params.mode & PPS_CAPTUREASSERT) {
+ memcpy(ppsinfo, &infobuf, sizeof(*ppsinfo));
+ return (0);
+ }
+
+ if (ioctl(punit->filedes, TIOCGPPSEV, (caddr_t) &ev) < 0) {
+ perror("time_pps_fetch:");
+ errno = EOPNOTSUPP;
+ return(-1);
+ }
+
+ infobuf.assert_sequence = ev.serial;
+ infobuf.assert_timestamp.tv_sec = ev.tv.tv_sec;
+ infobuf.assert_timestamp.tv_nsec = ev.tv.tv_usec * 1000;
+
+ /*
+ * Translate to specified format then apply offset
+ */
+
+ switch (tsformat) {
+ case PPS_TSFMT_TSPEC:
+ /* timespec format requires no conversion */
+ if (punit->params.mode & PPS_OFFSETASSERT) {
+ infobuf.assert_timestamp.tv_sec +=
+ punit->params.assert_offset.tv_sec;
+ infobuf.assert_timestamp.tv_nsec +=
+ punit->params.assert_offset.tv_nsec;
+ PPS_NORMALIZE(infobuf.assert_timestamp);
+ }
+ break;
+
+ case PPS_TSFMT_NTPFP:
+ /* NTP format requires conversion to fraction form */
+ PPS_TSPECTONTP(infobuf.assert_timestamp_ntpfp);
+ if (punit->params.mode & PPS_OFFSETASSERT)
+ NTPFP_L_ADDS(&infobuf.assert_timestamp_ntpfp,
+ &punit->params.assert_offset_ntpfp);
+ break;
+
+ default:
+ errno = EINVAL;
+ return (-1);
+ }
+
+ infobuf.current_mode = punit->params.mode;
+ memcpy(ppsinfo, &infobuf, sizeof(*ppsinfo));
+ return (0);
+}
+
+/*
+ * specify kernel consumer
+ */
+
+static inline int
+time_pps_kcbind(
+ pps_handle_t handle,
+ const int kernel_consumer,
+ const int edge,
+ const int tsformat
+ )
+{
+ /*
+ * Check for valid arguments and bind kernel consumer
+ */
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+ if (geteuid() != 0) {
+ errno = EPERM;
+ return (-1); /* must be superuser */
+ }
+ errno = EOPNOTSUPP;
+ return(-1);
+}
+
+#endif /* _SYS_TIMEPPS_H_ */
diff --git a/include/timepps-SunOS.h b/include/timepps-SunOS.h
new file mode 100644
index 0000000..4e4c05e
--- /dev/null
+++ b/include/timepps-SunOS.h
@@ -0,0 +1,504 @@
+/***********************************************************************
+ * *
+ * Copyright (c) David L. Mills 1999-2000 *
+ * *
+ * Permission to use, copy, modify, and distribute this software and *
+ * its documentation for any purpose and with or without fee is hereby *
+ * granted, provided that the above copyright notice appears in all *
+ * copies and that both the copyright notice and this permission *
+ * notice appear in supporting documentation, and that the name *
+ * University of Delaware not be used in advertising or publicity *
+ * pertaining to distribution of the software without specific, *
+ * written prior permission. The University of Delaware makes no *
+ * representations about the suitability this software for any *
+ * purpose. It is provided "as is" without express or implied *
+ * warranty. *
+ * *
+ ***********************************************************************
+ * *
+ * This header file complies with "Pulse-Per-Second API for UNIX-like *
+ * Operating Systems, Version 1.0", rfc2783. Credit is due Jeff Mogul *
+ * and Marc Brett, from whom much of this code was shamelessly stolen. *
+ * *
+ * this modified timepps.h can be used to provide a PPSAPI interface *
+ * to a machine running SunOS. *
+ * *
+ ***********************************************************************
+ * *
+ * A full PPSAPI interface to the SunOS kernel would be better, but *
+ * this at least removes the necessity for special coding from the NTP *
+ * NTP drivers. *
+ * *
+ ***********************************************************************
+ * *
+ * Some of this include file *
+ * Copyright (c) 1999 by Ulrich Windl, *
+ * based on code by Reg Clemens <reg@dwf.com> *
+ * based on code by Poul-Henning Kamp <phk@FreeBSD.org> *
+ * *
+ ***********************************************************************
+ * *
+ * "THE BEER-WARE LICENSE" (Revision 42): *
+ * <phk@FreeBSD.org> wrote this file. As long as you retain this *
+ * notice you can do whatever you want with this stuff. If we meet some*
+ * day, and you think this stuff is worth it, you can buy me a beer *
+ * in return. Poul-Henning Kamp *
+ * *
+ **********************************************************************/
+
+/* SunOS version, CIOGETEV assumed to exist for SunOS */
+
+#ifndef _SYS_TIMEPPS_H_
+#define _SYS_TIMEPPS_H_
+
+#include <termios.h> /* to get CIOGETEV */
+
+/* Implementation note: the logical states ``assert'' and ``clear''
+ * are implemented in terms of the UART register, i.e. ``assert''
+ * means the bit is set.
+ */
+
+/*
+ * The following definitions are architecture independent
+ */
+
+#define PPS_API_VERS_1 1 /* API version number */
+#define PPS_JAN_1970 2208988800UL /* 1970 - 1900 in seconds */
+#define PPS_NANOSECOND 1000000000L /* one nanosecond in decimal */
+#define PPS_FRAC 4294967296. /* 2^32 as a double */
+
+#define PPS_NORMALIZE(x) /* normalize timespec */ \
+ do { \
+ if ((x).tv_nsec >= PPS_NANOSECOND) { \
+ (x).tv_nsec -= PPS_NANOSECOND; \
+ (x).tv_sec++; \
+ } else if ((x).tv_nsec < 0) { \
+ (x).tv_nsec += PPS_NANOSECOND; \
+ (x).tv_sec--; \
+ } \
+ } while (0)
+
+#define PPS_TSPECTONTP(x) /* convert timespec to l_fp */ \
+ do { \
+ double d_temp; \
+ \
+ (x).integral += (unsigned int)PPS_JAN_1970; \
+ d_temp = (x).fractional * PPS_FRAC / PPS_NANOSECOND; \
+ if (d_temp >= PPS_FRAC) \
+ (x).integral++; \
+ (x).fractional = (unsigned int)d_temp; \
+ } while (0)
+
+/*
+ * Device/implementation parameters (mode)
+ */
+
+#define PPS_CAPTUREASSERT 0x01 /* capture assert events */
+#define PPS_CAPTURECLEAR 0x02 /* capture clear events */
+#define PPS_CAPTUREBOTH 0x03 /* capture assert and clear events */
+
+#define PPS_OFFSETASSERT 0x10 /* apply compensation for assert ev. */
+#define PPS_OFFSETCLEAR 0x20 /* apply compensation for clear ev. */
+#define PPS_OFFSETBOTH 0x30 /* apply compensation for both */
+
+#define PPS_CANWAIT 0x100 /* Can we wait for an event? */
+#define PPS_CANPOLL 0x200 /* "This bit is reserved for */
+
+/*
+ * Kernel actions (mode)
+ */
+
+#define PPS_ECHOASSERT 0x40 /* feed back assert event to output */
+#define PPS_ECHOCLEAR 0x80 /* feed back clear event to output */
+
+/*
+ * Timestamp formats (tsformat)
+ */
+
+#define PPS_TSFMT_TSPEC 0x1000 /* select timespec format */
+#define PPS_TSFMT_NTPFP 0x2000 /* select NTP format */
+
+/*
+ * Kernel discipline actions (not used in SunOS)
+ */
+
+#define PPS_KC_HARDPPS 0 /* enable kernel consumer */
+#define PPS_KC_HARDPPS_PLL 1 /* phase-lock mode */
+#define PPS_KC_HARDPPS_FLL 2 /* frequency-lock mode */
+
+/*
+ * Type definitions
+ */
+
+typedef unsigned long pps_seq_t; /* sequence number */
+
+typedef struct ntp_fp {
+ unsigned int integral;
+ unsigned int fractional;
+} ntp_fp_t; /* NTP-compatible time stamp */
+
+typedef union pps_timeu { /* timestamp format */
+ struct timespec tspec;
+ ntp_fp_t ntpfp;
+ unsigned long longpad[3];
+} pps_timeu_t; /* generic data type to represent time stamps */
+
+/*
+ * Timestamp information structure
+ */
+
+typedef struct pps_info {
+ pps_seq_t assert_sequence; /* seq. num. of assert event */
+ pps_seq_t clear_sequence; /* seq. num. of clear event */
+ pps_timeu_t assert_tu; /* time of assert event */
+ pps_timeu_t clear_tu; /* time of clear event */
+ int current_mode; /* current mode bits */
+} pps_info_t;
+
+#define assert_timestamp assert_tu.tspec
+#define clear_timestamp clear_tu.tspec
+
+#define assert_timestamp_ntpfp assert_tu.ntpfp
+#define clear_timestamp_ntpfp clear_tu.ntpfp
+
+/*
+ * Parameter structure
+ */
+
+typedef struct pps_params {
+ int api_version; /* API version # */
+ int mode; /* mode bits */
+ pps_timeu_t assert_off_tu; /* offset compensation for assert */
+ pps_timeu_t clear_off_tu; /* offset compensation for clear */
+} pps_params_t;
+
+#define assert_offset assert_off_tu.tspec
+#define clear_offset clear_off_tu.tspec
+
+#define assert_offset_ntpfp assert_off_tu.ntpfp
+#define clear_offset_ntpfp clear_off_tu.ntpfp
+
+/*
+ * The following definitions are architecture-dependent
+ */
+
+#define PPS_CAP (PPS_CAPTUREASSERT | PPS_OFFSETASSERT | PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)
+#define PPS_RO (PPS_CANWAIT | PPS_CANPOLL | PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)
+
+typedef struct {
+ int filedes; /* file descriptor */
+ pps_params_t params; /* PPS parameters set by user */
+} pps_unit_t;
+
+typedef pps_unit_t* pps_handle_t; /* pps handlebars */
+
+/*
+ *------ Here begins the implementation-specific part! ------
+ */
+
+#include <errno.h>
+
+/*
+ * create PPS handle from file descriptor
+ */
+
+static inline int
+time_pps_create(
+ int filedes, /* file descriptor */
+ pps_handle_t *handle /* returned handle */
+ )
+{
+ /*
+ * Check for valid arguments and attach PPS signal.
+ */
+
+ if (!handle) {
+ errno = EFAULT;
+ return (-1); /* null pointer */
+ }
+
+ if (ioctl(filedes, I_PUSH, "ppsclock") < 0) {
+ perror("time_pps_create: I_PUSH ppsclock failed");
+ return (-1);
+ }
+
+ /*
+ * Allocate and initialize default unit structure.
+ */
+
+ *handle = malloc(sizeof(pps_unit_t));
+ if (!(*handle)) {
+ errno = EBADF;
+ return (-1); /* what, no memory? */
+ }
+
+ memset(*handle, 0, sizeof(pps_unit_t));
+ (*handle)->filedes = filedes;
+ (*handle)->params.api_version = PPS_API_VERS_1;
+ (*handle)->params.mode = PPS_CAPTUREASSERT | PPS_TSFMT_TSPEC;
+ return (0);
+}
+
+/*
+ * release PPS handle
+ */
+
+static inline int
+time_pps_destroy(
+ pps_handle_t handle
+ )
+{
+ /*
+ * Check for valid arguments and detach PPS signal.
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+ free(handle);
+ return (0);
+}
+
+/*
+ * set parameters for handle
+ */
+
+static inline int
+time_pps_setparams(
+ pps_handle_t handle,
+ const pps_params_t *params
+ )
+{
+ int mode, mode_in;
+ /*
+ * Check for valid arguments and set parameters.
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+
+ if (!params) {
+ errno = EFAULT;
+ return (-1); /* bad argument */
+ }
+
+ /*
+ * There was no reasonable consensu in the API working group.
+ * I require `api_version' to be set!
+ */
+
+ if (params->api_version != PPS_API_VERS_1) {
+ errno = EINVAL;
+ return(-1);
+ }
+
+ /*
+ * only settable modes are PPS_CAPTUREASSERT and PPS_OFFSETASSERT
+ */
+
+ mode_in = params->mode;
+
+ /* turn off read-only bits */
+
+ mode_in &= ~PPS_RO;
+
+ /* test remaining bits, should only have captureassert and/or offsetassert */
+
+ if (mode_in & ~(PPS_CAPTUREASSERT | PPS_OFFSETASSERT)) {
+ errno = EOPNOTSUPP;
+ return(-1);
+ }
+
+ /*
+ * ok, ready to go.
+ */
+
+ mode = handle->params.mode;
+ memcpy(&handle->params, params, sizeof(pps_params_t));
+ handle->params.api_version = PPS_API_VERS_1;
+ handle->params.mode = mode | mode_in;
+ return (0);
+}
+
+/*
+ * get parameters for handle
+ */
+
+static inline int
+time_pps_getparams(
+ pps_handle_t handle,
+ pps_params_t *params
+ )
+{
+ /*
+ * Check for valid arguments and get parameters.
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+
+ if (!params) {
+ errno = EFAULT;
+ return (-1); /* bad argument */
+ }
+
+ memcpy(params, &handle->params, sizeof(pps_params_t));
+ return (0);
+}
+
+/* (
+ * get capabilities for handle
+ */
+
+static inline int
+time_pps_getcap(
+ pps_handle_t handle,
+ int *mode
+ )
+{
+ /*
+ * Check for valid arguments and get capabilities.
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+
+ if (!mode) {
+ errno = EFAULT;
+ return (-1); /* bad argument */
+ }
+ *mode = PPS_CAP;
+ return (0);
+}
+
+/*
+ * Fetch timestamps
+ */
+
+static inline int
+time_pps_fetch(
+ pps_handle_t handle,
+ const int tsformat,
+ pps_info_t *ppsinfo,
+ const struct timespec *timeout
+ )
+{
+ struct ppsclockev {
+ struct timeval tv;
+ u_int serial;
+ } ev;
+ pps_info_t infobuf;
+
+ /*
+ * Check for valid arguments and fetch timestamps
+ */
+
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+
+ if (!ppsinfo) {
+ errno = EFAULT;
+ return (-1); /* bad argument */
+ }
+
+ /*
+ * nb. PPS_CANWAIT is NOT set by the implementation, we can totally
+ * ignore the timeout variable.
+ */
+
+ memset(&infobuf, 0, sizeof(infobuf));
+
+ /*
+ * if not captureassert, nothing to return.
+ */
+
+ if (!handle->params.mode & PPS_CAPTUREASSERT) {
+ memcpy(ppsinfo, &infobuf, sizeof(pps_info_t));
+ return (0);
+ }
+
+#if defined(__STDC__)
+#define CIOGETEV _IOR('C', 0, struct ppsclockev) /* get last pps event */
+#else
+#define CIOGETEV _IOR(C, 0, struct ppsclockev) /* get last pps event */
+#endif
+
+ if (ioctl(handle->filedes, CIOGETEV, (caddr_t) &ev) < 0) {
+ perror("time_pps_fetch:");
+ errno = EOPNOTSUPP;
+ return(-1);
+ }
+
+ /*
+ * Apply offsets as specified. Note that only assert timestamps
+ * are captured by this interface.
+ */
+
+ infobuf.assert_sequence = ev.serial;
+ infobuf.assert_timestamp.tv_sec = ev.tv.tv_sec;
+ infobuf.assert_timestamp.tv_nsec = ev.tv.tv_usec * 1000;
+
+ if (handle->params.mode & PPS_OFFSETASSERT) {
+ infobuf.assert_timestamp.tv_sec += handle->params.assert_offset.tv_sec;
+ infobuf.assert_timestamp.tv_nsec += handle->params.assert_offset.tv_nsec;
+ PPS_NORMALIZE(infobuf.assert_timestamp);
+ }
+
+ /*
+ * Translate to specified format
+ */
+
+ switch (tsformat) {
+ case PPS_TSFMT_TSPEC:
+ break; /* timespec format requires no translation */
+
+ case PPS_TSFMT_NTPFP: /* NTP format requires conversion to fraction form */
+ PPS_TSPECTONTP(infobuf.assert_timestamp_ntpfp);
+ break;
+
+ default:
+ errno = EINVAL;
+ return (-1);
+ }
+
+ infobuf.current_mode = handle->params.mode;
+ memcpy(ppsinfo, &infobuf, sizeof(pps_info_t));
+ return (0);
+}
+
+/*
+ * specify kernel consumer
+ */
+
+static inline int
+time_pps_kcbind(
+ pps_handle_t handle,
+ const int kernel_consumer,
+ const int edge, const int tsformat
+ )
+{
+ /*
+ * Check for valid arguments and bind kernel consumer
+ */
+ if (!handle) {
+ errno = EBADF;
+ return (-1); /* bad handle */
+ }
+ if (geteuid() != 0) {
+ errno = EPERM;
+ return (-1); /* must be superuser */
+ }
+ errno = EOPNOTSUPP;
+ return(-1);
+}
+
+#endif /* _SYS_TIMEPPS_H_ */
diff --git a/include/timespecops.h b/include/timespecops.h
new file mode 100644
index 0000000..fa32e42
--- /dev/null
+++ b/include/timespecops.h
@@ -0,0 +1,393 @@
+/*
+ * timespecops.h -- calculations on 'struct timespec' values
+ *
+ * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
+ * The contents of 'html/copyright.html' apply.
+ *
+ * Rationale
+ * ---------
+ *
+ * Doing basic arithmetic on a 'struct timespec' is not exceedingly
+ * hard, but it requires tedious and repetitive code to keep the result
+ * normalised. We consider a timespec normalised when the nanosecond
+ * fraction is in the interval [0 .. 10^9[ ; there are multiple value
+ * pairs of seconds and nanoseconds that denote the same time interval,
+ * but the normalised representation is unique. No two different
+ * intervals can have the same normalised representation.
+ *
+ * Another topic is the representation of negative time intervals.
+ * There's more than one way to this, since both the seconds and the
+ * nanoseconds of a timespec are signed values. IMHO, the easiest way is
+ * to use a complement representation where the nanoseconds are still
+ * normalised, no matter what the sign of the seconds value. This makes
+ * normalisation easier, since the sign of the integer part is
+ * irrelevant, and it removes several sign decision cases during the
+ * calculations.
+ *
+ * As long as no signed integer overflow can occur with the nanosecond
+ * part of the operands, all operations work as expected and produce a
+ * normalised result.
+ *
+ * The exception to this are functions fix a '_fast' suffix, which do no
+ * normalisation on input data and therefore expect the input data to be
+ * normalised.
+ *
+ * Input and output operands may overlap; all input is consumed before
+ * the output is written to.
+ */
+#ifndef TIMESPECOPS_H
+#define TIMESPECOPS_H
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <math.h>
+
+#include "ntp.h"
+#include "timetoa.h"
+
+
+/* nanoseconds per second */
+#define NANOSECONDS 1000000000
+
+/* predicate: returns TRUE if the nanoseconds are in nominal range */
+#define timespec_isnormal(x) \
+ ((x)->tv_nsec >= 0 && (x)->tv_nsec < NANOSECONDS)
+
+/* predicate: returns TRUE if the nanoseconds are out-of-bounds */
+#define timespec_isdenormal(x) (!timespec_isnormal(x))
+
+/* conversion between l_fp fractions and nanoseconds */
+#ifdef HAVE_U_INT64
+# define FTOTVN(tsf) \
+ ((int32) \
+ (((u_int64)(tsf) * NANOSECONDS + 0x80000000) >> 32))
+# define TVNTOF(tvu) \
+ ((u_int32) \
+ ((((u_int64)(tvu) << 32) + NANOSECONDS / 2) / \
+ NANOSECONDS))
+#else
+# define NSECFRAC (FRAC / NANOSECONDS)
+# define FTOTVN(tsf) \
+ ((int32)((tsf) / NSECFRAC + 0.5))
+# define TVNTOF(tvu) \
+ ((u_int32)((tvu) * NSECFRAC + 0.5))
+#endif
+
+
+
+/* make sure nanoseconds are in nominal range */
+static inline struct timespec
+normalize_tspec(
+ struct timespec x
+ )
+{
+#if SIZEOF_LONG > 4
+ long z;
+
+ /*
+ * tv_nsec is of type 'long', and on a 64-bit machine using only
+ * loops becomes prohibitive once the upper 32 bits get
+ * involved. On the other hand, division by constant should be
+ * fast enough; so we do a division of the nanoseconds in that
+ * case. The floor adjustment step follows with the standard
+ * normalisation loops. And labs() is intentionally not used
+ * here: it has implementation-defined behaviour when applied
+ * to LONG_MIN.
+ */
+ if (x.tv_nsec < -3l * NANOSECONDS ||
+ x.tv_nsec > 3l * NANOSECONDS) {
+ z = x.tv_nsec / NANOSECONDS;
+ x.tv_nsec -= z * NANOSECONDS;
+ x.tv_sec += z;
+ }
+#endif
+ /* since 10**9 is close to 2**32, we don't divide but do a
+ * normalisation in a loop; this takes 3 steps max, and should
+ * outperform a division even if the mul-by-inverse trick is
+ * employed. */
+ if (x.tv_nsec < 0)
+ do {
+ x.tv_nsec += NANOSECONDS;
+ x.tv_sec--;
+ } while (x.tv_nsec < 0);
+ else if (x.tv_nsec >= NANOSECONDS)
+ do {
+ x.tv_nsec -= NANOSECONDS;
+ x.tv_sec++;
+ } while (x.tv_nsec >= NANOSECONDS);
+
+ return x;
+}
+
+/* x = a + b */
+static inline struct timespec
+add_tspec(
+ struct timespec a,
+ struct timespec b
+ )
+{
+ struct timespec x;
+
+ x = a;
+ x.tv_sec += b.tv_sec;
+ x.tv_nsec += b.tv_nsec;
+
+ return normalize_tspec(x);
+}
+
+/* x = a + b, b is fraction only */
+static inline struct timespec
+add_tspec_ns(
+ struct timespec a,
+ long b
+ )
+{
+ struct timespec x;
+
+ x = a;
+ x.tv_nsec += b;
+
+ return normalize_tspec(x);
+}
+
+/* x = a - b */
+static inline struct timespec
+sub_tspec(
+ struct timespec a,
+ struct timespec b
+ )
+{
+ struct timespec x;
+
+ x = a;
+ x.tv_sec -= b.tv_sec;
+ x.tv_nsec -= b.tv_nsec;
+
+ return normalize_tspec(x);
+}
+
+/* x = a - b, b is fraction only */
+static inline struct timespec
+sub_tspec_ns(
+ struct timespec a,
+ long b
+ )
+{
+ struct timespec x;
+
+ x = a;
+ x.tv_nsec -= b;
+
+ return normalize_tspec(x);
+}
+
+/* x = -a */
+static inline struct timespec
+neg_tspec(
+ struct timespec a
+ )
+{
+ struct timespec x;
+
+ x.tv_sec = -a.tv_sec;
+ x.tv_nsec = -a.tv_nsec;
+
+ return normalize_tspec(x);
+}
+
+/* x = abs(a) */
+static inline struct timespec
+abs_tspec(
+ struct timespec a
+ )
+{
+ struct timespec c;
+
+ c = normalize_tspec(a);
+ if (c.tv_sec < 0) {
+ if (c.tv_nsec != 0) {
+ c.tv_sec = -c.tv_sec - 1;
+ c.tv_nsec = NANOSECONDS - c.tv_nsec;
+ } else {
+ c.tv_sec = -c.tv_sec;
+ }
+ }
+
+ return c;
+}
+
+/*
+ * compare previously-normalised a and b
+ * return 1 / 0 / -1 if a < / == / > b
+ */
+static inline int
+cmp_tspec(
+ struct timespec a,
+ struct timespec b
+ )
+{
+ int r;
+
+ r = (a.tv_sec > b.tv_sec) - (a.tv_sec < b.tv_sec);
+ if (0 == r)
+ r = (a.tv_nsec > b.tv_nsec) -
+ (a.tv_nsec < b.tv_nsec);
+
+ return r;
+}
+
+/*
+ * compare possibly-denormal a and b
+ * return 1 / 0 / -1 if a < / == / > b
+ */
+static inline int
+cmp_tspec_denorm(
+ struct timespec a,
+ struct timespec b
+ )
+{
+ return cmp_tspec(normalize_tspec(a), normalize_tspec(b));
+}
+
+/*
+ * test previously-normalised a
+ * return 1 / 0 / -1 if a < / == / > 0
+ */
+static inline int
+test_tspec(
+ struct timespec a
+ )
+{
+ int r;
+
+ r = (a.tv_sec > 0) - (a.tv_sec < 0);
+ if (r == 0)
+ r = (a.tv_nsec > 0);
+
+ return r;
+}
+
+/*
+ * test possibly-denormal a
+ * return 1 / 0 / -1 if a < / == / > 0
+ */
+static inline int
+test_tspec_denorm(
+ struct timespec a
+ )
+{
+ return test_tspec(normalize_tspec(a));
+}
+
+/* return LIB buffer ptr to string rep */
+static inline const char *
+tspectoa(
+ struct timespec x
+ )
+{
+ return format_time_fraction(x.tv_sec, x.tv_nsec, 9);
+}
+
+/*
+ * convert to l_fp type, relative and absolute
+ */
+
+/* convert from timespec duration to l_fp duration */
+static inline l_fp
+tspec_intv_to_lfp(
+ struct timespec x
+ )
+{
+ struct timespec v;
+ l_fp y;
+
+ v = normalize_tspec(x);
+ y.l_uf = TVNTOF(v.tv_nsec);
+ y.l_i = (int32)v.tv_sec;
+
+ return y;
+}
+
+/* x must be UN*X epoch, output will be in NTP epoch */
+static inline l_fp
+tspec_stamp_to_lfp(
+ struct timespec x
+ )
+{
+ l_fp y;
+
+ y = tspec_intv_to_lfp(x);
+ y.l_ui += JAN_1970;
+
+ return y;
+}
+
+/* convert from l_fp type, relative signed/unsigned and absolute */
+static inline struct timespec
+lfp_intv_to_tspec(
+ l_fp x
+ )
+{
+ struct timespec out;
+ l_fp absx;
+ int neg;
+
+ neg = L_ISNEG(&x);
+ absx = x;
+ if (neg) {
+ L_NEG(&absx);
+ }
+ out.tv_nsec = FTOTVN(absx.l_uf);
+ out.tv_sec = absx.l_i;
+ if (neg) {
+ out.tv_sec = -out.tv_sec;
+ out.tv_nsec = -out.tv_nsec;
+ out = normalize_tspec(out);
+ }
+
+ return out;
+}
+
+static inline struct timespec
+lfp_uintv_to_tspec(
+ l_fp x
+ )
+{
+ struct timespec out;
+
+ out.tv_nsec = FTOTVN(x.l_uf);
+ out.tv_sec = x.l_ui;
+
+ return out;
+}
+
+/*
+ * absolute (timestamp) conversion. Input is time in NTP epoch, output
+ * is in UN*X epoch. The NTP time stamp will be expanded around the
+ * pivot time *p or the current time, if p is NULL.
+ */
+static inline struct timespec
+lfp_stamp_to_tspec(
+ l_fp x,
+ const time_t * p
+ )
+{
+ struct timespec out;
+ vint64 sec;
+
+ sec = ntpcal_ntp_to_time(x.l_ui, p);
+ out.tv_nsec = FTOTVN(x.l_uf);
+
+ /* copying a vint64 to a time_t needs some care... */
+#if SIZEOF_TIME_T <= 4
+ out.tv_sec = (time_t)sec.d_s.lo;
+#elif defined(HAVE_INT64)
+ out.tv_sec = (time_t)sec.q_s;
+#else
+ out.tv_sec = ((time_t)sec.d_s.hi << 32) | sec.d_s.lo;
+#endif
+
+ return out;
+}
+
+#endif /* TIMESPECOPS_H */
diff --git a/include/timetoa.h b/include/timetoa.h
new file mode 100644
index 0000000..2599449
--- /dev/null
+++ b/include/timetoa.h
@@ -0,0 +1,83 @@
+/*
+ * timetoa.h -- time_t related string formatting
+ *
+ * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
+ * The contents of 'html/copyright.html' apply.
+ *
+ * Printing a 'time_t' has some portability pitfalls, due to it's opaque
+ * base type. The only requirement imposed by the standard is that it
+ * must be a numeric type. For all practical purposes it's a signed int,
+ * and 32 bits are common.
+ *
+ * Since the UN*X time epoch will cause a signed integer overflow for
+ * 32-bit signed int values in the year 2038, implementations slowly
+ * move to 64bit base types for time_t, even in 32-bit environments. In
+ * such an environment sizeof(time_t) could be bigger than sizeof(long)
+ * and the commonly used idiom of casting to long leads to truncation.
+ *
+ * As the printf() family has no standardised type specifier for time_t,
+ * guessing the right output format specifier is a bit troublesome and
+ * best done with the help of the preprocessor and "config.h".
+ */
+#ifndef TIMETOA_H
+#define TIMETOA_H
+
+#include "ntp_fp.h"
+#include "ntp_stdlib.h"
+#include "ntp_unixtime.h"
+
+/*
+ * Given the size of time_t, guess what can be used as an unsigned value
+ * to hold a time_t and the printf() format specifcation.
+ *
+ * These should be used with the string constant concatenation feature
+ * of the compiler like this:
+ *
+ * printf("a time stamp: %" TIME_FORMAT " and more\n", a_time_t_value);
+ *
+ * It's not exactly nice, but there's not much leeway once we want to
+ * use the printf() family on time_t values.
+ */
+
+#if SIZEOF_TIME_T <= SIZEOF_INT
+
+typedef unsigned int u_time;
+#define TIME_FORMAT "d"
+#define UTIME_FORMAT "u"
+
+#elif SIZEOF_TIME_T <= SIZEOF_LONG
+
+typedef unsigned long u_time;
+#define TIME_FORMAT "ld"
+#define UTIME_FORMAT "lu"
+
+#elif defined(SIZEOF_LONG_LONG) && SIZEOF_TIME_T <= SIZEOF_LONG_LONG
+
+typedef unsigned long long u_time;
+#define TIME_FORMAT "lld"
+#define UTIME_FORMAT "llu"
+
+#else
+#include "GRONK: what size has a time_t here?"
+#endif
+
+/*
+ * general fractional time stamp formatting.
+ *
+ * secs - integral seconds of time stamp
+ * frac - fractional units
+ * prec - log10 of units per second (3=milliseconds, 6=microseconds,..)
+ * or in other words: the count of decimal digits required.
+ * If prec is < 0, abs(prec) is taken for the precision and secs
+ * is treated as an unsigned value.
+ *
+ * The function will eventually normalise the fraction and adjust the
+ * seconds accordingly.
+ *
+ * This function uses the string buffer library for the return value,
+ * so do not keep the resulting pointers around.
+ */
+extern const char *
+format_time_fraction(time_t secs, long frac, int prec);
+
+#endif /* !defined(TIMETOA_H) */
diff --git a/include/timevalops.h b/include/timevalops.h
new file mode 100644
index 0000000..e873b8b
--- /dev/null
+++ b/include/timevalops.h
@@ -0,0 +1,446 @@
+/*
+ * timevalops.h -- calculations on 'struct timeval' values
+ *
+ * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
+ * The contents of 'html/copyright.html' apply.
+ *
+ * For a rationale look at 'timespecops.h'; we do the same here, but the
+ * normalisation keeps the microseconds in [0 .. 10^6[, of course.
+ */
+#ifndef TIMEVALOPS_H
+#define TIMEVALOPS_H
+
+#include <sys/types.h>
+#include <stdio.h>
+
+#include "ntp.h"
+#include "timetoa.h"
+
+
+/* microseconds per second */
+#define MICROSECONDS 1000000
+
+#ifndef HAVE_U_INT64
+# define USE_TSF_USEC_TABLES
+#endif
+
+/*
+ * Convert usec to a time stamp fraction.
+ */
+#ifdef USE_TSF_USEC_TABLES
+extern const u_int32 ustotslo[];
+extern const u_int32 ustotsmid[];
+extern const u_int32 ustotshi[];
+
+# define TVUTOTSF(tvu, tsf) \
+ ((tsf) = ustotslo[(tvu) & 0xff] \
+ + ustotsmid[((tvu) >> 8) & 0xff] \
+ + ustotshi[((tvu) >> 16) & 0xf])
+#else
+# define TVUTOTSF(tvu, tsf) \
+ ((tsf) = (u_int32) \
+ ((((u_int64)(tvu) << 32) + MICROSECONDS / 2) / \
+ MICROSECONDS))
+#endif
+
+/*
+ * Convert a time stamp fraction to microseconds. The time stamp
+ * fraction is assumed to be unsigned.
+ */
+#ifdef USE_TSF_USEC_TABLES
+extern const u_int32 tstouslo[256];
+extern const u_int32 tstousmid[256];
+extern const u_int32 tstoushi[128];
+
+/*
+ * 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
+
+# define TSFTOTVU(tsf, tvu) \
+ ((tvu) = (tstoushi[((tsf) >> 24) & 0xff] \
+ + tstousmid[((tsf) >> 16) & 0xff] \
+ + tstouslo[((tsf) >> 9) & 0x7f] \
+ + TV_ROUNDBIT) >> TV_SHIFT)
+#else
+# define TSFTOTVU(tsf, tvu) \
+ ((tvu) = (int32) \
+ (((u_int64)(tsf) * MICROSECONDS + 0x80000000) >> 32))
+#endif
+
+/*
+ * 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 (FALSE)
+
+#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 (FALSE)
+
+/*
+ * 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 (FALSE)
+
+
+/*
+ * predicate: returns TRUE if the microseconds are in nominal range
+ * use like: int timeval_isnormal(const struct timeval *x)
+ */
+#define timeval_isnormal(x) \
+ ((x)->tv_usec >= 0 && (x)->tv_usec < MICROSECONDS)
+
+/*
+ * Convert milliseconds to a time stamp fraction. Unused except for
+ * refclock_leitch.c, so accompanying lookup tables were removed in
+ * favor of reusing the microseconds conversion tables.
+ */
+#define MSUTOTSF(msu, tsf) TVUTOTSF((msu) * 1000, tsf)
+
+/*
+ * predicate: returns TRUE if the microseconds are out-of-bounds
+ * use like: int timeval_isdenormal(const struct timeval *x)
+ */
+#define timeval_isdenormal(x) (!timeval_isnormal(x))
+
+/* make sure microseconds are in nominal range */
+static inline struct timeval
+normalize_tval(
+ struct timeval x
+ )
+{
+ long z;
+
+ /*
+ * If the fraction becomes excessive denormal, we use division
+ * to do first partial normalisation. The normalisation loops
+ * following will do the remaining cleanup. Since the size of
+ * tv_usec has a peculiar definition by the standard the range
+ * check is coded manually. And labs() is intentionally not used
+ * here: it has implementation-defined behaviour when applied
+ * to LONG_MIN.
+ */
+ if (x.tv_usec < -3l * MICROSECONDS ||
+ x.tv_usec > 3l * MICROSECONDS ) {
+ z = x.tv_usec / MICROSECONDS;
+ x.tv_usec -= z * MICROSECONDS;
+ x.tv_sec += z;
+ }
+
+ /*
+ * Do any remaining normalisation steps in loops. This takes 3
+ * steps max, and should outperform a division even if the
+ * mul-by-inverse trick is employed. (It also does the floor
+ * division adjustment if the above division was executed.)
+ */
+ if (x.tv_usec < 0)
+ do {
+ x.tv_usec += MICROSECONDS;
+ x.tv_sec--;
+ } while (x.tv_usec < 0);
+ else if (x.tv_usec >= MICROSECONDS)
+ do {
+ x.tv_usec -= MICROSECONDS;
+ x.tv_sec++;
+ } while (x.tv_usec >= MICROSECONDS);
+
+ return x;
+}
+
+/* x = a + b */
+static inline struct timeval
+add_tval(
+ struct timeval a,
+ struct timeval b
+ )
+{
+ struct timeval x;
+
+ x = a;
+ x.tv_sec += b.tv_sec;
+ x.tv_usec += b.tv_usec;
+
+ return normalize_tval(x);
+}
+
+/* x = a + b, b is fraction only */
+static inline struct timeval
+add_tval_us(
+ struct timeval a,
+ long b
+ )
+{
+ struct timeval x;
+
+ x = a;
+ x.tv_usec += b;
+
+ return normalize_tval(x);
+}
+
+/* x = a - b */
+static inline struct timeval
+sub_tval(
+ struct timeval a,
+ struct timeval b
+ )
+{
+ struct timeval x;
+
+ x = a;
+ x.tv_sec -= b.tv_sec;
+ x.tv_usec -= b.tv_usec;
+
+ return normalize_tval(x);
+}
+
+/* x = a - b, b is fraction only */
+static inline struct timeval
+sub_tval_us(
+ struct timeval a,
+ long b
+ )
+{
+ struct timeval x;
+
+ x = a;
+ x.tv_usec -= b;
+
+ return normalize_tval(x);
+}
+
+/* x = -a */
+static inline struct timeval
+neg_tval(
+ struct timeval a
+ )
+{
+ struct timeval x;
+
+ x.tv_sec = -a.tv_sec;
+ x.tv_usec = -a.tv_usec;
+
+ return normalize_tval(x);
+}
+
+/* x = abs(a) */
+static inline struct timeval
+abs_tval(
+ struct timeval a
+ )
+{
+ struct timeval c;
+
+ c = normalize_tval(a);
+ if (c.tv_sec < 0) {
+ if (c.tv_usec != 0) {
+ c.tv_sec = -c.tv_sec - 1;
+ c.tv_usec = MICROSECONDS - c.tv_usec;
+ } else {
+ c.tv_sec = -c.tv_sec;
+ }
+ }
+
+ return c;
+}
+
+/*
+ * compare previously-normalised a and b
+ * return 1 / 0 / -1 if a < / == / > b
+ */
+static inline int
+cmp_tval(
+ struct timeval a,
+ struct timeval b
+ )
+{
+ int r;
+
+ r = (a.tv_sec > b.tv_sec) - (a.tv_sec < b.tv_sec);
+ if (0 == r)
+ r = (a.tv_usec > b.tv_usec) -
+ (a.tv_usec < b.tv_usec);
+
+ return r;
+}
+
+/*
+ * compare possibly-denormal a and b
+ * return 1 / 0 / -1 if a < / == / > b
+ */
+static inline int
+cmp_tval_denorm(
+ struct timeval a,
+ struct timeval b
+ )
+{
+ return cmp_tval(normalize_tval(a), normalize_tval(b));
+}
+
+/*
+ * test previously-normalised a
+ * return 1 / 0 / -1 if a < / == / > 0
+ */
+static inline int
+test_tval(
+ struct timeval a
+ )
+{
+ int r;
+
+ r = (a.tv_sec > 0) - (a.tv_sec < 0);
+ if (r == 0)
+ r = (a.tv_usec > 0);
+
+ return r;
+}
+
+/*
+ * test possibly-denormal a
+ * return 1 / 0 / -1 if a < / == / > 0
+ */
+static inline int
+test_tval_denorm(
+ struct timeval a
+ )
+{
+ return test_tval(normalize_tval(a));
+}
+
+/* return LIB buffer ptr to string rep */
+static inline const char *
+tvaltoa(
+ struct timeval x
+ )
+{
+ return format_time_fraction(x.tv_sec, x.tv_usec, 6);
+}
+
+/* convert from timeval duration to l_fp duration */
+static inline l_fp
+tval_intv_to_lfp(
+ struct timeval x
+ )
+{
+ struct timeval v;
+ l_fp y;
+
+ v = normalize_tval(x);
+ TVUTOTSF(v.tv_usec, y.l_uf);
+ y.l_i = (int32)v.tv_sec;
+
+ return y;
+}
+
+/* x must be UN*X epoch, output *y will be in NTP epoch */
+static inline l_fp
+tval_stamp_to_lfp(
+ struct timeval x
+ )
+{
+ l_fp y;
+
+ y = tval_intv_to_lfp(x);
+ y.l_ui += JAN_1970;
+
+ return y;
+}
+
+/* convert to l_fp type, relative signed/unsigned and absolute */
+static inline struct timeval
+lfp_intv_to_tval(
+ l_fp x
+ )
+{
+ struct timeval out;
+ l_fp absx;
+ int neg;
+
+ neg = L_ISNEG(&x);
+ absx = x;
+ if (neg) {
+ L_NEG(&absx);
+ }
+ TSFTOTVU(absx.l_uf, out.tv_usec);
+ out.tv_sec = absx.l_i;
+ if (neg) {
+ out.tv_sec = -out.tv_sec;
+ out.tv_usec = -out.tv_usec;
+ out = normalize_tval(out);
+ }
+
+ return out;
+}
+
+static inline struct timeval
+lfp_uintv_to_tval(
+ l_fp x
+ )
+{
+ struct timeval out;
+
+ TSFTOTVU(x.l_uf, out.tv_usec);
+ out.tv_sec = x.l_ui;
+
+ return out;
+}
+
+/*
+ * absolute (timestamp) conversion. Input is time in NTP epoch, output
+ * is in UN*X epoch. The NTP time stamp will be expanded around the
+ * pivot time *p or the current time, if p is NULL.
+ */
+static inline struct timeval
+lfp_stamp_to_tval(
+ l_fp x,
+ const time_t * p
+ )
+{
+ struct timeval out;
+ vint64 sec;
+
+ sec = ntpcal_ntp_to_time(x.l_ui, p);
+ TSFTOTVU(x.l_uf, out.tv_usec);
+
+ /* copying a vint64 to a time_t needs some care... */
+#if SIZEOF_TIME_T <= 4
+ out.tv_sec = (time_t)sec.d_s.lo;
+#elif defined(HAVE_INT64)
+ out.tv_sec = (time_t)sec.q_s;
+#else
+ out.tv_sec = ((time_t)sec.d_s.hi << 32) | sec.d_s.lo;
+#endif
+ out = normalize_tval(out);
+
+ return out;
+}
+
+#endif /* TIMEVALOPS_H */
diff --git a/include/trimble.h b/include/trimble.h
new file mode 100644
index 0000000..aaa5baa
--- /dev/null
+++ b/include/trimble.h
@@ -0,0 +1,160 @@
+/*
+ * /src/NTP/ntp4-dev/include/trimble.h,v 4.6 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ *
+ * trimble.h,v 4.6 2005/04/16 17:32:10 kardel RELEASE_20050508_A
+ *
+ * $Created: Sun Aug 2 16:16:49 1998 $
+ *
+ * Copyright (c) 1998-2005 by Frank Kardel <kardel <AT> ntp.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#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 (unsigned int cmd, cmd_info_t *tbl);
+
+#endif
+/*
+ * History:
+ *
+ * trimble.h,v
+ * Revision 4.6 2005/04/16 17:32:10 kardel
+ * update copyright
+ *
+ * Revision 4.5 2004/11/14 15:29:41 kardel
+ * support PPSAPI, upgrade Copyright to Berkeley style
+ *
+ * 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
+ *
+ */
diff --git a/include/vint64ops.h b/include/vint64ops.h
new file mode 100644
index 0000000..2c3deff
--- /dev/null
+++ b/include/vint64ops.h
@@ -0,0 +1,28 @@
+/*
+ * vint64ops.h - operations on 'vint64' values
+ *
+ * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
+ * The contents of 'html/copyright.html' apply.
+ * ----------------------------------------------------------------------
+ * This is an attempt to get the vint64 calculations stuff centralised.
+ */
+#ifndef VINT64OPS_H
+#define VINT64OPS_H
+
+/* signed/unsigned compare. returns 1/0/-1 if lhs >/=/< rhs */
+extern int icmpv64(const vint64 * lhs, const vint64 * rhs);
+extern int ucmpv64(const vint64 * lhs, const vint64 * rhs);
+
+/* add / subtract */
+extern vint64 addv64(const vint64 *lhs, const vint64 *rhs);
+extern vint64 addv64i32(const vint64 * lhs, int32_t rhs);
+extern vint64 addv64u32(const vint64 * lhs, uint32_t rhs);
+
+extern vint64 subv64(const vint64 *lhs, const vint64 *rhs);
+extern vint64 subv64i32(const vint64 * lhs, int32_t rhs);
+extern vint64 subv64u32(const vint64 * lhs, uint32_t rhs);
+
+/* parsing. works like strtoul() or strtoull() */
+extern vint64 strtouv64(const char * begp, char ** endp, int base);
+
+#endif /*!defined(VINT64OPS_H)*/