summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/ntpdate
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2015-07-15 19:21:26 +0000
committerdelphij <delphij@FreeBSD.org>2015-07-15 19:21:26 +0000
commit2a25cee78ab1d37e7d2bc40ae675646974d99f56 (patch)
treeb0302ac4be59e104f4e1e54014561a1389397192 /contrib/ntp/ntpdate
parenta0741a75537b2e0514472ac3b28afc55a7846c30 (diff)
downloadFreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.zip
FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.tar.gz
MFC r280849,280915-280916,281015-281016,282097,282408,282415,283542,
284864,285169-285170,285435: ntp 4.2.8p3. Relnotes: yes Approved by: re (?)
Diffstat (limited to 'contrib/ntp/ntpdate')
-rw-r--r--contrib/ntp/ntpdate/Makefile.am48
-rw-r--r--contrib/ntp/ntpdate/Makefile.in740
-rw-r--r--contrib/ntp/ntpdate/ntpdate.c510
-rw-r--r--contrib/ntp/ntpdate/ntpdate.h14
-rw-r--r--contrib/ntp/ntpdate/ntptime_config.c552
-rw-r--r--contrib/ntp/ntpdate/ntptimeset.c2164
6 files changed, 851 insertions, 3177 deletions
diff --git a/contrib/ntp/ntpdate/Makefile.am b/contrib/ntp/ntpdate/Makefile.am
index 3372f49..774cf29 100644
--- a/contrib/ntp/ntpdate/Makefile.am
+++ b/contrib/ntp/ntpdate/Makefile.am
@@ -1,28 +1,40 @@
-#AUTOMAKE_OPTIONS= ../util/ansi2knr
+NULL =
-bindir= ${exec_prefix}/${BINSUBDIR}
-#bin_PROGRAMS= ntpdate ntptimeset
-bin_PROGRAMS= ntpdate
-EXTRA_PROGRAMS= ntptimeset
+BUILT_SOURCES =
+CLEANFILES =
+
+bin_PROGRAMS = $(NTPDATE_DB)
+libexec_PROGRAMS = $(NTPDATE_DL)
+sbin_PROGRAMS = $(NTPDATE_DS)
+
+EXTRA_PROGRAMS = ntpdate
+
+AM_CFLAGS = $(CFLAGS_NTP)
+
+AM_CPPFLAGS = $(NTP_INCS)
+AM_CPPFLAGS += $(CPPFLAGS_NTP)
+
+AM_LDFLAGS = $(LDFLAGS_NTP)
-ntptimeset_SOURCES= ntptimeset.c ntptime_config.c
-AM_CPPFLAGS= -I$(top_srcdir)/include
# LDADD might need RESLIB and ADJLIB
-LDADD= version.o ../libntp/libntp.a
+LDADD = version.o ../libntp/libntp.a
+ntpdate_LDADD = $(LDADD) $(LDADD_LIBNTP) $(PTHREAD_LIBS) $(LIBOPTS_LDADD)
+ntpdate_LDADD += $(LIBM) $(LDADD_NTP)
DISTCLEANFILES= .version version.c stamp-v
noinst_HEADERS= ntpdate.h
-ETAGS_ARGS= Makefile.am
$(PROGRAMS): $(LDADD)
-../libntp/libntp.a:
- cd ../libntp && $(MAKE)
-
-$(top_srcdir)/version :
- cd $(top_srcdir) && $(MAKE) version
+$(top_srcdir)/sntp/scm-rev:
+ cd ../sntp && $(MAKE) $(AM_MAKEFLAGS) check-scm-rev
-version.o: $(ntpdate_OBJECTS) ../libntp/libntp.a Makefile $(top_srcdir)/version
- env CSET=`cat $(top_srcdir)/version` $(top_builddir)/scripts/mkver ntpdate
- $(COMPILE) -c version.c
+version.c: $(ntpdate_OBJECTS) ../libntp/libntp.a Makefile $(top_srcdir)/sntp/scm-rev
+ env CSET=`cat $(top_srcdir)/sntp/scm-rev` $(top_builddir)/scripts/build/mkver ntpdate
+
+version.o: version.c
+ env CCACHE_DISABLE=1 $(COMPILE) -c version.c -o version.o
-include ../bincheck.mf
+include $(top_srcdir)/bincheck.mf
+include $(top_srcdir)/sntp/check-libntp.mf
+include $(top_srcdir)/depsver.mf
+include $(top_srcdir)/includes.mf
diff --git a/contrib/ntp/ntpdate/Makefile.in b/contrib/ntp/ntpdate/Makefile.in
index d127815..feae7e4 100644
--- a/contrib/ntp/ntpdate/Makefile.in
+++ b/contrib/ntp/ntpdate/Makefile.in
@@ -1,9 +1,8 @@
-# Makefile.in generated by automake 1.11 from Makefile.am.
+# Makefile.in generated by automake 1.15 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.
+# Copyright (C) 1994-2014 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.
@@ -15,14 +14,67 @@
@SET_MAKE@
-#AUTOMAKE_OPTIONS= ../util/ansi2knr
-
# we traditionally installed software in bindir, while it should have gone
# in sbindir. Now that we offer a choice, look in the "other" installation
# subdir to warn folks if there is another version there.
VPATH = @srcdir@
+am__is_gnu_make = { \
+ if test -z '$(MAKELEVEL)'; then \
+ false; \
+ elif test -n '$(MAKE_HOST)'; then \
+ true; \
+ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+ true; \
+ else \
+ false; \
+ fi; \
+}
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
+ esac; \
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
@@ -41,89 +93,200 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
-bin_PROGRAMS = ntpdate$(EXEEXT)
-EXTRA_PROGRAMS = ntptimeset$(EXEEXT)
-DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/../bincheck.mf \
- $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+EXTRA_PROGRAMS = ntpdate$(EXEEXT)
subdir = ntpdate
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/libopts/m4/libopts.m4 \
- $(top_srcdir)/m4/define_dir.m4 \
- $(top_srcdir)/m4/hs_ulong_const.m4 \
- $(top_srcdir)/m4/os_cflags.m4 $(top_srcdir)/version.m4 \
- $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/sntp/libopts/m4/libopts.m4 \
+ $(top_srcdir)/sntp/libopts/m4/stdnoreturn.m4 \
+ $(top_srcdir)/sntp/m4/ax_c99_struct_init.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_crypto_rand.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_unitytest.m4 \
+ $(top_srcdir)/sntp/m4/ntp_ver_suffix.m4 \
+ $(top_srcdir)/sntp/m4/ntp_vpathhack.m4 \
+ $(top_srcdir)/sntp/m4/openldap-thread-check.m4 \
+ $(top_srcdir)/sntp/m4/openldap.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)
+DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \
+ $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
-am__installdirs = "$(DESTDIR)$(bindir)"
-PROGRAMS = $(bin_PROGRAMS)
+am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(libexecdir)" \
+ "$(DESTDIR)$(sbindir)"
+PROGRAMS = $(bin_PROGRAMS) $(libexec_PROGRAMS) $(sbin_PROGRAMS)
ntpdate_SOURCES = ntpdate.c
ntpdate_OBJECTS = ntpdate.$(OBJEXT)
-ntpdate_LDADD = $(LDADD)
-ntpdate_DEPENDENCIES = version.o ../libntp/libntp.a
-am_ntptimeset_OBJECTS = ntptimeset.$(OBJEXT) ntptime_config.$(OBJEXT)
-ntptimeset_OBJECTS = $(am_ntptimeset_OBJECTS)
-ntptimeset_LDADD = $(LDADD)
-ntptimeset_DEPENDENCIES = version.o ../libntp/libntp.a
+am__DEPENDENCIES_1 =
+ntpdate_DEPENDENCIES = $(LDADD) $(am__DEPENDENCIES_1) \
+ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 =
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
-depcomp = $(SHELL) $(top_srcdir)/depcomp
+depcomp = $(SHELL) $(top_srcdir)/sntp/libevent/build-aux/depcomp
am__depfiles_maybe = depfiles
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
- --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
- $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
CCLD = $(CC)
-LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
- --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
- $(LDFLAGS) -o $@
-SOURCES = ntpdate.c $(ntptimeset_SOURCES)
-DIST_SOURCES = ntpdate.c $(ntptimeset_SOURCES)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
+SOURCES = ntpdate.c
+DIST_SOURCES = ntpdate.c
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
HEADERS = $(noinst_HEADERS)
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
+am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/bincheck.mf \
+ $(top_srcdir)/depsver.mf $(top_srcdir)/includes.mf \
+ $(top_srcdir)/sntp/check-libntp.mf \
+ $(top_srcdir)/sntp/libevent/build-aux/depcomp README
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
-ARLIB_DIR = @ARLIB_DIR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
-BINSUBDIR = @BINSUBDIR@
+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@
-CLKTEST = @CLKTEST@
+CONFIG_SHELL = @CONFIG_SHELL@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
+CPPFLAGS_LIBEVENT = @CPPFLAGS_LIBEVENT@
+CPPFLAGS_NTP = @CPPFLAGS_NTP@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DCFD = @DCFD@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
-ECHO = @ECHO@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
-EF_LIBS = @EF_LIBS@
-EF_PROGS = @EF_PROGS@
+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_LEAPSMEARINTERVAL = @HAVE_LEAPSMEARINTERVAL@
+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@
-LCRYPTO = @LCRYPTO@
+LD = @LD@
+LDADD_LIBEVENT = @LDADD_LIBEVENT@
+LDADD_LIBNTP = @LDADD_LIBNTP@
+LDADD_LIBUTIL = @LDADD_LIBUTIL@
+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@
@@ -131,6 +294,8 @@ LIBOPTS_LDADD = @LIBOPTS_LDADD@
LIBPARSE = @LIBPARSE@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIPO = @LIPO@
LN_S = @LN_S@
LSCF = @LSCF@
LTLIBOBJS = @LTLIBOBJS@
@@ -142,15 +307,76 @@ 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@
-OPENSSL = @OPENSSL@
-OPENSSL_INC = @OPENSSL_INC@
-OPENSSL_LIB = @OPENSSL_LIB@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
@@ -158,29 +384,65 @@ 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_RUBY = @PATH_RUBY@
PATH_SEPARATOR = @PATH_SEPARATOR@
-PATH_SH = @PATH_SH@
+PATH_TEST = @PATH_TEST@
+PERLLIBDIR = @PERLLIBDIR@
+PKG_CONFIG = @PKG_CONFIG@
+POSIX_SHELL = @POSIX_SHELL@
PROPDELAY = @PROPDELAY@
+PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@
-READLINE_LIBS = @READLINE_LIBS@
+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@
-U = @U@
+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@
+UPDATE_LEAP_DB = @UPDATE_LEAP_DB@
+UPDATE_LEAP_DL = @UPDATE_LEAP_DL@
+UPDATE_LEAP_DS = @UPDATE_LEAP_DS@
+UPDATE_LEAP_MS = @UPDATE_LEAP_MS@
+UPDATE_LEAP_NI = @UPDATE_LEAP_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 = ${exec_prefix}/${BINSUBDIR}
+bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
@@ -221,18 +483,31 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-ntptimeset_SOURCES = ntptimeset.c ntptime_config.c
-AM_CPPFLAGS = -I$(top_srcdir)/include
+NULL =
+BUILT_SOURCES = check-libntp .deps-ver
+CLEANFILES = check-libntp .deps-ver
+bin_PROGRAMS = $(NTPDATE_DB)
+libexec_PROGRAMS = $(NTPDATE_DL)
+sbin_PROGRAMS = $(NTPDATE_DS)
+AM_CFLAGS = $(CFLAGS_NTP)
+AM_CPPFLAGS = $(NTP_INCS) $(CPPFLAGS_NTP)
+AM_LDFLAGS = $(LDFLAGS_NTP)
+
# LDADD might need RESLIB and ADJLIB
LDADD = version.o ../libntp/libntp.a
+ntpdate_LDADD = $(LDADD) $(LDADD_LIBNTP) $(PTHREAD_LIBS) \
+ $(LIBOPTS_LDADD) $(LIBM) $(LDADD_NTP)
DISTCLEANFILES = .version version.c stamp-v
noinst_HEADERS = ntpdate.h
-ETAGS_ARGS = Makefile.am
-all: all-am
+NTP_INCS = -I$(top_srcdir)/include -I$(top_srcdir)/lib/isc/include \
+ -I$(top_srcdir)/lib/isc/$(LIBISC_PTHREADS_NOTHREADS)/include \
+ -I$(top_srcdir)/lib/isc/unix/include
+all: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
-$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(srcdir)/../bincheck.mf $(am__configure_deps)
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/bincheck.mf $(top_srcdir)/sntp/check-libntp.mf $(top_srcdir)/depsver.mf $(top_srcdir)/includes.mf $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
@@ -244,7 +519,6 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(srcdir)/../bincheck.mf $(am__con
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign ntpdate/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --foreign ntpdate/Makefile
-.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
@@ -253,6 +527,7 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
+$(top_srcdir)/bincheck.mf $(top_srcdir)/sntp/check-libntp.mf $(top_srcdir)/depsver.mf $(top_srcdir)/includes.mf $(am__empty):
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
@@ -264,14 +539,19 @@ $(ACLOCAL_M4): $(am__aclocal_m4_deps)
$(am__aclocal_m4_deps):
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
- test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \
+ fi; \
for p in $$list; do echo "$$p $$p"; done | \
sed 's/$(EXEEXT)$$//' | \
- while read p p1; do if test -f $$p || test -f $$p1; \
- then echo "$$p"; echo "$$p"; else :; fi; \
+ while read p p1; do if test -f $$p \
+ || test -f $$p1 \
+ ; then echo "$$p"; echo "$$p"; else :; fi; \
done | \
- sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \
+ sed -e 'p;s,.*/,,;n;h' \
+ -e 's|.*|.|' \
-e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
sed 'N;N;N;s,\n, ,g' | \
$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
@@ -292,7 +572,8 @@ uninstall-binPROGRAMS:
@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
files=`for p in $$list; do echo "$$p"; done | \
sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
- -e 's/$$/$(EXEEXT)/' `; \
+ -e 's/$$/$(EXEEXT)/' \
+ `; \
test -n "$$list" || exit 0; \
echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
cd "$(DESTDIR)$(bindir)" && rm -f $$files
@@ -305,12 +586,108 @@ clean-binPROGRAMS:
list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
echo " rm -f" $$list; \
rm -f $$list
-ntpdate$(EXEEXT): $(ntpdate_OBJECTS) $(ntpdate_DEPENDENCIES)
+install-libexecPROGRAMS: $(libexec_PROGRAMS)
+ @$(NORMAL_INSTALL)
+ @list='$(libexec_PROGRAMS)'; test -n "$(libexecdir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(libexecdir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(libexecdir)" || exit 1; \
+ fi; \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed 's/$(EXEEXT)$$//' | \
+ while read p p1; do if test -f $$p \
+ || test -f $$p1 \
+ ; then echo "$$p"; echo "$$p"; else :; fi; \
+ done | \
+ sed -e 'p;s,.*/,,;n;h' \
+ -e 's|.*|.|' \
+ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+ sed 'N;N;N;s,\n, ,g' | \
+ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+ if ($$2 == $$4) files[d] = files[d] " " $$1; \
+ else { print "f", $$3 "/" $$4, $$1; } } \
+ END { for (d in files) print "f", d, files[d] }' | \
+ while read type dir files; do \
+ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+ test -z "$$files" || { \
+ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(libexecdir)$$dir'"; \
+ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(libexecdir)$$dir" || exit $$?; \
+ } \
+ ; done
+
+uninstall-libexecPROGRAMS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(libexec_PROGRAMS)'; test -n "$(libexecdir)" || list=; \
+ files=`for p in $$list; do echo "$$p"; done | \
+ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+ -e 's/$$/$(EXEEXT)/' \
+ `; \
+ test -n "$$list" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(libexecdir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(libexecdir)" && rm -f $$files
+
+clean-libexecPROGRAMS:
+ @list='$(libexec_PROGRAMS)'; test -n "$$list" || exit 0; \
+ echo " rm -f" $$list; \
+ rm -f $$list || exit $$?; \
+ test -n "$(EXEEXT)" || exit 0; \
+ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f" $$list; \
+ rm -f $$list
+install-sbinPROGRAMS: $(sbin_PROGRAMS)
+ @$(NORMAL_INSTALL)
+ @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(sbindir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(sbindir)" || exit 1; \
+ fi; \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed 's/$(EXEEXT)$$//' | \
+ while read p p1; do if test -f $$p \
+ || test -f $$p1 \
+ ; then echo "$$p"; echo "$$p"; else :; fi; \
+ done | \
+ sed -e 'p;s,.*/,,;n;h' \
+ -e 's|.*|.|' \
+ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+ sed 'N;N;N;s,\n, ,g' | \
+ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+ if ($$2 == $$4) files[d] = files[d] " " $$1; \
+ else { print "f", $$3 "/" $$4, $$1; } } \
+ END { for (d in files) print "f", d, files[d] }' | \
+ while read type dir files; do \
+ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+ test -z "$$files" || { \
+ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(sbindir)$$dir'"; \
+ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(sbindir)$$dir" || exit $$?; \
+ } \
+ ; done
+
+uninstall-sbinPROGRAMS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \
+ files=`for p in $$list; do echo "$$p"; done | \
+ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+ -e 's/$$/$(EXEEXT)/' \
+ `; \
+ test -n "$$list" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(sbindir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(sbindir)" && rm -f $$files
+
+clean-sbinPROGRAMS:
+ @list='$(sbin_PROGRAMS)'; test -n "$$list" || exit 0; \
+ echo " rm -f" $$list; \
+ rm -f $$list || exit $$?; \
+ test -n "$(EXEEXT)" || exit 0; \
+ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f" $$list; \
+ rm -f $$list
+
+ntpdate$(EXEEXT): $(ntpdate_OBJECTS) $(ntpdate_DEPENDENCIES) $(EXTRA_ntpdate_DEPENDENCIES)
@rm -f ntpdate$(EXEEXT)
- $(LINK) $(ntpdate_OBJECTS) $(ntpdate_LDADD) $(LIBS)
-ntptimeset$(EXEEXT): $(ntptimeset_OBJECTS) $(ntptimeset_DEPENDENCIES)
- @rm -f ntptimeset$(EXEEXT)
- $(LINK) $(ntptimeset_OBJECTS) $(ntptimeset_LDADD) $(LIBS)
+ $(AM_V_CCLD)$(LINK) $(ntpdate_OBJECTS) $(ntpdate_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@@ -319,29 +696,27 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpdate.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntptime_config.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntptimeset.Po@am__quote@
.c.o:
-@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
.c.obj:
-@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
-@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
.c.lo:
-@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
@@ -349,26 +724,15 @@ mostlyclean-libtool:
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)
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
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; }; }'`; \
+ $(am__define_uniq_tagged_files); \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
@@ -380,15 +744,11 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$$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; }; }'`; \
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
@@ -397,6 +757,21 @@ GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
@@ -432,13 +807,15 @@ distdir: $(DISTFILES)
fi; \
done
check-am: all-am
-check: check-am
+check: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) check-am
all-am: Makefile $(PROGRAMS) $(HEADERS)
installdirs:
- for dir in "$(DESTDIR)$(bindir)"; do \
+ for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(libexecdir)" "$(DESTDIR)$(sbindir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
-install: install-am
+install: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
@@ -448,13 +825,19 @@ install-am: all-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
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
mostlyclean-generic:
clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
@@ -464,9 +847,11 @@ distclean-generic:
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
+ -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
clean: clean-am
-clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
+clean-am: clean-binPROGRAMS clean-generic clean-libexecPROGRAMS \
+ clean-libtool clean-sbinPROGRAMS mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
@@ -492,7 +877,8 @@ install-dvi: install-dvi-am
install-dvi-am:
-install-exec-am: install-binPROGRAMS
+install-exec-am: install-binPROGRAMS install-libexecPROGRAMS \
+ install-sbinPROGRAMS
@$(NORMAL_INSTALL)
$(MAKE) $(AM_MAKEFLAGS) install-exec-hook
install-html: install-html-am
@@ -533,49 +919,119 @@ ps: ps-am
ps-am:
-uninstall-am: uninstall-binPROGRAMS
-
-.MAKE: install-am install-exec-am install-strip
+uninstall-am: uninstall-binPROGRAMS uninstall-libexecPROGRAMS \
+ uninstall-sbinPROGRAMS
+
+.MAKE: all check install install-am install-exec-am install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean \
+ clean-binPROGRAMS clean-generic clean-libexecPROGRAMS \
+ clean-libtool clean-sbinPROGRAMS cscopelist-am ctags ctags-am \
+ distclean distclean-compile distclean-generic \
+ distclean-libtool distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-binPROGRAMS \
+ install-data install-data-am install-dvi install-dvi-am \
+ install-exec install-exec-am install-exec-hook install-html \
+ install-html-am install-info install-info-am \
+ install-libexecPROGRAMS install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-sbinPROGRAMS install-strip \
+ installcheck installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags tags-am uninstall uninstall-am uninstall-binPROGRAMS \
+ uninstall-libexecPROGRAMS uninstall-sbinPROGRAMS
-.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
- clean-generic clean-libtool ctags distclean distclean-compile \
- distclean-generic distclean-libtool distclean-tags distdir dvi \
- dvi-am html html-am info info-am install install-am \
- install-binPROGRAMS install-data install-data-am install-dvi \
- install-dvi-am install-exec install-exec-am install-exec-hook \
- 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-compile mostlyclean-generic \
- mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \
- uninstall-am uninstall-binPROGRAMS
+.PRECIOUS: Makefile
$(PROGRAMS): $(LDADD)
-../libntp/libntp.a:
- cd ../libntp && $(MAKE)
+$(top_srcdir)/sntp/scm-rev:
+ cd ../sntp && $(MAKE) $(AM_MAKEFLAGS) check-scm-rev
-$(top_srcdir)/version :
- cd $(top_srcdir) && $(MAKE) version
+version.c: $(ntpdate_OBJECTS) ../libntp/libntp.a Makefile $(top_srcdir)/sntp/scm-rev
+ env CSET=`cat $(top_srcdir)/sntp/scm-rev` $(top_builddir)/scripts/build/mkver ntpdate
-version.o: $(ntpdate_OBJECTS) ../libntp/libntp.a Makefile $(top_srcdir)/version
- env CSET=`cat $(top_srcdir)/version` $(top_builddir)/scripts/mkver ntpdate
- $(COMPILE) -c version.c
+version.o: version.c
+ env CCACHE_DISABLE=1 $(COMPILE) -c version.c -o version.o
install-exec-hook:
- @case ${BINSUBDIR} in \
- bin) ODIR=${exec_prefix}/sbin ;; \
- sbin) ODIR=${exec_prefix}/bin ;; \
- esac; \
- test -z "${bin_PROGRAMS}${bin_SCRIPTS}" \
- || for i in ${bin_PROGRAMS} ${bin_SCRIPTS} " "; do \
- test ! -f $$ODIR/$$i || echo "*** $$i is also in $$ODIR!"; \
+ @test -z "${bin_PROGRAMS}${bin_SCRIPTS}" \
+ || for i in ${bin_PROGRAMS} ${bin_SCRIPTS} " "; do \
+ test ! -f ${sbindir}/$$i \
+ || echo "*** $$i is also in ${sbindir}!"; \
+ done
+ @test -z "${sbin_PROGRAMS}${asbin_SCRIPTS}" \
+ || for i in ${sbin_PROGRAMS} ${sbin_SCRIPTS} " "; do \
+ test ! -f ${bindir}/$$i \
+ || echo "*** $$i is also in ${bindir}!"; \
done
#
+check-libntp: ../libntp/libntp.a
+ @echo stamp > $@
+
+../libntp/libntp.a:
+ cd ../libntp && $(MAKE) $(AM_MAKEFLAGS) libntp.a
+$(DEPDIR)/deps-ver: $(top_srcdir)/deps-ver
+ @[ -f $@ ] || \
+ cp $(top_srcdir)/deps-ver $@
+ @[ -w $@ ] || \
+ chmod ug+w $@
+ @cmp $(top_srcdir)/deps-ver $@ > /dev/null || ( \
+ $(MAKE) $(AM_MAKEFLAGS) clean && \
+ echo -n "Prior $(subdir)/$(DEPDIR) version " && \
+ cat $@ && \
+ rm -rf $(DEPDIR) && \
+ mkdir $(DEPDIR) && \
+ case "$(top_builddir)" in \
+ .) \
+ ./config.status Makefile depfiles \
+ ;; \
+ *) \
+ cd "$(top_builddir)" && \
+ ./config.status $(subdir)/Makefile depfiles && \
+ cd $(subdir) \
+ ;; \
+ esac && \
+ echo -n "Cleaned $(subdir)/$(DEPDIR) version " && \
+ cat $(top_srcdir)/deps-ver \
+ )
+ cp $(top_srcdir)/deps-ver $@
+
+.deps-ver: $(top_srcdir)/deps-ver
+ @[ ! -d $(DEPDIR) ] || $(MAKE) $(AM_MAKEFLAGS) $(DEPDIR)/deps-ver
+ @touch $@
+
+#
+# depsver.mf included in Makefile.am for directories with .deps
+#
+# When building in the same directory with sources that change over
+# time, such as when tracking using bk, the .deps files can become
+# stale with respect to moved, deleted, or superceded headers. Most
+# commonly, this would exhibit as make reporting a failure to make a
+# header file which is no longer in the location given. To address
+# this issue, we use a deps-ver file which is updated with each change
+# that breaks old .deps files. A copy of deps-ver is made into
+# $(DEPDIR) if not already present. If $(DEPDIR)/deps-ver is present
+# with different contents than deps-ver, we make clean to ensure all
+# .o files built before the incompatible change are rebuilt along with
+# their updated .deps files, then remove $(DEPDIR) and recreate it as
+# empty stubs.
+#
+# It is normal when configured with --disable-dependency-tracking for
+# the DEPDIR to not have been created. For this reason, we use the
+# intermediate target .deps-ver, which invokes make recursively if
+# DEPDIR exists.
+#
+# If you modify depsver.mf, please make the changes to the master
+# copy, the one in sntp is copied by the bootstrap script from it.
+#
+# This comment block follows rather than leads the related code so that
+# it stays with it in the generated Makefile.in and Makefile.
+#
+
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
diff --git a/contrib/ntp/ntpdate/ntpdate.c b/contrib/ntp/ntpdate/ntpdate.c
index a0a90ce..08edc8b 100644
--- a/contrib/ntp/ntpdate/ntpdate.c
+++ b/contrib/ntp/ntpdate/ntpdate.c
@@ -14,15 +14,14 @@
#include "ntp_fp.h"
#include "ntp.h"
#include "ntp_io.h"
-#include "ntp_unixtime.h"
+#include "timevalops.h"
#include "ntpdate.h"
#include "ntp_string.h"
#include "ntp_syslog.h"
#include "ntp_select.h"
#include "ntp_stdlib.h"
+#include <ssl_applink.c>
-/* Don't include ISC's version of IPv6 variables and structures */
-#define ISC_IPV6_H 1
#include "isc/net.h"
#include "isc/result.h"
#include "isc/sockaddr.h"
@@ -37,19 +36,15 @@
#ifdef HAVE_POLL_H
# include <poll.h>
#endif
-#ifndef SYS_WINNT
-# ifdef HAVE_SYS_SIGNAL_H
-# include <sys/signal.h>
-# else
-# include <signal.h>
-# endif
-# ifdef HAVE_SYS_IOCTL_H
-# include <sys/ioctl.h>
-# endif
-#endif /* SYS_WINNT */
+#ifdef HAVE_SYS_SIGNAL_H
+# include <sys/signal.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+# include <sys/ioctl.h>
+#endif
#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
-#endif /* HAVE_SYS_RESOURCE_H */
+#endif
#include <arpa/inet.h>
@@ -63,9 +58,9 @@ struct timeval timeout = {0,0};
#elif defined(SYS_WINNT)
/*
* Windows does not abort a select select call if SIGALRM goes off
- * so a 200 ms timeout is needed
+ * so a 200 ms timeout is needed (TIMER_HZ is 5).
*/
-struct timeval timeout = {0,1000000/TIMER_HZ};
+struct sock_timeval timeout = {0,1000000/TIMER_HZ};
#else
struct timeval timeout = {60,0};
#endif
@@ -77,9 +72,6 @@ struct timeval timeout = {60,0};
#include "recvbuff.h"
#ifdef SYS_WINNT
-#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
-#define EAFNOSUPPORT WSAEAFNOSUPPORT
-#define EPFNOSUPPORT WSAEPFNOSUPPORT
#define TARGET_RESOLUTION 1 /* Try for 1-millisecond accuracy
on Windows NT timers. */
#pragma comment(lib, "winmm")
@@ -96,7 +88,7 @@ UINT wTimerRes;
# define NTPDATE_PRIO (100)
#endif
-#if defined(HAVE_TIMER_SETTIME) || defined (HAVE_TIMER_CREATE)
+#ifdef HAVE_TIMER_CREATE
/* POSIX TIMERS - vxWorks doesn't have itimer - casey */
static timer_t ntpdate_timerid;
#endif
@@ -118,18 +110,13 @@ static timer_t ntpdate_timerid;
s_char sys_precision; /* local clock precision (log2 s) */
/*
- * Debugging flag
- */
-volatile int debug = 0;
-
-/*
* File descriptor masks etc. for call to select
*/
int ai_fam_templ;
-int nbsock; /* the number of sockets used */
+int nbsock; /* the number of sockets used */
SOCKET fd[MAX_AF];
-int fd_family[MAX_AF]; /* to remember the socket family */
+int fd_family[MAX_AF]; /* to remember the socket family */
#ifdef HAVE_POLL_H
struct pollfd fdmask[MAX_AF];
#else
@@ -211,35 +198,34 @@ int verbose = 0;
int always_step = 0;
int never_step = 0;
-int ntpdatemain P((int, char **));
-
-static void transmit P((struct server *));
-static void receive P((struct recvbuf *));
-static void server_data P((struct server *, s_fp, l_fp *, u_fp));
-static void clock_filter P((struct server *));
-static struct server *clock_select P((void));
-static int clock_adjust P((void));
-static void addserver P((char *));
-static struct server *findserver P((struct sockaddr_storage *));
-void timer P((void));
-static void init_alarm P((void));
+int ntpdatemain (int, char **);
+
+static void transmit (struct server *);
+static void receive (struct recvbuf *);
+static void server_data (struct server *, s_fp, l_fp *, u_fp);
+static void clock_filter (struct server *);
+static struct server *clock_select (void);
+static int clock_adjust (void);
+static void addserver (char *);
+static struct server *findserver (sockaddr_u *);
+ void timer (void);
+static void init_alarm (void);
#ifndef SYS_WINNT
-static RETSIGTYPE alarming P((int));
+static RETSIGTYPE alarming (int);
#endif /* SYS_WINNT */
-static void init_io P((void));
-static void sendpkt P((struct sockaddr_storage *, struct pkt *, int));
-void input_handler P((void));
+static void init_io (void);
+static void sendpkt (sockaddr_u *, struct pkt *, int);
+void input_handler (void);
-static int l_adj_systime P((l_fp *));
-static int l_step_systime P((l_fp *));
+static int l_adj_systime (l_fp *);
+static int l_step_systime (l_fp *);
-static void printserver P((struct server *, FILE *));
+static void printserver (struct server *, FILE *);
#ifdef SYS_WINNT
int on = 1;
WORD wVersionRequested;
WSADATA wsaData;
-HANDLE TimerThreadHandle = NULL;
#endif /* SYS_WINNT */
#ifdef NO_MAIN_ALLOWED
@@ -299,7 +285,7 @@ void clear_globals()
#endif
#ifdef HAVE_NETINFO
-static ni_namelist *getnetinfoservers P((void));
+static ni_namelist *getnetinfoservers (void);
#endif
/*
@@ -335,31 +321,23 @@ ntpdatemain (
ni_namelist *netinfoservers;
#endif
#ifdef SYS_WINNT
- HANDLE process_handle;
-
- wVersionRequested = MAKEWORD(1,1);
- if (WSAStartup(wVersionRequested, &wsaData)) {
- netsyslog(LOG_ERR, "No useable winsock.dll: %m");
- exit(1);
- }
-
key_file = key_file_storage;
if (!ExpandEnvironmentStrings(KEYFILE, key_file, MAX_PATH))
- {
- msyslog(LOG_ERR, "ExpandEnvironmentStrings(KEYFILE) failed: %m\n");
- }
+ msyslog(LOG_ERR, "ExpandEnvironmentStrings(KEYFILE) failed: %m");
+
+ ssl_applink();
#endif /* SYS_WINNT */
#ifdef NO_MAIN_ALLOWED
clear_globals();
#endif
+ init_lib(); /* sets up ipv4_works, ipv6_works */
- /* Check to see if we have IPv6. Otherwise force the -4 flag */
- if (isc_net_probeipv6() != ISC_R_SUCCESS) {
+ /* Check to see if we have IPv6. Otherwise default to IPv4 */
+ if (!ipv6_works)
ai_fam_templ = AF_INET;
- }
errflg = 0;
progname = argv[0];
@@ -436,8 +414,7 @@ ntpdatemain (
} else {
sys_timeout = ((LFPTOFP(&tmp) * TIMER_HZ)
+ 0x8000) >> 16;
- if (sys_timeout == 0)
- sys_timeout = 1;
+ sys_timeout = max(sys_timeout, MINTIMEOUT);
}
break;
case 'v':
@@ -463,12 +440,7 @@ ntpdatemain (
if (debug || simple_query) {
#ifdef HAVE_SETVBUF
static char buf[BUFSIZ];
-#ifdef SYS_WINNT
- /* Win32 does not implement line buffering */
- setvbuf(stdout, NULL, _IONBF, BUFSIZ);
-#else
setvbuf(stdout, buf, _IOLBF, BUFSIZ);
-#endif /* SYS_WINNT */
#else
setlinebuf(stdout);
#endif
@@ -561,13 +533,6 @@ ntpdatemain (
#if defined(HAVE_BSD_NICE)
(void) setpriority(PRIO_PROCESS, 0, NTPDATE_PRIO);
#endif
-#ifdef SYS_WINNT
- process_handle = GetCurrentProcess();
- if (!SetPriorityClass(process_handle, (DWORD) REALTIME_PRIORITY_CLASS)) {
- msyslog(LOG_ERR, "SetPriorityClass failed: %m");
- }
-#endif /* SYS_WINNT */
-
initializing = 0;
@@ -608,7 +573,7 @@ ntpdatemain (
#else
if (WSAGetLastError() != WSAEINTR)
#endif
- netsyslog(LOG_ERR,
+ msyslog(LOG_ERR,
#ifdef HAVE_POLL_H
"poll() error: %m"
#else
@@ -617,7 +582,7 @@ ntpdatemain (
);
} else if (errno != 0) {
#ifndef SYS_VXWORKS
- netsyslog(LOG_DEBUG,
+ msyslog(LOG_DEBUG,
#ifdef HAVE_POLL_H
"poll(): nfound = %d, error: %m",
#else
@@ -687,7 +652,7 @@ transmit(
struct pkt xpkt;
if (debug)
- printf("transmit(%s)\n", stoa(&(server->srcadr)));
+ printf("transmit(%s)\n", stoa(&server->srcadr));
if (server->filter_nextpt < server->xmtcnt) {
l_fp ts;
@@ -719,7 +684,7 @@ transmit(
xpkt.ppoll = NTP_MINPOLL;
xpkt.precision = NTPDATE_PRECISION;
xpkt.rootdelay = htonl(NTPDATE_DISTANCE);
- xpkt.rootdispersion = htonl(NTPDATE_DISP);
+ xpkt.rootdisp = htonl(NTPDATE_DISP);
xpkt.refid = htonl(NTPDATE_REFID);
L_CLR(&xpkt.reftime);
L_CLR(&xpkt.org);
@@ -738,18 +703,18 @@ transmit(
L_ADDUF(&server->xmt, sys_authdelay);
HTONL_FP(&server->xmt, &xpkt.xmt);
len = authencrypt(sys_authkey, (u_int32 *)&xpkt, LEN_PKT_NOMAC);
- sendpkt(&(server->srcadr), &xpkt, (int)(LEN_PKT_NOMAC + len));
+ sendpkt(&server->srcadr, &xpkt, (int)(LEN_PKT_NOMAC + len));
if (debug > 1)
printf("transmit auth to %s\n",
- stoa(&(server->srcadr)));
+ stoa(&server->srcadr));
} else {
get_systime(&(server->xmt));
HTONL_FP(&server->xmt, &xpkt.xmt);
- sendpkt(&(server->srcadr), &xpkt, LEN_PKT_NOMAC);
+ sendpkt(&server->srcadr, &xpkt, LEN_PKT_NOMAC);
if (debug > 1)
- printf("transmit to %s\n", stoa(&(server->srcadr)));
+ printf("transmit to %s\n", stoa(&server->srcadr));
}
/*
@@ -786,7 +751,7 @@ receive(
*/
if (rbufp->recv_length == LEN_PKT_NOMAC)
has_mac = 0;
- else if (rbufp->recv_length >= LEN_PKT_NOMAC)
+ else if (rbufp->recv_length >= (int)LEN_PKT_NOMAC)
has_mac = 1;
else {
if (debug)
@@ -858,13 +823,26 @@ receive(
server->trust |= 1;
/*
+ * Check for a KoD (rate limiting) response, cease and decist.
+ */
+ if (LEAP_NOTINSYNC == PKT_LEAP(rpkt->li_vn_mode) &&
+ STRATUM_PKT_UNSPEC == rpkt->stratum &&
+ !memcmp("RATE", &rpkt->refid, 4)) {
+ msyslog(LOG_ERR, "%s rate limit response from server.",
+ stoa(&rbufp->recv_srcadr));
+ server->event_time = 0;
+ complete_servers++;
+ return;
+ }
+
+ /*
* Looks good. Record info from the packet.
*/
server->leap = PKT_LEAP(rpkt->li_vn_mode);
server->stratum = PKT_TO_STRATUM(rpkt->stratum);
server->precision = rpkt->precision;
server->rootdelay = ntohl(rpkt->rootdelay);
- server->rootdispersion = ntohl(rpkt->rootdispersion);
+ server->rootdisp = ntohl(rpkt->rootdisp);
server->refid = rpkt->refid;
NTOHL_FP(&rpkt->reftime, &server->reftime);
NTOHL_FP(&rpkt->rec, &rec);
@@ -875,7 +853,7 @@ receive(
* again.
*/
if (L_ISZERO(&rec) || !L_ISHIS(&server->org, &rec)) {
- transmit(server);
+ server->event_time = current_time + sys_timeout;
return;
}
@@ -924,10 +902,21 @@ receive(
}
/*
- * Shift this data in, then transmit again.
+ * Shift this data in, then schedule another transmit.
*/
server_data(server, (s_fp) di, &ci, 0);
- transmit(server);
+
+ if ((int)server->filter_nextpt >= sys_samples) {
+ /*
+ * Got all the data we need. Mark this guy
+ * completed and return.
+ */
+ server->event_time = 0;
+ complete_servers++;
+ return;
+ }
+
+ server->event_time = current_time + sys_timeout;
}
@@ -1035,12 +1024,14 @@ clock_filter(
static struct server *
clock_select(void)
{
- register struct server *server;
- register int i;
- register int nlist;
- register s_fp d;
- register int j;
- register int n;
+ struct server *server;
+ u_int nlist;
+ s_fp d;
+ u_int count;
+ u_int i;
+ u_int j;
+ u_int k;
+ int n;
s_fp local_threshold;
struct server *server_list[NTP_MAXCLOCK];
u_fp server_badness[NTP_MAXCLOCK];
@@ -1136,12 +1127,14 @@ clock_select(void)
* Got the five-or-less best. Cut the list where the number of
* strata exceeds two.
*/
- j = 0;
+ count = 0;
for (i = 1; i < nlist; i++)
- if (server_list[i]->stratum > server_list[i-1]->stratum)
- if (++j == 2) {
- nlist = i;
- break;
+ if (server_list[i]->stratum > server_list[i-1]->stratum) {
+ count++;
+ if (2 == count) {
+ nlist = i;
+ break;
+ }
}
/*
@@ -1151,9 +1144,9 @@ clock_select(void)
* detection.
*/
- if (nlist == 0)
- sys_server = 0;
- else if (nlist == 1) {
+ if (0 == nlist)
+ sys_server = NULL;
+ else if (1 == nlist) {
sys_server = server_list[0];
} else {
/*
@@ -1162,12 +1155,13 @@ clock_select(void)
*/
for (i = 0; i < nlist-1; i++)
for (j = i+1; j < nlist; j++) {
- if (server_list[i]->stratum
- < server_list[j]->stratum)
- break; /* already sorted by stratum */
- if (server_list[i]->delay
- < server_list[j]->delay)
- continue;
+ if (server_list[i]->stratum <
+ server_list[j]->stratum)
+ /* already sorted by stratum */
+ break;
+ if (server_list[i]->delay <
+ server_list[j]->delay)
+ continue;
server = server_list[i];
server_list[i] = server_list[j];
server_list[j] = server;
@@ -1183,14 +1177,14 @@ clock_select(void)
* Now drop samples until we're down to one.
*/
while (nlist > 1) {
- for (n = 0; n < nlist; n++) {
- server_badness[n] = 0;
+ for (k = 0; k < nlist; k++) {
+ server_badness[k] = 0;
for (j = 0; j < nlist; j++) {
- if (j == n) /* with self? */
+ if (j == k) /* with self? */
continue;
- d = server_list[j]->soffset
- - server_list[n]->soffset;
- if (d < 0) /* absolute value */
+ d = server_list[j]->soffset -
+ server_list[k]->soffset;
+ if (d < 0) /* abs value */
d = -d;
/*
* XXX This code *knows* that
@@ -1198,7 +1192,7 @@ clock_select(void)
*/
for (i = 0; i < j; i++)
d = (d>>1) + (d>>2);
- server_badness[n] += d;
+ server_badness[k] += d;
}
}
@@ -1289,7 +1283,7 @@ clock_adjust(void)
lfptoa(&server->offset, 6));
}
} else {
-#if !defined SYS_WINNT && !defined SYS_CYGWIN32
+#ifndef SYS_WINNT
if (simple_query || l_adj_systime(&server->offset)) {
msyslog(LOG_NOTICE, "adjust time server %s offset %s sec",
stoa(&server->srcadr),
@@ -1318,16 +1312,16 @@ clock_adjust(void)
* (non-blocking).
*/
static int
-is_reachable (struct sockaddr_storage *dst)
+is_reachable (sockaddr_u *dst)
{
SOCKET sockfd;
- sockfd = socket(dst->ss_family, SOCK_DGRAM, 0);
+ sockfd = socket(AF(dst), SOCK_DGRAM, 0);
if (sockfd == -1) {
return 0;
}
- if(connect(sockfd, (struct sockaddr *)dst, SOCKLEN(dst))) {
+ if (connect(sockfd, &dst->sa, SOCKLEN(dst))) {
closesocket(sockfd);
return 0;
}
@@ -1356,10 +1350,12 @@ addserver(
int error;
/* Service name */
char service[5];
- strcpy(service, "ntp");
+ sockaddr_u addr;
+
+ strlcpy(service, "ntp", sizeof(service));
/* Get host address. Looking for UDP datagram connection. */
- memset(&hints, 0, sizeof(hints));
+ ZERO(hints);
hints.ai_family = ai_fam_templ;
hints.ai_socktype = SOCK_DGRAM;
@@ -1375,28 +1371,35 @@ addserver(
/* Name server is unusable. Exit after failing on the
first server, in order to shorten the timeout caused
by waiting for resolution of several servers */
- fprintf(stderr, "Name server cannot be used, exiting");
- msyslog(LOG_ERR, "name server cannot be used, reason: %s\n", gai_strerror(error));
+ fprintf(stderr, "Exiting, name server cannot be used: %s (%d)",
+ gai_strerror(error), error);
+ msyslog(LOG_ERR, "name server cannot be used: %s (%d)",
+ gai_strerror(error), error);
exit(1);
}
- fprintf(stderr, "Error : %s\n", gai_strerror(error));
- msyslog(LOG_ERR, "can't find host %s\n", serv);
+ fprintf(stderr, "Error resolving %s: %s (%d)\n", serv,
+ gai_strerror(error), error);
+ msyslog(LOG_ERR, "Can't find host %s: %s (%d)", serv,
+ gai_strerror(error), error);
return;
}
#ifdef DEBUG
- else if (debug) {
- fprintf(stderr, "host found : %s\n", stohost((struct sockaddr_storage*)addrResult->ai_addr));
+ if (debug) {
+ ZERO(addr);
+ INSIST(addrResult->ai_addrlen <= sizeof(addr));
+ memcpy(&addr, addrResult->ai_addr, addrResult->ai_addrlen);
+ fprintf(stderr, "host found : %s\n", stohost(&addr));
}
#endif
/* We must get all returned server in case the first one fails */
for (ptr = addrResult; ptr != NULL; ptr = ptr->ai_next) {
- if (is_reachable ((struct sockaddr_storage *)ptr->ai_addr)) {
- server = (struct server *)emalloc(sizeof(struct server));
- memset((char *)server, 0, sizeof(struct server));
-
- memset(&(server->srcadr), 0, sizeof(struct sockaddr_storage));
- memcpy(&(server->srcadr), ptr->ai_addr, ptr->ai_addrlen);
+ ZERO(addr);
+ INSIST(ptr->ai_addrlen <= sizeof(addr));
+ memcpy(&addr, ptr->ai_addr, ptr->ai_addrlen);
+ if (is_reachable(&addr)) {
+ server = emalloc_zero(sizeof(*server));
+ memcpy(&server->srcadr, ptr->ai_addr, ptr->ai_addrlen);
server->event_time = ++sys_numservers;
if (sys_servers == NULL)
sys_servers = server;
@@ -1404,7 +1407,8 @@ addserver(
struct server *sp;
for (sp = sys_servers; sp->next_server != NULL;
- sp = sp->next_server) ;
+ sp = sp->next_server)
+ /* empty */;
sp->next_server = server;
}
}
@@ -1420,40 +1424,23 @@ addserver(
*/
static struct server *
findserver(
- struct sockaddr_storage *addr
+ sockaddr_u *addr
)
{
struct server *server;
struct server *mc_server;
- isc_sockaddr_t laddr;
- isc_sockaddr_t saddr;
-
- if(addr->ss_family == AF_INET) {
- isc_sockaddr_fromin( &laddr, &((struct sockaddr_in*)addr)->sin_addr, 0);
- }
- else {
- isc_sockaddr_fromin6(&laddr, &((struct sockaddr_in6*)addr)->sin6_addr, 0);
- }
-
mc_server = NULL;
- if (htons(((struct sockaddr_in*)addr)->sin_port) != NTP_PORT)
+ if (SRCPORT(addr) != NTP_PORT)
return 0;
for (server = sys_servers; server != NULL;
server = server->next_server) {
-
- if(server->srcadr.ss_family == AF_INET) {
- isc_sockaddr_fromin(&saddr, &((struct sockaddr_in*)&server->srcadr)->sin_addr, 0);
- }
- else {
- isc_sockaddr_fromin6(&saddr, &((struct sockaddr_in6*)&server->srcadr)->sin6_addr, 0);
- }
- if (isc_sockaddr_eqaddr(&laddr, &saddr) == ISC_TRUE)
+ if (SOCK_EQ(addr, &server->srcadr))
return server;
- if(addr->ss_family == server->srcadr.ss_family) {
- if (isc_sockaddr_ismulticast(&saddr) == ISC_TRUE)
+ if (AF(addr) == AF(&server->srcadr)) {
+ if (IS_MCAST(&server->srcadr))
mc_server = server;
}
}
@@ -1467,15 +1454,15 @@ findserver(
complete_servers++;
}
- server = (struct server *)emalloc(sizeof(struct server));
- memset((char *)server, 0, sizeof(struct server));
+ server = emalloc_zero(sizeof(*server));
- memcpy(&server->srcadr, addr, sizeof(struct sockaddr_storage));
+ server->srcadr = *addr;
server->event_time = ++sys_numservers;
for (sp = sys_servers; sp->next_server != NULL;
- sp = sp->next_server) ;
+ sp = sp->next_server)
+ /* empty */;
sp->next_server = server;
transmit(server);
}
@@ -1526,16 +1513,16 @@ alarming(
{
alarm_flag++;
}
-#else
+#else /* SYS_WINNT follows */
void CALLBACK
alarming(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
+ UNUSED_ARG(uTimerID); UNUSED_ARG(uMsg); UNUSED_ARG(dwUser);
+ UNUSED_ARG(dw1); UNUSED_ARG(dw2);
+
alarm_flag++;
}
-#endif /* SYS_WINNT */
-
-#ifdef SYS_WINNT
static void
callTimeEndPeriod(void)
{
@@ -1552,16 +1539,14 @@ static void
init_alarm(void)
{
#ifndef SYS_WINNT
-# ifndef HAVE_TIMER_SETTIME
- struct itimerval itimer;
+# ifdef HAVE_TIMER_CREATE
+ struct itimerspec its;
# else
- struct itimerspec ntpdate_itimer;
+ struct itimerval itv;
# endif
-#else
+#else /* SYS_WINNT follows */
TIMECAPS tc;
UINT wTimerID;
-# endif /* SYS_WINNT */
-#if defined SYS_CYGWIN32 || defined SYS_WINNT
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
DWORD dwUser = 0;
@@ -1570,7 +1555,7 @@ init_alarm(void)
alarm_flag = 0;
#ifndef SYS_WINNT
-# if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME)
+# ifdef HAVE_TIMER_CREATE
alarm_flag = 0;
/* this code was put in as setitimer() is non existant this us the
* POSIX "equivalents" setup - casey
@@ -1592,44 +1577,26 @@ init_alarm(void)
* Set up the alarm interrupt. The first comes 1/(2*TIMER_HZ)
* seconds from now and they continue on every 1/TIMER_HZ seconds.
*/
- (void) signal_no_reset(SIGALRM, alarming);
- ntpdate_itimer.it_interval.tv_sec = ntpdate_itimer.it_value.tv_sec = 0;
- ntpdate_itimer.it_interval.tv_nsec = 1000000000/TIMER_HZ;
- ntpdate_itimer.it_value.tv_nsec = 1000000000/(TIMER_HZ<<1);
- timer_settime(ntpdate_timerid, 0 /* !TIMER_ABSTIME */, &ntpdate_itimer, NULL);
-# else
+ signal_no_reset(SIGALRM, alarming);
+ its.it_interval.tv_sec = 0;
+ its.it_value.tv_sec = 0;
+ its.it_interval.tv_nsec = 1000000000/TIMER_HZ;
+ its.it_value.tv_nsec = 1000000000/(TIMER_HZ<<1);
+ timer_settime(ntpdate_timerid, 0 /* !TIMER_ABSTIME */, &its, NULL);
+# else /* !HAVE_TIMER_CREATE follows */
/*
* Set up the alarm interrupt. The first comes 1/(2*TIMER_HZ)
* seconds from now and they continue on every 1/TIMER_HZ seconds.
*/
- (void) signal_no_reset(SIGALRM, alarming);
- itimer.it_interval.tv_sec = itimer.it_value.tv_sec = 0;
- itimer.it_interval.tv_usec = 1000000/TIMER_HZ;
- itimer.it_value.tv_usec = 1000000/(TIMER_HZ<<1);
-
- setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
-# endif
-#if defined SYS_CYGWIN32
- /*
- * Get privileges needed for fiddling with the clock
- */
-
- /* get the current process token handle */
- if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
- msyslog(LOG_ERR, "OpenProcessToken failed: %m");
- exit(1);
- }
- /* get the LUID for system-time privilege. */
- LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid);
- tkp.PrivilegeCount = 1; /* one privilege to set */
- tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- /* get set-time privilege for this process. */
- AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES) NULL, 0);
- /* cannot test return value of AdjustTokenPrivileges. */
- if (GetLastError() != ERROR_SUCCESS)
- msyslog(LOG_ERR, "AdjustTokenPrivileges failed: %m");
-#endif
-#else /* SYS_WINNT */
+ signal_no_reset(SIGALRM, alarming);
+ itv.it_interval.tv_sec = 0;
+ itv.it_value.tv_sec = 0;
+ itv.it_interval.tv_usec = 1000000/TIMER_HZ;
+ itv.it_value.tv_usec = 1000000/(TIMER_HZ<<1);
+
+ setitimer(ITIMER_REAL, &itv, NULL);
+# endif /* !HAVE_TIMER_CREATE */
+#else /* SYS_WINNT follows */
_tzset();
/*
@@ -1707,7 +1674,9 @@ init_io(void)
{
struct addrinfo *res, *ressave;
struct addrinfo hints;
+ sockaddr_u addr;
char service[5];
+ int rc;
int optval = 1;
int check_ntp_port_in_use = !debug && !simple_query && !unpriv_port;
@@ -1720,25 +1689,25 @@ init_io(void)
* Open the socket
*/
- strcpy(service, "ntp");
+ strlcpy(service, "ntp", sizeof(service));
/*
* Init hints addrinfo structure
*/
- memset(&hints, 0, sizeof(hints));
+ ZERO(hints);
hints.ai_family = ai_fam_templ;
hints.ai_flags = AI_PASSIVE;
hints.ai_socktype = SOCK_DGRAM;
- if(getaddrinfo(NULL, service, &hints, &res) != 0) {
- msyslog(LOG_ERR, "getaddrinfo() failed: %m");
- exit(1);
- /*NOTREACHED*/
+ if (getaddrinfo(NULL, service, &hints, &res) != 0) {
+ msyslog(LOG_ERR, "getaddrinfo() failed: %m");
+ exit(1);
+ /*NOTREACHED*/
}
#ifdef SYS_WINNT
if (check_ntp_port_in_use && ntp_port_inuse(AF_INET, NTP_PORT)){
- netsyslog(LOG_ERR, "the NTP socket is in use, exiting: %m");
+ msyslog(LOG_ERR, "the NTP socket is in use, exiting: %m");
exit(1);
}
#endif
@@ -1762,13 +1731,13 @@ init_io(void)
err == WSAEPFNOSUPPORT)
#endif
continue;
- netsyslog(LOG_ERR, "socket() failed: %m");
+ msyslog(LOG_ERR, "socket() failed: %m");
exit(1);
/*NOTREACHED*/
}
/* set socket to reuse address */
if (setsockopt(fd[nbsock], SOL_SOCKET, SO_REUSEADDR, (void*) &optval, sizeof(optval)) < 0) {
- netsyslog(LOG_ERR, "setsockopt() SO_REUSEADDR failed: %m");
+ msyslog(LOG_ERR, "setsockopt() SO_REUSEADDR failed: %m");
exit(1);
/*NOTREACHED*/
}
@@ -1776,7 +1745,7 @@ init_io(void)
/* Restricts AF_INET6 socket to IPv6 communications (see RFC 2553bis-03) */
if (res->ai_family == AF_INET6)
if (setsockopt(fd[nbsock], IPPROTO_IPV6, IPV6_V6ONLY, (void*) &optval, sizeof(optval)) < 0) {
- netsyslog(LOG_ERR, "setsockopt() IPV6_V6ONLY failed: %m");
+ msyslog(LOG_ERR, "setsockopt() IPV6_V6ONLY failed: %m");
exit(1);
/*NOTREACHED*/
}
@@ -1789,15 +1758,15 @@ init_io(void)
* bind the socket to the NTP port
*/
if (check_ntp_port_in_use) {
- if (bind(fd[nbsock], res->ai_addr, SOCKLEN(res->ai_addr)) < 0) {
-#ifndef SYS_WINNT
- if (errno == EADDRINUSE)
-#else
- if (WSAGetLastError() == WSAEADDRINUSE)
-#endif /* SYS_WINNT */
- netsyslog(LOG_ERR, "the NTP socket is in use, exiting");
+ ZERO(addr);
+ INSIST(res->ai_addrlen <= sizeof(addr));
+ memcpy(&addr, res->ai_addr, res->ai_addrlen);
+ rc = bind(fd[nbsock], &addr.sa, SOCKLEN(&addr));
+ if (rc < 0) {
+ if (EADDRINUSE == socket_errno())
+ msyslog(LOG_ERR, "the NTP socket is in use, exiting");
else
- netsyslog(LOG_ERR, "bind() fails: %m");
+ msyslog(LOG_ERR, "bind() fails: %m");
exit(1);
}
}
@@ -1818,24 +1787,24 @@ init_io(void)
#ifndef SYS_WINNT
# ifdef SYS_VXWORKS
{
- int on = TRUE;
+ int on = TRUE;
- if (ioctl(fd[nbsock],FIONBIO, &on) == ERROR) {
- netsyslog(LOG_ERR, "ioctl(FIONBIO) fails: %m");
- exit(1);
- }
+ if (ioctl(fd[nbsock],FIONBIO, &on) == ERROR) {
+ msyslog(LOG_ERR, "ioctl(FIONBIO) fails: %m");
+ exit(1);
+ }
}
# else /* not SYS_VXWORKS */
# if defined(O_NONBLOCK)
if (fcntl(fd[nbsock], F_SETFL, O_NONBLOCK) < 0) {
- netsyslog(LOG_ERR, "fcntl(FNDELAY|FASYNC) fails: %m");
+ msyslog(LOG_ERR, "fcntl(FNDELAY|FASYNC) fails: %m");
exit(1);
/*NOTREACHED*/
}
# else /* not O_NONBLOCK */
# if defined(FNDELAY)
if (fcntl(fd[nbsock], F_SETFL, FNDELAY) < 0) {
- netsyslog(LOG_ERR, "fcntl(FNDELAY|FASYNC) fails: %m");
+ msyslog(LOG_ERR, "fcntl(FNDELAY|FASYNC) fails: %m");
exit(1);
/*NOTREACHED*/
}
@@ -1846,7 +1815,7 @@ init_io(void)
# endif /* SYS_VXWORKS */
#else /* SYS_WINNT */
if (ioctlsocket(fd[nbsock], FIONBIO, (u_long *) &on) == SOCKET_ERROR) {
- netsyslog(LOG_ERR, "ioctlsocket(FIONBIO) fails: %m");
+ msyslog(LOG_ERR, "ioctlsocket(FIONBIO) fails: %m");
exit(1);
}
#endif /* SYS_WINNT */
@@ -1860,7 +1829,7 @@ init_io(void)
*/
static void
sendpkt(
- struct sockaddr_storage *dest,
+ sockaddr_u *dest,
struct pkt *pkt,
int len
)
@@ -1875,14 +1844,14 @@ sendpkt(
/* Find a local family compatible socket to send ntp packet to ntp server */
for(i = 0; (i < MAX_AF); i++) {
- if(dest->ss_family == fd_family[i]) {
+ if(AF(dest) == fd_family[i]) {
sock = fd[i];
break;
}
}
- if ( sock == INVALID_SOCKET ) {
- netsyslog(LOG_ERR, "cannot find family compatible socket to send ntp packet");
+ if (INVALID_SOCKET == sock) {
+ msyslog(LOG_ERR, "cannot find family compatible socket to send ntp packet");
exit(1);
/*NOTREACHED*/
}
@@ -1890,14 +1859,14 @@ sendpkt(
cc = sendto(sock, (char *)pkt, len, 0, (struct sockaddr *)dest,
SOCKLEN(dest));
- if (cc == SOCKET_ERROR) {
+ if (SOCKET_ERROR == cc) {
#ifndef SYS_WINNT
if (errno != EWOULDBLOCK && errno != ENOBUFS)
#else
err = WSAGetLastError();
if (err != WSAEWOULDBLOCK && err != WSAENOBUFS)
#endif /* SYS_WINNT */
- netsyslog(LOG_ERR, "sendto(%s): %m", stohost(dest));
+ msyslog(LOG_ERR, "sendto(%s): %m", stohost(dest));
}
}
@@ -1910,8 +1879,8 @@ input_handler(void)
{
register int n;
register struct recvbuf *rb;
- struct timeval tvzero;
- int fromlen;
+ struct sock_timeval tvzero;
+ GETSOCKNAME_SOCKLEN_TYPE fromlen;
l_fp ts;
int i;
#ifdef HAVE_POLL_H
@@ -1967,7 +1936,7 @@ input_handler(void)
return;
else if (n == -1) {
if (errno != EINTR)
- netsyslog(LOG_ERR,
+ msyslog(LOG_ERR,
#ifdef HAVE_POLL_H
"poll() error: %m"
#else
@@ -2002,7 +1971,7 @@ input_handler(void)
rb = get_free_recv_buffer();
- fromlen = sizeof(struct sockaddr_storage);
+ fromlen = sizeof(rb->recv_srcadr);
rb->recv_length = recvfrom(fdc, (char *)&rb->recv_pkt,
sizeof(rb->recv_pkt), 0,
(struct sockaddr *)&rb->recv_srcadr, &fromlen);
@@ -2069,7 +2038,7 @@ l_adj_systime(
if (adjtv.tv_usec != 0 && !debug) {
if (adjtime(&adjtv, &oadjtv) < 0) {
msyslog(LOG_ERR, "Can't adjust the time of day: %m");
- return 0;
+ exit(1);
}
}
return 1;
@@ -2150,7 +2119,7 @@ printserver(
{
register int i;
char junk[5];
- char *str;
+ const char *str;
if (!debug) {
(void) fprintf(fp, "server %s, stratum %d, offset %s, delay %s\n",
@@ -2213,57 +2182,6 @@ printserver(
lfptoa(&pp->offset, 6));
}
-#if !defined(HAVE_VSPRINTF)
-int
-vsprintf(
- char *str,
- const char *fmt,
- va_list ap
- )
-{
- FILE f;
- int len;
-
- f._flag = _IOWRT+_IOSTRG;
- f._ptr = str;
- f._cnt = 32767;
- len = _doprnt(fmt, ap, &f);
- *f._ptr = 0;
- return (len);
-}
-#endif
-
-#if 0
-/* override function in library since SA_RESTART makes ALL syscalls restart */
-#ifdef SA_RESTART
-void
-signal_no_reset(
- int sig,
- void (*func)()
- )
-{
- int n;
- struct sigaction vec;
-
- vec.sa_handler = func;
- sigemptyset(&vec.sa_mask);
- vec.sa_flags = 0;
-
- while (1)
- {
- n = sigaction(sig, &vec, NULL);
- if (n == -1 && errno == EINTR)
- continue;
- break;
- }
- if (n == -1)
- {
- perror("sigaction");
- exit(1);
- }
-}
-#endif
-#endif
#ifdef HAVE_NETINFO
static ni_namelist *
@@ -2272,7 +2190,7 @@ getnetinfoservers(void)
ni_status status;
void *domain;
ni_id confdir;
- ni_namelist *namelist = (ni_namelist*)malloc(sizeof(ni_namelist));
+ ni_namelist *namelist = emalloc(sizeof(ni_namelist));
/* Find a time server in NetInfo */
if ((status = ni_open(NULL, ".", &domain)) != NI_OK) return NULL;
diff --git a/contrib/ntp/ntpdate/ntpdate.h b/contrib/ntp/ntpdate/ntpdate.h
index f3531b3..df9c49e 100644
--- a/contrib/ntp/ntpdate/ntpdate.h
+++ b/contrib/ntp/ntpdate/ntpdate.h
@@ -4,7 +4,7 @@
#include "ntp_malloc.h"
-extern void loadservers P((char *cfgpath));
+extern void loadservers (char *cfgpath);
/*
* The server structure is a much simplified version of the
@@ -15,14 +15,14 @@ extern void loadservers P((char *cfgpath));
*/
struct server {
struct server *next_server; /* next server in build list */
- struct sockaddr_storage srcadr; /* address of remote host */
+ sockaddr_u srcadr; /* address of remote host */
u_char version; /* version to use */
u_char leap; /* leap indicator */
u_char stratum; /* stratum of remote server */
s_char precision; /* server's clock precision */
u_char trust; /* trustability of the filtered data */
u_fp rootdelay; /* distance from primary clock */
- u_fp rootdispersion; /* peer clock dispersion */
+ u_fp rootdisp; /* peer clock dispersion */
u_int32 refid; /* peer reference ID */
l_fp reftime; /* time of peer's last update */
u_long event_time; /* time for next timeout */
@@ -89,9 +89,13 @@ struct server {
/*
- * Some defaults
+ * No less than 2s between requests to a server to stay within ntpd's
+ * default "discard minimum 1" (and 1s enforcement slop). That is
+ * enforced only if the nondefault limited restriction is in place, such
+ * as with "restrict ... limited" and "restrict ... kod limited".
*/
-#define DEFTIMEOUT 5 /* 5 timer increments */
+#define MINTIMEOUT (1 * TIMER_HZ) /* 1s min. between packets */
+#define DEFTIMEOUT (2 * TIMER_HZ) /* 2s by default */
#define DEFSAMPLES 4 /* get 4 samples per server */
#define DEFPRECISION (-5) /* the precision we claim */
#define DEFMAXPERIOD 60 /* maximum time to wait */
diff --git a/contrib/ntp/ntpdate/ntptime_config.c b/contrib/ntp/ntpdate/ntptime_config.c
deleted file mode 100644
index e784d28..0000000
--- a/contrib/ntp/ntpdate/ntptime_config.c
+++ /dev/null
@@ -1,552 +0,0 @@
-/*
- * ntptime_config.c
- *
- * What follows is a simplified version of the config parsing code
- * in ntpd/ntp_config.c. We only parse a subset of the configuration
- * syntax, and don't bother whining about things we don't understand.
- *
- */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include "ntp_fp.h"
-#include "ntp.h"
-#include "ntp_io.h"
-#include "ntp_unixtime.h"
-#include "ntp_filegen.h"
-#include "ntpdate.h"
-#include "ntp_syslog.h"
-#include "ntp_stdlib.h"
-
-#include <stdio.h>
-#include <signal.h>
-#include <ctype.h>
-
-/*
- * These routines are used to read the configuration file at
- * startup time. An entry in the file must fit on a single line.
- * Entries are processed as multiple tokens separated by white space
- * Lines are considered terminated when a '#' is encountered. Blank
- * lines are ignored.
- */
-
-/*
- * Configuration file name
- */
-#ifndef CONFIG_FILE
-# ifndef SYS_WINNT
-# define CONFIG_FILE "/etc/ntp.conf"
-# else /* SYS_WINNT */
-# define CONFIG_FILE "%windir%\\ntp.conf"
-# define ALT_CONFIG_FILE "%windir%\\ntp.ini"
-# endif /* SYS_WINNT */
-#endif /* not CONFIG_FILE */
-
-/*
- *
- * We understand the following configuration entries and defaults.
- *
- * peer [ addr ] [ version 3 ] [ key 0 ] [ minpoll 6 ] [ maxpoll 10 ]
- * server [ addr ] [ version 3 ] [ key 0 ] [ minpoll 6 ] [ maxpoll 10 ]
- * keys file_name
- */
-
-#define CONFIG_UNKNOWN 0
-
-#define CONFIG_PEER 1
-#define CONFIG_SERVER 2
-#define CONFIG_KEYS 8
-
-#define CONF_MOD_VERSION 1
-#define CONF_MOD_KEY 2
-#define CONF_MOD_MINPOLL 3
-#define CONF_MOD_MAXPOLL 4
-#define CONF_MOD_PREFER 5
-#define CONF_MOD_BURST 6
-#define CONF_MOD_SKEY 7
-#define CONF_MOD_TTL 8
-#define CONF_MOD_MODE 9
-
-/*
- * Translation table - keywords to function index
- */
-struct keyword {
- const char *text;
- int keytype;
-};
-
-/*
- * Command keywords
- */
-static struct keyword keywords[] = {
- { "peer", CONFIG_PEER },
- { "server", CONFIG_SERVER },
- { "keys", CONFIG_KEYS },
- { "", CONFIG_UNKNOWN }
-};
-
-/*
- * "peer", "server", "broadcast" modifier keywords
- */
-static struct keyword mod_keywords[] = {
- { "version", CONF_MOD_VERSION },
- { "key", CONF_MOD_KEY },
- { "minpoll", CONF_MOD_MINPOLL },
- { "maxpoll", CONF_MOD_MAXPOLL },
- { "prefer", CONF_MOD_PREFER },
- { "burst", CONF_MOD_BURST },
- { "autokey", CONF_MOD_SKEY },
- { "mode", CONF_MOD_MODE }, /* reference clocks */
- { "ttl", CONF_MOD_TTL }, /* NTP peers */
- { "", CONFIG_UNKNOWN }
-};
-
-/*
- * Limits on things
- */
-#define MAXTOKENS 20 /* 20 tokens on line */
-#define MAXLINE 1024 /* maximum length of line */
-#define MAXFILENAME 128 /* maximum length of a file name (alloca()?) */
-
-/*
- * Miscellaneous macros
- */
-#define STRSAME(s1, s2) (*(s1) == *(s2) && strcmp((s1), (s2)) == 0)
-#define ISEOL(c) ((c) == '#' || (c) == '\n' || (c) == '\0')
-#define ISSPACE(c) ((c) == ' ' || (c) == '\t')
-#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
-
-/*
- * Systemwide parameters and flags
- */
-extern struct server **sys_servers; /* the server list */
-extern int sys_numservers; /* number of servers to poll */
-extern char *key_file;
-
-/*
- * Function prototypes
- */
-static int gettokens P((FILE *, char *, char **, int *));
-static int matchkey P((char *, struct keyword *));
-static int getnetnum P((const char *num, struct sockaddr_in *addr,
- int complain));
-
-
-/*
- * loadservers - load list of NTP servers from configuration file
- */
-void
-loadservers(
- char *cfgpath
- )
-{
- register int i;
- int errflg;
- int peerversion;
- int minpoll;
- int maxpoll;
- /* int ttl; */
- int srvcnt;
- /* u_long peerkey; */
- int peerflags;
- struct sockaddr_in peeraddr;
- FILE *fp;
- char line[MAXLINE];
- char *(tokens[MAXTOKENS]);
- int ntokens;
- int tok;
- const char *config_file;
-#ifdef SYS_WINNT
- char *alt_config_file;
- LPTSTR temp;
- char config_file_storage[MAX_PATH];
- char alt_config_file_storage[MAX_PATH];
-#endif /* SYS_WINNT */
- struct server *server, *srvlist;
-
- /*
- * Initialize, initialize
- */
- srvcnt = 0;
- srvlist = 0;
- errflg = 0;
-#ifdef DEBUG
- debug = 0;
-#endif /* DEBUG */
-#ifndef SYS_WINNT
- config_file = cfgpath ? cfgpath : CONFIG_FILE;
-#else
- if (cfgpath) {
- config_file = cfgpath;
- } else {
- temp = CONFIG_FILE;
- if (!ExpandEnvironmentStrings((LPCTSTR)temp, (LPTSTR)config_file_storage, (DWORD)sizeof(config_file_storage))) {
- msyslog(LOG_ERR, "ExpandEnvironmentStrings CONFIG_FILE failed: %m\n");
- exit(1);
- }
- config_file = config_file_storage;
- }
-
- temp = ALT_CONFIG_FILE;
- if (!ExpandEnvironmentStrings((LPCTSTR)temp, (LPTSTR)alt_config_file_storage, (DWORD)sizeof(alt_config_file_storage))) {
- msyslog(LOG_ERR, "ExpandEnvironmentStrings ALT_CONFIG_FILE failed: %m\n");
- exit(1);
- }
- alt_config_file = alt_config_file_storage;
-M
-#endif /* SYS_WINNT */
-
- if ((fp = fopen(FindConfig(config_file), "r")) == NULL)
- {
- fprintf(stderr, "getconfig: Couldn't open <%s>\n", FindConfig(config_file));
- msyslog(LOG_INFO, "getconfig: Couldn't open <%s>", FindConfig(config_file));
-#ifdef SYS_WINNT
- /* Under WinNT try alternate_config_file name, first NTP.CONF, then NTP.INI */
-
- if ((fp = fopen(FindConfig(alt_config_file), "r")) == NULL) {
-
- /*
- * Broadcast clients can sometimes run without
- * a configuration file.
- */
-
- fprintf(stderr, "getconfig: Couldn't open <%s>\n", FindConfig(alt_config_file));
- msyslog(LOG_INFO, "getconfig: Couldn't open <%s>", FindConfig(alt_config_file));
- return;
- }
-#else /* not SYS_WINNT */
- return;
-#endif /* not SYS_WINNT */
- }
-
- while ((tok = gettokens(fp, line, tokens, &ntokens))
- != CONFIG_UNKNOWN) {
- switch(tok) {
- case CONFIG_PEER:
- case CONFIG_SERVER:
-
- if (ntokens < 2) {
- msyslog(LOG_ERR,
- "No address for %s, line ignored",
- tokens[0]);
- break;
- }
-
- if (!getnetnum(tokens[1], &peeraddr, 1)) {
- /* Resolve now, or lose! */
- break;
- } else {
- errflg = 0;
-
- /* Shouldn't be able to specify multicast */
- if (IN_CLASSD(ntohl(peeraddr.sin_addr.s_addr))
- || ISBADADR(&peeraddr)) {
- msyslog(LOG_ERR,
- "attempt to configure invalid address %s",
- ntoa(&peeraddr));
- break;
- }
- }
-
- peerversion = NTP_VERSION;
- minpoll = NTP_MINDPOLL;
- maxpoll = NTP_MAXDPOLL;
- /* peerkey = 0; */
- peerflags = 0;
- /* ttl = 0; */
- for (i = 2; i < ntokens; i++)
- switch (matchkey(tokens[i], mod_keywords)) {
- case CONF_MOD_VERSION:
- if (i >= ntokens-1) {
- msyslog(LOG_ERR,
- "peer/server version requires an argument");
- errflg = 1;
- break;
- }
- peerversion = atoi(tokens[++i]);
- if ((u_char)peerversion > NTP_VERSION
- || (u_char)peerversion < NTP_OLDVERSION) {
- msyslog(LOG_ERR,
- "inappropriate version number %s, line ignored",
- tokens[i]);
- errflg = 1;
- }
- break;
-
- case CONF_MOD_KEY:
- if (i >= ntokens-1) {
- msyslog(LOG_ERR,
- "key: argument required");
- errflg = 1;
- break;
- }
- ++i;
- /* peerkey = (int)atol(tokens[i]); */
- peerflags |= FLAG_AUTHENABLE;
- break;
-
- case CONF_MOD_MINPOLL:
- if (i >= ntokens-1) {
- msyslog(LOG_ERR,
- "minpoll: argument required");
- errflg = 1;
- break;
- }
- minpoll = atoi(tokens[++i]);
- if (minpoll < NTP_MINPOLL)
- minpoll = NTP_MINPOLL;
- break;
-
- case CONF_MOD_MAXPOLL:
- if (i >= ntokens-1) {
- msyslog(LOG_ERR,
- "maxpoll: argument required"
- );
- errflg = 1;
- break;
- }
- maxpoll = atoi(tokens[++i]);
- if (maxpoll > NTP_MAXPOLL)
- maxpoll = NTP_MAXPOLL;
- break;
-
- case CONF_MOD_PREFER:
- peerflags |= FLAG_PREFER;
- break;
-
- case CONF_MOD_BURST:
- peerflags |= FLAG_BURST;
- break;
-
- case CONF_MOD_SKEY:
- peerflags |= FLAG_SKEY | FLAG_AUTHENABLE;
- break;
-
- case CONF_MOD_TTL:
- if (i >= ntokens-1) {
- msyslog(LOG_ERR,
- "ttl: argument required");
- errflg = 1;
- break;
- }
- ++i;
- /* ttl = atoi(tokens[i]); */
- break;
-
- case CONF_MOD_MODE:
- if (i >= ntokens-1) {
- msyslog(LOG_ERR,
- "mode: argument required");
- errflg = 1;
- break;
- }
- ++i;
- /* ttl = atoi(tokens[i]); */
- break;
-
- case CONFIG_UNKNOWN:
- errflg = 1;
- break;
- }
- if (minpoll > maxpoll) {
- msyslog(LOG_ERR, "config error: minpoll > maxpoll");
- errflg = 1;
- }
- if (errflg == 0) {
- server = (struct server *)emalloc(sizeof(struct server));
- memset((char *)server, 0, sizeof(struct server));
- server->srcadr = peeraddr;
- server->version = peerversion;
- server->dispersion = PEER_MAXDISP;
- server->next_server = srvlist;
- srvlist = server;
- srvcnt++;
- }
- break;
-
- case CONFIG_KEYS:
- if (ntokens >= 2) {
- key_file = (char *) emalloc(strlen(tokens[1]) + 1);
- strcpy(key_file, tokens[1]);
- }
- break;
- }
- }
- (void) fclose(fp);
-
- /* build final list */
- sys_numservers = srvcnt;
- sys_servers = (struct server **)
- emalloc(sys_numservers * sizeof(struct server *));
- for(i=0;i<sys_numservers;i++) {
- sys_servers[i] = srvlist;
- srvlist = srvlist->next_server;
- }
-}
-
-
-
-/*
- * gettokens - read a line and return tokens
- */
-static int
-gettokens(
- FILE *fp,
- char *line,
- char **tokenlist,
- int *ntokens
- )
-{
- register char *cp;
- register int eol;
- register int ntok;
- register int quoted = 0;
-
- /*
- * Find start of first token
- */
- again:
- while ((cp = fgets(line, MAXLINE, fp)) != NULL) {
- cp = line;
- while (ISSPACE(*cp))
- cp++;
- if (!ISEOL(*cp))
- break;
- }
- if (cp == NULL) {
- *ntokens = 0;
- return CONFIG_UNKNOWN; /* hack. Is recognized as EOF */
- }
-
- /*
- * Now separate out the tokens
- */
- eol = 0;
- ntok = 0;
- while (!eol) {
- tokenlist[ntok++] = cp;
- while (!ISEOL(*cp) && (!ISSPACE(*cp) || quoted))
- quoted ^= (*cp++ == '"');
-
- if (ISEOL(*cp)) {
- *cp = '\0';
- eol = 1;
- } else { /* must be space */
- *cp++ = '\0';
- while (ISSPACE(*cp))
- cp++;
- if (ISEOL(*cp))
- eol = 1;
- }
- if (ntok == MAXTOKENS)
- eol = 1;
- }
-
- /*
- * Return the match
- */
- *ntokens = ntok;
- ntok = matchkey(tokenlist[0], keywords);
- if (ntok == CONFIG_UNKNOWN)
- goto again;
- return ntok;
-}
-
-
-
-/*
- * matchkey - match a keyword to a list
- */
-static int
-matchkey(
- register char *word,
- register struct keyword *keys
- )
-{
- for (;;) {
- if (keys->keytype == CONFIG_UNKNOWN) {
- return CONFIG_UNKNOWN;
- }
- if (STRSAME(word, keys->text))
- return keys->keytype;
- keys++;
- }
-}
-
-
-/*
- * getnetnum - return a net number (this is crude, but careful)
- */
-static int
-getnetnum(
- const char *num,
- struct sockaddr_in *addr,
- int complain
- )
-{
- register const char *cp;
- register char *bp;
- register int i;
- register int temp;
- char buf[80]; /* will core dump on really stupid stuff */
- u_int32 netnum;
-
- /* XXX ELIMINATE replace with decodenetnum */
- cp = num;
- netnum = 0;
- for (i = 0; i < 4; i++) {
- bp = buf;
- while (isdigit((int)*cp))
- *bp++ = *cp++;
- if (bp == buf)
- break;
-
- if (i < 3) {
- if (*cp++ != '.')
- break;
- } else if (*cp != '\0')
- break;
-
- *bp = '\0';
- temp = atoi(buf);
- if (temp > 255)
- break;
- netnum <<= 8;
- netnum += temp;
-#ifdef DEBUG
- if (debug > 3)
- printf("getnetnum %s step %d buf %s temp %d netnum %lu\n",
- num, i, buf, temp, (u_long)netnum);
-#endif
- }
-
- if (i < 4) {
- if (complain)
- msyslog(LOG_ERR,
- "getnetnum: \"%s\" invalid host number, line ignored",
- num);
-#ifdef DEBUG
- if (debug > 3)
- printf(
- "getnetnum: \"%s\" invalid host number, line ignored\n",
- num);
-#endif
- return 0;
- }
-
- /*
- * make up socket address. Clear it out for neatness.
- */
- memset((void *)addr, 0, sizeof(struct sockaddr_in));
- addr->sin_family = AF_INET;
- addr->sin_port = htons(NTP_PORT);
- addr->sin_addr.s_addr = htonl(netnum);
-#ifdef DEBUG
- if (debug > 1)
- printf("getnetnum given %s, got %s (%lx)\n",
- num, ntoa(addr), (u_long)netnum);
-#endif
- return 1;
-}
diff --git a/contrib/ntp/ntpdate/ntptimeset.c b/contrib/ntp/ntpdate/ntptimeset.c
deleted file mode 100644
index 2485aad..0000000
--- a/contrib/ntp/ntpdate/ntptimeset.c
+++ /dev/null
@@ -1,2164 +0,0 @@
-/*
- * ntptimeset - get/set the time via ntp
- *
- * GOAL:
- * The goal of ntptime is to set the current time on system startup
- * to the best possible time using the network very wisely. It is assumed
- * that after a resonable time has been sett then ntp daemon will
- * maintain it.
- *
- * PROBLEM DOMAIN:
- * We have three sets of issues related to acheiving the goal. The first
- * issue is using the network when normal traffic is happening or when
- * the entire network world is recovering from a campus wide power failure
- * and is restarting. The second issue is the class of machine whether it
- * is a user's office workstation being handled by an uneducated user or
- * a server computer being handled by a trained operations staff. The third
- * issue is whether the ratio of people to computers and whether the
- * environment is stable and viable or not.
- *
- * NETWORK USAGE:
- * The first issue of using the network wisely is a question of whether
- * the network load and time server load and state are normal. If things
- * are normal ntptime can do what ntpdate does of sending out 4 packets
- * quickly to each server (new transmit done with each ack). However
- * if network or time load is high then this scheme will simply contribute
- * to problems. Given we have minimal state, we simply weight lost packets
- * significantly and make sure we throttle output as much as possible
- * without performance lost for quick startups.
- *
- * TRAINING AND KNOWLEDGE:
- * The second issue of uneducated user of a office workstation versus a
- * trained operation staff of a server machine translates into simply an
- * issue of untrained and trained users.
- *
- * The training issue implies that for the sake of the users involved in the
- * handling of their office workstation, problems and options should be
- * communicated simply and effectively and not in terse expert related
- * descriptions without possible options to be taken. The operator's training
- * and education enables them to deal with either type of communication and
- * control.
- *
- * AUTOMATION AND MANUAL CONTROL:
- * The last issue boils down to a design problem. If the design tends to go
- * into a manual mode when the environment is non-viable then one person
- * handling many computers all at the same time will be heavily impacted. On
- * the other hand, if the design tends to be automatic and does not indicate
- * a way for the user to take over control then the computer will be
- * unavailable for the user until the proble is resolved by someone else or
- * the user.
- *
- * NOTE: Please do not have this program print out every minute some line,
- * of output. If this happens and the environment is in trouble then
- * many pages of paper on many different machines will be filled up.
- * Save some tress in your lifetime.
- *
- * CONCLUSION:
- * The behavior of the program derived from these three issues should be
- * that during normal situations it quickly sets the time and allow the
- * system to startup.
- *
- * However during abnormal conditions as detected by unresponsive servers,
- * out-of-sync or bad responses and other detections, it should print out
- * a simple but clear message and continue in a mellow way to get the best
- * possible time. It may never get the time and if so should also indicate
- * this.
- *
- * Rudy Nedved
- * 18-May-1993
- *
- ****************************************************************
- *
- * Much of the above is confusing or no longer relevant. For example,
- * it is rare these days for a machine's console to be a printing terminal,
- * so the comment about saving trees doesn't mean much. Nonetheless,
- * the basic principles still stand:
- *
- * - Work automatically, without human control or intervention. To
- * this end, we use the same configuration file as ntpd itself, so
- * you don't have to specify servers or other information on the
- * command line. We also recognize that sometimes we won't be able
- * to contact any servers, and give up in that event instead of
- * hanging forever.
- *
- * - Behave in a sane way, both internally and externally, even in the
- * face of insane conditions. That means we back off quickly when
- * we don't hear a response, to avoid network congestion. Like
- * ntpd, we verify responses from several servers before accepting
- * the new time data.
- *
- * However, we don't assume that the local clock is right, or even
- * close, because it might not be at boot time, and we want to catch
- * and correct that situation. This behaviour has saved us in several
- * instances. On HP-UX 9.0x, there used to be a bug in adjtimed which
- * would cause the time to be set to some wild value, making the machine
- * essentially unusable (we use Kerberos authentication pervasively,
- * and it requires workstations and servers to have a time within five
- * minutes of the Kerberos server). We also have problems on PC's
- * running both Linux and some Microsoft OS -- they tend to disagree
- * on what the BIOS clock should say, and who should update it, and
- * when. On those systems, we not only run ntptimeset at boot, we
- * also reset the BIOS clock based on the result, so the correct
- * time will be retained across reboots.
- *
- * For these reasons, and others, we have continued to use this tool
- * rather than ntpdate. It is run automatically at boot time on every
- * workstation and server in our facility.
- *
- * In the past, we called this program 'ntptime'. Unfortunately, the
- * ntp v4 distribution also includes a program with that name. In
- * order to avoid confusion, we have renamed our program 'ntptimeset',
- * which more accurately describes what it does.
- *
- * Jeffrey T. Hutzelman (N3NHS) <jhutz+@cmu.edu>
- * School of Computer Science - Research Computing Facility
- * Carnegie Mellon University - Pittsburgh, PA
- * 16-Aug-1999
- *
- */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include "ntp_machine.h"
-#include "ntp_fp.h"
-#include "ntp.h"
-#include "ntp_io.h"
-#include "iosignal.h"
-#include "ntp_unixtime.h"
-#include "ntpdate.h"
-#include "ntp_string.h"
-#include "ntp_syslog.h"
-#include "ntp_select.h"
-#include "ntp_stdlib.h"
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-#include <stdio.h>
-#include <signal.h>
-#include <ctype.h>
-#ifndef SYS_WINNT
-# ifdef HAVE_SYS_SIGNAL_H
-# include <sys/signal.h>
-# else
-# include <signal.h>
-# endif
-# include <sys/ioctl.h>
-#endif /* SYS_WINNT */
-
-#ifdef HAVE_SYS_RESOURCE_H
-# include <sys/resource.h>
-#endif /* HAVE_SYS_RESOURCE_H */
-
-#ifdef SYS_VXWORKS
-# include "ioLib.h"
-# include "sockLib.h"
-# include "timers.h"
-#endif
-
-#include "recvbuff.h"
-
-#ifdef SYS_WINNT
-# define TARGET_RESOLUTION 1 /* Try for 1-millisecond accuracy
- on Windows NT timers. */
-#pragma comment(lib, "winmm")
-#endif /* SYS_WINNT */
-
-/*
- * Scheduling priority we run at
- */
-#ifndef SYS_VXWORKS
-# define NTPDATE_PRIO (-12)
-#else
-# define NTPDATE_PRIO (100)
-#endif
-
-#if defined(HAVE_TIMER_SETTIME) || defined (HAVE_TIMER_CREATE)
-/* POSIX TIMERS - vxWorks doesn't have itimer - casey */
-static timer_t ntpdate_timerid;
-#endif
-
-/*
- * Compatibility stuff for Version 2
- */
-#define NTP_MAXSKW 0x28f /* 0.01 sec in fp format */
-#define NTP_MINDIST 0x51f /* 0.02 sec in fp format */
-#define NTP_INFIN 15 /* max stratum, infinity a la Bellman-Ford */
-#define NTP_MAXWGT (8*FP_SECOND) /* maximum select weight 8 seconds */
-#define NTP_MAXLIST 5 /* maximum select list size */
-#define PEER_SHIFT 8 /* 8 suitable for crystal time base */
-
-/*
- * Debugging flag
- */
-volatile int debug = 0;
-
-/*
- * File descriptor masks etc. for call to select
- */
-int fd;
-fd_set fdmask;
-
-/*
- * Initializing flag. All async routines watch this and only do their
- * thing when it is clear.
- */
-int initializing = 1;
-
-/*
- * Alarm flag. Set when an alarm occurs
- */
-volatile int alarm_flag = 0;
-
-/*
- * Set the time if valid time determined
- */
-int set_time = 0;
-
-/*
- * transmission rate control
- */
-#define MINTRANSMITS (3) /* minimum total packets per server */
-#define MAXXMITCOUNT (2) /* maximum packets per time interrupt */
-
-/*
- * time setting constraints
- */
-#define DESIREDDISP (4*FP_SECOND) /* desired dispersion, (fp 4) */
-int max_period = DEFMAXPERIOD;
-int min_servers = DEFMINSERVERS;
-int min_valid = DEFMINVALID;
-
-/*
- * counters related to time setting constraints
- */
-int contacted = 0; /* # of servers we have sent to */
-int responding = 0; /* servers responding */
-int validcount = 0; /* servers with valid time */
-int valid_n_low = 0; /* valid time servers with low dispersion */
-
-/*
- * Unpriviledged port flag.
- */
-int unpriv_port = 0;
-
-/*
- * Program name.
- */
-char *progname;
-
-/*
- * Systemwide parameters and flags
- */
-struct server **sys_servers; /* the server list */
-int sys_numservers = 0; /* number of servers to poll */
-int sys_authenticate = 0; /* true when authenticating */
-u_int32 sys_authkey = 0; /* set to authentication key in use */
-u_long sys_authdelay = 0; /* authentication delay */
-
-/*
- * The current internal time
- */
-u_long current_time = 0;
-
-/*
- * File of encryption keys
- */
-
-#ifndef KEYFILE
-# ifndef SYS_WINNT
-#define KEYFILE "/etc/ntp.keys"
-# else
-#define KEYFILE "%windir%\\ntp.keys"
-# endif /* SYS_WINNT */
-#endif /* KEYFILE */
-
-#ifndef SYS_WINNT
-const char *key_file = KEYFILE;
-#else
-char key_file_storage[MAX_PATH+1], *key_file ;
-#endif /* SYS_WINNT */
-
-/*
- * total packet counts
- */
-u_long total_xmit = 0;
-u_long total_recv = 0;
-
-/*
- * Miscellaneous flags
- */
-int verbose = 0;
-#define HORRIBLEOK 3 /* how many packets to let out */
-int horrible = 0; /* how many packets we drop for testing */
-int secondhalf = 0; /* second half of timeout period */
-int printmsg = 0; /* print time response analysis */
-
-/*
- * The half time and finish time in internal time
- */
-u_long half_time = 0;
-u_long finish_time = 0;
-
-
-int ntptimesetmain P((int argc, char *argv[]));
-static void analysis P((int final));
-static int have_enough P((void));
-static void transmit P((register struct server *server));
-static void receive P((struct recvbuf *rbufp));
-static void clock_filter P((register struct server *server, s_fp d, l_fp *c));
-static void clock_count P((void));
-static struct server *clock_select P((void));
-static void set_local_clock P((void));
-static struct server *findserver P((struct sockaddr_in *addr));
-static void timer P((void));
-#ifndef SYS_WINNT
-static RETSIGTYPE alarming P((int sig));
-#endif /* SYS_WINNT */
-static void init_alarm P((void));
-static void init_io P((void));
-static int sendpkt P((struct sockaddr_in *dest, struct pkt *pkt, int len));
- void input_handler P((l_fp *xts));
-static void printserver P((register struct server *pp, FILE *fp));
-#if !defined(HAVE_VSPRINTF)
-int vsprintf P((char *str, const char *fmt, va_list ap));
-#endif
-
-#ifdef HAVE_SIGNALED_IO
-extern void wait_for_signal P((void));
-extern void unblock_io_and_alarm P((void));
-extern void block_io_and_alarm P((void));
-#endif
-
-
-#ifdef NO_MAIN_ALLOWED
-CALL(ntptimeset,"ntptimeset",ntptimesetmain);
-
-void clear_globals()
-{
- /*
- * Debugging flag
- */
- debug = 0;
-
- ntp_optind = 0;
-
- /*
- * Initializing flag. All async routines watch this and only do their
- * thing when it is clear.
- */
- initializing = 1;
-
- /*
- * Alarm flag. Set when an alarm occurs
- */
- alarm_flag = 0;
-
- /*
- * Unpriviledged port flag.
- */
- unpriv_port = 0;
-
- /*
- * Systemwide parameters and flags
- */
- sys_numservers = 0; /* number of servers to poll */
- sys_authenticate = 0; /* true when authenticating */
- sys_authkey = 0; /* set to authentication key in use */
- sys_authdelay = 0; /* authentication delay */
-
- /*
- * The current internal time
- */
- current_time = 0;
-
- verbose = 0;
-}
-#endif /* NO_MAIN_ALLOWED */
-
-/*
- * Main program. Initialize us and loop waiting for I/O and/or
- * timer expiries.
- */
-#ifndef NO_MAIN_ALLOWED
-int
-main(
- int argc,
- char *argv[]
- )
-{
- return ntptimesetmain(argc, argv);
-}
-#endif /* NO_MAIN_ALLOWED */
-
-
-int
-ntptimesetmain(
- int argc,
- char *argv[]
- )
-{
- int was_alarmed;
- int tot_recvbufs;
- struct recvbuf *rbuf;
- l_fp tmp;
- int errflg;
- int c;
- extern char *ntp_optarg;
- extern int ntp_optind;
- int ltmp;
- char *cfgpath;
-
-#ifdef SYS_WINNT
- HANDLE process_handle;
-
- wVersionRequested = MAKEWORD(1,1);
- if (WSAStartup(wVersionRequested, &wsaData)) {
- msyslog(LOG_ERR, "No useable winsock.dll: %m");
- exit(1);
- }
-#endif /* SYS_WINNT */
-
-#ifdef NO_MAIN_ALLOWED
- clear_globals();
-#endif
-
- errflg = 0;
- cfgpath = 0;
- progname = argv[0];
- syslogit = 0;
-
- /*
- * Decode argument list
- */
- while ((c = ntp_getopt(argc, argv, "a:c:de:slt:uvHS:V:")) != EOF)
- switch (c)
- {
- case 'a':
- c = atoi(ntp_optarg);
- sys_authenticate = 1;
- sys_authkey = c;
- break;
- case 'c':
- cfgpath = ntp_optarg;
- break;
- case 'd':
- ++debug;
- break;
- case 'e':
- if (!atolfp(ntp_optarg, &tmp)
- || tmp.l_ui != 0) {
- (void) fprintf(stderr,
- "%s: encryption delay %s is unlikely\n",
- progname, ntp_optarg);
- errflg++;
- } else {
- sys_authdelay = tmp.l_uf;
- }
- break;
- case 's':
- set_time = 1;
- break;
- case 'l':
- syslogit = 1;
- break;
- case 't':
- ltmp = atoi(ntp_optarg);
- if (ltmp <= 0) {
- (void) fprintf(stderr,
- "%s: maximum time period (%d) is invalid\n",
- progname, ltmp);
- errflg++;
- }
- else
- max_period = ltmp;
- break;
- case 'u':
- unpriv_port = 1;
- break;
- case 'v':
- ++verbose;
- break;
- case 'H':
- horrible++;
- break;
- case 'S':
- ltmp = atoi(ntp_optarg);
- if (ltmp <= 0) {
- (void) fprintf(stderr,
- "%s: minimum responding (%d) is invalid\n",
- progname, ltmp);
- errflg++;
- }
- else
- min_servers = ltmp;
- break;
- case 'V':
- ltmp = atoi(ntp_optarg);
- if (ltmp <= 0) {
- (void) fprintf(stderr,
- "%s: minimum valid (%d) is invalid\n",
- progname, ltmp);
- errflg++;
- }
- else
- min_valid = ltmp;
- break;
- case '?':
- ++errflg;
- break;
- default:
- break;
- }
-
-
- if (errflg || ntp_optind < argc) {
- fprintf(stderr,"usage: %s [switches...]\n",progname);
- fprintf(stderr," -v (verbose)\n");
- fprintf(stderr," -c path (set config file path)\n");
- fprintf(stderr," -a key (authenticate using key)\n");
- fprintf(stderr," -e delay (authentication delay)\n");
- fprintf(stderr," -S num (# of servers that must respond)\n");
- fprintf(stderr," -V num (# of servers that must valid)\n");
- fprintf(stderr," -s (set the time based if okay)\n");
- fprintf(stderr," -t secs (time period before ending)\n");
- fprintf(stderr," -l (use syslog facility)\n");
- fprintf(stderr," -u (use unprivileged port)\n");
- fprintf(stderr," -H (drop packets for debugging)\n");
- fprintf(stderr," -d (debug output)\n");
- exit(2);
- }
-
- /*
- * Logging. Open the syslog if we have to
- */
- if (syslogit) {
-#if !defined (SYS_WINNT) && !defined (SYS_VXWORKS) && !defined SYS_CYGWIN32
-# ifndef LOG_DAEMON
- openlog("ntptimeset", LOG_PID);
-# else
-
-# ifndef LOG_NTP
-# define LOG_NTP LOG_DAEMON
-# endif
- openlog("ntptimeset", LOG_PID | LOG_NDELAY, LOG_NTP);
- if (debug)
- setlogmask(LOG_UPTO(LOG_DEBUG));
- else
- setlogmask(LOG_UPTO(LOG_INFO));
-# endif /* LOG_DAEMON */
-#endif /* SYS_WINNT */
- }
-
- if (debug || verbose)
- msyslog(LOG_INFO, "%s", Version);
-
- if (horrible)
- msyslog(LOG_INFO, "Dropping %d out of %d packets",
- horrible,horrible+HORRIBLEOK);
- /*
- * Add servers we are going to be polling
- */
- loadservers(cfgpath);
-
- if (sys_numservers < min_servers) {
- msyslog(LOG_ERR, "Found %d servers, require %d servers",
- sys_numservers,min_servers);
- exit(2);
- }
-
- /*
- * determine when we will end at least
- */
- finish_time = max_period * TIMER_HZ;
- half_time = finish_time >> 1;
-
- /*
- * Initialize the time of day routines and the I/O subsystem
- */
- if (sys_authenticate) {
- init_auth();
-#ifdef SYS_WINNT
- if (!key_file) key_file = KEYFILE;
- if (!ExpandEnvironmentStrings(key_file, key_file_storage, MAX_PATH))
- {
- msyslog(LOG_ERR, "ExpandEnvironmentStrings(%s) failed: %m\n",
- key_file);
- } else {
- key_file = key_file_storage;
- }
-#endif /* SYS_WINNT */
-
- if (!authreadkeys(key_file)) {
- msyslog(LOG_ERR, "no key file, exiting");
- exit(1);
- }
- if (!authistrusted(sys_authkey)) {
- char buf[10];
-
- (void) sprintf(buf, "%lu", (unsigned long)sys_authkey);
- msyslog(LOG_ERR, "authentication key %s unknown", buf);
- exit(1);
- }
- }
- init_io();
- init_alarm();
-
- /*
- * Set the priority.
- */
-#ifdef SYS_VXWORKS
- taskPrioritySet( taskIdSelf(), NTPDATE_PRIO);
-#endif
-#if defined(HAVE_ATT_NICE)
- nice (NTPDATE_PRIO);
-#endif
-#if defined(HAVE_BSD_NICE)
- (void) setpriority(PRIO_PROCESS, 0, NTPDATE_PRIO);
-#endif
-#ifdef SYS_WINNT
- process_handle = GetCurrentProcess();
- if (!SetPriorityClass(process_handle, (DWORD) REALTIME_PRIORITY_CLASS)) {
- msyslog(LOG_ERR, "SetPriorityClass failed: %m");
- }
-#endif /* SYS_WINNT */
-
- initializing = 0;
-
- /*
- * Use select() on all on all input fd's for unlimited
- * time. select() will terminate on SIGALARM or on the
- * reception of input. Using select() means we can't do
- * robust signal handling and we get a potential race
- * between checking for alarms and doing the select().
- * Mostly harmless, I think.
- * Keep going until we have enough information, or time is up.
- */
- /* On VMS, I suspect that select() can't be interrupted
- * by a "signal" either, so I take the easy way out and
- * have select() time out after one second.
- * System clock updates really aren't time-critical,
- * and - lacking a hardware reference clock - I have
- * yet to learn about anything else that is.
- */
- was_alarmed = 0;
- while (finish_time > current_time) {
-#if !defined(HAVE_SIGNALED_IO)
- fd_set rdfdes;
- int nfound;
-#elif defined(HAVE_SIGNALED_IO)
- block_io_and_alarm();
-#endif
-
- tot_recvbufs = full_recvbuffs(); /* get received buffers */
- if (printmsg) {
- printmsg = 0;
- analysis(0);
- }
- if (alarm_flag) { /* alarmed? */
- was_alarmed = 1;
- alarm_flag = 0;
- }
-
- if (!was_alarmed && tot_recvbufs > 0) {
- /*
- * Nothing to do. Wait for something.
- */
-#ifndef HAVE_SIGNALED_IO
- rdfdes = fdmask;
-# if defined(VMS) || defined(SYS_VXWORKS)
- /* make select() wake up after one second */
- {
- struct timeval t1;
-
- t1.tv_sec = 1; t1.tv_usec = 0;
- nfound = select(fd+1, &rdfdes, (fd_set *)0,
- (fd_set *)0, &t1);
- }
-# else
- nfound = select(fd+1, &rdfdes, (fd_set *)0,
- (fd_set *)0, (struct timeval *)0);
-# endif /* VMS */
- if (nfound > 0) {
- l_fp ts;
- get_systime(&ts);
- (void)input_handler(&ts);
- }
- else if (nfound == -1 && errno != EINTR)
- msyslog(LOG_ERR, "select() error: %m");
- else if (debug) {
-# if !defined SYS_VXWORKS && !defined SYS_CYGWIN32 /* to unclutter log */
- msyslog(LOG_DEBUG, "select(): nfound=%d, error: %m", nfound);
-# endif
- }
-#else /* HAVE_SIGNALED_IO */
-
- wait_for_signal();
-#endif /* HAVE_SIGNALED_IO */
- if (alarm_flag) /* alarmed? */
- {
- was_alarmed = 1;
- alarm_flag = 0;
- }
- tot_recvbufs = full_recvbuffs(); /* get received buffers */
- }
-#ifdef HAVE_SIGNALED_IO
- unblock_io_and_alarm();
-#endif /* HAVE_SIGNALED_IO */
-
- /*
- * Out here, signals are unblocked. Call timer routine
- * to process expiry.
- */
- if (was_alarmed)
- {
- timer();
- was_alarmed = 0;
- }
-
- /*
- * Call the data procedure to handle each received
- * packet.
- */
- rbuf = get_full_recv_buffer();
- while (rbuf != NULL)
- {
- receive(rbuf);
- freerecvbuf(rbuf);
- rbuf = get_full_recv_buffer();
- }
-
- /*
- * Do we have enough information to stop now?
- */
- if (have_enough())
- break; /* time to end */
-
- /*
- * Go around again
- */
- }
-
- /*
- * adjust the clock and exit accordingly
- */
- set_local_clock();
-
- /*
- * if we get here then we are in trouble
- */
- return(1);
-}
-
-
-/*
- * analysis - print a message indicating what is happening with time service
- * must mimic have_enough() procedure.
- */
-static void
-analysis(
- int final
- )
-{
- if (contacted < sys_numservers) {
- printf("%d servers of %d have been probed with %d packets\n",
- contacted,sys_numservers,MINTRANSMITS);
- return;
- }
- if (!responding) {
- printf("No response from any of %d servers, network problem?\n",
- sys_numservers);
- return;
- }
- else if (responding < min_servers) {
- printf("%d servers out of %d responding, need at least %d.\n",
- responding, sys_numservers, min_servers);
- return;
- }
- if (!validcount) {
- printf("%d servers responding but none have valid time\n",
- responding);
- return;
- }
- else if (validcount < min_valid) {
- printf("%d servers responding, %d are valid, need %d valid\n",
- responding,validcount,min_valid);
- return;
- }
- if (!final && valid_n_low != validcount) {
- printf("%d valid servers but only %d have low dispersion\n",
- validcount,valid_n_low);
- return;
- }
-}
-
-
-/* have_enough - see if we have enough information to terminate probing
- */
-static int
-have_enough(void)
-{
- /* have we contacted all servers yet? */
- if (contacted < sys_numservers)
- return 0; /* no...try some more */
-
- /* have we got at least minimum servers responding? */
- if (responding < min_servers)
- return 0; /* no...try some more */
-
- /* count the clocks */
- (void) clock_count();
-
- /* have we got at least minimum valid clocks? */
- if (validcount <= 0 || validcount < min_valid)
- return 0; /* no...try some more */
-
- /* do we have all valid servers with low dispersion */
- if (!secondhalf && valid_n_low != validcount)
- return 0;
-
- /* if we get into the secondhalf then we ignore dispersion */
-
- /* all conditions have been met...end */
- return 1;
-}
-
-
-/*
- * transmit - transmit a packet to the given server, or mark it completed.
- * This is called by the timeout routine and by the receive
- * procedure.
- */
-static void
-transmit(
- register struct server *server
- )
-{
- struct pkt xpkt;
- int timeout;
-
- if (debug > 2)
- printf("transmit(%s)\n", ntoa(&server->srcadr));
-
- if ((server->reach & 01) == 0) {
- l_fp ts;
- /*
- * Last message to this server timed out. Shift
- * zeros into the filter.
- */
- L_CLR(&ts);
- clock_filter(server, 0, &ts);
- }
-
- /*
- * shift reachable register over
- */
- server->reach <<= 1;
-
- /*
- * If we're here, send another message to the server. Fill in
- * the packet and let 'er rip.
- */
- xpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOTINSYNC,
- server->version, MODE_CLIENT);
- xpkt.stratum = STRATUM_TO_PKT(STRATUM_UNSPEC);
- xpkt.ppoll = NTP_MINPOLL;
- xpkt.precision = NTPDATE_PRECISION;
- xpkt.rootdelay = htonl(NTPDATE_DISTANCE);
- xpkt.rootdispersion = htonl(NTPDATE_DISP);
- xpkt.refid = htonl(NTPDATE_REFID);
- L_CLR(&xpkt.reftime);
- L_CLR(&xpkt.org);
- L_CLR(&xpkt.rec);
-
- /*
- * Determine whether to authenticate or not. If so,
- * fill in the extended part of the packet and do it.
- * If not, just timestamp it and send it away.
- */
- if (sys_authenticate) {
- int len;
-
- xpkt.exten[0] = htonl(sys_authkey);
- get_systime(&server->xmt);
- L_ADDUF(&server->xmt, sys_authdelay);
- HTONL_FP(&server->xmt, &xpkt.xmt);
- len = authencrypt(sys_authkey, (u_int32 *)&xpkt, LEN_PKT_NOMAC);
- if (sendpkt(&(server->srcadr), &xpkt, (int)(LEN_PKT_NOMAC + len))) {
- if (debug > 1)
- printf("failed transmit auth to %s\n",
- ntoa(&(server->srcadr)));
- return;
- }
-
- if (debug > 1)
- printf("transmit auth to %s\n",
- ntoa(&(server->srcadr)));
- } else {
- get_systime(&(server->xmt));
- HTONL_FP(&server->xmt, &xpkt.xmt);
- if (sendpkt(&(server->srcadr), &xpkt, LEN_PKT_NOMAC)) {
- if (debug > 1)
- printf("failed transmit to %s\n",
- ntoa(&(server->srcadr)));
- return;
- }
-
- if (debug > 1)
- printf("transmit to %s\n", ntoa(&(server->srcadr)));
- }
-
- /*
- * count transmits, record contacted count and set transmit time
- */
- if (++server->xmtcnt == MINTRANSMITS)
- contacted++;
- server->last_xmit = current_time;
-
- /*
- * determine timeout for this packet. The more packets we send
- * to the host, the slower we get. If the host indicates that
- * it is not "sane" then we expect even less.
- */
- if (server->xmtcnt < MINTRANSMITS) {
- /* we have not sent enough */
- timeout = TIMER_HZ; /* 1 second probe */
- }
- else if (server->rcvcnt <= 0) {
- /* we have heard nothing */
- if (secondhalf)
- timeout = TIMER_HZ<<4; /* 16 second probe */
- else
- timeout = TIMER_HZ<<3; /* 8 second probe */
- }
- else {
- /* if we have low dispersion then probe infrequently */
- if (server->dispersion <= DESIREDDISP)
- timeout = TIMER_HZ<<4; /* 16 second probe */
- /* if the server is not in sync then let it alone */
- else if (server->leap == LEAP_NOTINSYNC)
- timeout = TIMER_HZ<<4; /* 16 second probe */
- /* if the server looks broken ignore it */
- else if (server->org.l_ui < server->reftime.l_ui)
- timeout = TIMER_HZ<<5; /* 32 second probe */
- else if (secondhalf)
- timeout = TIMER_HZ<<2; /* 4 second probe */
- else
- timeout = TIMER_HZ<<1; /* 2 second probe */
- }
-
- /*
- * set next transmit time based on timeout
- */
- server->event_time = current_time + timeout;
-}
-
-
-/*
- * receive - receive and process an incoming frame
- */
-static void
-receive(
- struct recvbuf *rbufp
- )
-{
- register struct pkt *rpkt;
- register struct server *server;
- register s_fp di;
- l_fp t10, t23;
- l_fp org;
- l_fp rec;
- l_fp ci;
- int has_mac;
- int is_authentic;
-
- if (debug > 2)
- printf("receive(%s)\n", ntoa(&rbufp->srcadr));
- /*
- * Check to see if the packet basically looks like something
- * intended for us.
- */
- if (rbufp->recv_length == LEN_PKT_NOMAC)
- has_mac = 0;
- else if (rbufp->recv_length >= LEN_PKT_NOMAC)
- has_mac = 1;
- else {
- if (debug > 2)
- printf("receive: packet length %d\n",
- rbufp->recv_length);
- return; /* funny length packet */
- }
-
- rpkt = &(rbufp->recv_pkt);
- if (PKT_VERSION(rpkt->li_vn_mode) < NTP_OLDVERSION ||
- PKT_VERSION(rpkt->li_vn_mode) > NTP_VERSION) {
- if (debug > 1)
- printf("receive: bad version %d\n",
- PKT_VERSION(rpkt->li_vn_mode));
- return;
- }
-
- if ((PKT_MODE(rpkt->li_vn_mode) != MODE_SERVER
- && PKT_MODE(rpkt->li_vn_mode) != MODE_PASSIVE)
- || rpkt->stratum >=STRATUM_UNSPEC) {
- if (debug > 1)
- printf("receive: mode %d stratum %d\n",
- PKT_MODE(rpkt->li_vn_mode), rpkt->stratum);
- return;
- }
-
- /*
- * So far, so good. See if this is from a server we know.
- */
- server = findserver(&(rbufp->srcadr));
- if (server == NULL) {
- if (debug > 1)
- printf("receive: server not found\n");
- return;
- }
-
- /*
- * Decode the org timestamp and make sure we're getting a response
- * to our last request.
- */
- NTOHL_FP(&rpkt->org, &org);
- if (!L_ISEQU(&org, &server->xmt)) {
- if (debug > 1)
- printf("receive: pkt.org and peer.xmt differ\n");
- return;
- }
-
- /*
- * Check out the authenticity if we're doing that.
- */
- if (!sys_authenticate)
- is_authentic = 1;
- else {
- is_authentic = 0;
-
- if (debug > 3)
- printf("receive: rpkt keyid=%ld sys_authkey=%ld decrypt=%ld\n",
- (long int)ntohl(rpkt->exten[0]), (long int)sys_authkey,
- (long int)authdecrypt(sys_authkey, (u_int32 *)rpkt,
- LEN_PKT_NOMAC, (int)(rbufp->recv_length - LEN_PKT_NOMAC)));
-
- if (has_mac && ntohl(rpkt->exten[0]) == sys_authkey &&
- authdecrypt(sys_authkey, (u_int32 *)rpkt, LEN_PKT_NOMAC,
- (int)(rbufp->recv_length - LEN_PKT_NOMAC)))
- is_authentic = 1;
- if (debug)
- printf("receive: authentication %s\n",
- is_authentic ? "passed" : "failed");
- }
- server->trust <<= 1;
- if (!is_authentic)
- server->trust |= 1;
-
- /*
- * Looks good. Record info from the packet.
- */
- server->leap = PKT_LEAP(rpkt->li_vn_mode);
- server->stratum = PKT_TO_STRATUM(rpkt->stratum);
- server->precision = rpkt->precision;
- server->rootdelay = ntohl(rpkt->rootdelay);
- server->rootdispersion = ntohl(rpkt->rootdispersion);
- server->refid = rpkt->refid;
- NTOHL_FP(&rpkt->reftime, &server->reftime);
- NTOHL_FP(&rpkt->rec, &rec);
- NTOHL_FP(&rpkt->xmt, &server->org);
-
- /*
- * count this guy as responding
- */
- server->reach |= 1;
- if (server->rcvcnt++ == 0)
- responding++;
-
- /*
- * Make sure the server is at least somewhat sane. If not, ignore
- * it for later.
- */
- if (L_ISZERO(&rec) || !L_ISHIS(&server->org, &rec)) {
- if (debug > 1)
- printf("receive: pkt insane\n");
- return;
- }
-
- /*
- * Calculate the round trip delay (di) and the clock offset (ci).
- * We use the equations (reordered from those in the spec):
- *
- * d = (t2 - t3) - (t1 - t0)
- * c = ((t2 - t3) + (t1 - t0)) / 2
- */
- t10 = server->org; /* pkt.xmt == t1 */
- L_SUB(&t10, &rbufp->recv_time); /* recv_time == t0*/
-
- t23 = rec; /* pkt.rec == t2 */
- L_SUB(&t23, &org); /* pkt->org == t3 */
-
- /* now have (t2 - t3) and (t0 - t1). Calculate (ci) and (di) */
- ci = t10;
- L_ADD(&ci, &t23);
- L_RSHIFT(&ci);
-
- /*
- * Calculate di in t23 in full precision, then truncate
- * to an s_fp.
- */
- L_SUB(&t23, &t10);
- di = LFPTOFP(&t23);
-
- if (debug > 3)
- printf("offset: %s, delay %s\n", lfptoa(&ci, 6), fptoa(di, 5));
-
- di += (FP_SECOND >> (-(int)NTPDATE_PRECISION))
- + (FP_SECOND >> (-(int)server->precision)) + NTP_MAXSKW;
-
- if (di <= 0) { /* value still too raunchy to use? */
- L_CLR(&ci);
- di = 0;
- } else {
- di = max(di, NTP_MINDIST);
- }
-
-
- /*
- * This one is valid. Give it to clock_filter(),
- */
- clock_filter(server, di, &ci);
- if (debug > 1)
- printf("receive from %s\n", ntoa(&rbufp->srcadr));
-
- /*
- * See if we should goes the transmission. If not return now
- * otherwise have the next event time be shortened
- */
- if (server->stratum <= NTP_INFIN)
- return; /* server does not have a stratum */
- if (server->leap == LEAP_NOTINSYNC)
- return; /* just booted server or out of sync */
- if (!L_ISHIS(&server->org, &server->reftime))
- return; /* broken host */
- if (server->trust != 0)
- return; /* can not trust it */
-
- if (server->dispersion < DESIREDDISP)
- return; /* we have the desired dispersion */
-
- server->event_time -= (TIMER_HZ+1);
-}
-
-
-/*
- * clock_filter - add clock sample, determine a server's delay, dispersion
- * and offset
- */
-static void
-clock_filter(
- register struct server *server,
- s_fp di,
- l_fp *c
- )
-{
- register int i, j;
- int ord[NTP_SHIFT];
-
- /*
- * Insert sample and increment nextpt
- */
-
- i = server->filter_nextpt;
- server->filter_delay[i] = di;
- server->filter_offset[i] = *c;
- server->filter_soffset[i] = LFPTOFP(c);
- server->filter_nextpt++;
- if (server->filter_nextpt >= NTP_SHIFT)
- server->filter_nextpt = 0;
-
- /*
- * Sort indices into increasing delay order
- */
- for (i = 0; i < NTP_SHIFT; i++)
- ord[i] = i;
-
- for (i = 0; i < (NTP_SHIFT-1); i++) {
- for (j = i+1; j < NTP_SHIFT; j++) {
- if (server->filter_delay[ord[j]] == 0)
- continue;
- if (server->filter_delay[ord[i]] == 0
- || (server->filter_delay[ord[i]]
- > server->filter_delay[ord[j]])) {
- register int tmp;
-
- tmp = ord[i];
- ord[i] = ord[j];
- ord[j] = tmp;
- }
- }
- }
-
- /*
- * Now compute the dispersion, and assign values to delay and
- * offset. If there are no samples in the register, delay and
- * offset go to zero and dispersion is set to the maximum.
- */
- if (server->filter_delay[ord[0]] == 0) {
- server->delay = 0;
- L_CLR(&server->offset);
- server->soffset = 0;
- server->dispersion = PEER_MAXDISP;
- } else {
- register s_fp d;
-
- server->delay = server->filter_delay[ord[0]];
- server->offset = server->filter_offset[ord[0]];
- server->soffset = LFPTOFP(&server->offset);
- server->dispersion = 0;
- for (i = 1; i < NTP_SHIFT; i++) {
- if (server->filter_delay[ord[i]] == 0)
- d = PEER_MAXDISP;
- else {
- d = server->filter_soffset[ord[i]]
- - server->filter_soffset[ord[0]];
- if (d < 0)
- d = -d;
- if (d > PEER_MAXDISP)
- d = PEER_MAXDISP;
- }
- /*
- * XXX This *knows* PEER_FILTER is 1/2
- */
- server->dispersion += (u_fp)(d) >> i;
- }
- }
- /*
- * We're done
- */
-}
-
-
-/* clock_count - count the clock sources we have
- */
-static void
-clock_count(void)
-{
- register struct server *server;
- register int n;
-
- /* reset counts */
- validcount = valid_n_low = 0;
-
- /* go through the list of servers and count the clocks we believe
- * and that have low dispersion
- */
- for (n = 0; n < sys_numservers; n++) {
- server = sys_servers[n];
- if (server->delay == 0) {
- continue; /* no data */
- }
- if (server->stratum > NTP_INFIN) {
- continue; /* stratum no good */
- }
- if (server->delay > NTP_MAXWGT) {
- continue; /* too far away */
- }
- if (server->leap == LEAP_NOTINSYNC)
- continue; /* he's in trouble */
- if (!L_ISHIS(&server->org, &server->reftime)) {
- continue; /* very broken host */
- }
- if ((server->org.l_ui - server->reftime.l_ui) >= NTP_MAXAGE) {
- continue; /* too long without sync */
- }
- if (server->trust != 0) {
- continue;
- }
-
- /*
- * This one is a valid time source..
- */
- validcount++;
-
- /*
- * See if this one has a okay low dispersion
- */
- if (server->dispersion <= DESIREDDISP)
- valid_n_low++;
- }
-
- if (debug > 1)
- printf("have %d, valid %d, low %d\n",
- responding, validcount, valid_n_low);
-}
-
-
-/*
- * clock_select - select the pick-of-the-litter clock from the samples
- * we've got.
- */
-static struct server *
-clock_select(void)
-{
- register struct server *server;
- register int i;
- register int nlist;
- register s_fp d;
- register int j;
- register int n;
- s_fp local_threshold;
- struct server *server_list[NTP_MAXCLOCK];
- u_fp server_badness[NTP_MAXCLOCK];
- struct server *sys_server;
-
- /*
- * This first chunk of code is supposed to go through all
- * servers we know about to find the NTP_MAXLIST servers which
- * are most likely to succeed. We run through the list
- * doing the sanity checks and trying to insert anyone who
- * looks okay. We are at all times aware that we should
- * only keep samples from the top two strata and we only need
- * NTP_MAXLIST of them.
- */
- nlist = 0; /* none yet */
- for (n = 0; n < sys_numservers; n++) {
- server = sys_servers[n];
- if (server->delay == 0)
- continue; /* no data */
- if (server->stratum > NTP_INFIN)
- continue; /* stratum no good */
- if (server->delay > NTP_MAXWGT) {
- continue; /* too far away */
- }
- if (server->leap == LEAP_NOTINSYNC)
- continue; /* he's in trouble */
- if (!L_ISHIS(&server->org, &server->reftime)) {
- continue; /* very broken host */
- }
- if ((server->org.l_ui - server->reftime.l_ui)
- >= NTP_MAXAGE) {
- continue; /* too long without sync */
- }
- if (server->trust != 0) {
- continue;
- }
-
- /*
- * This one seems sane. Find where he belongs
- * on the list.
- */
- d = server->dispersion + server->dispersion;
- for (i = 0; i < nlist; i++)
- if (server->stratum <= server_list[i]->stratum)
- break;
- for ( ; i < nlist; i++) {
- if (server->stratum < server_list[i]->stratum)
- break;
- if (d < (s_fp) server_badness[i])
- break;
- }
-
- /*
- * If i points past the end of the list, this
- * guy is a loser, else stick him in.
- */
- if (i >= NTP_MAXLIST)
- continue;
- for (j = nlist; j > i; j--)
- if (j < NTP_MAXLIST) {
- server_list[j] = server_list[j-1];
- server_badness[j]
- = server_badness[j-1];
- }
-
- server_list[i] = server;
- server_badness[i] = d;
- if (nlist < NTP_MAXLIST)
- nlist++;
- }
-
- /*
- * Got the five-or-less best. Cut the list where the number of
- * strata exceeds two.
- */
- j = 0;
- for (i = 1; i < nlist; i++)
- if (server_list[i]->stratum > server_list[i-1]->stratum)
- if (++j == 2) {
- nlist = i;
- break;
- }
-
- /*
- * Whew! What we should have by now is 0 to 5 candidates for
- * the job of syncing us. If we have none, we're out of luck.
- * If we have one, he's a winner. If we have more, do falseticker
- * detection.
- */
-
- if (nlist == 0)
- sys_server = 0;
- else if (nlist == 1) {
- sys_server = server_list[0];
- } else {
- /*
- * Re-sort by stratum, bdelay estimate quality and
- * server.delay.
- */
- for (i = 0; i < nlist-1; i++)
- for (j = i+1; j < nlist; j++) {
- if (server_list[i]->stratum
- < server_list[j]->stratum)
- break; /* already sorted by stratum */
- if (server_list[i]->delay
- < server_list[j]->delay)
- continue;
- server = server_list[i];
- server_list[i] = server_list[j];
- server_list[j] = server;
- }
-
- /*
- * Calculate the fixed part of the dispersion limit
- */
- local_threshold = (FP_SECOND >> (-(int)NTPDATE_PRECISION))
- + NTP_MAXSKW;
-
- /*
- * Now drop samples until we're down to one.
- */
- while (nlist > 1) {
- for (n = 0; n < nlist; n++) {
- server_badness[n] = 0;
- for (j = 0; j < nlist; j++) {
- if (j == n) /* with self? */
- continue;
- d = server_list[j]->soffset
- - server_list[n]->soffset;
- if (d < 0) /* absolute value */
- d = -d;
- /*
- * XXX This code *knows* that
- * NTP_SELECT is 3/4
- */
- for (i = 0; i < j; i++)
- d = (d>>1) + (d>>2);
- server_badness[n] += d;
- }
- }
-
- /*
- * We now have an array of nlist badness
- * coefficients. Find the badest. Find
- * the minimum precision while we're at
- * it.
- */
- i = 0;
- n = server_list[0]->precision;;
- for (j = 1; j < nlist; j++) {
- if (server_badness[j] >= server_badness[i])
- i = j;
- if (n > server_list[j]->precision)
- n = server_list[j]->precision;
- }
-
- /*
- * i is the index of the server with the worst
- * dispersion. If his dispersion is less than
- * the threshold, stop now, else delete him and
- * continue around again.
- */
- if (server_badness[i] < (local_threshold
- + (FP_SECOND >> (-n))))
- break;
- for (j = i + 1; j < nlist; j++)
- server_list[j-1] = server_list[j];
- nlist--;
- }
-
- /*
- * What remains is a list of less than 5 servers. Take
- * the best.
- */
- sys_server = server_list[0];
- }
-
- /*
- * That's it. Return our server.
- */
- return sys_server;
-}
-
-
-/*
- * set_local_clock -- handle setting the local clock or displaying info.
- */
-static void
-set_local_clock(void)
-{
- register int i;
- register struct server *server;
- time_t tmp;
- double dtemp;
-
- /*
- * if setting time then print final analysis
- */
- if (set_time)
- analysis(1);
-
- /*
- * pick a clock
- */
- server = clock_select();
-
- /*
- * do some display of information
- */
- if (debug || verbose) {
- for (i = 0; i < sys_numservers; i++)
- printserver(sys_servers[i], stdout);
- if (debug)
- printf("packets sent %ld, received %ld\n",
- total_xmit, total_recv);
- }
-
- /*
- * see if we have a server to set the time with
- */
- if (server == 0) {
- if (!set_time || verbose)
- fprintf(stdout,"No servers available to sync time with\n");
- exit(1);
- }
-
- /*
- * we have a valid and selected time to use!!!!!
- */
-
- /*
- * if we are not setting the time then display offset and exit
- */
- if (!set_time) {
- fprintf(stdout,
- "Your clock is off by %s seconds. (%s) [%ld/%ld]\n",
- lfptoa(&server->offset, 7),
- ntoa(&server->srcadr),
- total_xmit, total_recv);
- exit(0);
- }
-
- /*
- * set the clock
- * XXX: Examine the more flexible approach used by ntpdate.
- * Note that a design consideration here is that we sometimes
- * _want_ to step the clock by a _huge_ amount in either
- * direction, because the local clock is completely bogus.
- * This condition must be recognized and dealt with, so
- * that we always get a good time when this completes.
- * -- jhutz+@cmu.edu, 16-Aug-1999
- */
- LFPTOD(&server->offset, dtemp);
- step_systime(dtemp);
- time(&tmp);
- fprintf(stdout,"Time set to %.20s [%s %s %ld/%ld]\n",
- ctime(&tmp)+4,
- ntoa(&server->srcadr),
- lfptoa(&server->offset, 7),
- total_xmit, total_recv);
- exit(0);
-}
-
-
-/*
- * findserver - find a server in the list given its address
- */
-static struct server *
-findserver(
- struct sockaddr_in *addr
- )
-{
- register int i;
- register u_int32 netnum;
-
- if (htons(addr->sin_port) != NTP_PORT)
- return 0;
- netnum = addr->sin_addr.s_addr;
-
- for (i = 0; i < sys_numservers; i++) {
- if (netnum == sys_servers[i]->srcadr.sin_addr.s_addr)
- return sys_servers[i];
- }
- return 0;
-}
-
-
-/*
- * timer - process a timer interrupt
- */
-static void
-timer(void)
-{
- register int k;
-
- /*
- * Bump the current idea of the time
- */
- current_time++;
-
- /*
- * see if we have reached half time
- */
- if (current_time >= half_time && !secondhalf) {
- secondhalf++;
- if (debug)
- printf("\nSecond Half of Timeout!\n");
- printmsg++;
- }
-
- /*
- * We only want to send a few packets per transmit interrupt
- * to throttle things
- */
- for(k = 0;k < MAXXMITCOUNT;k++) {
- register int i, oldi;
- register u_long oldxtime;
-
- /*
- * We want to send a packet out for a server that has an
- * expired event time. However to be mellow about this, we only
- * use one expired event timer and to avoid starvation we use
- * the one with the oldest last transmit time.
- */
- oldi = -1;
- oldxtime = 0;
- for (i = 0; i < sys_numservers; i++) {
- if (sys_servers[i]->event_time <= current_time) {
- if (oldi < 0 || oldxtime > sys_servers[i]->last_xmit) {
- oldxtime = sys_servers[i]->last_xmit;
- oldi = i;
- }
- }
- }
- if (oldi >= 0)
- transmit(sys_servers[oldi]);
- else
- break; /* no expired event */
- } /* end of transmit loop */
-}
-
-
-#ifndef SYS_WINNT
-/*
- * alarming - record the occurance of an alarm interrupt
- */
-static RETSIGTYPE
-alarming(
- int sig
- )
-#else
-void CALLBACK
-alarming(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
-#endif /* SYS_WINNT */
-{
- alarm_flag++;
-}
-
-
-/*
- * init_alarm - set up the timer interrupt
- */
-static void
-init_alarm(void)
-{
-#ifndef SYS_WINNT
-# ifndef HAVE_TIMER_SETTIME
- struct itimerval itimer;
-# else
- struct itimerspec ntpdate_itimer;
-# endif
-#else
- TIMECAPS tc;
- UINT wTimerRes, wTimerID;
-# endif /* SYS_WINNT */
-#if defined SYS_CYGWIN32 || defined SYS_WINNT
- HANDLE hToken;
- TOKEN_PRIVILEGES tkp;
- DWORD dwUser = 0;
-#endif /* SYS_WINNT */
-
- alarm_flag = 0;
-
-#ifndef SYS_WINNT
-# if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME)
- alarm_flag = 0;
- /* this code was put in as setitimer() is non existant this us the
- * POSIX "equivalents" setup - casey
- */
- /* ntpdate_timerid is global - so we can kill timer later */
- if (timer_create (CLOCK_REALTIME, NULL, &ntpdate_timerid) ==
-# ifdef SYS_VXWORKS
- ERROR
-# else
- -1
-# endif
- )
- {
- fprintf (stderr, "init_alarm(): timer_create (...) FAILED\n");
- return;
- }
-
- /* TIMER_HZ = (5)
- * Set up the alarm interrupt. The first comes 1/(2*TIMER_HZ)
- * seconds from now and they continue on every 1/TIMER_HZ seconds.
- */
- (void) signal_no_reset(SIGALRM, alarming);
- ntpdate_itimer.it_interval.tv_sec = ntpdate_itimer.it_value.tv_sec = 0;
- ntpdate_itimer.it_interval.tv_nsec = 1000000000/TIMER_HZ;
- ntpdate_itimer.it_value.tv_nsec = 1000000000/(TIMER_HZ<<1);
- timer_settime(ntpdate_timerid, 0 /* !TIMER_ABSTIME */, &ntpdate_itimer, NULL);
-# else
- /*
- * Set up the alarm interrupt. The first comes 1/(2*TIMER_HZ)
- * seconds from now and they continue on every 1/TIMER_HZ seconds.
- */
- (void) signal_no_reset(SIGALRM, alarming);
- itimer.it_interval.tv_sec = itimer.it_value.tv_sec = 0;
- itimer.it_interval.tv_usec = 1000000/TIMER_HZ;
- itimer.it_value.tv_usec = 1000000/(TIMER_HZ<<1);
- setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
-# endif
-#if defined SYS_CYGWIN32
- /*
- * Get previleges needed for fiddling with the clock
- */
-
- /* get the current process token handle */
- if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
- msyslog(LOG_ERR, "OpenProcessToken failed: %m");
- exit(1);
- }
- /* get the LUID for system-time privilege. */
- LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid);
- tkp.PrivilegeCount = 1; /* one privilege to set */
- tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- /* get set-time privilege for this process. */
- AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES) NULL, 0);
- /* cannot test return value of AdjustTokenPrivileges. */
- if (GetLastError() != ERROR_SUCCESS)
- msyslog(LOG_ERR, "AdjustTokenPrivileges failed: %m");
-#endif
-#else /* SYS_WINNT */
- _tzset();
-
- /*
- * Get previleges needed for fiddling with the clock
- */
-
- /* get the current process token handle */
- if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
- msyslog(LOG_ERR, "OpenProcessToken failed: %m");
- exit(1);
- }
- /* get the LUID for system-time privilege. */
- LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid);
- tkp.PrivilegeCount = 1; /* one privilege to set */
- tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- /* get set-time privilege for this process. */
- AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES) NULL, 0);
- /* cannot test return value of AdjustTokenPrivileges. */
- if (GetLastError() != ERROR_SUCCESS)
- msyslog(LOG_ERR, "AdjustTokenPrivileges failed: %m");
-
- /*
- * Set up timer interrupts for every 2**EVENT_TIMEOUT seconds
- * Under Win/NT, expiry of timer interval leads to invocation
- * of a callback function (on a different thread) rather than
- * generating an alarm signal
- */
-
- /* determine max and min resolution supported */
- if(timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
- msyslog(LOG_ERR, "timeGetDevCaps failed: %m");
- exit(1);
- }
- wTimerRes = min(max(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax);
- /* establish the minimum timer resolution that we'll use */
- timeBeginPeriod(wTimerRes);
-
- /* start the timer event */
- wTimerID = timeSetEvent(
- (UINT) (1000/TIMER_HZ), /* Delay */
- wTimerRes, /* Resolution */
- (LPTIMECALLBACK) alarming, /* Callback function */
- (DWORD) dwUser, /* User data */
- TIME_PERIODIC); /* Event type (periodic) */
- if (wTimerID == 0) {
- msyslog(LOG_ERR, "timeSetEvent failed: %m");
- exit(1);
- }
-#endif /* SYS_WINNT */
-}
-
-
-/*
- * init_io - initialize I/O data and open socket
- */
-static void
-init_io(void)
-{
-#ifdef SYS_WINNT
- WORD wVersionRequested;
- WSADATA wsaData;
- init_transmitbuff();
-#endif /* SYS_WINNT */
-
- /*
- * Init buffer free list and stat counters
- */
- init_recvbuff(sys_numservers + 2);
-
-#if defined(HAVE_SIGNALED_IO)
- set_signal();
-#endif
-
-#ifdef SYS_WINNT
- wVersionRequested = MAKEWORD(1,1);
- if (WSAStartup(wVersionRequested, &wsaData))
- {
- msyslog(LOG_ERR, "No useable winsock.dll: %m");
- exit(1);
- }
-#endif /* SYS_WINNT */
-
- BLOCKIO();
-
- /* create a datagram (UDP) socket */
- if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- msyslog(LOG_ERR, "socket() failed: %m");
- exit(1);
- /*NOTREACHED*/
- }
-
- /*
- * bind the socket to the NTP port
- */
- if (!debug && set_time && !unpriv_port) {
- struct sockaddr_in addr;
-
- memset((char *)&addr, 0, sizeof addr);
- addr.sin_family = AF_INET;
- addr.sin_port = htons(NTP_PORT);
- addr.sin_addr.s_addr = htonl(INADDR_ANY);
- if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
-#ifndef SYS_WINNT
- if (errno == EADDRINUSE)
-#else
- if (WSAGetLastError() == WSAEADDRINUSE)
-#endif
- msyslog(LOG_ERR,
- "the NTP socket is in use, exiting");
- else
- msyslog(LOG_ERR, "bind() fails: %m");
- exit(1);
- }
- }
-
- FD_ZERO(&fdmask);
- FD_SET(fd, &fdmask);
-
- /*
- * set non-blocking,
- */
-
-#ifdef USE_FIONBIO
- /* in vxWorks we use FIONBIO, but the others are defined for old systems, so
- * all hell breaks loose if we leave them defined
- */
-#undef O_NONBLOCK
-#undef FNDELAY
-#undef O_NDELAY
-#endif
-
-#if defined(O_NONBLOCK) /* POSIX */
- if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
- {
- msyslog(LOG_ERR, "fcntl(O_NONBLOCK) fails: %m");
- exit(1);
- /*NOTREACHED*/
- }
-#elif defined(FNDELAY)
- if (fcntl(fd, F_SETFL, FNDELAY) < 0)
- {
- msyslog(LOG_ERR, "fcntl(FNDELAY) fails: %m");
- exit(1);
- /*NOTREACHED*/
- }
-#elif defined(O_NDELAY) /* generally the same as FNDELAY */
- if (fcntl(fd, F_SETFL, O_NDELAY) < 0)
- {
- msyslog(LOG_ERR, "fcntl(O_NDELAY) fails: %m");
- exit(1);
- /*NOTREACHED*/
- }
-#elif defined(FIONBIO)
- if (
-# if defined(VMS)
- (ioctl(fd,FIONBIO,&1) < 0)
-# elif defined(SYS_WINNT)
- (ioctlsocket(fd,FIONBIO,(u_long *) &on) == SOCKET_ERROR)
-# else
- (ioctl(fd,FIONBIO,&on) < 0)
-# endif
- )
- {
- msyslog(LOG_ERR, "ioctl(FIONBIO) fails: %m");
- exit(1);
- /*NOTREACHED*/
- }
-#elif defined(FIOSNBIO)
- if (ioctl(fd,FIOSNBIO,&on) < 0)
- {
- msyslog(LOG_ERR, "ioctl(FIOSNBIO) fails: %m");
- exit(1);
- /*NOTREACHED*/
- }
-#else
-# include "Bletch: Need non-blocking I/O!"
-#endif
-
-#ifdef HAVE_SIGNALED_IO
- init_socket_sig(fd);
-#endif /* not HAVE_SIGNALED_IO */
-
- UNBLOCKIO();
-}
-
-
-/*
- * sendpkt - send a packet to the specified destination
- */
-static int
-sendpkt(
- struct sockaddr_in *dest,
- struct pkt *pkt,
- int len
- )
-{
- int cc;
- static int horriblecnt = 0;
-#ifdef SYS_WINNT
- DWORD err;
-#endif /* SYS_WINNT */
-
- total_xmit++; /* count it */
-
- if (horrible) {
- if (++horriblecnt > HORRIBLEOK) {
- if (debug > 3)
- printf("dropping send (%s)\n", ntoa(dest));
- if (horriblecnt >= HORRIBLEOK+horrible)
- horriblecnt = 0;
- return 0;
- }
- }
-
-
- cc = sendto(fd, (char *)pkt, (size_t)len, 0, (struct sockaddr *)dest,
- sizeof(struct sockaddr_in));
-#ifndef SYS_WINNT
- if (cc == -1) {
- if (errno != EWOULDBLOCK && errno != ENOBUFS)
-#else
- if (cc == SOCKET_ERROR) {
- err = WSAGetLastError();
- if (err != WSAEWOULDBLOCK && err != WSAENOBUFS)
-#endif /* SYS_WINNT */
- msyslog(LOG_ERR, "sendto(%s): %m", ntoa(dest));
- return -1;
- }
- return 0;
-}
-
-
-/*
- * input_handler - receive packets asynchronously
- */
-void
-input_handler(l_fp *xts)
-{
- register int n;
- register struct recvbuf *rb;
- struct timeval tvzero;
- int fromlen;
- fd_set fds;
- l_fp ts;
- ts = *xts; /* we ignore xts, but make the compiler happy */
-
- /*
- * Do a poll to see if we have data
- */
- for (;;) {
- fds = fdmask;
- tvzero.tv_sec = tvzero.tv_usec = 0;
- n = select(fd+1, &fds, (fd_set *)0, (fd_set *)0, &tvzero);
-
- /*
- * If nothing to do, just return. If an error occurred,
- * complain and return. If we've got some, freeze a
- * timestamp.
- */
- if (n == 0)
- return;
- else if (n == -1) {
- if (errno != EINTR) {
- msyslog(LOG_ERR, "select() error: %m");
- }
- return;
- }
- get_systime(&ts);
-
- /*
- * Get a buffer and read the frame. If we
- * haven't got a buffer, or this is received
- * on the wild card socket, just dump the packet.
- */
- if (initializing || free_recvbuffs == 0) {
- char buf[100];
-
-#ifndef SYS_WINNT
- (void) read(fd, buf, sizeof buf);
-#else
- /* NT's _read does not operate on nonblocking sockets
- * either recvfrom or ReadFile() has to be used here.
- * ReadFile is used in [ntpd]ntp_intres() and ntpdc,
- * just to be different use recvfrom() here
- */
- recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)0, NULL);
-#endif /* SYS_WINNT */
- continue;
- }
-
- rb = get_free_recv_buffer();
-
- fromlen = sizeof(struct sockaddr_in);
- rb->recv_length = recvfrom(fd, (char *)&rb->recv_pkt,
- sizeof(rb->recv_pkt), 0,
- (struct sockaddr *)&rb->srcadr, &fromlen);
- if (rb->recv_length == -1) {
- freerecvbuf(rb);
- continue;
- }
-
- /*
- * Got one. Mark how and when it got here,
- * put it on the full list.
- */
- rb->recv_time = ts;
- add_full_recv_buffer(rb);
- total_recv++; /* count it */
- }
-}
-
-
-/* XXX ELIMINATE printserver similar in ntptrace.c, ntpdate.c */
-/*
- * printserver - print detail information for a server
- */
-static void
-printserver(
- register struct server *pp,
- FILE *fp
- )
-{
- register int i;
- char junk[5];
- char *str;
-
- if (!debug) {
- (void) fprintf(fp,
- "%-15s %d/%d %03o v%d s%d offset %9s delay %s disp %s\n",
- ntoa(&pp->srcadr),
- pp->xmtcnt,pp->rcvcnt,pp->reach,
- pp->version,pp->stratum,
- lfptoa(&pp->offset, 6), ufptoa(pp->delay, 5),
- ufptoa(pp->dispersion, 4));
- return;
- }
-
- (void) fprintf(fp, "server %s, port %d\n",
- ntoa(&pp->srcadr), ntohs(pp->srcadr.sin_port));
-
- (void) fprintf(fp, "stratum %d, precision %d, leap %c%c, trust %03o\n",
- pp->stratum, pp->precision,
- pp->leap & 0x2 ? '1' : '0',
- pp->leap & 0x1 ? '1' : '0',
- pp->trust);
-
- if (pp->stratum == 1) {
- junk[4] = 0;
- memmove(junk, (char *)&pp->refid, 4);
- str = junk;
- } else {
- str = numtoa(pp->refid);
- }
- (void) fprintf(fp,
- "refid [%s], delay %s, dispersion %s\n",
- str, fptoa((s_fp)pp->delay, 5),
- ufptoa(pp->dispersion, 5));
-
- (void) fprintf(fp, "transmitted %d, received %d, reachable %03o\n",
- pp->xmtcnt, pp->rcvcnt, pp->reach);
-
- (void) fprintf(fp, "reference time: %s\n",
- prettydate(&pp->reftime));
- (void) fprintf(fp, "originate timestamp: %s\n",
- prettydate(&pp->org));
- (void) fprintf(fp, "transmit timestamp: %s\n",
- prettydate(&pp->xmt));
-
- (void) fprintf(fp, "filter delay: ");
- for (i = 0; i < NTP_SHIFT; i++) {
- (void) fprintf(fp, " %-8.8s", fptoa(pp->filter_delay[i], 5));
- if (i == (NTP_SHIFT>>1)-1)
- (void) fprintf(fp, "\n ");
- }
- (void) fprintf(fp, "\n");
-
- (void) fprintf(fp, "filter offset:");
- for (i = 0; i < PEER_SHIFT; i++) {
- (void) fprintf(fp, " %-8.8s", lfptoa(&pp->filter_offset[i], 6));
- if (i == (PEER_SHIFT>>1)-1)
- (void) fprintf(fp, "\n ");
- }
- (void) fprintf(fp, "\n");
-
- (void) fprintf(fp, "delay %s, dispersion %s\n",
- fptoa((s_fp)pp->delay, 5), ufptoa(pp->dispersion, 5));
-
- (void) fprintf(fp, "offset %s\n\n",
- lfptoa(&pp->offset, 6));
-}
-
-#if !defined(HAVE_VSPRINTF)
-int
-vsprintf(
- char *str,
- const char *fmt,
- va_list ap
- )
-{
- FILE f;
- int len;
-
- f._flag = _IOWRT+_IOSTRG;
- f._ptr = str;
- f._cnt = 32767;
- len = _doprnt(fmt, ap, &f);
- *f._ptr = 0;
- return (len);
-}
-#endif
OpenPOWER on IntegriCloud