summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/ntpdate
diff options
context:
space:
mode:
authorroberto <roberto@FreeBSD.org>2008-08-22 15:58:00 +0000
committerroberto <roberto@FreeBSD.org>2008-08-22 15:58:00 +0000
commitb85c7169a740b2edf0106ad59fdaa1b0160f823c (patch)
tree2b9fb7f64eacb322e95695e412c923e97ba33e88 /contrib/ntp/ntpdate
parent1d197cfe9feac6bc29537d8e53c30b6435937b95 (diff)
parent7a6072eb585696f8856cd498c3fd194cf49f14c6 (diff)
downloadFreeBSD-src-b85c7169a740b2edf0106ad59fdaa1b0160f823c.zip
FreeBSD-src-b85c7169a740b2edf0106ad59fdaa1b0160f823c.tar.gz
Merge ntpd & friends 4.2.4p5 from vendor/ntp/dist into head. Next commit
will update usr.sbin/ntp to match this. MFC after: 2 weeks
Diffstat (limited to 'contrib/ntp/ntpdate')
-rw-r--r--contrib/ntp/ntpdate/Makefile.am30
-rw-r--r--contrib/ntp/ntpdate/Makefile.in332
-rw-r--r--contrib/ntp/ntpdate/ntpdate.c625
-rw-r--r--contrib/ntp/ntpdate/ntptimeset.c21
4 files changed, 583 insertions, 425 deletions
diff --git a/contrib/ntp/ntpdate/Makefile.am b/contrib/ntp/ntpdate/Makefile.am
index bfe3fea..3372f49 100644
--- a/contrib/ntp/ntpdate/Makefile.am
+++ b/contrib/ntp/ntpdate/Makefile.am
@@ -1,22 +1,28 @@
-#AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies
-AUTOMAKE_OPTIONS = ../util/ansi2knr
-#bin_PROGRAMS = ntpdate ntptimeset
-bin_PROGRAMS = ntpdate
-EXTRA_PROGRAMS = ntptimeset
-ntptimeset_SOURCES = ntptimeset.c ntptime_config.c
-INCLUDES = -I$(top_srcdir)/include
+#AUTOMAKE_OPTIONS= ../util/ansi2knr
+
+bindir= ${exec_prefix}/${BINSUBDIR}
+#bin_PROGRAMS= ntpdate ntptimeset
+bin_PROGRAMS= ntpdate
+EXTRA_PROGRAMS= ntptimeset
+
+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
-DISTCLEANFILES = .version version.c stamp-v
-noinst_HEADERS = ntpdate.h
-#EXTRA_DIST = ntpdate.mak
-ETAGS_ARGS = Makefile.am
+LDADD= version.o ../libntp/libntp.a
+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
+
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
+
+include ../bincheck.mf
diff --git a/contrib/ntp/ntpdate/Makefile.in b/contrib/ntp/ntpdate/Makefile.in
index 391f494..fadcd18 100644
--- a/contrib/ntp/ntpdate/Makefile.in
+++ b/contrib/ntp/ntpdate/Makefile.in
@@ -1,8 +1,8 @@
-# Makefile.in generated by automake 1.7.7 from Makefile.am.
+# Makefile.in generated by automake 1.9.6 from Makefile.am.
# @configure_input@
-# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
-# Free Software Foundation, Inc.
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005 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.
@@ -14,6 +14,13 @@
@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.
+
+
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
@@ -21,7 +28,6 @@ pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
-
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
@@ -37,16 +43,61 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
-target_triplet = @target@
+bin_PROGRAMS = ntpdate$(EXEEXT)
+EXTRA_PROGRAMS = ntptimeset$(EXEEXT)
+DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/../bincheck.mf \
+ $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+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__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+am__installdirs = "$(DESTDIR)$(bindir)"
+binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
+PROGRAMS = $(bin_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
+DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = ntpdate.c $(ntptimeset_SOURCES)
+DIST_SOURCES = ntpdate.c $(ntptimeset_SOURCES)
+HEADERS = $(noinst_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
+AR = @AR@
ARLIB_DIR = @ARLIB_DIR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
+BINSUBDIR = @BINSUBDIR@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
@@ -54,10 +105,15 @@ CHUTEST = @CHUTEST@
CLKTEST = @CLKTEST@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DCFD = @DCFD@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
+ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
@@ -65,30 +121,39 @@ EF_LIBS = @EF_LIBS@
EF_PROGS = @EF_PROGS@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
+F77 = @F77@
+FFLAGS = @FFLAGS@
INSTALL_DATA = @INSTALL_DATA@
+INSTALL_LIBOPTS_FALSE = @INSTALL_LIBOPTS_FALSE@
+INSTALL_LIBOPTS_TRUE = @INSTALL_LIBOPTS_TRUE@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LCRYPTO = @LCRYPTO@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
+LIBOPTS_CFLAGS = @LIBOPTS_CFLAGS@
+LIBOPTS_DIR = @LIBOPTS_DIR@
+LIBOPTS_LDADD = @LIBOPTS_LDADD@
LIBPARSE = @LIBPARSE@
LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MAKE_ADJTIMED = @MAKE_ADJTIMED@
+MAKE_CHECK_LAYOUT = @MAKE_CHECK_LAYOUT@
MAKE_CHECK_Y2K = @MAKE_CHECK_Y2K@
MAKE_LIBNTPSIM = @MAKE_LIBNTPSIM@
MAKE_LIBPARSE = @MAKE_LIBPARSE@
MAKE_LIBPARSE_KERNEL = @MAKE_LIBPARSE_KERNEL@
MAKE_NTPDSIM = @MAKE_NTPDSIM@
MAKE_NTPTIME = @MAKE_NTPTIME@
-MAKE_NTP_KEYGEN = @MAKE_NTP_KEYGEN@
MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@
-MAKE_SNTP = @MAKE_SNTP@
MAKE_TICKADJ = @MAKE_TICKADJ@
MAKE_TIMETRIM = @MAKE_TIMETRIM@
+NEED_LIBOPTS_FALSE = @NEED_LIBOPTS_FALSE@
+NEED_LIBOPTS_TRUE = @NEED_LIBOPTS_TRUE@
OBJEXT = @OBJEXT@
OPENSSL = @OPENSSL@
OPENSSL_INC = @OPENSSL_INC@
@@ -111,15 +176,22 @@ STRIP = @STRIP@
TESTDCF = @TESTDCF@
U = @U@
VERSION = @VERSION@
+ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_F77 = @ac_ct_F77@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
+am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
+am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
-bindir = @bindir@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = ${exec_prefix}/${BINSUBDIR}
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
@@ -139,6 +211,7 @@ libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
+mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
@@ -146,83 +219,58 @@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
subdirs = @subdirs@
sysconfdir = @sysconfdir@
-target = @target@
target_alias = @target_alias@
-target_cpu = @target_cpu@
-target_os = @target_os@
-target_vendor = @target_vendor@
-
-#AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies
-AUTOMAKE_OPTIONS = ../util/ansi2knr
-#bin_PROGRAMS = ntpdate ntptimeset
-bin_PROGRAMS = ntpdate
-EXTRA_PROGRAMS = ntptimeset
ntptimeset_SOURCES = ntptimeset.c ntptime_config.c
-INCLUDES = -I$(top_srcdir)/include
+AM_CPPFLAGS = -I$(top_srcdir)/include
# LDADD might need RESLIB and ADJLIB
LDADD = version.o ../libntp/libntp.a
DISTCLEANFILES = .version version.c stamp-v
noinst_HEADERS = ntpdate.h
-#EXTRA_DIST = ntpdate.mak
ETAGS_ARGS = Makefile.am
-subdir = ntpdate
-ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
-CONFIG_HEADER = $(top_builddir)/config.h
-CONFIG_CLEAN_FILES =
-EXTRA_PROGRAMS = ntptimeset$(EXEEXT)
-bin_PROGRAMS = ntpdate$(EXEEXT)
-PROGRAMS = $(bin_PROGRAMS)
-
-ntpdate_SOURCES = ntpdate.c
-ntpdate_OBJECTS = ntpdate$U.$(OBJEXT)
-ntpdate_LDADD = $(LDADD)
-ntpdate_DEPENDENCIES = version.o ../libntp/libntp.a
-ntpdate_LDFLAGS =
-am_ntptimeset_OBJECTS = ntptimeset$U.$(OBJEXT) \
- ntptime_config$U.$(OBJEXT)
-ntptimeset_OBJECTS = $(am_ntptimeset_OBJECTS)
-ntptimeset_LDADD = $(LDADD)
-ntptimeset_DEPENDENCIES = version.o ../libntp/libntp.a
-ntptimeset_LDFLAGS =
-
-DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
-depcomp = $(SHELL) $(top_srcdir)/depcomp
-am__depfiles_maybe = depfiles
-@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/ntpdate$U.Po \
-@AMDEP_TRUE@ ./$(DEPDIR)/ntptime_config$U.Po \
-@AMDEP_TRUE@ ./$(DEPDIR)/ntptimeset$U.Po
-COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
- $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-CCLD = $(CC)
-LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
-DIST_SOURCES = ntpdate.c $(ntptimeset_SOURCES)
-HEADERS = $(noinst_HEADERS)
-
-DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/Makefile.in \
- Makefile.am
-SOURCES = ntpdate.c $(ntptimeset_SOURCES)
-
all: all-am
.SUFFIXES:
-.SUFFIXES: .c .o .obj
-$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(srcdir)/../bincheck.mf $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign ntpdate/Makefile'; \
cd $(top_srcdir) && \
- $(AUTOMAKE) --gnu ntpdate/Makefile
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
- cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
-binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
+ $(AUTOMAKE) --foreign ntpdate/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
- $(mkinstalldirs) $(DESTDIR)$(bindir)
+ test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
@list='$(bin_PROGRAMS)'; for p in $$list; do \
p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
if test -f $$p \
+ || test -f $$p1 \
; then \
f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
- echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f"; \
- $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f || exit 1; \
+ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
+ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
else :; fi; \
done
@@ -230,12 +278,16 @@ uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
- echo " rm -f $(DESTDIR)$(bindir)/$$f"; \
- rm -f $(DESTDIR)$(bindir)/$$f; \
+ echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
+ rm -f "$(DESTDIR)$(bindir)/$$f"; \
done
clean-binPROGRAMS:
- -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
+ @list='$(bin_PROGRAMS)'; for p in $$list; do \
+ f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f $$p $$f"; \
+ rm -f $$p $$f ; \
+ done
ntpdate$(EXEEXT): $(ntpdate_OBJECTS) $(ntpdate_DEPENDENCIES)
@rm -f ntpdate$(EXEEXT)
$(LINK) $(ntpdate_LDFLAGS) $(ntpdate_OBJECTS) $(ntpdate_LDADD) $(LIBS)
@@ -244,60 +296,45 @@ ntptimeset$(EXEEXT): $(ntptimeset_OBJECTS) $(ntptimeset_DEPENDENCIES)
$(LINK) $(ntptimeset_LDFLAGS) $(ntptimeset_OBJECTS) $(ntptimeset_LDADD) $(LIBS)
mostlyclean-compile:
- -rm -f *.$(OBJEXT) core *.core
+ -rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
-ANSI2KNR = ../util/ansi2knr
-../util/ansi2knr:
- cd ../util && $(MAKE) $(AM_MAKEFLAGS) ansi2knr
-
-mostlyclean-kr:
- -test "$U" = "" || rm -f *_.c
-
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpdate$U.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntptime_config$U.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntptimeset$U.Po@am__quote@
+@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@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
-@am__fastdepCC_TRUE@ -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \
-@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
-@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
-@am__fastdepCC_TRUE@ fi
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
.c.obj:
-@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
-@am__fastdepCC_TRUE@ -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
-@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
-@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
-@am__fastdepCC_TRUE@ fi
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`
-ntpdate_.c: ntpdate.c $(ANSI2KNR)
- $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntpdate.c; then echo $(srcdir)/ntpdate.c; else echo ntpdate.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
-ntptime_config_.c: ntptime_config.c $(ANSI2KNR)
- $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntptime_config.c; then echo $(srcdir)/ntptime_config.c; else echo ntptime_config.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
-ntptimeset_.c: ntptimeset.c $(ANSI2KNR)
- $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntptimeset.c; then echo $(srcdir)/ntptimeset.c; else echo ntptimeset.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
-ntpdate_.$(OBJEXT) ntptime_config_.$(OBJEXT) ntptimeset_.$(OBJEXT) : \
-$(ANSI2KNR)
-uninstall-info-am:
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
-ETAGS = etags
-ETAGSFLAGS =
+.c.lo:
+@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
-CTAGS = ctags
-CTAGSFLAGS =
+mostlyclean-libtool:
+ -rm -f *.lo
-tags: TAGS
+clean-libtool:
+ -rm -rf .libs _libs
+
+distclean-libtool:
+ -rm -f libtool
+uninstall-info-am:
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
@@ -307,6 +344,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
+tags: TAGS
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
@@ -318,10 +356,11 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
- test -z "$(ETAGS_ARGS)$$tags$$unique" \
- || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
- $$tags $$unique
-
+ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique; \
+ fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
@@ -344,12 +383,9 @@ GTAGS:
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
-DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
-
-top_distdir = ..
-distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
distdir: $(DISTFILES)
+ $(mkdir_p) $(distdir)/..
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
@@ -361,7 +397,7 @@ distdir: $(DISTFILES)
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
- $(mkinstalldirs) "$(distdir)$$dir"; \
+ $(mkdir_p) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
@@ -379,9 +415,10 @@ distdir: $(DISTFILES)
check-am: all-am
check: check-am
all-am: Makefile $(PROGRAMS) $(HEADERS)
-
installdirs:
- $(mkinstalldirs) $(DESTDIR)$(bindir)
+ for dir in "$(DESTDIR)$(bindir)"; do \
+ test -z "$$dir" || $(mkdir_p) "$$dir"; \
+ done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
@@ -393,7 +430,7 @@ install-am: all-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
- INSTALL_STRIP_FLAG=-s \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
@@ -401,7 +438,7 @@ mostlyclean-generic:
clean-generic:
distclean-generic:
- -rm -f $(CONFIG_CLEAN_FILES)
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
maintainer-clean-generic:
@@ -409,19 +446,20 @@ maintainer-clean-generic:
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
-clean-am: clean-binPROGRAMS clean-generic mostlyclean-am
+clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
-
distclean-am: clean-am distclean-compile distclean-generic \
- distclean-tags
+ distclean-libtool distclean-tags
dvi: dvi-am
dvi-am:
+html: html-am
+
info: info-am
info-am:
@@ -429,6 +467,8 @@ info-am:
install-data-am:
install-exec-am: install-binPROGRAMS
+ @$(NORMAL_INSTALL)
+ $(MAKE) $(AM_MAKEFLAGS) install-exec-hook
install-info: install-info-am
@@ -439,12 +479,12 @@ installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
-
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
-mostlyclean-am: mostlyclean-compile mostlyclean-generic mostlyclean-kr
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
pdf: pdf-am
@@ -457,15 +497,16 @@ ps-am:
uninstall-am: uninstall-binPROGRAMS uninstall-info-am
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
- clean-generic ctags distclean distclean-compile \
- distclean-generic distclean-tags distdir dvi dvi-am info \
- info-am install install-am install-binPROGRAMS install-data \
- install-data-am install-exec install-exec-am install-info \
- install-info-am install-man install-strip installcheck \
- installcheck-am installdirs maintainer-clean \
- maintainer-clean-generic mostlyclean mostlyclean-compile \
- mostlyclean-generic mostlyclean-kr pdf pdf-am ps ps-am tags \
- uninstall uninstall-am uninstall-binPROGRAMS uninstall-info-am
+ 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-exec \
+ install-exec-am install-exec-hook install-info install-info-am \
+ install-man 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 uninstall-info-am
$(PROGRAMS): $(LDADD)
@@ -473,9 +514,24 @@ $(PROGRAMS): $(LDADD)
../libntp/libntp.a:
cd ../libntp && $(MAKE)
+$(top_srcdir)/version :
+ cd $(top_srcdir) && $(MAKE) version
+
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
+
+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!"; \
+ done
+
+#
# 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 b2cbe7e..a0a90ce 100644
--- a/contrib/ntp/ntpdate/ntpdate.c
+++ b/contrib/ntp/ntpdate/ntpdate.c
@@ -21,6 +21,12 @@
#include "ntp_select.h"
#include "ntp_stdlib.h"
+/* 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"
+
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
@@ -32,7 +38,6 @@
# include <poll.h>
#endif
#ifndef SYS_WINNT
-# include <netdb.h>
# ifdef HAVE_SYS_SIGNAL_H
# include <sys/signal.h>
# else
@@ -48,10 +53,6 @@
#include <arpa/inet.h>
-#ifdef __QNXNTO__
-# include "adjtime.h"
-#endif
-
#ifdef SYS_VXWORKS
# include "ioLib.h"
# include "sockLib.h"
@@ -59,6 +60,12 @@
/* select wants a zero structure ... */
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
+ */
+struct timeval timeout = {0,1000000/TIMER_HZ};
#else
struct timeval timeout = {60,0};
#endif
@@ -71,11 +78,13 @@ struct timeval timeout = {60,0};
#ifdef SYS_WINNT
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
-#define EAFNOSUPPORT WSAEAFNOSUPPORT
-#define EPFNOSUPPORT WSAEPFNOSUPPORT
+#define EAFNOSUPPORT WSAEAFNOSUPPORT
+#define EPFNOSUPPORT WSAEPFNOSUPPORT
#define TARGET_RESOLUTION 1 /* Try for 1-millisecond accuracy
on Windows NT timers. */
#pragma comment(lib, "winmm")
+isc_boolean_t ntp_port_inuse(int af, u_short port);
+UINT wTimerRes;
#endif /* SYS_WINNT */
/*
@@ -96,14 +105,19 @@ static timer_t ntpdate_timerid;
* 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_MINDIST 0x51f /* 0.02 sec in fp format */
#define PEER_MAXDISP (64*FP_SECOND) /* maximum dispersion (fp 64) */
#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 NTP_MAXLIST 5 /* maximum select list size */
#define PEER_SHIFT 8 /* 8 suitable for crystal time base */
/*
+ * for get_systime()
+ */
+s_char sys_precision; /* local clock precision (log2 s) */
+
+/*
* Debugging flag
*/
volatile int debug = 0;
@@ -113,14 +127,14 @@ volatile int debug = 0;
*/
int ai_fam_templ;
-int nbsock;
-SOCKET fd[MAX_AF]; /* support up to 2 sockets */
+int nbsock; /* the number of sockets used */
+SOCKET fd[MAX_AF];
int fd_family[MAX_AF]; /* to remember the socket family */
#ifdef HAVE_POLL_H
struct pollfd fdmask[MAX_AF];
#else
fd_set fdmask;
-int maxfd;
+SOCKET maxfd;
#endif
int polltest = 0;
@@ -141,16 +155,11 @@ volatile int alarm_flag = 0;
int simple_query = 0;
/*
- * Unpriviledged port flag.
+ * Unprivileged port flag.
*/
int unpriv_port = 0;
/*
- * Time to spend measuring drift rate
- */
-int rate = 0;
-
-/*
* Program name.
*/
char *progname;
@@ -202,7 +211,7 @@ int verbose = 0;
int always_step = 0;
int never_step = 0;
-int ntpdatemain P((int, char **));
+int ntpdatemain P((int, char **));
static void transmit P((struct server *));
static void receive P((struct recvbuf *));
@@ -212,7 +221,7 @@ 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));
+void timer P((void));
static void init_alarm P((void));
#ifndef SYS_WINNT
static RETSIGTYPE alarming P((int));
@@ -229,7 +238,7 @@ static void printserver P((struct server *, FILE *));
#ifdef SYS_WINNT
int on = 1;
WORD wVersionRequested;
-WSADATA wsaData;
+WSADATA wsaData;
HANDLE TimerThreadHandle = NULL;
#endif /* SYS_WINNT */
@@ -261,15 +270,11 @@ void clear_globals()
simple_query = 0;
/*
- * Unpriviledged port flag.
+ * Unprivileged port flag.
*/
unpriv_port = 0;
/*
- * Time to spend measuring drift rate
- */
- rate = 0;
- /*
* Systemwide parameters and flags
*/
sys_numservers = 0; /* number of servers to poll */
@@ -319,12 +324,12 @@ ntpdatemain (
)
{
int was_alarmed;
- struct recvbuf *rbuflist;
+ int tot_recvbufs;
struct recvbuf *rbuf;
l_fp tmp;
int errflg;
int c;
- int nfound;
+ int nfound;
#ifdef HAVE_NETINFO
ni_namelist *netinfoservers;
@@ -350,6 +355,12 @@ ntpdatemain (
clear_globals();
#endif
+
+ /* Check to see if we have IPv6. Otherwise force the -4 flag */
+ if (isc_net_probeipv6() != ISC_R_SUCCESS) {
+ ai_fam_templ = AF_INET;
+ }
+
errflg = 0;
progname = argv[0];
syslogit = 0;
@@ -357,7 +368,7 @@ ntpdatemain (
/*
* Decode argument list
*/
- while ((c = ntp_getopt(argc, argv, "46a:bBde:k:o:p:qr:st:uv")) != EOF)
+ while ((c = ntp_getopt(argc, argv, "46a:bBde:k:o:p:qst:uv")) != EOF)
switch (c)
{
case '4':
@@ -413,17 +424,6 @@ ntpdatemain (
case 'q':
simple_query = 1;
break;
- case 'r':
- c = atoi(ntp_optarg);
- if (c <= 0 || c > (60 * 60)) {
- (void) fprintf(stderr,
- "%s: rate (%d) is invalid: 0 - %d\n",
- progname, c, (60 * 60));
- errflg++;
- } else {
- rate = c;
- }
- break;
case 's':
syslogit = 1;
break;
@@ -455,7 +455,7 @@ ntpdatemain (
if (errflg) {
(void) fprintf(stderr,
- "usage: %s [-46bBdqsuv] [-a key#] [-e delay] [-k file] [-p samples] [-o version#] [-r rate] [-t timeo] server ...\n",
+ "usage: %s [-46bBdqsuv] [-a key#] [-e delay] [-k file] [-p samples] [-o version#] [-t timeo] server ...\n",
progname);
exit(2);
}
@@ -463,7 +463,12 @@ 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
@@ -536,10 +541,8 @@ ntpdatemain (
}
authtrust(sys_authkey, 1);
if (!authistrusted(sys_authkey)) {
- char buf[10];
-
- (void) sprintf(buf, "%lu", (unsigned long)sys_authkey);
- msyslog(LOG_ERR, "authentication key %s unknown", buf);
+ msyslog(LOG_ERR, "authentication key %lu unknown",
+ (unsigned long) sys_authkey);
exit(1);
}
}
@@ -569,45 +572,41 @@ ntpdatemain (
initializing = 0;
was_alarmed = 0;
- rbuflist = (struct recvbuf *)0;
while (complete_servers < sys_numservers) {
#ifdef HAVE_POLL_H
- struct pollfd* rdfdes;
- rdfdes = fdmask;
+ struct pollfd* rdfdes;
+ rdfdes = fdmask;
#else
fd_set rdfdes;
- rdfdes = fdmask;
+ rdfdes = fdmask;
#endif
if (alarm_flag) { /* alarmed? */
was_alarmed = 1;
alarm_flag = 0;
}
- rbuflist = getrecvbufs(); /* get received buffers */
+ tot_recvbufs = full_recvbuffs(); /* get received buffers */
- if (!was_alarmed && rbuflist == (struct recvbuf *)0) {
+ if (!was_alarmed && tot_recvbufs == 0) {
/*
* Nothing to do. Wait for something.
*/
#ifdef HAVE_POLL_H
- nfound = poll(rdfdes, (unsigned int)nbsock, timeout.tv_sec * 1000);
+ nfound = poll(rdfdes, (unsigned int)nbsock, timeout.tv_sec * 1000);
#else
- nfound = select(maxfd, &rdfdes, (fd_set *)0,
+ nfound = select(maxfd, &rdfdes, (fd_set *)0,
(fd_set *)0, &timeout);
#endif
if (nfound > 0)
input_handler();
- else if (
-#ifndef SYS_WINNT
- nfound == -1
-#else
- nfound == SOCKET_ERROR
-#endif /* SYS_WINNT */
- ) {
+ else if (nfound == SOCKET_ERROR)
+ {
#ifndef SYS_WINNT
if (errno != EINTR)
+#else
+ if (WSAGetLastError() != WSAEINTR)
#endif
netsyslog(LOG_ERR,
#ifdef HAVE_POLL_H
@@ -616,7 +615,7 @@ ntpdatemain (
"select() error: %m"
#endif
);
- } else {
+ } else if (errno != 0) {
#ifndef SYS_VXWORKS
netsyslog(LOG_DEBUG,
#ifdef HAVE_POLL_H
@@ -631,18 +630,19 @@ ntpdatemain (
was_alarmed = 1;
alarm_flag = 0;
}
- rbuflist = getrecvbufs(); /* get received buffers */
+ tot_recvbufs = full_recvbuffs(); /* get received buffers */
}
/*
* Out here, signals are unblocked. Call receive
* procedure for each incoming packet.
*/
- while (rbuflist != (struct recvbuf *)0) {
- rbuf = rbuflist;
- rbuflist = rbuf->next;
+ rbuf = get_full_recv_buffer();
+ while (rbuf != NULL)
+ {
receive(rbuf);
freerecvbuf(rbuf);
+ rbuf = get_full_recv_buffer();
}
/*
@@ -676,8 +676,8 @@ ntpdatemain (
/*
* transmit - transmit a packet to the given server, or mark it completed.
- * This is called by the timeout routine and by the receive
- * procedure.
+ * This is called by the timeout routine and by the receive
+ * procedure.
*/
static void
transmit(
@@ -710,7 +710,7 @@ transmit(
}
/*
- * If we're here, send another message to the server. Fill in
+ * 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,
@@ -779,7 +779,7 @@ receive(
int is_authentic;
if (debug)
- printf("receive(%s)\n", stoa(&rbufp->recv_srcadr));
+ printf("receive(%s)\n", stoa(&rbufp->recv_srcadr));
/*
* Check to see if the packet basically looks like something
* intended for us.
@@ -1060,29 +1060,29 @@ clock_select(void)
if (server->delay == 0) {
if (debug)
printf("%s: Server dropped: no data\n", ntoa(&server->srcadr));
- continue; /* no data */
+ continue; /* no data */
}
if (server->stratum > NTP_INFIN) {
if (debug)
printf("%s: Server dropped: strata too high\n", ntoa(&server->srcadr));
- continue; /* stratum no good */
+ continue; /* stratum no good */
}
if (server->delay > NTP_MAXWGT) {
if (debug)
printf("%s: Server dropped: server too far away\n",
- ntoa(&server->srcadr));
- continue; /* too far away */
+ ntoa(&server->srcadr));
+ continue; /* too far away */
}
if (server->leap == LEAP_NOTINSYNC) {
if (debug)
printf("%s: Server dropped: Leap not in sync\n", ntoa(&server->srcadr));
- continue; /* he's in trouble */
+ continue; /* he's in trouble */
}
if (!L_ISHIS(&server->org, &server->reftime)) {
if (debug)
printf("%s: Server dropped: server is very broken\n",
ntoa(&server->srcadr));
- continue; /* very broken host */
+ continue; /* very broken host */
}
if ((server->org.l_ui - server->reftime.l_ui)
>= NTP_MAXAGE) {
@@ -1239,7 +1239,7 @@ clock_select(void)
}
/*
- * That's it. Return our server.
+ * That's it. Return our server.
*/
return sys_server;
}
@@ -1283,7 +1283,7 @@ clock_adjust(void)
}
if (dostep) {
- if (simple_query || l_step_systime(&server->offset)) {
+ if (simple_query || debug || l_step_systime(&server->offset)){
msyslog(LOG_NOTICE, "step time server %s offset %s sec",
stoa(&server->srcadr),
lfptoa(&server->offset, 6));
@@ -1313,10 +1313,34 @@ clock_adjust(void)
}
+/*
+ * is_unreachable - check to see if we have a route to given destination
+ * (non-blocking).
+ */
+static int
+is_reachable (struct sockaddr_storage *dst)
+{
+ SOCKET sockfd;
+
+ sockfd = socket(dst->ss_family, SOCK_DGRAM, 0);
+ if (sockfd == -1) {
+ return 0;
+ }
+
+ if(connect(sockfd, (struct sockaddr *)dst, SOCKLEN(dst))) {
+ closesocket(sockfd);
+ return 0;
+ }
+ closesocket(sockfd);
+ return 1;
+}
+
+
+
/* XXX ELIMINATE: merge BIG slew into adj_systime in lib/systime.c */
/*
* addserver - determine a server's address and allocate a new structure
- * for it.
+ * for it.
*/
static void
addserver(
@@ -1324,54 +1348,69 @@ addserver(
)
{
register struct server *server;
- /* Address infos structure to store result of getaddrinfo */
- struct addrinfo *addrResult;
- /* Address infos structure to store hints for getaddrinfo */
- struct addrinfo hints;
- /* Error variable for getaddrinfo */
- int error;
- /* Service name */
- char service[5];
+ /* Address infos structure to store result of getaddrinfo */
+ struct addrinfo *addrResult, *ptr;
+ /* Address infos structure to store hints for getaddrinfo */
+ struct addrinfo hints;
+ /* Error variable for getaddrinfo */
+ int error;
+ /* Service name */
+ char service[5];
strcpy(service, "ntp");
- /* Get host address. Looking for UDP datagram connection. */
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = ai_fam_templ;
- hints.ai_socktype = SOCK_DGRAM;
+ /* Get host address. Looking for UDP datagram connection. */
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = ai_fam_templ;
+ hints.ai_socktype = SOCK_DGRAM;
#ifdef DEBUG
- if (debug)
- printf("Looking for host %s and service %s\n", serv, service);
+ if (debug)
+ printf("Looking for host %s and service %s\n", serv, service);
#endif
- error = getaddrinfo(serv, service, &hints, &addrResult);
- if (error != 0) {
- fprintf(stderr, "Error : %s\n", gai_strerror(error));
+ error = getaddrinfo(serv, service, &hints, &addrResult);
+ if (error != 0) {
+ /* Conduct more refined error analysis */
+ if (error == EAI_FAIL || error == EAI_AGAIN){
+ /* 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));
+ exit(1);
+ }
+ fprintf(stderr, "Error : %s\n", gai_strerror(error));
msyslog(LOG_ERR, "can't find host %s\n", serv);
return;
}
#ifdef DEBUG
- else if (debug) {
- fprintf(stderr, "host found : %s\n", stohost((struct sockaddr_storage*)addrResult->ai_addr));
- }
+ else if (debug) {
+ fprintf(stderr, "host found : %s\n", stohost((struct sockaddr_storage*)addrResult->ai_addr));
+ }
#endif
- server = (struct server *)emalloc(sizeof(struct server));
- memset((char *)server, 0, sizeof(struct server));
-
- /* For now we only get the first returned server of the addrinfo list */
- memset(&(server->srcadr), 0, sizeof(struct sockaddr_storage));
- memcpy(&(server->srcadr), addrResult->ai_addr, addrResult->ai_addrlen);
- server->event_time = ++sys_numservers;
- if (sys_servers == NULL)
- sys_servers = server;
- else {
- struct server *sp;
+ /* 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);
+ server->event_time = ++sys_numservers;
+ if (sys_servers == NULL)
+ sys_servers = server;
+ else {
+ struct server *sp;
- for (sp = sys_servers; sp->next_server != NULL;
- sp = sp->next_server) ;
- sp->next_server = server;
+ for (sp = sys_servers; sp->next_server != NULL;
+ sp = sp->next_server) ;
+ sp->next_server = server;
+ }
+ }
}
+
+ freeaddrinfo(addrResult);
}
@@ -1386,6 +1425,16 @@ findserver(
{
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)
@@ -1394,21 +1443,19 @@ findserver(
for (server = sys_servers; server != NULL;
server = server->next_server) {
- if (memcmp(addr, &server->srcadr, SOCKLEN(addr))==0)
+ 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)
return server;
- /* Multicast compatibility to verify here... I'm not sure it's working */
- if(addr->ss_family == AF_INET) {
- if (IN_MULTICAST(ntohl(((struct sockaddr_in*)addr)->sin_addr.s_addr)))
- mc_server = server;
- }
- else {
-#ifdef AF_INET6
- if (IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)(&server->srcadr))->sin6_addr))
- mc_server = server;
-#else
- return 0;
-#endif
- }
+
+ if(addr->ss_family == server->srcadr.ss_family) {
+ if (isc_sockaddr_ismulticast(&saddr) == ISC_TRUE)
+ mc_server = server;
+ }
}
if (mc_server != NULL) {
@@ -1423,7 +1470,7 @@ findserver(
server = (struct server *)emalloc(sizeof(struct server));
memset((char *)server, 0, sizeof(struct server));
- memcpy(&server->srcadr, &addr, sizeof(struct sockaddr_storage));
+ memcpy(&server->srcadr, addr, sizeof(struct sockaddr_storage));
server->event_time = ++sys_numservers;
@@ -1488,6 +1535,16 @@ alarming(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
#endif /* SYS_WINNT */
+#ifdef SYS_WINNT
+static void
+callTimeEndPeriod(void)
+{
+ timeEndPeriod( wTimerRes );
+ wTimerRes = 0;
+}
+#endif /* SYS_WINNT */
+
+
/*
* init_alarm - set up the timer interrupt
*/
@@ -1502,7 +1559,7 @@ init_alarm(void)
# endif
#else
TIMECAPS tc;
- UINT wTimerRes, wTimerID;
+ UINT wTimerID;
# endif /* SYS_WINNT */
#if defined SYS_CYGWIN32 || defined SYS_WINNT
HANDLE hToken;
@@ -1554,7 +1611,7 @@ init_alarm(void)
# endif
#if defined SYS_CYGWIN32
/*
- * Get previleges needed for fiddling with the clock
+ * Get privileges needed for fiddling with the clock
*/
/* get the current process token handle */
@@ -1564,7 +1621,7 @@ init_alarm(void)
}
/* get the LUID for system-time privilege. */
LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid);
- tkp.PrivilegeCount = 1; /* one privilege to set */
+ 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);
@@ -1576,7 +1633,7 @@ init_alarm(void)
_tzset();
/*
- * Get previleges needed for fiddling with the clock
+ * Get privileges needed for fiddling with the clock
*/
/* get the current process token handle */
@@ -1586,7 +1643,7 @@ init_alarm(void)
}
/* get the LUID for system-time privilege. */
LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid);
- tkp.PrivilegeCount = 1; /* one privilege to set */
+ 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);
@@ -1609,14 +1666,15 @@ init_alarm(void)
wTimerRes = min(max(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax);
/* establish the minimum timer resolution that we'll use */
timeBeginPeriod(wTimerRes);
+ atexit(callTimeEndPeriod);
/* 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) */
+ (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);
@@ -1647,10 +1705,11 @@ init_alarm(void)
static void
init_io(void)
{
- struct addrinfo *res, *ressave;
- struct addrinfo hints;
+ struct addrinfo *res, *ressave;
+ struct addrinfo hints;
char service[5];
- int optval = 1;
+ int optval = 1;
+ int check_ntp_port_in_use = !debug && !simple_query && !unpriv_port;
/*
* Init buffer free list and stat counters
@@ -1663,123 +1722,137 @@ init_io(void)
strcpy(service, "ntp");
- /*
- * Init hints addrinfo structure
- */
- memset(&hints, 0, sizeof(hints));
- 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*/
- }
-
- /* Remember the address of the addrinfo structure chain */
- ressave = res;
-
- /*
- * For each structure returned, open and bind socket
- */
- for(nbsock = 0; (nbsock < MAX_AF) && res ; res = res->ai_next) {
+ /*
+ * Init hints addrinfo structure
+ */
+ memset(&hints, 0, sizeof(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*/
+ }
+
+#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");
+ exit(1);
+ }
+#endif
+
+ /* Remember the address of the addrinfo structure chain */
+ ressave = res;
+
+ /*
+ * For each structure returned, open and bind socket
+ */
+ for(nbsock = 0; (nbsock < MAX_AF) && res ; res = res->ai_next) {
/* create a datagram (UDP) socket */
- if ((fd[nbsock] = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
+ fd[nbsock] = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+ if (fd[nbsock] == SOCKET_ERROR) {
+#ifndef SYS_WINNT
if (errno == EPROTONOSUPPORT || errno == EAFNOSUPPORT ||
errno == EPFNOSUPPORT)
+#else
+ int err = WSAGetLastError();
+ if (err == WSAEPROTONOSUPPORT || err == WSAEAFNOSUPPORT ||
+ err == WSAEPFNOSUPPORT)
+#endif
continue;
netsyslog(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");
- 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");
+ exit(1);
+ /*NOTREACHED*/
+ }
#ifdef IPV6_V6ONLY
- /* 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");
- exit(1);
- /*NOTREACHED*/
- }
+ /* 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");
+ exit(1);
+ /*NOTREACHED*/
+ }
#endif
- /* Remember the socket family in fd_family structure */
- fd_family[nbsock] = res->ai_family;
+ /* Remember the socket family in fd_family structure */
+ fd_family[nbsock] = res->ai_family;
- /*
- * bind the socket to the NTP port
- */
- if (!debug && !simple_query && !unpriv_port) {
- if (bind(fd[nbsock], res->ai_addr, SOCKLEN(res->ai_addr)) < 0) {
+ /*
+ * 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)
+ if (errno == EADDRINUSE)
#else
if (WSAGetLastError() == WSAEADDRINUSE)
#endif /* SYS_WINNT */
- netsyslog(LOG_ERR,
- "the NTP socket is in use, exiting");
+ netsyslog(LOG_ERR, "the NTP socket is in use, exiting");
else
- netsyslog(LOG_ERR, "bind() fails: %m");
- exit(1);
+ netsyslog(LOG_ERR, "bind() fails: %m");
+ exit(1);
+ }
}
- }
#ifdef HAVE_POLL_H
- fdmask[nbsock].fd = fd[nbsock];
- fdmask[nbsock].events = POLLIN;
+ fdmask[nbsock].fd = fd[nbsock];
+ fdmask[nbsock].events = POLLIN;
#else
- FD_SET(fd[nbsock], &fdmask);
- if ((SOCKET) maxfd < fd[nbsock]+1) {
- maxfd = fd[nbsock]+1;
- }
+ FD_SET(fd[nbsock], &fdmask);
+ if (maxfd < fd[nbsock]+1) {
+ maxfd = fd[nbsock]+1;
+ }
#endif
- /*
- * set non-blocking,
- */
+ /*
+ * set non-blocking,
+ */
#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) {
+ netsyslog(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");
- exit(1);
- /*NOTREACHED*/
- }
+ if (fcntl(fd[nbsock], F_SETFL, O_NONBLOCK) < 0) {
+ netsyslog(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");
- exit(1);
- /*NOTREACHED*/
- }
+ if (fcntl(fd[nbsock], F_SETFL, FNDELAY) < 0) {
+ netsyslog(LOG_ERR, "fcntl(FNDELAY|FASYNC) fails: %m");
+ exit(1);
+ /*NOTREACHED*/
+ }
# else /* FNDELAY */
# include "Bletch: Need non blocking I/O"
# endif /* FNDELAY */
# endif /* not O_NONBLOCK */
# endif /* SYS_VXWORKS */
#else /* SYS_WINNT */
- if (ioctlsocket(fd[nbsock], FIONBIO, (u_long *) &on) == SOCKET_ERROR) {
- netsyslog(LOG_ERR, "ioctlsocket(FIONBIO) fails: %m");
- exit(1);
- }
+ if (ioctlsocket(fd[nbsock], FIONBIO, (u_long *) &on) == SOCKET_ERROR) {
+ netsyslog(LOG_ERR, "ioctlsocket(FIONBIO) fails: %m");
+ exit(1);
+ }
#endif /* SYS_WINNT */
- nbsock++;
- }
- freeaddrinfo(ressave);
+ nbsock++;
+ }
+ freeaddrinfo(ressave);
}
/*
@@ -1792,40 +1865,39 @@ sendpkt(
int len
)
{
- int i;
+ int i;
int cc;
- SOCKET sock = 0;
+ SOCKET sock = INVALID_SOCKET;
#ifdef SYS_WINNT
DWORD err;
#endif /* SYS_WINNT */
- /* 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]) {
- sock = fd[i];
- break;
- }
- }
+ /* 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]) {
+ sock = fd[i];
+ break;
+ }
+ }
- if ( sock == 0 ) {
- netsyslog(LOG_ERR, "cannot find family compatible socket to send ntp packet");
- exit(1);
- /*NOTREACHED*/
- }
+ if ( sock == INVALID_SOCKET ) {
+ netsyslog(LOG_ERR, "cannot find family compatible socket to send ntp packet");
+ exit(1);
+ /*NOTREACHED*/
+ }
cc = sendto(sock, (char *)pkt, len, 0, (struct sockaddr *)dest,
SOCKLEN(dest));
+ if (cc == SOCKET_ERROR) {
#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 */
- netsyslog(LOG_ERR, "sendto(%s): %m", stohost(dest));
+ netsyslog(LOG_ERR, "sendto(%s): %m", stohost(dest));
}
}
@@ -1841,13 +1913,13 @@ input_handler(void)
struct timeval tvzero;
int fromlen;
l_fp ts;
- int i;
+ int i;
#ifdef HAVE_POLL_H
struct pollfd fds[MAX_AF];
#else
fd_set fds;
#endif
- int fdc = 0;
+ int fdc = 0;
/*
* Do a poll to see if we have data
@@ -1856,33 +1928,33 @@ input_handler(void)
tvzero.tv_sec = tvzero.tv_usec = 0;
#ifdef HAVE_POLL_H
memcpy(fds, fdmask, sizeof(fdmask));
- n = poll(fds, (unsigned int)nbsock, tvzero.tv_sec * 1000);
+ n = poll(fds, (unsigned int)nbsock, tvzero.tv_sec * 1000);
- /*
- * Determine which socket received data
- */
+ /*
+ * Determine which socket received data
+ */
- for(i=0; i < nbsock; i++) {
- if(fds[i].revents & POLLIN) {
- fdc = fd[i];
- break;
- }
- }
+ for(i=0; i < nbsock; i++) {
+ if(fds[i].revents & POLLIN) {
+ fdc = fd[i];
+ break;
+ }
+ }
#else
fds = fdmask;
- n = select(maxfd, &fds, (fd_set *)0, (fd_set *)0, &tvzero);
+ n = select(maxfd, &fds, (fd_set *)0, (fd_set *)0, &tvzero);
- /*
- * Determine which socket received data
- */
+ /*
+ * Determine which socket received data
+ */
- for(i=0; i < maxfd; i++) {
- if(FD_ISSET(fd[i], &fds)) {
- fdc = fd[i];
- break;
- }
- }
+ for(i=0; i < nbsock; i++) {
+ if(FD_ISSET(fd[i], &fds)) {
+ fdc = fd[i];
+ break;
+ }
+ }
#endif
@@ -2057,7 +2129,7 @@ l_step_systime(
l_adj_systime(ts);
return 1;
#endif
-#else /* SLEWALWAYS */
+#else /* SLEWALWAYS */
if (debug)
return 1;
LFPTOD(ts, dtemp);
@@ -2223,3 +2295,34 @@ getnetinfoservers(void)
return(namelist);
}
#endif
+
+#ifdef SYS_WINNT
+isc_boolean_t ntp_port_inuse(int af, u_short port)
+{
+ /*
+ * Check if NTP socket is already in use on this system
+ * This is only for Windows Systems, as they tend not to fail on the real bind() below
+ */
+
+ SOCKET checksocket;
+ struct sockaddr_in checkservice;
+ checksocket = socket(af, SOCK_DGRAM, 0);
+ if (checksocket == INVALID_SOCKET) {
+ return (ISC_TRUE);
+ }
+
+ checkservice.sin_family = (short) AF_INET;
+ checkservice.sin_addr.s_addr = INADDR_LOOPBACK;
+ checkservice.sin_port = htons(port);
+
+ if (bind(checksocket, (struct sockaddr *)&checkservice,
+ sizeof(checkservice)) == SOCKET_ERROR) {
+ if ( WSAGetLastError() == WSAEADDRINUSE ){
+ closesocket(checksocket);
+ return (ISC_TRUE);
+ }
+ }
+ closesocket(checksocket);
+ return (ISC_FALSE);
+}
+#endif
diff --git a/contrib/ntp/ntpdate/ntptimeset.c b/contrib/ntp/ntpdate/ntptimeset.c
index 6d9332f..2485aad 100644
--- a/contrib/ntp/ntpdate/ntptimeset.c
+++ b/contrib/ntp/ntpdate/ntptimeset.c
@@ -141,7 +141,6 @@
#include <signal.h>
#include <ctype.h>
#ifndef SYS_WINNT
-# include <netdb.h>
# ifdef HAVE_SYS_SIGNAL_H
# include <sys/signal.h>
# else
@@ -403,7 +402,7 @@ ntptimesetmain(
)
{
int was_alarmed;
- struct recvbuf *rbuflist;
+ int tot_recvbufs;
struct recvbuf *rbuf;
l_fp tmp;
int errflg;
@@ -646,7 +645,6 @@ ntptimesetmain(
* yet to learn about anything else that is.
*/
was_alarmed = 0;
- rbuflist = (struct recvbuf *)0;
while (finish_time > current_time) {
#if !defined(HAVE_SIGNALED_IO)
fd_set rdfdes;
@@ -655,7 +653,7 @@ ntptimesetmain(
block_io_and_alarm();
#endif
- rbuflist = getrecvbufs(); /* get received buffers */
+ tot_recvbufs = full_recvbuffs(); /* get received buffers */
if (printmsg) {
printmsg = 0;
analysis(0);
@@ -665,7 +663,7 @@ ntptimesetmain(
alarm_flag = 0;
}
- if (!was_alarmed && rbuflist == (struct recvbuf *)0) {
+ if (!was_alarmed && tot_recvbufs > 0) {
/*
* Nothing to do. Wait for something.
*/
@@ -705,7 +703,7 @@ ntptimesetmain(
was_alarmed = 1;
alarm_flag = 0;
}
- rbuflist = getrecvbufs(); /* get received buffers */
+ tot_recvbufs = full_recvbuffs(); /* get received buffers */
}
#ifdef HAVE_SIGNALED_IO
unblock_io_and_alarm();
@@ -725,18 +723,13 @@ ntptimesetmain(
* Call the data procedure to handle each received
* packet.
*/
- while (rbuflist != (struct recvbuf *)0)
+ rbuf = get_full_recv_buffer();
+ while (rbuf != NULL)
{
- rbuf = rbuflist;
- rbuflist = rbuf->next;
receive(rbuf);
freerecvbuf(rbuf);
+ rbuf = get_full_recv_buffer();
}
-#if defined DEBUG && defined SYS_WINNT
- if (debug > 4)
- printf("getrecvbufs: %ld handler interrupts, %ld frames\n",
- handler_calls, handler_pkts);
-#endif
/*
* Do we have enough information to stop now?
OpenPOWER on IntegriCloud