summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/libntp
diff options
context:
space:
mode:
authorroberto <roberto@FreeBSD.org>1999-12-09 13:01:21 +0000
committerroberto <roberto@FreeBSD.org>1999-12-09 13:01:21 +0000
commitef64b99e8412f2273dd2e8b3291c2f78ffc4667f (patch)
treefc0cfa1aab0ff6b228f511b410733ef4f35d1ead /contrib/ntp/libntp
downloadFreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.zip
FreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.tar.gz
Virgin import of ntpd 4.0.98f
Diffstat (limited to 'contrib/ntp/libntp')
-rw-r--r--contrib/ntp/libntp/Makefile.am31
-rw-r--r--contrib/ntp/libntp/Makefile.in796
-rw-r--r--contrib/ntp/libntp/README5
-rw-r--r--contrib/ntp/libntp/a_md5encrypt.c132
-rw-r--r--contrib/ntp/libntp/adjtime.c152
-rw-r--r--contrib/ntp/libntp/adjtimex.c15
-rw-r--r--contrib/ntp/libntp/atoint.c50
-rw-r--r--contrib/ntp/libntp/atolfp.c118
-rw-r--r--contrib/ntp/libntp/atouint.c35
-rw-r--r--contrib/ntp/libntp/authencrypt.c97
-rw-r--r--contrib/ntp/libntp/authkeys.c574
-rw-r--r--contrib/ntp/libntp/authparity.c57
-rw-r--r--contrib/ntp/libntp/authreadkeys.c205
-rw-r--r--contrib/ntp/libntp/authusekey.c134
-rw-r--r--contrib/ntp/libntp/binio.c128
-rw-r--r--contrib/ntp/libntp/buftvtots.c65
-rw-r--r--contrib/ntp/libntp/caljulian.c115
-rw-r--r--contrib/ntp/libntp/calleapwhen.c59
-rw-r--r--contrib/ntp/libntp/caltontp.c42
-rw-r--r--contrib/ntp/libntp/calyearstart.c22
-rw-r--r--contrib/ntp/libntp/clocktime.c132
-rw-r--r--contrib/ntp/libntp/clocktypes.c98
-rw-r--r--contrib/ntp/libntp/decodenetnum.c59
-rw-r--r--contrib/ntp/libntp/dofptoa.c118
-rw-r--r--contrib/ntp/libntp/dolfptoa.c162
-rw-r--r--contrib/ntp/libntp/emalloc.c48
-rw-r--r--contrib/ntp/libntp/findconfig.c72
-rw-r--r--contrib/ntp/libntp/fptoa.c25
-rw-r--r--contrib/ntp/libntp/fptoms.c24
-rw-r--r--contrib/ntp/libntp/getopt.c107
-rw-r--r--contrib/ntp/libntp/gpstolfp.c41
-rw-r--r--contrib/ntp/libntp/hextoint.c39
-rw-r--r--contrib/ntp/libntp/hextolfp.c67
-rw-r--r--contrib/ntp/libntp/humandate.c62
-rw-r--r--contrib/ntp/libntp/ieee754io.c575
-rw-r--r--contrib/ntp/libntp/inttoa.c20
-rw-r--r--contrib/ntp/libntp/iosignal.c518
-rw-r--r--contrib/ntp/libntp/lib_strbuf.c22
-rw-r--r--contrib/ntp/libntp/lib_strbuf.h27
-rw-r--r--contrib/ntp/libntp/log.c152
-rw-r--r--contrib/ntp/libntp/log.h21
-rw-r--r--contrib/ntp/libntp/machines.c218
-rw-r--r--contrib/ntp/libntp/md5c.c350
-rw-r--r--contrib/ntp/libntp/memmove.c136
-rw-r--r--contrib/ntp/libntp/mexit.c34
-rw-r--r--contrib/ntp/libntp/mfp_mul.c140
-rw-r--r--contrib/ntp/libntp/mfptoa.c23
-rw-r--r--contrib/ntp/libntp/mfptoms.c23
-rw-r--r--contrib/ntp/libntp/mktime.c282
-rw-r--r--contrib/ntp/libntp/modetoa.c34
-rw-r--r--contrib/ntp/libntp/mstolfp.c100
-rw-r--r--contrib/ntp/libntp/msutotsf.c35
-rw-r--r--contrib/ntp/libntp/msyslog.c170
-rw-r--r--contrib/ntp/libntp/netof.c25
-rw-r--r--contrib/ntp/libntp/numtoa.c24
-rw-r--r--contrib/ntp/libntp/numtohost.c39
-rw-r--r--contrib/ntp/libntp/octtoint.c35
-rw-r--r--contrib/ntp/libntp/prettydate.c72
-rw-r--r--contrib/ntp/libntp/ranny.c82
-rw-r--r--contrib/ntp/libntp/recvbuff.c277
-rw-r--r--contrib/ntp/libntp/refnumtoa.c31
-rw-r--r--contrib/ntp/libntp/statestr.c271
-rw-r--r--contrib/ntp/libntp/strerror.c40
-rw-r--r--contrib/ntp/libntp/syssignal.c123
-rw-r--r--contrib/ntp/libntp/systime.c404
-rw-r--r--contrib/ntp/libntp/tsftomsu.c38
-rw-r--r--contrib/ntp/libntp/tstotv.c135
-rw-r--r--contrib/ntp/libntp/tvtoa.c38
-rw-r--r--contrib/ntp/libntp/tvtots.c159
-rw-r--r--contrib/ntp/libntp/uglydate.c50
-rw-r--r--contrib/ntp/libntp/uinttoa.c20
-rw-r--r--contrib/ntp/libntp/utvtoa.c26
-rw-r--r--contrib/ntp/libntp/ymd2yd.c37
73 files changed, 8692 insertions, 0 deletions
diff --git a/contrib/ntp/libntp/Makefile.am b/contrib/ntp/libntp/Makefile.am
new file mode 100644
index 0000000..9ba3c09
--- /dev/null
+++ b/contrib/ntp/libntp/Makefile.am
@@ -0,0 +1,31 @@
+#AUTOMAKE_OPTIONS = ../ansi2knr no-dependencies
+AUTOMAKE_OPTIONS = ../util/ansi2knr
+noinst_LIBRARIES = libntp.a
+libntp_a_SOURCES = a_md5encrypt.c adjtime.c atoint.c atolfp.c atouint.c \
+ authencrypt.c authkeys.c authparity.c authreadkeys.c authusekey.c \
+ buftvtots.c caljulian.c calleapwhen.c caltontp.c calyearstart.c \
+ clocktime.c clocktypes.c decodenetnum.c dofptoa.c dolfptoa.c \
+ emalloc.c findconfig.c fptoa.c fptoms.c getopt.c hextoint.c \
+ hextolfp.c humandate.c inttoa.c lib_strbuf.c machines.c md5c.c \
+ memmove.c mexit.c mfptoa.c mfptoms.c modetoa.c mstolfp.c msutotsf.c \
+ msyslog.c netof.c numtoa.c numtohost.c octtoint.c prettydate.c \
+ ranny.c refnumtoa.c statestr.c syssignal.c systime.c tsftomsu.c \
+ tstotv.c tvtoa.c tvtots.c uglydate.c uinttoa.c utvtoa.c ymd2yd.c \
+ mfp_mul.c binio.c ieee754io.c gpstolfp.c recvbuff.c iosignal.c
+libntp_a_LIBADD = @LIBOBJS@
+libntp_a_DEPENDENCIES = @LIBOBJS@
+INCLUDES = -I$(top_srcdir)/include
+ETAGS_ARGS = Makefile.am
+
+noinst_HEADERS = lib_strbuf.h log.h
+
+../include/des.h:
+ touch ../include/des.h
+
+EXTRA_DIST = README $(HEADERS) adjtimex.c log.c strerror.c mktime.c
+
+#mktime_.c: mktime.c $(ANSI2KNR)
+# $(ANSI2KNR) $< mktime_.c
+
+#strerror_.c: strerror.c $(ANSI2KNR)
+# $(ANSI2KNR) $< strerror_.c
diff --git a/contrib/ntp/libntp/Makefile.in b/contrib/ntp/libntp/Makefile.in
new file mode 100644
index 0000000..53eda67
--- /dev/null
+++ b/contrib/ntp/libntp/Makefile.in
@@ -0,0 +1,796 @@
+# Makefile.in generated automatically by automake 1.4a from Makefile.am
+
+# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+SHELL = @SHELL@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+infodir = @infodir@
+mandir = @mandir@
+includedir = @includedir@
+oldincludedir = /usr/include
+
+DESTDIR =
+
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+
+top_builddir = ..
+
+ACLOCAL = @ACLOCAL@
+AUTOCONF = @AUTOCONF@
+AUTOMAKE = @AUTOMAKE@
+AUTOHEADER = @AUTOHEADER@
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_FLAG =
+transform = @program_transform_name@
+
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_alias = @build_alias@
+build_triplet = @build@
+host_alias = @host_alias@
+host_triplet = @host@
+target_alias = @target_alias@
+target_triplet = @target@
+AMTAR = @AMTAR@
+AMTARFLAGS = @AMTARFLAGS@
+AWK = @AWK@
+CC = @CC@
+CFLAGS = @CFLAGS@
+CHUTEST = @CHUTEST@
+CLKTEST = @CLKTEST@
+CPP = @CPP@
+DCFD = @DCFD@
+LDFLAGS = @LDFLAGS@
+LIBPARSE = @LIBPARSE@
+LIBRSAREF = @LIBRSAREF@
+LN_S = @LN_S@
+MAKEINFO = @MAKEINFO@
+MAKE_ADJTIMED = @MAKE_ADJTIMED@
+MAKE_CHECK_Y2K = @MAKE_CHECK_Y2K@
+MAKE_LIBPARSE = @MAKE_LIBPARSE@
+MAKE_LIBPARSE_KERNEL = @MAKE_LIBPARSE_KERNEL@
+MAKE_LIBRSAREF = @MAKE_LIBRSAREF@
+MAKE_NTPTIME = @MAKE_NTPTIME@
+MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@
+MAKE_TICKADJ = @MAKE_TICKADJ@
+PACKAGE = @PACKAGE@
+PATH_SH = @PATH_SH@
+PROPDELAY = @PROPDELAY@
+RANLIB = @RANLIB@
+RSAREF = @RSAREF@
+TESTDCF = @TESTDCF@
+U = @U@
+VERSION = @VERSION@
+
+#AUTOMAKE_OPTIONS = ../ansi2knr no-dependencies
+
+
+AUTOMAKE_OPTIONS = ../util/ansi2knr
+noinst_LIBRARIES = libntp.a
+libntp_a_SOURCES = a_md5encrypt.c adjtime.c atoint.c atolfp.c atouint.c \
+ authencrypt.c authkeys.c authparity.c authreadkeys.c authusekey.c \
+ buftvtots.c caljulian.c calleapwhen.c caltontp.c calyearstart.c \
+ clocktime.c clocktypes.c decodenetnum.c dofptoa.c dolfptoa.c \
+ emalloc.c findconfig.c fptoa.c fptoms.c getopt.c hextoint.c \
+ hextolfp.c humandate.c inttoa.c lib_strbuf.c machines.c md5c.c \
+ memmove.c mexit.c mfptoa.c mfptoms.c modetoa.c mstolfp.c msutotsf.c \
+ msyslog.c netof.c numtoa.c numtohost.c octtoint.c prettydate.c \
+ ranny.c refnumtoa.c statestr.c syssignal.c systime.c tsftomsu.c \
+ tstotv.c tvtoa.c tvtots.c uglydate.c uinttoa.c utvtoa.c ymd2yd.c \
+ mfp_mul.c binio.c ieee754io.c gpstolfp.c recvbuff.c iosignal.c
+
+libntp_a_LIBADD = @LIBOBJS@
+libntp_a_DEPENDENCIES = @LIBOBJS@
+INCLUDES = -I$(top_srcdir)/include
+ETAGS_ARGS = Makefile.am
+
+noinst_HEADERS = lib_strbuf.h log.h
+
+EXTRA_DIST = README $(HEADERS) adjtimex.c log.c strerror.c mktime.c
+subdir = libntp
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = ../config.h
+CONFIG_CLEAN_FILES =
+LIBRARIES = $(noinst_LIBRARIES)
+
+
+DEFS = @DEFS@ -I. -I$(srcdir) -I..
+CPPFLAGS = @CPPFLAGS@
+LIBS = @LIBS@
+ANSI2KNR = ../util/ansi2knr
+am_libntp_a_OBJECTS = a_md5encrypt$U.o adjtime$U.o atoint$U.o \
+atolfp$U.o atouint$U.o authencrypt$U.o authkeys$U.o authparity$U.o \
+authreadkeys$U.o authusekey$U.o buftvtots$U.o caljulian$U.o \
+calleapwhen$U.o caltontp$U.o calyearstart$U.o clocktime$U.o \
+clocktypes$U.o decodenetnum$U.o dofptoa$U.o dolfptoa$U.o emalloc$U.o \
+findconfig$U.o fptoa$U.o fptoms$U.o getopt$U.o hextoint$U.o \
+hextolfp$U.o humandate$U.o inttoa$U.o lib_strbuf$U.o machines$U.o \
+md5c$U.o memmove$U.o mexit$U.o mfptoa$U.o mfptoms$U.o modetoa$U.o \
+mstolfp$U.o msutotsf$U.o msyslog$U.o netof$U.o numtoa$U.o numtohost$U.o \
+octtoint$U.o prettydate$U.o ranny$U.o refnumtoa$U.o statestr$U.o \
+syssignal$U.o systime$U.o tsftomsu$U.o tstotv$U.o tvtoa$U.o tvtots$U.o \
+uglydate$U.o uinttoa$U.o utvtoa$U.o ymd2yd$U.o mfp_mul$U.o binio$U.o \
+ieee754io$U.o gpstolfp$U.o recvbuff$U.o iosignal$U.o
+libntp_a_OBJECTS = $(am_libntp_a_OBJECTS)
+AR = ar
+COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+DIST_SOURCES = $(libntp_a_SOURCES)
+HEADERS = $(noinst_HEADERS)
+
+DIST_COMMON = README $(noinst_HEADERS) Makefile.am Makefile.in mktime.c \
+strerror.c
+
+
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+
+GZIP_ENV = --best
+SOURCES = $(libntp_a_SOURCES)
+OBJECTS = $(am_libntp_a_OBJECTS)
+
+all: all-redirect
+.SUFFIXES:
+.SUFFIXES: .c .o
+$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+ cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps libntp/Makefile
+
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ cd $(top_builddir) \
+ && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
+
+mostlyclean-noinstLIBRARIES:
+
+clean-noinstLIBRARIES:
+ -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
+
+distclean-noinstLIBRARIES:
+
+maintainer-clean-noinstLIBRARIES:
+
+.c.o:
+ $(COMPILE) -c $<
+
+mostlyclean-compile:
+ -rm -f *.o core *.core
+
+clean-compile:
+
+distclean-compile:
+ -rm -f *.tab.c
+
+maintainer-clean-compile:
+../util/ansi2knr: ../util/ansi2knr.o
+ cd ../util && $(MAKE) $(AM_MAKEFLAGS) ansi2knr
+
+../util/ansi2knr.o:
+ cd ../util && $(MAKE) $(AM_MAKEFLAGS) ansi2knr.o
+
+
+mostlyclean-kr:
+ -rm -f *_.c
+
+clean-kr:
+
+distclean-kr:
+
+maintainer-clean-kr:
+a_md5encrypt$U.o:
+adjtime$U.o:
+atoint$U.o:
+atolfp$U.o:
+atouint$U.o:
+authencrypt$U.o:
+authkeys$U.o:
+authparity$U.o:
+authreadkeys$U.o:
+authusekey$U.o:
+buftvtots$U.o:
+caljulian$U.o:
+calleapwhen$U.o:
+caltontp$U.o:
+calyearstart$U.o:
+clocktime$U.o:
+clocktypes$U.o:
+decodenetnum$U.o:
+dofptoa$U.o:
+dolfptoa$U.o:
+emalloc$U.o:
+findconfig$U.o:
+fptoa$U.o:
+fptoms$U.o:
+getopt$U.o:
+hextoint$U.o:
+hextolfp$U.o:
+humandate$U.o:
+inttoa$U.o:
+lib_strbuf$U.o:
+machines$U.o:
+md5c$U.o:
+memmove$U.o:
+mexit$U.o:
+mfptoa$U.o:
+mfptoms$U.o:
+modetoa$U.o:
+mstolfp$U.o:
+msutotsf$U.o:
+msyslog$U.o:
+netof$U.o:
+numtoa$U.o:
+numtohost$U.o:
+octtoint$U.o:
+prettydate$U.o:
+ranny$U.o:
+refnumtoa$U.o:
+statestr$U.o:
+syssignal$U.o:
+systime$U.o:
+tsftomsu$U.o:
+tstotv$U.o:
+tvtoa$U.o:
+tvtots$U.o:
+uglydate$U.o:
+uinttoa$U.o:
+utvtoa$U.o:
+ymd2yd$U.o:
+mfp_mul$U.o:
+binio$U.o:
+ieee754io$U.o:
+gpstolfp$U.o:
+recvbuff$U.o:
+iosignal$U.o:
+
+libntp.a: $(libntp_a_OBJECTS) $(libntp_a_DEPENDENCIES)
+ -rm -f libntp.a
+ $(AR) cru libntp.a $(libntp_a_OBJECTS) $(libntp_a_LIBADD)
+ $(RANLIB) libntp.a
+a_md5encrypt_.c: a_md5encrypt.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/a_md5encrypt.c; then echo $(srcdir)/a_md5encrypt.c; else echo a_md5encrypt.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > a_md5encrypt_.c
+adjtime_.c: adjtime.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/adjtime.c; then echo $(srcdir)/adjtime.c; else echo adjtime.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > adjtime_.c
+atoint_.c: atoint.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/atoint.c; then echo $(srcdir)/atoint.c; else echo atoint.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > atoint_.c
+atolfp_.c: atolfp.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/atolfp.c; then echo $(srcdir)/atolfp.c; else echo atolfp.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > atolfp_.c
+atouint_.c: atouint.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/atouint.c; then echo $(srcdir)/atouint.c; else echo atouint.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > atouint_.c
+authencrypt_.c: authencrypt.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/authencrypt.c; then echo $(srcdir)/authencrypt.c; else echo authencrypt.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > authencrypt_.c
+authkeys_.c: authkeys.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/authkeys.c; then echo $(srcdir)/authkeys.c; else echo authkeys.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > authkeys_.c
+authparity_.c: authparity.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/authparity.c; then echo $(srcdir)/authparity.c; else echo authparity.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > authparity_.c
+authreadkeys_.c: authreadkeys.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/authreadkeys.c; then echo $(srcdir)/authreadkeys.c; else echo authreadkeys.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > authreadkeys_.c
+authusekey_.c: authusekey.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/authusekey.c; then echo $(srcdir)/authusekey.c; else echo authusekey.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > authusekey_.c
+binio_.c: binio.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/binio.c; then echo $(srcdir)/binio.c; else echo binio.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > binio_.c
+buftvtots_.c: buftvtots.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/buftvtots.c; then echo $(srcdir)/buftvtots.c; else echo buftvtots.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > buftvtots_.c
+caljulian_.c: caljulian.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/caljulian.c; then echo $(srcdir)/caljulian.c; else echo caljulian.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > caljulian_.c
+calleapwhen_.c: calleapwhen.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/calleapwhen.c; then echo $(srcdir)/calleapwhen.c; else echo calleapwhen.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > calleapwhen_.c
+caltontp_.c: caltontp.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/caltontp.c; then echo $(srcdir)/caltontp.c; else echo caltontp.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > caltontp_.c
+calyearstart_.c: calyearstart.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/calyearstart.c; then echo $(srcdir)/calyearstart.c; else echo calyearstart.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > calyearstart_.c
+clocktime_.c: clocktime.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/clocktime.c; then echo $(srcdir)/clocktime.c; else echo clocktime.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > clocktime_.c
+clocktypes_.c: clocktypes.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/clocktypes.c; then echo $(srcdir)/clocktypes.c; else echo clocktypes.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > clocktypes_.c
+decodenetnum_.c: decodenetnum.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/decodenetnum.c; then echo $(srcdir)/decodenetnum.c; else echo decodenetnum.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > decodenetnum_.c
+dofptoa_.c: dofptoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/dofptoa.c; then echo $(srcdir)/dofptoa.c; else echo dofptoa.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > dofptoa_.c
+dolfptoa_.c: dolfptoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/dolfptoa.c; then echo $(srcdir)/dolfptoa.c; else echo dolfptoa.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > dolfptoa_.c
+emalloc_.c: emalloc.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/emalloc.c; then echo $(srcdir)/emalloc.c; else echo emalloc.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > emalloc_.c
+findconfig_.c: findconfig.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/findconfig.c; then echo $(srcdir)/findconfig.c; else echo findconfig.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > findconfig_.c
+fptoa_.c: fptoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/fptoa.c; then echo $(srcdir)/fptoa.c; else echo fptoa.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > fptoa_.c
+fptoms_.c: fptoms.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/fptoms.c; then echo $(srcdir)/fptoms.c; else echo fptoms.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > fptoms_.c
+getopt_.c: getopt.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/getopt.c; then echo $(srcdir)/getopt.c; else echo getopt.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > getopt_.c
+gpstolfp_.c: gpstolfp.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/gpstolfp.c; then echo $(srcdir)/gpstolfp.c; else echo gpstolfp.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > gpstolfp_.c
+hextoint_.c: hextoint.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/hextoint.c; then echo $(srcdir)/hextoint.c; else echo hextoint.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > hextoint_.c
+hextolfp_.c: hextolfp.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/hextolfp.c; then echo $(srcdir)/hextolfp.c; else echo hextolfp.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > hextolfp_.c
+humandate_.c: humandate.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/humandate.c; then echo $(srcdir)/humandate.c; else echo humandate.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > humandate_.c
+ieee754io_.c: ieee754io.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ieee754io.c; then echo $(srcdir)/ieee754io.c; else echo ieee754io.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > ieee754io_.c
+inttoa_.c: inttoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/inttoa.c; then echo $(srcdir)/inttoa.c; else echo inttoa.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > inttoa_.c
+iosignal_.c: iosignal.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/iosignal.c; then echo $(srcdir)/iosignal.c; else echo iosignal.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > iosignal_.c
+lib_strbuf_.c: lib_strbuf.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/lib_strbuf.c; then echo $(srcdir)/lib_strbuf.c; else echo lib_strbuf.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > lib_strbuf_.c
+machines_.c: machines.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/machines.c; then echo $(srcdir)/machines.c; else echo machines.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > machines_.c
+md5c_.c: md5c.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/md5c.c; then echo $(srcdir)/md5c.c; else echo md5c.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > md5c_.c
+memmove_.c: memmove.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/memmove.c; then echo $(srcdir)/memmove.c; else echo memmove.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > memmove_.c
+mexit_.c: mexit.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/mexit.c; then echo $(srcdir)/mexit.c; else echo mexit.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > mexit_.c
+mfp_mul_.c: mfp_mul.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/mfp_mul.c; then echo $(srcdir)/mfp_mul.c; else echo mfp_mul.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > mfp_mul_.c
+mfptoa_.c: mfptoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/mfptoa.c; then echo $(srcdir)/mfptoa.c; else echo mfptoa.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > mfptoa_.c
+mfptoms_.c: mfptoms.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/mfptoms.c; then echo $(srcdir)/mfptoms.c; else echo mfptoms.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > mfptoms_.c
+mktime_.c: mktime.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/mktime.c; then echo $(srcdir)/mktime.c; else echo mktime.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > mktime_.c
+modetoa_.c: modetoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/modetoa.c; then echo $(srcdir)/modetoa.c; else echo modetoa.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > modetoa_.c
+mstolfp_.c: mstolfp.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/mstolfp.c; then echo $(srcdir)/mstolfp.c; else echo mstolfp.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > mstolfp_.c
+msutotsf_.c: msutotsf.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/msutotsf.c; then echo $(srcdir)/msutotsf.c; else echo msutotsf.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > msutotsf_.c
+msyslog_.c: msyslog.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/msyslog.c; then echo $(srcdir)/msyslog.c; else echo msyslog.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > msyslog_.c
+netof_.c: netof.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/netof.c; then echo $(srcdir)/netof.c; else echo netof.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > netof_.c
+numtoa_.c: numtoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/numtoa.c; then echo $(srcdir)/numtoa.c; else echo numtoa.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > numtoa_.c
+numtohost_.c: numtohost.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/numtohost.c; then echo $(srcdir)/numtohost.c; else echo numtohost.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > numtohost_.c
+octtoint_.c: octtoint.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/octtoint.c; then echo $(srcdir)/octtoint.c; else echo octtoint.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > octtoint_.c
+prettydate_.c: prettydate.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/prettydate.c; then echo $(srcdir)/prettydate.c; else echo prettydate.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > prettydate_.c
+ranny_.c: ranny.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ranny.c; then echo $(srcdir)/ranny.c; else echo ranny.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > ranny_.c
+recvbuff_.c: recvbuff.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/recvbuff.c; then echo $(srcdir)/recvbuff.c; else echo recvbuff.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > recvbuff_.c
+refnumtoa_.c: refnumtoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/refnumtoa.c; then echo $(srcdir)/refnumtoa.c; else echo refnumtoa.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > refnumtoa_.c
+statestr_.c: statestr.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/statestr.c; then echo $(srcdir)/statestr.c; else echo statestr.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > statestr_.c
+strerror_.c: strerror.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/strerror.c; then echo $(srcdir)/strerror.c; else echo strerror.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > strerror_.c
+syssignal_.c: syssignal.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/syssignal.c; then echo $(srcdir)/syssignal.c; else echo syssignal.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > syssignal_.c
+systime_.c: systime.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/systime.c; then echo $(srcdir)/systime.c; else echo systime.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > systime_.c
+tsftomsu_.c: tsftomsu.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/tsftomsu.c; then echo $(srcdir)/tsftomsu.c; else echo tsftomsu.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > tsftomsu_.c
+tstotv_.c: tstotv.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/tstotv.c; then echo $(srcdir)/tstotv.c; else echo tstotv.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > tstotv_.c
+tvtoa_.c: tvtoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/tvtoa.c; then echo $(srcdir)/tvtoa.c; else echo tvtoa.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > tvtoa_.c
+tvtots_.c: tvtots.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/tvtots.c; then echo $(srcdir)/tvtots.c; else echo tvtots.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > tvtots_.c
+uglydate_.c: uglydate.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/uglydate.c; then echo $(srcdir)/uglydate.c; else echo uglydate.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > uglydate_.c
+uinttoa_.c: uinttoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/uinttoa.c; then echo $(srcdir)/uinttoa.c; else echo uinttoa.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > uinttoa_.c
+utvtoa_.c: utvtoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/utvtoa.c; then echo $(srcdir)/utvtoa.c; else echo utvtoa.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > utvtoa_.c
+ymd2yd_.c: ymd2yd.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ymd2yd.c; then echo $(srcdir)/ymd2yd.c; else echo ymd2yd.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > ymd2yd_.c
+a_md5encrypt_.o adjtime_.o atoint_.o atolfp_.o atouint_.o \
+authencrypt_.o authkeys_.o authparity_.o authreadkeys_.o authusekey_.o \
+binio_.o buftvtots_.o caljulian_.o calleapwhen_.o caltontp_.o \
+calyearstart_.o clocktime_.o clocktypes_.o decodenetnum_.o dofptoa_.o \
+dolfptoa_.o emalloc_.o findconfig_.o fptoa_.o fptoms_.o getopt_.o \
+gpstolfp_.o hextoint_.o hextolfp_.o humandate_.o ieee754io_.o inttoa_.o \
+iosignal_.o lib_strbuf_.o machines_.o md5c_.o memmove_.o mexit_.o \
+mfp_mul_.o mfptoa_.o mfptoms_.o mktime_.o modetoa_.o mstolfp_.o \
+msutotsf_.o msyslog_.o netof_.o numtoa_.o numtohost_.o octtoint_.o \
+prettydate_.o ranny_.o recvbuff_.o refnumtoa_.o statestr_.o strerror_.o \
+syssignal_.o systime_.o tsftomsu_.o tstotv_.o tvtoa_.o tvtots_.o \
+uglydate_.o uinttoa_.o utvtoa_.o ymd2yd_.o : $(ANSI2KNR)
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP)
+ list='$(SOURCES) $(HEADERS)'; \
+ unique=`for i in $$list; do echo $$i; done | \
+ ${AWK:-awk} ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ here=`pwd` && cd $(srcdir) \
+ && mkid -f$$here/ID $$unique $(LISP)
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS)'; \
+ unique=`for i in $$list; do echo $$i; done | \
+ ${AWK:-awk} ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
+ || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
+
+mostlyclean-tags:
+
+clean-tags:
+
+distclean-tags:
+ -rm -f TAGS ID
+
+maintainer-clean-tags:
+
+distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
+
+distdir: $(DISTFILES)
+ @for file in $(DISTFILES); do \
+ d=$(srcdir); \
+ if test -d $$d/$$file; then \
+ cp -pr $$d/$$file $(distdir)/$$file; \
+ else \
+ test -f $(distdir)/$$file \
+ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
+ || cp -p $$d/$$file $(distdir)/$$file || :; \
+ fi; \
+ done
+a_md5encrypt.o: a_md5encrypt.c ../include/ntp_machine.h ../config.h \
+ ../include/ntp_proto.h ../include/ntp_types.h \
+ ../include/ntp_fp.h ../include/ntp_string.h ../include/global.h \
+ ../include/md5.h ../include/ntp_stdlib.h ../include/l_stdlib.h
+adjtime.o: adjtime.c ../config.h
+atoint.o: atoint.c ../include/ntp_types.h ../include/ntp_machine.h \
+ ../config.h ../include/ntp_proto.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+atolfp.o: atolfp.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_string.h
+atouint.o: atouint.c ../include/ntp_types.h ../include/ntp_machine.h \
+ ../config.h ../include/ntp_proto.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+authencrypt.o: authencrypt.c ../include/ntp_machine.h ../config.h \
+ ../include/ntp_proto.h
+authkeys.o: authkeys.c ../config.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../include/ntp_proto.h \
+ ../include/ntp_fp.h ../include/ntp.h ../include/ntpd.h \
+ ../include/ntp_syslog.h ../include/ntp_select.h \
+ ../include/ntp_malloc.h ../include/ntp_refclock.h \
+ ../include/recvbuff.h ../include/ntp_string.h \
+ ../include/ntp_stdlib.h ../include/l_stdlib.h
+authparity.o: authparity.c ../include/ntp_stdlib.h \
+ ../include/ntp_types.h ../include/ntp_machine.h ../config.h \
+ ../include/ntp_proto.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+authreadkeys.o: authreadkeys.c ../include/ntp_fp.h \
+ ../include/ntp_types.h ../include/ntp_machine.h ../config.h \
+ ../include/ntp_proto.h ../include/ntp.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/l_stdlib.h \
+ ../include/ntp_syslog.h
+authusekey.o: authusekey.c ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_string.h ../include/ntp_stdlib.h \
+ ../include/l_stdlib.h
+binio.o: binio.c ../include/binio.h ../include/ntp_stdlib.h \
+ ../include/ntp_types.h ../include/ntp_machine.h ../config.h \
+ ../include/ntp_proto.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+buftvtots.o: buftvtots.c ../config.h ../include/ntp_fp.h \
+ ../include/ntp_types.h ../include/ntp_machine.h \
+ ../include/ntp_proto.h ../include/ntp_unixtime.h
+caljulian.o: caljulian.c ../include/ntp_types.h ../include/ntp_machine.h \
+ ../config.h ../include/ntp_proto.h ../include/ntp_calendar.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+calleapwhen.o: calleapwhen.c ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_calendar.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+caltontp.o: caltontp.c ../include/ntp_types.h ../include/ntp_machine.h \
+ ../config.h ../include/ntp_proto.h ../include/ntp_calendar.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+calyearstart.o: calyearstart.c ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_calendar.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+clocktime.o: clocktime.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_unixtime.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+clocktypes.o: clocktypes.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp.h lib_strbuf.h ../include/ntp_refclock.h \
+ ../include/recvbuff.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+decodenetnum.o: decodenetnum.c ../include/ntp_stdlib.h \
+ ../include/ntp_types.h ../include/ntp_machine.h ../config.h \
+ ../include/ntp_proto.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+desc.o: desc.c ../include/global.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/rsaref.h ../include/md2.h ../include/md5.h \
+ ../include/des.h
+dofptoa.o: dofptoa.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ lib_strbuf.h ../include/ntp_string.h ../include/ntp_stdlib.h \
+ ../include/l_stdlib.h
+dolfptoa.o: dolfptoa.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ lib_strbuf.h ../include/ntp_string.h ../include/ntp_stdlib.h \
+ ../include/l_stdlib.h
+emalloc.o: emalloc.c ../include/ntp_types.h ../include/ntp_machine.h \
+ ../config.h ../include/ntp_proto.h ../include/ntp_malloc.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h ../include/ntp_syslog.h
+findconfig.o: findconfig.c ../config.h ../include/ntp_stdlib.h \
+ ../include/ntp_types.h ../include/ntp_machine.h \
+ ../include/ntp_proto.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+fptoa.o: fptoa.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+fptoms.o: fptoms.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h
+getopt.o: getopt.c ../include/ntp_stdlib.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+gpstolfp.o: gpstolfp.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h
+hextoint.o: hextoint.c ../include/ntp_stdlib.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+hextolfp.o: hextolfp.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_string.h ../include/ntp_stdlib.h \
+ ../include/l_stdlib.h
+humandate.o: humandate.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_unixtime.h lib_strbuf.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+ieee754io.o: ieee754io.c ../config.h ../include/l_stdlib.h \
+ ../include/ntp_types.h ../include/ntp_machine.h \
+ ../include/ntp_proto.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/ntp_fp.h \
+ ../include/ieee754io.h
+inttoa.o: inttoa.c lib_strbuf.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+iosignal.o: iosignal.c ../config.h ../include/ntp_machine.h \
+ ../include/ntp_proto.h ../include/ntpd.h \
+ ../include/ntp_syslog.h ../include/ntp_fp.h \
+ ../include/ntp_types.h ../include/ntp.h ../include/ntp_select.h \
+ ../include/ntp_malloc.h ../include/ntp_refclock.h \
+ ../include/recvbuff.h ../include/ntp_io.h ../include/ntp_if.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h ../include/iosignal.h
+lib_strbuf.o: lib_strbuf.c lib_strbuf.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h
+machines.o: machines.c ../config.h ../include/ntp_machine.h \
+ ../include/ntp_proto.h ../include/ntp_syslog.h \
+ ../include/ntp_stdlib.h ../include/ntp_types.h \
+ ../include/ntp_string.h ../include/l_stdlib.h \
+ ../include/ntp_unixtime.h
+md5c.o: md5c.c ../include/global.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/md5.h
+memmove.o: memmove.c ../config.h
+mexit.o: mexit.c
+mfp_mul.o: mfp_mul.c ../include/ntp_stdlib.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_string.h ../include/l_stdlib.h \
+ ../include/ntp_fp.h
+mfptoa.o: mfptoa.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+mfptoms.o: mfptoms.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+modetoa.o: modetoa.c lib_strbuf.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+mstolfp.o: mstolfp.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+msutotsf.o: msutotsf.c ../include/ntp_types.h ../include/ntp_machine.h \
+ ../config.h ../include/ntp_proto.h
+msyslog.o: msyslog.c ../config.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../include/ntp_proto.h \
+ ../include/ntp_string.h ../include/ntp_stdlib.h \
+ ../include/l_stdlib.h ../include/ntp_syslog.h
+netof.o: netof.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+numtoa.o: numtoa.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ lib_strbuf.h ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+numtohost.o: numtohost.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h lib_strbuf.h
+octtoint.o: octtoint.c ../include/ntp_stdlib.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+prettydate.o: prettydate.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_unixtime.h lib_strbuf.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+ranny.o: ranny.c ../include/ntp_stdlib.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+recvbuff.o: recvbuff.c ../config.h ../include/ntp_machine.h \
+ ../include/ntp_proto.h ../include/ntp_fp.h \
+ ../include/ntp_types.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/l_stdlib.h \
+ ../include/ntp_syslog.h ../include/ntp_io.h \
+ ../include/recvbuff.h ../include/ntp.h ../include/iosignal.h \
+ ../include/ntp_refclock.h
+refnumtoa.o: refnumtoa.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ lib_strbuf.h ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+statestr.o: statestr.c ../config.h ../include/ntp_stdlib.h \
+ ../include/ntp_types.h ../include/ntp_machine.h \
+ ../include/ntp_proto.h ../include/ntp_string.h \
+ ../include/l_stdlib.h ../include/ntp_fp.h ../include/ntp.h \
+ lib_strbuf.h ../include/ntp_refclock.h ../include/recvbuff.h \
+ ../include/ntp_control.h
+syssignal.o: syssignal.c ../config.h ../include/ntp_syslog.h \
+ ../include/ntp_stdlib.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../include/ntp_proto.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+systime.o: systime.c ../config.h ../include/ntp_machine.h \
+ ../include/ntp_proto.h ../include/ntp_fp.h \
+ ../include/ntp_types.h ../include/ntp_syslog.h \
+ ../include/ntp_unixtime.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+tsftomsu.o: tsftomsu.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+tstotv.o: tstotv.c ../include/ntp_types.h ../include/ntp_machine.h \
+ ../config.h ../include/ntp_proto.h
+tvtoa.o: tvtoa.c lib_strbuf.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h ../include/ntp_unixtime.h
+tvtots.o: tvtots.c ../include/ntp_types.h ../include/ntp_machine.h \
+ ../config.h ../include/ntp_proto.h
+uglydate.o: uglydate.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_unixtime.h lib_strbuf.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+uinttoa.o: uinttoa.c lib_strbuf.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h
+utvtoa.o: utvtoa.c lib_strbuf.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_stdlib.h ../include/ntp_string.h \
+ ../include/l_stdlib.h ../include/ntp_unixtime.h
+ymd2yd.o: ymd2yd.c ../include/ntp_fp.h ../include/ntp_types.h \
+ ../include/ntp_machine.h ../config.h ../include/ntp_proto.h \
+ ../include/ntp_unixtime.h ../include/ntp_stdlib.h \
+ ../include/ntp_string.h ../include/l_stdlib.h
+
+info-am:
+info: info-am
+dvi-am:
+dvi: dvi-am
+check-am: all-am
+check: check-am
+installcheck-am:
+installcheck: installcheck-am
+install-exec-am:
+install-exec: install-exec-am
+
+install-data-am:
+install-data: install-data-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+install: install-am
+uninstall-am:
+uninstall: uninstall-am
+all-am: Makefile $(LIBRARIES) $(HEADERS)
+all-redirect: all-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install
+installdirs:
+
+
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -rm -f Makefile $(CONFIG_CLEAN_FILES)
+ -rm -f config.cache config.log stamp-h stamp-h[0-9]*
+
+maintainer-clean-generic:
+mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
+ mostlyclean-kr mostlyclean-tags mostlyclean-generic
+
+mostlyclean: mostlyclean-am
+
+clean-am: clean-noinstLIBRARIES clean-compile clean-kr clean-tags \
+ clean-generic mostlyclean-am
+
+clean: clean-am
+
+distclean-am: distclean-noinstLIBRARIES distclean-compile distclean-kr \
+ distclean-tags distclean-generic clean-am
+
+distclean: distclean-am
+
+maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
+ maintainer-clean-compile maintainer-clean-kr \
+ maintainer-clean-tags maintainer-clean-generic \
+ distclean-am
+ @echo "This command is intended for maintainers to use;"
+ @echo "it deletes files that may require special tools to rebuild."
+
+maintainer-clean: maintainer-clean-am
+
+.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
+clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
+mostlyclean-compile distclean-compile clean-compile \
+maintainer-clean-compile mostlyclean-kr distclean-kr clean-kr \
+maintainer-clean-kr tags mostlyclean-tags distclean-tags clean-tags \
+maintainer-clean-tags distdir info-am info dvi-am dvi check check-am \
+installcheck-am installcheck install-exec-am install-exec \
+install-data-am install-data install-am install uninstall-am uninstall \
+all-redirect all-am all install-strip installdirs mostlyclean-generic \
+distclean-generic clean-generic maintainer-clean-generic clean \
+mostlyclean distclean maintainer-clean
+
+
+../include/des.h:
+ touch ../include/des.h
+
+#mktime_.c: mktime.c $(ANSI2KNR)
+# $(ANSI2KNR) $< mktime_.c
+
+#strerror_.c: strerror.c $(ANSI2KNR)
+# $(ANSI2KNR) $< strerror_.c
+
+# 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/libntp/README b/contrib/ntp/libntp/README
new file mode 100644
index 0000000..fac7185
--- /dev/null
+++ b/contrib/ntp/libntp/README
@@ -0,0 +1,5 @@
+README file for directory ./libntp of the NTP Version 4 distribution
+
+This directory contains the sources for the NTP library used by most
+programs in this distribution. See the README and RELNOTES files in the
+parent directory for directions on how to make this library.
diff --git a/contrib/ntp/libntp/a_md5encrypt.c b/contrib/ntp/libntp/a_md5encrypt.c
new file mode 100644
index 0000000..76f9c4f
--- /dev/null
+++ b/contrib/ntp/libntp/a_md5encrypt.c
@@ -0,0 +1,132 @@
+/*
+ * MD5 interface for rsaref2.0
+ *
+ * These routines implement an interface for the RSA Laboratories
+ * implementation of the Message Digest 5 (MD5) algorithm. This
+ * algorithm is included in the rsaref2.0 package available from RSA in
+ * the US and foreign countries. Further information is available at
+ * www.rsa.com.
+ */
+
+#include "ntp_machine.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef MD5
+#include <stdio.h>
+
+#include "ntp_types.h"
+#include "ntp_fp.h"
+#include "ntp_string.h"
+#include "global.h"
+#include "md5.h"
+#include "ntp_stdlib.h"
+
+#define BLOCK_OCTETS 16 /* message digest size */
+#define NTP_MAXKEY 65535 /* max identifier from ntp.h */
+
+
+/*
+ * MD5authencrypt - generate MD5 message authenticator
+ *
+ * Returns length of authenticator field.
+ */
+int
+MD5authencrypt(
+ u_char *key, /* key pointer */
+ u_int32 *pkt, /* packet pointer */
+ int length /* packet length */
+ )
+{
+ MD5_CTX ctx;
+ u_char digest[BLOCK_OCTETS];
+ int i;
+
+ /*
+ * MD5 with key identifier concatenated with packet.
+ */
+ MD5Init(&ctx);
+ MD5Update(&ctx, key, (u_int)cache_keylen);
+ MD5Update(&ctx, (u_char *)pkt, (u_int)length);
+ MD5Final(digest, &ctx);
+ i = length / 4;
+ memmove((char *)&pkt[i + 1], (char *)digest, BLOCK_OCTETS);
+ return (BLOCK_OCTETS + 4);
+}
+
+
+/*
+ * MD5authdecrypt - verify MD5 message authenticator
+ *
+ * Returns one if authenticator valid, zero if invalid.
+ */
+int
+MD5authdecrypt(
+ u_char *key, /* key pointer */
+ u_int32 *pkt, /* packet pointer */
+ int length, /* packet length */
+ int size /* MAC size */
+ )
+{
+ MD5_CTX ctx;
+ u_char digest[BLOCK_OCTETS];
+
+ /*
+ * MD5 with key identifier concatenated with packet.
+ */
+ if (size != BLOCK_OCTETS + 4)
+ return (0);
+ MD5Init(&ctx);
+ MD5Update(&ctx, key, (u_int)cache_keylen);
+ MD5Update(&ctx, (u_char *)pkt, (u_int)length);
+ MD5Final(digest, &ctx);
+ return (!memcmp((char *)digest, (char *)pkt + length + 4,
+ BLOCK_OCTETS));
+}
+
+
+/*
+ * session_key - generate session key from supplied plaintext.
+ *
+ * Returns hashed session key for validation.
+ */
+u_long
+session_key(
+ u_int32 srcadr, /* source address */
+ u_int32 dstadr, /* destination address */
+ u_long keyno, /* key identifier */
+ u_long lifetime /* key lifetime */
+ )
+{
+ MD5_CTX ctx;
+ u_int32 header[3];
+ u_long keyid;
+ u_char digest[BLOCK_OCTETS];
+
+ /*
+ * Generate the session key and retrieve the hash for later. If
+ * the lifetime is greater than zero, call the key trusted.
+ */
+ header[0] = htonl(srcadr);
+ header[1] = htonl(dstadr);
+ header[2] = htonl(keyno);
+ MD5Init(&ctx);
+ MD5Update(&ctx, (u_char *)header, sizeof(header));
+ MD5Final(digest, &ctx);
+ memcpy(&keyid, digest, 4);
+ if (lifetime != 0) {
+ MD5auth_setkey(keyno, digest, BLOCK_OCTETS);
+ authtrust(keyno, (int)lifetime);
+ }
+#ifdef DEBUG
+ if (debug > 1)
+ printf(
+ "session_key: from %s to %s keyid %08lx hash %08lx life %ld\n",
+ numtoa(htonl(srcadr)), numtoa(htonl(dstadr)), keyno,
+ keyid, lifetime);
+#endif
+ return (keyid);
+}
+#endif /* MD5 */
diff --git a/contrib/ntp/libntp/adjtime.c b/contrib/ntp/libntp/adjtime.c
new file mode 100644
index 0000000..72be860
--- /dev/null
+++ b/contrib/ntp/libntp/adjtime.c
@@ -0,0 +1,152 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef NEED_HPUX_ADJTIME
+/*************************************************************************/
+/* (c) Copyright Tai Jin, 1988. All Rights Reserved. */
+/* Hewlett-Packard Laboratories. */
+/* */
+/* Permission is hereby granted for unlimited modification, use, and */
+/* distribution. This software is made available with no warranty of */
+/* any kind, express or implied. This copyright notice must remain */
+/* intact in all versions of this software. */
+/* */
+/* The author would appreciate it if any bug fixes and enhancements were */
+/* to be sent back to him for incorporation into future versions of this */
+/* software. Please send changes to tai@iag.hp.com or ken@sdd.hp.com. */
+/*************************************************************************/
+
+/*
+ * Revision history
+ *
+ * 9 Jul 94 David L. Mills, Unibergity of Delabunch
+ * Implemented variable threshold to limit age of
+ * corrections; reformatted code for readability.
+ */
+
+#ifndef lint
+static char RCSid[] = "adjtime.c,v 3.1 1993/07/06 01:04:42 jbj Exp";
+#endif
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <time.h>
+#include <signal.h>
+#include "adjtime.h"
+
+#define abs(x) ((x) < 0 ? -(x) : (x))
+
+/*
+ * The following paramters are appropriate for an NTP adjustment
+ * interval of one second.
+ */
+#define ADJ_THRESH 200 /* initial threshold */
+#define ADJ_DELTA 4 /* threshold decrement */
+
+static long adjthresh; /* adjustment threshold */
+static long saveup; /* corrections accumulator */
+
+/*
+ * clear_adjtime - reset accumulator and threshold variables
+ */
+void
+_clear_adjtime(void)
+{
+ saveup = 0;
+ adjthresh = ADJ_THRESH;
+}
+
+/*
+ * adjtime - hp-ux copout of the standard Unix adjtime() system call
+ */
+int
+adjtime(
+ register struct timeval *delta,
+ register struct timeval *olddelta
+ )
+{
+ struct timeval newdelta;
+
+ /*
+ * Corrections greater than one second are done immediately.
+ */
+ if (delta->tv_sec) {
+ adjthresh = ADJ_THRESH;
+ saveup = 0;
+ return(_adjtime(delta, olddelta));
+ }
+
+ /*
+ * Corrections less than one second are accumulated until
+ * tripping a threshold, which is initially set at ADJ_THESH and
+ * reduced in ADJ_DELTA steps to zero. The idea here is to
+ * introduce large corrections quickly, while making sure that
+ * small corrections are introduced without excessive delay. The
+ * idea comes from the ARPAnet routing update algorithm.
+ */
+ saveup += delta->tv_usec;
+ if (abs(saveup) >= adjthresh) {
+ adjthresh = ADJ_THRESH;
+ newdelta.tv_sec = 0;
+ newdelta.tv_usec = saveup;
+ saveup = 0;
+ return(_adjtime(&newdelta, olddelta));
+ } else {
+ adjthresh -= ADJ_DELTA;
+ }
+
+ /*
+ * While nobody uses it, return the residual before correction,
+ * as per Unix convention.
+ */
+ if (olddelta)
+ olddelta->tv_sec = olddelta->tv_usec = 0;
+ return(0);
+}
+
+/*
+ * _adjtime - does the actual work
+ */
+int
+_adjtime(
+ register struct timeval *delta,
+ register struct timeval *olddelta
+ )
+{
+ register int mqid;
+ MsgBuf msg;
+ register MsgBuf *msgp = &msg;
+
+ /*
+ * Get the key to the adjtime message queue (note that we must
+ * get it every time because the queue might have been removed
+ * and recreated)
+ */
+ if ((mqid = msgget(KEY, 0)) == -1)
+ return (-1);
+ msgp->msgb.mtype = CLIENT;
+ msgp->msgb.tv = *delta;
+ if (olddelta)
+ msgp->msgb.code = DELTA2;
+ else
+ msgp->msgb.code = DELTA1;
+
+ /*
+ * Tickle adjtimed and snatch residual, if indicated. Lots of
+ * fanatic error checking here.
+ */
+ if (msgsnd(mqid, &msgp->msgp, MSGSIZE, 0) == -1)
+ return (-1);
+ if (olddelta) {
+ if (msgrcv(mqid, &msgp->msgp, MSGSIZE, SERVER, 0) == -1)
+ return (-1);
+ *olddelta = msgp->msgb.tv;
+ }
+ return (0);
+}
+
+#else /* not NEED_HPUX_ADJTIME */
+int adjtime_bs;
+#endif /* not NEED_HPUX_ADJTIME */
diff --git a/contrib/ntp/libntp/adjtimex.c b/contrib/ntp/libntp/adjtimex.c
new file mode 100644
index 0000000..03e9d79
--- /dev/null
+++ b/contrib/ntp/libntp/adjtimex.c
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+_sccsid:.asciz "11/19/91 ULTRIX @(#)adjtime.c 6.1"
+#endif not lint
+
+#include "SYS.h"
+
+SYSCALL(adjtimex)
+ ret
+
diff --git a/contrib/ntp/libntp/atoint.c b/contrib/ntp/libntp/atoint.c
new file mode 100644
index 0000000..46cd96d
--- /dev/null
+++ b/contrib/ntp/libntp/atoint.c
@@ -0,0 +1,50 @@
+/*
+ * atoint - convert an ascii string to a signed long, with error checking
+ */
+#include <sys/types.h>
+#include <ctype.h>
+
+#include "ntp_types.h"
+#include "ntp_stdlib.h"
+
+int
+atoint(
+ const char *str,
+ long *ival
+ )
+{
+ register long u;
+ register const char *cp;
+ register int isneg;
+ register int oflow_digit;
+
+ cp = str;
+
+ if (*cp == '-') {
+ cp++;
+ isneg = 1;
+ oflow_digit = '8';
+ } else {
+ isneg = 0;
+ oflow_digit = '7';
+ }
+
+ if (*cp == '\0')
+ return 0;
+
+ u = 0;
+ while (*cp != '\0') {
+ if (!isdigit((int)*cp))
+ return 0;
+ if (u > 214748364 || (u == 214748364 && *cp > oflow_digit))
+ return 0; /* overflow */
+ u = (u << 3) + (u << 1);
+ u += *cp++ - '0'; /* ascii dependent */
+ }
+
+ if (isneg)
+ *ival = -u;
+ else
+ *ival = u;
+ return 1;
+}
diff --git a/contrib/ntp/libntp/atolfp.c b/contrib/ntp/libntp/atolfp.c
new file mode 100644
index 0000000..ff50947
--- /dev/null
+++ b/contrib/ntp/libntp/atolfp.c
@@ -0,0 +1,118 @@
+/*
+ * atolfp - convert an ascii string to an l_fp number
+ */
+#include <stdio.h>
+#include <ctype.h>
+
+#include "ntp_fp.h"
+#include "ntp_string.h"
+
+/*
+ * Powers of 10
+ */
+static u_long ten_to_the_n[10] = {
+ 0,
+ 10,
+ 100,
+ 1000,
+ 10000,
+ 100000,
+ 1000000,
+ 10000000,
+ 100000000,
+ 1000000000,
+};
+
+
+int
+atolfp(
+ const char *str,
+ l_fp *lfp
+ )
+{
+ register const char *cp;
+ register u_long dec_i;
+ register u_long dec_f;
+ char *ind;
+ int ndec;
+ int isneg;
+ static const char *digits = "0123456789";
+
+ isneg = 0;
+ dec_i = dec_f = 0;
+ ndec = 0;
+ cp = str;
+
+ /*
+ * We understand numbers of the form:
+ *
+ * [spaces][-|+][digits][.][digits][spaces|\n|\0]
+ */
+ while (isspace((int)*cp))
+ cp++;
+
+ if (*cp == '-') {
+ cp++;
+ isneg = 1;
+ }
+
+ if (*cp == '+')
+ cp++;
+
+ if (*cp != '.' && !isdigit((int)*cp))
+ return 0;
+
+ while (*cp != '\0' && (ind = strchr(digits, *cp)) != NULL) {
+ dec_i = (dec_i << 3) + (dec_i << 1); /* multiply by 10 */
+ dec_i += (ind - digits);
+ cp++;
+ }
+
+ if (*cp != '\0' && !isspace((int)*cp)) {
+ if (*cp++ != '.')
+ return 0;
+
+ while (ndec < 9 && *cp != '\0'
+ && (ind = strchr(digits, *cp)) != NULL) {
+ ndec++;
+ dec_f = (dec_f << 3) + (dec_f << 1); /* *10 */
+ dec_f += (ind - digits);
+ cp++;
+ }
+
+ while (isdigit((int)*cp))
+ cp++;
+
+ if (*cp != '\0' && !isspace((int)*cp))
+ return 0;
+ }
+
+ if (ndec > 0) {
+ register u_long tmp;
+ register u_long bit;
+ register u_long ten_fact;
+
+ ten_fact = ten_to_the_n[ndec];
+
+ tmp = 0;
+ bit = 0x80000000;
+ while (bit != 0) {
+ dec_f <<= 1;
+ if (dec_f >= ten_fact) {
+ tmp |= bit;
+ dec_f -= ten_fact;
+ }
+ bit >>= 1;
+ }
+ if ((dec_f << 1) > ten_fact)
+ tmp++;
+ dec_f = tmp;
+ }
+
+ if (isneg)
+ M_NEG(dec_i, dec_f);
+
+ lfp->l_ui = dec_i;
+ lfp->l_uf = dec_f;
+ return 1;
+}
diff --git a/contrib/ntp/libntp/atouint.c b/contrib/ntp/libntp/atouint.c
new file mode 100644
index 0000000..c25e3a0
--- /dev/null
+++ b/contrib/ntp/libntp/atouint.c
@@ -0,0 +1,35 @@
+/*
+ * atouint - convert an ascii string to an unsigned long, with error checking
+ */
+#include <sys/types.h>
+#include <ctype.h>
+
+#include "ntp_types.h"
+#include "ntp_stdlib.h"
+
+int
+atouint(
+ const char *str,
+ u_long *uval
+ )
+{
+ register u_long u;
+ register const char *cp;
+
+ cp = str;
+ if (*cp == '\0')
+ return 0;
+
+ u = 0;
+ while (*cp != '\0') {
+ if (!isdigit((int)*cp))
+ return 0;
+ if (u > 429496729 || (u == 429496729 && *cp >= '6'))
+ return 0; /* overflow */
+ u = (u << 3) + (u << 1);
+ u += *cp++ - '0'; /* ascii dependent */
+ }
+
+ *uval = u;
+ return 1;
+}
diff --git a/contrib/ntp/libntp/authencrypt.c b/contrib/ntp/libntp/authencrypt.c
new file mode 100644
index 0000000..22f910c
--- /dev/null
+++ b/contrib/ntp/libntp/authencrypt.c
@@ -0,0 +1,97 @@
+/*
+ * DES interface for rsaref2.0
+ *
+ * These routines implement an interface for the RSA Laboratories
+ * implementation of the Data Encryption Standard (DES) algorithm
+ * operating in Cipher-Block Chaining (CBC) mode. This algorithm is
+ * included in the rsaref2.0 package available from RSA in the US and
+ * foreign countries. Further information is available at www.rsa.com.
+ */
+
+#include "ntp_machine.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef DES
+#include "ntp_types.h"
+#include "ntp_fp.h"
+#include "ntp_string.h"
+#include "global.h"
+#include "des.h"
+#include "ntp_stdlib.h"
+
+#define BLOCK_OCTETS 8 /* message digest size */
+#define MAXTPKT 128 /* max packet size */
+
+
+/*
+ * DESauthencrypt - generate DES-CBC message authenticator
+ *
+ * Returns length of authenticator field.
+ */
+int
+DESauthencrypt(
+ u_char *key, /* key pointer */
+ u_int32 *pkt, /* packet pointer */
+ int length /* packet length */
+ )
+{
+ DES_CBC_CTX ctx;
+ u_int32 tpkt[MAXTPKT];
+ u_int32 work[2];
+ int i, j;
+
+ /*
+ * DES-CBC with zero IV. Note the encrypted text is discarded.
+ */
+ work[0] = work[1] = 0;
+ DES_CBCInit(&ctx, key, (u_char *)work, 1);
+ DES_CBCUpdate(&ctx, (u_char *)tpkt, (u_char *)pkt,
+ (u_int)length);
+ i = length / 4 + 1;
+ j = i - 3;
+ pkt[i++] = (u_int32)htonl(tpkt[j++]);
+ pkt[i] = (u_int32)htonl(tpkt[j]);
+ return (BLOCK_OCTETS + 4);
+}
+
+
+/*
+ * DESauthdecrypt - verify DES message authenticator
+ *
+ * Returns one if authenticator valid, zero if invalid.
+ */
+int
+DESauthdecrypt(
+ u_char *key, /* key pointer */
+ u_int32 *pkt, /* packet pointer */
+ int length, /* packet length */
+ int size /* size of MAC field */
+ )
+{
+ DES_CBC_CTX ctx;
+ u_int32 tpkt[MAXTPKT];
+ u_int32 work[2];
+ int i, j;
+
+ /*
+ * DES-CBC with zero IV. Note the encrypted text is discarded.
+ */
+ if (size != BLOCK_OCTETS + 4)
+ return (0);
+ work[0] = work[1] = 0;
+ DES_CBCInit (&ctx, key, (u_char *)work, 1);
+ DES_CBCUpdate (&ctx, (u_char *)tpkt, (u_char *)pkt,
+ (u_int)length);
+ i = length / 4 + 1;
+ j = i - 3;
+ if ((u_int32)ntohl(pkt[i++]) == tpkt[j++] &&
+ (u_int32)ntohl(pkt[i]) == tpkt[j])
+ return (1);
+ return (0);
+}
+#else
+int authencrypt_bs;
+#endif /* DES */
diff --git a/contrib/ntp/libntp/authkeys.c b/contrib/ntp/libntp/authkeys.c
new file mode 100644
index 0000000..39ca493
--- /dev/null
+++ b/contrib/ntp/libntp/authkeys.c
@@ -0,0 +1,574 @@
+/*
+ * authkeys.c - routines to manage the storage of authentication keys
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+
+#include "ntp_types.h"
+#include "ntp_fp.h"
+#include "ntp.h"
+#include "ntpd.h"
+#include "ntp_string.h"
+#include "ntp_malloc.h"
+#include "ntp_stdlib.h"
+
+/*
+ * Structure to store keys in in the hash table.
+ */
+struct savekey {
+ struct savekey *next;
+ union {
+ long bogon; /* Make sure nonempty */
+#ifdef DES
+ u_int32 DES_key[2]; /* DES key */
+#endif
+#ifdef MD5
+ u_char MD5_key[32]; /* MD5 key */
+#endif
+ } k;
+ u_long keyid; /* key identifier */
+ u_short flags; /* flags that wave */
+ u_long lifetime; /* remaining lifetime */
+#ifdef MD5
+ int keylen; /* key length */
+#endif
+};
+
+#define KEY_TRUSTED 0x001 /* this key is trusted */
+#define KEY_DES 0x100 /* this is a DES type key */
+#define KEY_MD5 0x200 /* this is a MD5 type key */
+
+/*
+ * The hash table. This is indexed by the low order bits of the
+ * keyid. We make this fairly big for potentially busy servers.
+ */
+#define HASHSIZE 64
+#define HASHMASK ((HASHSIZE)-1)
+#define KEYHASH(keyid) ((keyid) & HASHMASK)
+
+struct savekey *key_hash[HASHSIZE];
+
+u_long authkeynotfound; /* keys not found */
+u_long authkeylookups; /* calls to lookup keys */
+u_long authnumkeys; /* number of active keys */
+u_long authkeyexpired; /* key lifetime expirations */
+u_long authkeyuncached; /* cache misses */
+u_long authnokey; /* calls to encrypt with no key */
+u_long authencryptions; /* calls to encrypt */
+u_long authdecryptions; /* calls to decrypt */
+
+/*
+ * Storage for free key structures. We malloc() such things but
+ * never free them.
+ */
+struct savekey *authfreekeys;
+int authnumfreekeys;
+
+#define MEMINC 12 /* number of new free ones to get */
+
+/*
+ * The key cache. We cache the last key we looked at here.
+ */
+u_long cache_keyid; /* key identifier */
+u_char *cache_key; /* key pointer */
+u_int cache_keylen; /* key length */
+u_short cache_flags; /* flags that wave */
+
+
+/*
+ * init_auth - initialize internal data
+ */
+void
+init_auth(void)
+{
+ /*
+ * Initialize hash table and free list
+ */
+ memset((char *)key_hash, 0, sizeof key_hash);
+}
+
+
+/*
+ * auth_findkey - find a key in the hash table
+ */
+struct savekey *
+auth_findkey(
+ u_long keyno
+ )
+{
+ struct savekey *sk;
+
+ sk = key_hash[KEYHASH(keyno)];
+ while (sk != 0) {
+ if (keyno == sk->keyid)
+ return (sk);
+
+ sk = sk->next;
+ }
+ return (0);
+}
+
+
+/*
+ * auth_havekey - return one if the key is known
+ */
+int
+auth_havekey(
+ u_long keyno
+ )
+{
+ struct savekey *sk;
+
+ if (keyno == 0 || (keyno == cache_keyid))
+ return (1);
+
+ sk = key_hash[KEYHASH(keyno)];
+ while (sk != 0) {
+ if (keyno == sk->keyid)
+ return (1);
+
+ sk = sk->next;
+ }
+ return (0);
+}
+
+
+/*
+ * authhavekey - return one and cache the key, if known and trusted.
+ */
+int
+authhavekey(
+ u_long keyno
+ )
+{
+ struct savekey *sk;
+
+ authkeylookups++;
+ if (keyno == 0 || keyno == cache_keyid)
+ return (1);
+
+ authkeyuncached++;
+ sk = key_hash[KEYHASH(keyno)];
+ while (sk != 0) {
+ if (keyno == sk->keyid)
+ break;
+ sk = sk->next;
+ }
+ if (sk == 0) {
+ authkeynotfound++;
+ return (0);
+ } else if (!(sk->flags & KEY_TRUSTED)) {
+ authnokey++;
+ return (0);
+ }
+ cache_keyid = sk->keyid;
+ cache_flags = sk->flags;
+#ifdef MD5
+ if (sk->flags & KEY_MD5) {
+ cache_key = sk->k.MD5_key;
+ cache_keylen = sk->keylen;
+ return (1);
+ }
+#endif
+#ifdef DES
+ if (sk->flags & KEY_DES) {
+ cache_key = (u_char *)sk->k.DES_key;
+ return (1);
+ }
+#endif
+ return (0);
+}
+
+
+/*
+ * auth_moremem - get some more free key structures
+ */
+int
+auth_moremem(void)
+{
+ struct savekey *sk;
+ int i;
+
+ sk = (struct savekey *)malloc(MEMINC * sizeof(struct savekey));
+ if (sk == 0)
+ return (0);
+
+ for (i = MEMINC; i > 0; i--) {
+ sk->next = authfreekeys;
+ authfreekeys = sk++;
+ }
+ authnumfreekeys += MEMINC;
+ return (authnumfreekeys);
+}
+
+
+/*
+ * authtrust - declare a key to be trusted/untrusted
+ */
+void
+authtrust(
+ u_long keyno,
+ int trust
+ )
+{
+ struct savekey *sk;
+
+#ifdef DEBUG
+ if (debug > 1)
+ printf("authtrust: keyid %08lx life %d\n", (u_long)keyno, trust);
+#endif
+ sk = key_hash[KEYHASH(keyno)];
+ while (sk != 0) {
+ if (keyno == sk->keyid)
+ break;
+ sk = sk->next;
+ }
+
+ if (sk == 0 && !trust)
+ return;
+
+ if (sk != 0) {
+ if (cache_keyid == keyno) {
+ cache_flags = 0;
+ cache_keyid = 0;
+ }
+
+ if (trust > 0) {
+ sk->flags |= KEY_TRUSTED;
+ if (trust > 1)
+ sk->lifetime = current_time + trust;
+ else
+ sk->lifetime = 0;
+ return;
+ }
+
+ sk->flags &= ~KEY_TRUSTED; {
+ struct savekey *skp;
+
+ skp = key_hash[KEYHASH(keyno)];
+ if (skp == sk) {
+ key_hash[KEYHASH(keyno)] = sk->next;
+ } else {
+ while (skp->next != sk)
+ skp = skp->next;
+ skp->next = sk->next;
+ }
+ authnumkeys--;
+
+ sk->next = authfreekeys;
+ authfreekeys = sk;
+ authnumfreekeys++;
+ }
+ return;
+ }
+
+ if (authnumfreekeys == 0)
+ if (auth_moremem() == 0)
+ return;
+
+ sk = authfreekeys;
+ authfreekeys = sk->next;
+ authnumfreekeys--;
+
+ sk->keyid = keyno;
+ sk->flags = KEY_TRUSTED;
+ sk->next = key_hash[KEYHASH(keyno)];
+ key_hash[KEYHASH(keyno)] = sk;
+ authnumkeys++;
+ return;
+}
+
+
+/*
+ * authistrusted - determine whether a key is trusted
+ */
+int
+authistrusted(
+ u_long keyno
+ )
+{
+ struct savekey *sk;
+
+ if (keyno == cache_keyid)
+ return ((cache_flags & KEY_TRUSTED) != 0);
+
+ authkeyuncached++;
+ sk = key_hash[KEYHASH(keyno)];
+ while (sk != 0) {
+ if (keyno == sk->keyid)
+ break;
+ sk = sk->next;
+ }
+ if (sk == 0) {
+ authkeynotfound++;
+ return (0);
+ } else if (!(sk->flags & KEY_TRUSTED)) {
+ authkeynotfound++;
+ return (0);
+ }
+ return (1);
+}
+
+
+
+#ifdef DES
+/*
+ * DESauth_setkey - set a key into the key array
+ */
+void
+DESauth_setkey(
+ u_long keyno,
+ const u_int32 *key
+ )
+{
+ struct savekey *sk;
+
+ /*
+ * See if we already have the key. If so just stick in the
+ * new value.
+ */
+ sk = key_hash[KEYHASH(keyno)];
+ while (sk != 0) {
+ if (keyno == sk->keyid) {
+ sk->k.DES_key[0] = key[0];
+ sk->k.DES_key[1] = key[1];
+ sk->flags |= KEY_DES;
+ if (cache_keyid == keyno)
+ cache_flags = 0;
+ cache_keyid = 0;
+ return;
+ }
+ sk = sk->next;
+ }
+
+ /*
+ * Need to allocate new structure. Do it.
+ */
+ if (authnumfreekeys == 0) {
+ if (auth_moremem() == 0)
+ return;
+ }
+ sk = authfreekeys;
+ authfreekeys = sk->next;
+ authnumfreekeys--;
+
+ sk->k.DES_key[0] = key[0];
+ sk->k.DES_key[1] = key[1];
+ sk->keyid = keyno;
+ sk->flags = KEY_DES;
+ sk->lifetime = 0;
+ sk->next = key_hash[KEYHASH(keyno)];
+ key_hash[KEYHASH(keyno)] = sk;
+ authnumkeys++;
+ return;
+}
+#endif
+
+#ifdef MD5
+void
+MD5auth_setkey(
+ u_long keyno,
+ const u_char *key,
+ const int len
+ )
+{
+ struct savekey *sk;
+
+ /*
+ * See if we already have the key. If so just stick in the
+ * new value.
+ */
+ sk = key_hash[KEYHASH(keyno)];
+ while (sk != 0) {
+ if (keyno == sk->keyid) {
+ strncpy((char *)sk->k.MD5_key, (const char *)key,
+ sizeof(sk->k.MD5_key));
+ if ((sk->keylen = len) > sizeof(sk->k.MD5_key))
+ sk->keylen = sizeof(sk->k.MD5_key);
+
+ sk->flags |= KEY_MD5;
+ if (cache_keyid == keyno) {
+ cache_flags = 0;
+ cache_keyid = 0;
+ }
+ return;
+ }
+ sk = sk->next;
+ }
+
+ /*
+ * Need to allocate new structure. Do it.
+ */
+ if (authnumfreekeys == 0) {
+ if (auth_moremem() == 0)
+ return;
+ }
+
+ sk = authfreekeys;
+ authfreekeys = sk->next;
+ authnumfreekeys--;
+
+ strncpy((char *)sk->k.MD5_key, (const char *)key,
+ sizeof(sk->k.MD5_key));
+ if ((sk->keylen = len) > sizeof(sk->k.MD5_key))
+ sk->keylen = sizeof(sk->k.MD5_key);
+
+ sk->keyid = keyno;
+ sk->flags = KEY_MD5;
+ sk->lifetime = 0;
+ sk->next = key_hash[KEYHASH(keyno)];
+ key_hash[KEYHASH(keyno)] = sk;
+ authnumkeys++;
+ return;
+}
+#endif
+
+/*
+ * auth_delkeys - delete all known keys, in preparation for rereading
+ * the keys file (presumably)
+ */
+void
+auth_delkeys(void)
+{
+ struct savekey *sk;
+ struct savekey **skp;
+ int i;
+
+ for (i = 0; i < HASHSIZE; i++) {
+ skp = &(key_hash[i]);
+ sk = key_hash[i];
+ /*
+ * Leave autokey keys alone.
+ */
+ while (sk != 0 && sk->keyid <= NTP_MAXKEY) {
+ /*
+ * Don't loose info which keys are trusted.
+ */
+ if (sk->flags & KEY_TRUSTED) {
+ memset(&sk->k, 0, sizeof(sk->k));
+ sk->lifetime = 0;
+#ifdef MD5
+ sk->keylen = 0;
+#endif
+ sk = sk->next;
+ } else {
+ *skp = sk->next;
+ authnumkeys--;
+ sk->next = authfreekeys;
+ authfreekeys = sk;
+ authnumfreekeys++;
+ sk = *skp;
+ }
+ }
+ }
+}
+
+/*
+ * auth_agekeys - delete keys whose lifetimes have expired
+ */
+void
+auth_agekeys(void)
+{
+ struct savekey *sk;
+ struct savekey *skp;
+ int i;
+
+ for (i = 0; i < HASHSIZE; i++) {
+ sk = skp = key_hash[i];
+ while (sk != 0) {
+ skp = sk->next;
+ if (sk->lifetime > 0 && current_time >
+ sk->lifetime) {
+ authtrust(sk->keyid, 0);
+ authkeyexpired++;
+ }
+ sk = skp;
+ }
+ }
+#ifdef DEBUG
+ if (debug)
+ printf("auth_agekeys: at %lu keys %lu expired %lu\n",
+ current_time, authnumkeys, authkeyexpired);
+#endif
+}
+
+/*
+ * authencrypt - generate message authenticator
+ *
+ * Returns length of authenticator field, zero if key not found.
+ */
+int
+authencrypt(
+ u_long keyno,
+ u_int32 *pkt,
+ int length
+ )
+{
+
+ /*
+ * A zero key identifier means the sender has not verified
+ * the last message was correctly authenticated. The MAC
+ * consists of a single word with value zero.
+ */
+ authencryptions++;
+ pkt[length / 4] = (u_long)htonl(keyno);
+ if (keyno == 0) {
+ return (4);
+ }
+ if (!authhavekey(keyno))
+ return (0);
+
+#ifdef DES
+ if (cache_flags & KEY_DES)
+ return (DESauthencrypt(cache_key, pkt, length));
+#endif
+
+#ifdef MD5
+ if (cache_flags & KEY_MD5)
+ return (MD5authencrypt(cache_key, pkt, length));
+#endif
+ return (0);
+}
+
+/*
+ * authdecrypt - verify message authenticator
+ *
+ * Returns one if authenticator valid, zero if invalid or key not found.
+ */
+int
+authdecrypt(
+ u_long keyno,
+ u_int32 *pkt,
+ int length,
+ int size
+ )
+{
+
+ /*
+ * A zero key identifier means the sender has not verified
+ * the last message was correctly authenticated. Nevertheless,
+ * the authenticator itself is considered valid.
+ */
+ authdecryptions++;
+ if (keyno == 0)
+ return (1);
+
+ if (!authhavekey(keyno) || size < 4)
+ return (0);
+
+#ifdef DES
+ if (cache_flags & KEY_DES)
+ return (DESauthdecrypt(cache_key, pkt, length, size));
+#endif
+
+#ifdef MD5
+ if (cache_flags & KEY_MD5)
+ return (MD5authdecrypt(cache_key, pkt, length, size));
+#endif
+
+ return (0);
+}
diff --git a/contrib/ntp/libntp/authparity.c b/contrib/ntp/libntp/authparity.c
new file mode 100644
index 0000000..32fde58
--- /dev/null
+++ b/contrib/ntp/libntp/authparity.c
@@ -0,0 +1,57 @@
+/*
+ * auth_parity - set parity on a key/check for odd parity
+ */
+#include "ntp_stdlib.h"
+
+int
+DESauth_parity(
+ u_int32 *key
+ )
+{
+ u_int32 mask;
+ int parity_err;
+ int bitcount;
+ int half;
+ int byte;
+ int i;
+
+ /*
+ * Go through counting bits in each byte. Check to see if
+ * each parity bit was set correctly. If not, note the error
+ * and set it right.
+ */
+ parity_err = 0;
+ for (half = 0; half < 2; half++) { /* two halves of key */
+ mask = 0x80000000;
+ for (byte = 0; byte < 4; byte++) { /* 4 bytes per half */
+ bitcount = 0;
+ for (i = 0; i < 7; i++) { /* 7 data bits / byte */
+ if (key[half] & mask)
+ bitcount++;
+ mask >>= 1;
+ }
+
+ /*
+ * If bitcount is even, parity must be set. If
+ * bitcount is odd, parity must be clear.
+ */
+ if ((bitcount & 0x1) == 0) {
+ if (!(key[half] & mask)) {
+ parity_err++;
+ key[half] |= mask;
+ }
+ } else {
+ if (key[half] & mask) {
+ parity_err++;
+ key[half] &= ~mask;
+ }
+ }
+ mask >>= 1;
+ }
+ }
+
+ /*
+ * Return the result of the parity check.
+ */
+ return (parity_err == 0);
+}
diff --git a/contrib/ntp/libntp/authreadkeys.c b/contrib/ntp/libntp/authreadkeys.c
new file mode 100644
index 0000000..18ac0dd
--- /dev/null
+++ b/contrib/ntp/libntp/authreadkeys.c
@@ -0,0 +1,205 @@
+/*
+ * authreadkeys.c - routines to support the reading of the key file
+ */
+#include <stdio.h>
+#include <ctype.h>
+
+#include "ntp_fp.h"
+#include "ntp.h"
+#include "ntp_stdlib.h"
+#include "ntp_syslog.h"
+
+#ifdef DES
+/*
+ * Types of ascii representations for keys. "Standard" means a 64 bit
+ * hex number in NBS format, i.e. with the low order bit of each byte
+ * a parity bit. "NTP" means a 64 bit key in NTP format, with the
+ * high order bit of each byte a parity bit. "Ascii" means a 1-to-8
+ * character string whose ascii representation is used as the key.
+ */
+#define KEY_TYPE_STD 1
+#define KEY_TYPE_NTP 2
+#define KEY_TYPE_ASCII 3
+#endif
+
+#ifdef MD5
+/*
+ * Arbitrary long string of ASCII characters.
+ */
+#define KEY_TYPE_MD5 4
+#endif
+
+/* Forwards */
+static char *nexttok P((char **));
+
+/*
+ * nexttok - basic internal tokenizing routine
+ */
+static char *
+nexttok(
+ char **str
+ )
+{
+ register char *cp;
+ char *starttok;
+
+ cp = *str;
+
+ /*
+ * Space past white space
+ */
+ while (*cp == ' ' || *cp == '\t')
+ cp++;
+
+ /*
+ * Save this and space to end of token
+ */
+ starttok = cp;
+ while (*cp != '\0' && *cp != '\n' && *cp != ' '
+ && *cp != '\t' && *cp != '#')
+ cp++;
+
+ /*
+ * If token length is zero return an error, else set end of
+ * token to zero and return start.
+ */
+ if (starttok == cp)
+ return 0;
+
+ if (*cp == ' ' || *cp == '\t')
+ *cp++ = '\0';
+ else
+ *cp = '\0';
+
+ *str = cp;
+ return starttok;
+}
+
+
+/*
+ * authreadkeys - (re)read keys from a file.
+ */
+int
+authreadkeys(
+ const char *file
+ )
+{
+ FILE *fp;
+ char *line;
+ char *token;
+ u_long keyno;
+ int keytype;
+ char buf[512]; /* lots of room for line */
+
+ /*
+ * Open file. Complain and return if it can't be opened.
+ */
+ fp = fopen(file, "r");
+ if (fp == NULL) {
+ msyslog(LOG_ERR, "can't open key file %s: %m", file);
+ return 0;
+ }
+
+ /*
+ * Remove all existing keys
+ */
+ auth_delkeys();
+
+ /*
+ * Now read lines from the file, looking for key entries
+ */
+ while ((line = fgets(buf, sizeof buf, fp)) != NULL) {
+ token = nexttok(&line);
+ if (token == 0)
+ continue;
+
+ /*
+ * First is key number. See if it is okay.
+ */
+ keyno = atoi(token);
+ if (keyno == 0) {
+ msyslog(LOG_ERR,
+ "cannot change keyid 0, key entry `%s' ignored",
+ token);
+ continue;
+ }
+
+ if (keyno > NTP_MAXKEY) {
+ msyslog(LOG_ERR,
+ "keyid's > %d reserved for autokey, key entry `%s' ignored",
+ NTP_MAXKEY, token);
+ continue;
+ }
+
+ /*
+ * Next is keytype. See if that is all right.
+ */
+ token = nexttok(&line);
+ if (token == 0) {
+ msyslog(LOG_ERR,
+ "no key type for key number %ld, entry ignored",
+ keyno);
+ continue;
+ }
+ switch (*token) {
+#ifdef DES
+ case 'S':
+ case 's':
+ keytype = KEY_TYPE_STD; break;
+
+ case 'N':
+ case 'n':
+ keytype = KEY_TYPE_NTP; break;
+
+ case 'A':
+ case 'a':
+ keytype = KEY_TYPE_ASCII; break;
+#endif
+#ifdef MD5
+ case 'M':
+ case 'm':
+ keytype = KEY_TYPE_MD5; break;
+#endif
+ default:
+ msyslog(LOG_ERR,
+ "invalid key type for key number %ld, entry ignored",
+ keyno);
+ continue;
+ }
+
+ /*
+ * Finally, get key and insert it
+ */
+ token = nexttok(&line);
+ if (token == 0) {
+ msyslog(LOG_ERR,
+ "no key for number %ld entry, entry ignored",
+ keyno);
+ } else {
+ switch(keytype) {
+#ifdef DES
+ case KEY_TYPE_STD:
+ case KEY_TYPE_NTP:
+ case KEY_TYPE_ASCII:
+ if (!authusekey(keyno, keytype,
+ (u_char *)token))
+ msyslog(LOG_ERR,
+ "format/parity error for DES key %ld, not used",
+ keyno);
+ break;
+#endif
+#ifdef MD5
+ case KEY_TYPE_MD5:
+ if (!authusekey(keyno, keytype,
+ (u_char *)token))
+ msyslog(LOG_ERR,
+ "format/parity error for MD5 key %ld, not used",
+ keyno);
+ break;
+#endif
+ }
+ }
+ }
+ (void) fclose(fp);
+ return 1;
+}
diff --git a/contrib/ntp/libntp/authusekey.c b/contrib/ntp/libntp/authusekey.c
new file mode 100644
index 0000000..a399a48
--- /dev/null
+++ b/contrib/ntp/libntp/authusekey.c
@@ -0,0 +1,134 @@
+/*
+ * authusekey - decode a key from ascii and use it
+ */
+#include <stdio.h>
+#include <ctype.h>
+
+#include "ntp_types.h"
+#include "ntp_string.h"
+#include "ntp_stdlib.h"
+
+/*
+ * Types of ascii representations for keys. "Standard" means a 64 bit
+ * hex number in NBS format, i.e. with the low order bit of each byte
+ * a parity bit. "NTP" means a 64 bit key in NTP format, with the
+ * high order bit of each byte a parity bit. "Ascii" means a 1-to-8
+ * character string whose ascii representation is used as the key.
+ */
+#ifdef DES
+#define KEY_TYPE_STD 1
+#define KEY_TYPE_NTP 2
+#define KEY_TYPE_ASCII 3
+
+#define STD_PARITY_BITS ((unsigned)0x01010101)
+
+#endif
+
+#ifdef MD5
+#define KEY_TYPE_MD5 4
+#endif
+
+int
+authusekey(
+ u_long keyno,
+ int keytype,
+ const u_char *str
+ )
+{
+#ifdef DES
+ u_int32 key[2];
+ u_char keybytes[8];
+ char *xdigit;
+ int i;
+ static const char *hex = "0123456789abcdef";
+#endif
+ const u_char *cp;
+ int len;
+
+ cp = str;
+ len = strlen((const char *)cp);
+ if (len == 0)
+ return 0;
+
+ switch(keytype) {
+#ifdef DES
+ case KEY_TYPE_STD:
+ case KEY_TYPE_NTP:
+ if (len != 16) /* Lazy. Should define constant */
+ return 0;
+ /*
+ * Decode hex key.
+ */
+ key[0] = 0;
+ key[1] = 0;
+ for (i = 0; i < 16; i++) {
+ if (!isascii(*cp))
+ return 0;
+ xdigit = strchr(hex, isupper(*cp) ? tolower(*cp) : *cp);
+ cp++;
+ if (xdigit == 0)
+ return 0;
+ key[i>>3] <<= 4;
+ key[i>>3] |= (u_int32)(xdigit - hex) & 0xf;
+ }
+
+ /*
+ * If this is an NTP format key, put it into NBS format
+ */
+ if (keytype == KEY_TYPE_NTP) {
+ for (i = 0; i < 2; i++)
+ key[i] = ((key[i] << 1) & ~STD_PARITY_BITS)
+ | ((key[i] >> 7) & STD_PARITY_BITS);
+ }
+
+ /*
+ * Check the parity, reject the key if the check fails
+ */
+ if (!DESauth_parity(key)) {
+ return 0;
+ }
+
+ /*
+ * We can't find a good reason not to use this key.
+ * So use it.
+ */
+ DESauth_setkey(keyno, key);
+ break;
+
+ case KEY_TYPE_ASCII:
+ /*
+ * Make up key from ascii representation
+ */
+ memset((char *) keybytes, 0, sizeof(keybytes));
+ for (i = 0; i < 8 && i < len; i++)
+ keybytes[i] = *cp++ << 1;
+ key[0] = (u_int32)keybytes[0] << 24 | (u_int32)keybytes[1] << 16
+ | (u_int32)keybytes[2] << 8 | (u_int32)keybytes[3];
+ key[1] = (u_int32)keybytes[4] << 24 | (u_int32)keybytes[5] << 16
+ | (u_int32)keybytes[6] << 8 | (u_int32)keybytes[7];
+
+ /*
+ * Set parity on key
+ */
+ (void)DESauth_parity(key);
+
+ /*
+ * Now set key in.
+ */
+ DESauth_setkey(keyno, key);
+ break;
+#endif
+
+#ifdef MD5
+ case KEY_TYPE_MD5:
+ MD5auth_setkey(keyno, str, (int)strlen((const char *)str));
+ break;
+#endif
+
+ default:
+ /* Oh, well */
+ return 0;
+ }
+
+ return 1;
+}
diff --git a/contrib/ntp/libntp/binio.c b/contrib/ntp/libntp/binio.c
new file mode 100644
index 0000000..cc3b408
--- /dev/null
+++ b/contrib/ntp/libntp/binio.c
@@ -0,0 +1,128 @@
+/*
+ * /src/NTP/ntp-4/libntp/binio.c,v 4.2 1999/02/21 12:17:34 kardel RELEASE_19990228_A
+ *
+ * $Created: Sun Jul 20 12:55:33 1997 $
+ *
+ * Copyright (C) 1997, 1998 by Frank Kardel
+ */
+
+#include "binio.h"
+
+long
+get_lsb_short(
+ unsigned char **bufpp
+ )
+{
+ long retval;
+
+ retval = *((*bufpp)++);
+ retval |= *((*bufpp)++) << 8;
+
+ return (retval & 0x8000) ? (~0xFFFF | retval) : retval;
+}
+
+void
+put_lsb_short(
+ unsigned char **bufpp,
+ long val
+ )
+{
+ *((*bufpp)++) = val & 0xFF;
+ *((*bufpp)++) = (val >> 8) & 0xFF;
+}
+
+long
+get_lsb_long(
+ unsigned char **bufpp
+ )
+{
+ long retval;
+
+ retval = *((*bufpp)++);
+ retval |= *((*bufpp)++) << 8;
+ retval |= *((*bufpp)++) << 16;
+ retval |= *((*bufpp)++) << 24;
+
+ return retval;
+}
+
+void
+put_lsb_long(
+ unsigned char **bufpp,
+ long val
+ )
+{
+ *((*bufpp)++) = val & 0xFF;
+ *((*bufpp)++) = (val >> 8) & 0xFF;
+ *((*bufpp)++) = (val >> 16) & 0xFF;
+ *((*bufpp)++) = (val >> 24) & 0xFF;
+}
+
+long
+get_msb_short(
+ unsigned char **bufpp
+ )
+{
+ long retval;
+
+ retval = *((*bufpp)++) << 8;
+ retval |= *((*bufpp)++);
+
+ return (retval & 0x8000) ? (~0xFFFF | retval) : retval;
+}
+
+void
+put_msb_short(
+ unsigned char **bufpp,
+ long val
+ )
+{
+ *((*bufpp)++) = (val >> 8) & 0xFF;
+ *((*bufpp)++) = val & 0xFF;
+}
+
+long
+get_msb_long(
+ unsigned char **bufpp
+ )
+{
+ long retval;
+
+ retval = *((*bufpp)++) << 24;
+ retval |= *((*bufpp)++) << 16;
+ retval |= *((*bufpp)++) << 8;
+ retval |= *((*bufpp)++);
+
+ return retval;
+}
+
+void
+put_msb_long(
+ unsigned char **bufpp,
+ long val
+ )
+{
+ *((*bufpp)++) = (val >> 24) & 0xFF;
+ *((*bufpp)++) = (val >> 16) & 0xFF;
+ *((*bufpp)++) = (val >> 8 ) & 0xFF;
+ *((*bufpp)++) = val & 0xFF;
+}
+
+/*
+ * binio.c,v
+ * Revision 4.2 1999/02/21 12:17:34 kardel
+ * 4.91f reconcilation
+ *
+ * Revision 4.1 1998/06/28 16:47:50 kardel
+ * added {get,put}_msb_{short,long} functions
+ *
+ * Revision 4.0 1998/04/10 19:46:16 kardel
+ * Start 4.0 release version numbering
+ *
+ * Revision 1.1 1998/04/10 19:27:46 kardel
+ * initial NTP VERSION 4 integration of PARSE with GPS166 binary support
+ *
+ * Revision 1.1 1997/10/06 21:05:46 kardel
+ * new parse structure
+ *
+ */
diff --git a/contrib/ntp/libntp/buftvtots.c b/contrib/ntp/libntp/buftvtots.c
new file mode 100644
index 0000000..96338bc
--- /dev/null
+++ b/contrib/ntp/libntp/buftvtots.c
@@ -0,0 +1,65 @@
+/*
+ * buftvtots - pull a Unix-format (struct timeval) time stamp out of
+ * an octet stream and convert it to a l_fp time stamp.
+ * This is useful when using the clock line discipline.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "ntp_fp.h"
+#include "ntp_unixtime.h"
+
+int
+buftvtots(
+ const char *bufp,
+ l_fp *ts
+ )
+{
+ register const u_char *bp;
+ register u_long sec;
+ register u_long usec;
+
+#ifdef WORDS_BIGENDIAN
+ bp = (const u_char *)bufp;
+
+ sec = (u_long)*bp++ & 0xff;
+ sec <<= 8;
+ sec += (u_long)*bp++ & 0xff;
+ sec <<= 8;
+ sec += (u_long)*bp++ & 0xff;
+ sec <<= 8;
+ sec += (u_long)*bp++ & 0xff;
+
+ usec = (u_long)*bp++ & 0xff;
+ usec <<= 8;
+ usec += (u_long)*bp++ & 0xff;
+ usec <<= 8;
+ usec += (u_long)*bp++ & 0xff;
+ usec <<= 8;
+ usec += (u_long)*bp & 0xff;
+#else
+ bp = (const u_char *)bufp + 7;
+
+ usec = (u_long)*bp-- & 0xff;
+ usec <<= 8;
+ usec += (u_long)*bp-- & 0xff;
+ usec <<= 8;
+ usec += (u_long)*bp-- & 0xff;
+ usec <<= 8;
+ usec += (u_long)*bp-- & 0xff;
+
+ sec = (u_long)*bp-- & 0xff;
+ sec <<= 8;
+ sec += (u_long)*bp-- & 0xff;
+ sec <<= 8;
+ sec += (u_long)*bp-- & 0xff;
+ sec <<= 8;
+ sec += (u_long)*bp & 0xff;
+#endif
+ ts->l_ui = sec + (u_long)JAN_1970;
+ if (usec > 999999)
+ return 0;
+ TVUTOTSF(usec, ts->l_uf);
+ return 1;
+}
diff --git a/contrib/ntp/libntp/caljulian.c b/contrib/ntp/libntp/caljulian.c
new file mode 100644
index 0000000..948bb1c
--- /dev/null
+++ b/contrib/ntp/libntp/caljulian.c
@@ -0,0 +1,115 @@
+/*
+ * caljulian - determine the Julian date from an NTP time.
+ */
+#include <sys/types.h>
+
+#include "ntp_types.h"
+#include "ntp_calendar.h"
+#include "ntp_stdlib.h"
+
+/*
+ * calmonthtab - days-in-the-month table
+ */
+static u_short calmonthtab[11] = {
+ JAN,
+ FEB,
+ MAR,
+ APR,
+ MAY,
+ JUN,
+ JUL,
+ AUG,
+ SEP,
+ OCT,
+ NOV
+};
+
+void
+caljulian(
+ u_long ntptime,
+ register struct calendar *jt
+ )
+{
+ u_long ntp_day;
+ u_long minutes;
+ /*
+ * Absolute, zero-adjusted Christian era day, starting from the
+ * mythical day 12/1/1 BC
+ */
+ u_long acez_day;
+
+ u_long d400; /* Days into a Gregorian cycle */
+ u_long d100; /* Days into a normal century */
+ u_long d4; /* Days into a 4-year cycle */
+ u_long n400; /* # of Gregorian cycles */
+ u_long n100; /* # of normal centuries */
+ u_long n4; /* # of 4-year cycles */
+ u_long n1; /* # of years into a leap year */
+ /* cycle */
+
+ /*
+ * Do the easy stuff first: take care of hh:mm:ss, ignoring leap
+ * seconds
+ */
+ jt->second = (u_char)(ntptime % SECSPERMIN);
+ minutes = ntptime / SECSPERMIN;
+ jt->minute = (u_char)(minutes % MINSPERHR);
+ jt->hour = (u_char)((minutes / MINSPERHR) % HRSPERDAY);
+
+ /*
+ * Find the day past 1900/01/01 00:00 UTC
+ */
+ ntp_day = ntptime / SECSPERDAY;
+ acez_day = DAY_NTP_STARTS + ntp_day - 1;
+ n400 = acez_day/GREGORIAN_CYCLE_DAYS;
+ d400 = acez_day%GREGORIAN_CYCLE_DAYS;
+ n100 = d400 / GREGORIAN_NORMAL_CENTURY_DAYS;
+ d100 = d400 % GREGORIAN_NORMAL_CENTURY_DAYS;
+ n4 = d100 / GREGORIAN_NORMAL_LEAP_CYCLE_DAYS;
+ d4 = d100 % GREGORIAN_NORMAL_LEAP_CYCLE_DAYS;
+ n1 = d4 / DAYSPERYEAR;
+
+ /*
+ * Calculate the year and year-of-day
+ */
+ jt->yearday = (u_short)(1 + d4%DAYSPERYEAR);
+ jt->year = (u_short)(400*n400 + 100*n100 + n4*4 + n1);
+
+ if (n100 == 4 || n1 == 4)
+ {
+ /*
+ * If the cycle year ever comes out to 4, it must be December 31st
+ * of a leap year.
+ */
+ jt->month = 12;
+ jt->monthday = 31;
+ jt->yearday = 366;
+ }
+ else
+ {
+ /*
+ * Else, search forwards through the months to get the right month
+ * and date.
+ */
+ int monthday;
+
+ jt->year++;
+ monthday = jt->yearday;
+
+ for (jt->month=0;jt->month<11; jt->month++)
+ {
+ int t;
+
+ t = monthday - calmonthtab[jt->month];
+ if (jt->month == 1 && is_leapyear(jt->year))
+ t--;
+
+ if (t > 0)
+ monthday = t;
+ else
+ break;
+ }
+ jt->month++;
+ jt->monthday = monthday;
+ }
+}
diff --git a/contrib/ntp/libntp/calleapwhen.c b/contrib/ntp/libntp/calleapwhen.c
new file mode 100644
index 0000000..c954901
--- /dev/null
+++ b/contrib/ntp/libntp/calleapwhen.c
@@ -0,0 +1,59 @@
+/*
+ * calleapwhen - determine the number of seconds to the next possible
+ * leap occurance.
+ */
+#include <sys/types.h>
+
+#include "ntp_types.h"
+#include "ntp_calendar.h"
+#include "ntp_stdlib.h"
+
+/*
+ * calleaptab - leaps occur at the end of December and June
+ */
+long calleaptab[10] = {
+ -(JAN+FEBLEAP)*SECSPERDAY, /* leap previous to cycle */
+ (MAR+APR+MAY+JUN)*SECSPERDAY, /* end of June */
+ (MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC)*SECSPERDAY, /* end of Dec */
+ (MAR+APR+MAY+JUN)*SECSPERDAY + SECSPERYEAR,
+ (MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC)*SECSPERDAY + SECSPERYEAR,
+ (MAR+APR+MAY+JUN)*SECSPERDAY + 2*SECSPERYEAR,
+ (MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC)*SECSPERDAY + 2*SECSPERYEAR,
+ (MAR+APR+MAY+JUN)*SECSPERDAY + 3*SECSPERYEAR,
+ (MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC)*SECSPERDAY + 3*SECSPERYEAR,
+ (MAR+APR+MAY+JUN+JUL+AUG+SEP+OCT+NOV+DEC+JAN+FEBLEAP+MAR+APR+MAY+JUN)
+ *SECSPERDAY + 3*SECSPERYEAR, /* next after current cycle */
+};
+
+u_long
+calleapwhen(
+ u_long ntpdate
+ )
+{
+ register u_long dateincycle;
+ register int i;
+
+ /*
+ * Find the offset from the start of the cycle
+ */
+ dateincycle = ntpdate;
+ if (dateincycle >= MAR1988)
+ dateincycle -= MAR1988;
+ else
+ dateincycle -= MAR1900;
+
+ while (dateincycle >= SECSPERCYCLE)
+ dateincycle -= SECSPERCYCLE;
+
+ /*
+ * Find where we are with respect to the leap events.
+ */
+ for (i = 1; i < 9; i++)
+ if (dateincycle < (u_long)calleaptab[i])
+ break;
+
+ /*
+ * i points at the next leap. Compute the last and the next.
+ */
+ return (u_long)(calleaptab[i] - (long)dateincycle);
+}
diff --git a/contrib/ntp/libntp/caltontp.c b/contrib/ntp/libntp/caltontp.c
new file mode 100644
index 0000000..9ec1064
--- /dev/null
+++ b/contrib/ntp/libntp/caltontp.c
@@ -0,0 +1,42 @@
+/*
+ * caltontp - convert a date to an NTP time
+ */
+#include <sys/types.h>
+
+#include "ntp_types.h"
+#include "ntp_calendar.h"
+#include "ntp_stdlib.h"
+
+u_long
+caltontp(
+ register const struct calendar *jt
+ )
+{
+ u_long ace_days; /* absolute Christian Era days */
+ u_long ntp_days;
+ int prior_years;
+ u_long ntp_time;
+
+ /*
+ * First convert today's date to absolute days past 12/1/1 BC
+ */
+ prior_years = jt->year-1;
+ ace_days = jt->yearday /* days this year */
+ +(DAYSPERYEAR*prior_years) /* plus days in previous years */
+ +(prior_years/4) /* plus prior years's leap days */
+ -(prior_years/100) /* minus leapless century years */
+ +(prior_years/400); /* plus leapful Gregorian yrs */
+
+ /*
+ * Subtract out 1/1/1900, the beginning of the NTP epoch
+ */
+ ntp_days = ace_days - DAY_NTP_STARTS;
+
+ /*
+ * Do the obvious:
+ */
+ ntp_time =
+ ntp_days*SECSPERDAY+SECSPERMIN*(MINSPERHR*jt->hour + jt->minute);
+
+ return ntp_time;
+}
diff --git a/contrib/ntp/libntp/calyearstart.c b/contrib/ntp/libntp/calyearstart.c
new file mode 100644
index 0000000..0f7ca4f
--- /dev/null
+++ b/contrib/ntp/libntp/calyearstart.c
@@ -0,0 +1,22 @@
+/*
+ * calyearstart - determine the NTP time at midnight of January 1 in
+ * the year of the given date.
+ */
+#include <sys/types.h>
+
+#include "ntp_types.h"
+#include "ntp_calendar.h"
+#include "ntp_stdlib.h"
+
+u_long
+calyearstart(u_long ntp_time)
+{
+ struct calendar jt;
+
+ caljulian(ntp_time,&jt);
+ jt.yearday = 1;
+ jt.monthday = 1;
+ jt.month = 1;
+ jt.hour = jt.minute = jt.second = 0;
+ return caltontp(&jt);
+}
diff --git a/contrib/ntp/libntp/clocktime.c b/contrib/ntp/libntp/clocktime.c
new file mode 100644
index 0000000..371859c
--- /dev/null
+++ b/contrib/ntp/libntp/clocktime.c
@@ -0,0 +1,132 @@
+/*
+ * clocktime - compute the NTP date from a day of year, hour, minute
+ * and second.
+ */
+#include "ntp_fp.h"
+#include "ntp_unixtime.h"
+#include "ntp_stdlib.h"
+
+/*
+ * Hacks to avoid excercising the multiplier. I have no pride.
+ */
+#define MULBY10(x) (((x)<<3) + ((x)<<1))
+#define MULBY60(x) (((x)<<6) - ((x)<<2)) /* watch overflow */
+#define MULBY24(x) (((x)<<4) + ((x)<<3))
+
+/*
+ * Two days, in seconds.
+ */
+#define TWODAYS (2*24*60*60)
+
+/*
+ * We demand that the time be within CLOSETIME seconds of the receive
+ * time stamp. This is about 4 hours, which hopefully should be
+ * wide enough to collect most data, while close enough to keep things
+ * from getting confused.
+ */
+#define CLOSETIME (4*60*60)
+
+
+int
+clocktime(
+ int yday,
+ int hour,
+ int minute,
+ int second,
+ int tzoff,
+ u_long rec_ui,
+ u_long *yearstart,
+ u_int32 *ts_ui
+ )
+{
+ register long tmp;
+ register u_long date;
+ register u_long yst;
+
+ /*
+ * Compute the offset into the year in seconds. Note that
+ * this could come out to be a negative number.
+ */
+ tmp = (long)(MULBY24((yday-1)) + hour + tzoff);
+ tmp = MULBY60(tmp) + (long)minute;
+ tmp = MULBY60(tmp) + (long)second;
+
+ /*
+ * Initialize yearstart, if necessary.
+ */
+ yst = *yearstart;
+ if (yst == 0) {
+ yst = calyearstart(rec_ui);
+ *yearstart = yst;
+ }
+
+ /*
+ * Now the fun begins. We demand that the received clock time
+ * be within CLOSETIME of the receive timestamp, but
+ * there is uncertainty about the year the timestamp is in.
+ * Use the current year start for the first check, this should
+ * work most of the time.
+ */
+ date = (u_long)(tmp + (long)yst);
+ if (date < (rec_ui + CLOSETIME) &&
+ date > (rec_ui - CLOSETIME)) {
+ *ts_ui = date;
+ return 1;
+ }
+
+ /*
+ * Trouble. Next check is to see if the year rolled over and, if
+ * so, try again with the new year's start.
+ */
+ yst = calyearstart(rec_ui);
+ if (yst != *yearstart) {
+ date = (u_long)((long)yst + tmp);
+ *ts_ui = date;
+ if (date < (rec_ui + CLOSETIME) &&
+ date > (rec_ui - CLOSETIME)) {
+ *yearstart = yst;
+ return 1;
+ }
+ }
+
+ /*
+ * Here we know the year start matches the current system
+ * time. One remaining possibility is that the time code
+ * is in the year previous to that of the system time. This
+ * is only worth checking if the receive timestamp is less
+ * than a couple of days into the new year.
+ */
+ if ((rec_ui - yst) < TWODAYS) {
+ yst = calyearstart(yst - TWODAYS);
+ if (yst != *yearstart) {
+ date = (u_long)(tmp + (long)yst);
+ if (date < (rec_ui + CLOSETIME) &&
+ date > (rec_ui - CLOSETIME)) {
+ *yearstart = yst;
+ *ts_ui = date;
+ return 1;
+ }
+ }
+ }
+
+ /*
+ * One last possibility is that the time stamp is in the year
+ * following the year the system is in. Try this one before
+ * giving up.
+ */
+ yst = calyearstart(rec_ui + TWODAYS);
+ if (yst != *yearstart) {
+ date = (u_long)((long)yst + tmp);
+ if (date < (rec_ui + CLOSETIME) &&
+ date > (rec_ui - CLOSETIME)) {
+ *yearstart = yst;
+ *ts_ui = date;
+ return 1;
+ }
+ }
+
+ /*
+ * Give it up.
+ */
+ return 0;
+}
diff --git a/contrib/ntp/libntp/clocktypes.c b/contrib/ntp/libntp/clocktypes.c
new file mode 100644
index 0000000..c9a6766
--- /dev/null
+++ b/contrib/ntp/libntp/clocktypes.c
@@ -0,0 +1,98 @@
+/*
+ * Data for pretty printing clock types
+ */
+#include <stdio.h>
+
+#include "ntp_fp.h"
+#include "ntp.h"
+#include "lib_strbuf.h"
+#include "ntp_refclock.h"
+#include "ntp_stdlib.h"
+
+struct clktype clktypes[] = {
+ { REFCLK_NONE, "unspecified type (0)",
+ "UNKNOWN" },
+ { REFCLK_LOCALCLOCK, "Undisciplined local clock (1)",
+ "LOCAL" },
+ { REFCLK_GPS_TRAK, "TRAK 8810 GPS Receiver (2)",
+ "GPS_TRAK" },
+ { REFCLK_WWV_PST, "PSTI/Traconex WWV/WWVH Receiver (3)",
+ "WWV_PST" },
+ { REFCLK_WWVB_SPECTRACOM, "Spectracom WWVB Receiver (4)",
+ "WWVB_SPEC" },
+ { REFCLK_TRUETIME, "TrueTime (generic) Receivers (5)",
+ "TRUETIME" },
+ { REFCLK_IRIG_AUDIO, "IRIG Audio Decoder (6)",
+ "IRIG_AUDIO" },
+ { REFCLK_CHU, "Scratchbuilt CHU Receiver (7)",
+ "CHU" },
+ { REFCLK_PARSE, "Generic reference clock driver (8)",
+ "GENERIC" },
+ { REFCLK_GPS_MX4200, "Magnavox MX4200 GPS Receiver (9)",
+ "GPS_MX4200" },
+ { REFCLK_GPS_AS2201, "Austron 2201A GPS Receiver (10)",
+ "GPS_AS2201" },
+ { REFCLK_GPS_ARBITER, "Arbiter 1088A/B GPS Receiver (11)",
+ "GPS_ARBITER" },
+ { REFCLK_IRIG_TPRO, "KSI/Odetics TPRO/S IRIG Interface (12)",
+ "IRIG_TPRO" },
+ { REFCLK_ATOM_LEITCH, "Leitch CSD 5300 Master Clock Controller (13)",
+ "ATOM_LEITCH" },
+ { REFCLK_MSF_EES, "EES M201 MSF Receiver (14)",
+ "MSF_EES" },
+ { REFCLK_GPSTM_TRUE, "TrueTime (old GPSTM driver) Receiver (15)",
+ "GPSTM_TRUE" },
+ { REFCLK_IRIG_BANCOMM, "Bancomm GPS/IRIG Receiver (16)",
+ "GPS_BANC" },
+ { REFCLK_GPS_DATUM, "Datum Precision Time System (17)",
+ "GPS_DATUM" },
+ { REFCLK_NIST_ACTS, "NIST Automated Computer Time Service (18)",
+ "ACTS_NIST" },
+ { REFCLK_WWV_HEATH, "Heath WWV/WWVH Receiver (19)",
+ "WWV_HEATH" },
+ { REFCLK_GPS_NMEA, "Generic NMEA GPS Receiver (20)",
+ "GPS_NMEA" },
+ { REFCLK_GPS_VME, "TrueTime GPS-VME Interface (21)",
+ "GPS_VME" },
+ { REFCLK_ATOM_PPS, "PPS Clock Discipline (22)",
+ "PPS" },
+ { REFCLK_PTB_ACTS, "PTB Automated Computer Time Service (23)",
+ "ACTS_PTB" },
+ { REFCLK_USNO, "Naval Observatory dialup (24)",
+ "ACTS_USNO" },
+ { REFCLK_TRUETIME, "TrueTime (generic) Receivers (25)",
+ "TRUETIME" },
+ { REFCLK_GPS_HP, "HP 58503A GPS Time & Frequency Receiver (26)",
+ "GPS_HP" },
+ { REFCLK_ARCRON_MSF, "ARCRON MSF (and DCF77) Receiver (27)",
+ "MSF_ARCRON" },
+ { REFCLK_SHM, "Clock attached thru shared Memory (28)",
+ "SHM" },
+ { REFCLK_PALISADE, "Trimble Navigation Palisade GPS (29)",
+ "GPS_PALISADE" },
+ { REFCLK_ONCORE, "Motorola UT Oncore GPS (30)",
+ "GPS_ONCORE" },
+ { REFCLK_GPS_JUPITER, "Rockwell Jupiter GPS (31)",
+ "GPS_JUPITER" },
+ { REFCLK_CHRONOLOG, "Chrono-log K (32)",
+ "CHRONOLOG" },
+ { REFCLK_DUMBCLOCK, "Dumb generic hh:mm:ss local clock",
+ "DUMBCLOCK" },
+ { REFCLK_ULINK, "Ultralink M320 WWVB receiver",
+ "ULINK_M320"},
+ { -1, "", "" }
+};
+
+const char *
+clockname(
+ int num
+ )
+{
+ register struct clktype *clk;
+
+ for (clk = clktypes; clk->code != -1; clk++) {
+ if (num == clk->code)
+ return (clk->abbrev);
+ }
+ return (NULL);
+}
diff --git a/contrib/ntp/libntp/decodenetnum.c b/contrib/ntp/libntp/decodenetnum.c
new file mode 100644
index 0000000..a24e493
--- /dev/null
+++ b/contrib/ntp/libntp/decodenetnum.c
@@ -0,0 +1,59 @@
+/*
+ * decodenetnum - return a net number (this is crude, but careful)
+ */
+#include <sys/types.h>
+#include <ctype.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include "ntp_stdlib.h"
+
+int
+decodenetnum(
+ const char *num,
+ u_int32 *netnum
+ )
+{
+ register const char *cp;
+ register char *bp;
+ register int i;
+ register int temp;
+ register int eos;
+ char buf[80]; /* will core dump on really stupid stuff */
+
+ cp = num;
+ *netnum = 0;
+
+ if (*cp == '[') {
+ eos = ']';
+ cp++;
+ } else {
+ eos = '\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 != eos)
+ break;
+
+ *bp = '\0';
+ temp = atoi(buf);
+ if (temp > 255)
+ break;
+ *netnum <<= 8;
+ *netnum += temp;
+ }
+
+ if (i < 4)
+ return 0;
+ *netnum = htonl(*netnum);
+ return 1;
+}
diff --git a/contrib/ntp/libntp/dofptoa.c b/contrib/ntp/libntp/dofptoa.c
new file mode 100644
index 0000000..caa0997
--- /dev/null
+++ b/contrib/ntp/libntp/dofptoa.c
@@ -0,0 +1,118 @@
+/*
+ * dofptoa - do the grunge work to convert an fp number to ascii
+ */
+#include <stdio.h>
+
+#include "ntp_fp.h"
+#include "lib_strbuf.h"
+#include "ntp_string.h"
+#include "ntp_stdlib.h"
+
+char *
+dofptoa(
+ u_fp fpv,
+ int neg,
+ int ndec,
+ int msec
+ )
+{
+ register u_char *cp, *cpend;
+ register u_long val;
+ register short dec;
+ u_char cbuf[12];
+ u_char *cpdec;
+ char *buf;
+ char *bp;
+
+ /*
+ * Get a string buffer before starting
+ */
+ LIB_GETBUF(buf);
+
+ /*
+ * Zero out the buffer
+ */
+ memset((char *)cbuf, 0, sizeof cbuf);
+
+ /*
+ * Set the pointers to point at the first
+ * decimal place. Get a local copy of the value.
+ */
+ cp = cpend = &cbuf[5];
+ val = fpv;
+
+ /*
+ * If we have to, decode the integral part
+ */
+ if (!(val & 0xffff0000))
+ cp--;
+ else {
+ register u_short sv = (u_short)(val >> 16);
+ register u_short tmp;
+ register u_short ten = 10;
+
+ do {
+ tmp = sv;
+ sv /= ten;
+ *(--cp) = tmp - ((sv<<3) + (sv<<1));
+ } while (sv != 0);
+ }
+
+ /*
+ * Figure out how much of the fraction to do
+ */
+ if (msec) {
+ dec = ndec + 3;
+ if (dec < 3)
+ dec = 3;
+ cpdec = &cbuf[8];
+ } else {
+ dec = ndec;
+ cpdec = cpend;
+ }
+
+ if (dec > 6)
+ dec = 6;
+
+ if (dec > 0) {
+ do {
+ val &= 0xffff;
+ val = (val << 3) + (val << 1);
+ *cpend++ = (u_char)(val >> 16);
+ } while (--dec > 0);
+ }
+
+ if (val & 0x8000) {
+ register u_char *tp;
+ /*
+ * Round it. Ick.
+ */
+ tp = cpend;
+ *(--tp) += 1;
+ while (*tp >= 10) {
+ *tp = 0;
+ *(--tp) += 1;
+ }
+ }
+
+ /*
+ * Remove leading zeroes if necessary
+ */
+ while (cp < (cpdec -1) && *cp == 0)
+ cp++;
+
+ /*
+ * Copy it into the buffer, asciizing as we go.
+ */
+ bp = buf;
+ if (neg)
+ *bp++ = '-';
+
+ while (cp < cpend) {
+ if (cp == cpdec)
+ *bp++ = '.';
+ *bp++ = (char)(*cp++ + '0');
+ }
+ *bp = '\0';
+ return buf;
+}
diff --git a/contrib/ntp/libntp/dolfptoa.c b/contrib/ntp/libntp/dolfptoa.c
new file mode 100644
index 0000000..5602331
--- /dev/null
+++ b/contrib/ntp/libntp/dolfptoa.c
@@ -0,0 +1,162 @@
+/*
+ * dolfptoa - do the grunge work of converting an l_fp number to decimal
+ */
+#include <stdio.h>
+
+#include "ntp_fp.h"
+#include "lib_strbuf.h"
+#include "ntp_string.h"
+#include "ntp_stdlib.h"
+
+char *
+dolfptoa(
+ u_long fpi,
+ u_long fpv,
+ int neg,
+ int ndec,
+ int msec
+ )
+{
+ register u_char *cp, *cpend;
+ register u_long lwork;
+ register int dec;
+ u_char cbuf[24];
+ u_char *cpdec;
+ char *buf;
+ char *bp;
+
+ /*
+ * Get a string buffer before starting
+ */
+ LIB_GETBUF(buf);
+
+ /*
+ * Zero the character buffer
+ */
+ memset((char *) cbuf, 0, sizeof(cbuf));
+
+ /*
+ * Work on the integral part. This is biased by what I know
+ * compiles fairly well for a 68000.
+ */
+ cp = cpend = &cbuf[10];
+ lwork = fpi;
+ if (lwork & 0xffff0000) {
+ register u_long lten = 10;
+ register u_long ltmp;
+
+ do {
+ ltmp = lwork;
+ lwork /= lten;
+ ltmp -= (lwork << 3) + (lwork << 1);
+ *--cp = (u_char)ltmp;
+ } while (lwork & 0xffff0000);
+ }
+ if (lwork != 0) {
+ register u_short sten = 10;
+ register u_short stmp;
+ register u_short swork = (u_short)lwork;
+
+ do {
+ stmp = swork;
+ swork /= sten;
+ stmp -= (swork<<3) + (swork<<1);
+ *--cp = (u_char)stmp;
+ } while (swork != 0);
+ }
+
+ /*
+ * Done that, now deal with the problem of the fraction. First
+ * determine the number of decimal places.
+ */
+ if (msec) {
+ dec = ndec + 3;
+ if (dec < 3)
+ dec = 3;
+ cpdec = &cbuf[13];
+ } else {
+ dec = ndec;
+ if (dec < 0)
+ dec = 0;
+ cpdec = &cbuf[10];
+ }
+ if (dec > 12)
+ dec = 12;
+
+ /*
+ * If there's a fraction to deal with, do so.
+ */
+ if (fpv != 0) {
+ l_fp work;
+
+ work.l_ui = 0;
+ work.l_uf = fpv;
+ while (dec > 0) {
+ l_fp ftmp;
+
+ dec--;
+ /*
+ * The scheme here is to multiply the
+ * fraction (0.1234...) by ten. This moves
+ * a junk of BCD into the units part.
+ * record that and iterate.
+ */
+ work.l_ui = 0;
+ L_LSHIFT(&work);
+ ftmp = work;
+ L_LSHIFT(&work);
+ L_LSHIFT(&work);
+ L_ADD(&work, &ftmp);
+ *cpend++ = (u_char)work.l_ui;
+ if (work.l_uf == 0)
+ break;
+ }
+
+ /*
+ * Rounding is rotten
+ */
+ if (work.l_uf & 0x80000000) {
+ register u_char *tp = cpend;
+
+ *(--tp) += 1;
+ while (*tp >= 10) {
+ *tp = 0;
+ *(--tp) += 1;
+ };
+ if (tp < cp)
+ cp = tp;
+ }
+ }
+ cpend += dec;
+
+
+ /*
+ * We've now got the fraction in cbuf[], with cp pointing at
+ * the first character, cpend pointing past the last, and
+ * cpdec pointing at the first character past the decimal.
+ * Remove leading zeros, then format the number into the
+ * buffer.
+ */
+ while (cp < cpdec) {
+ if (*cp != 0)
+ break;
+ cp++;
+ }
+ if (cp == cpdec)
+ --cp;
+
+ bp = buf;
+ if (neg)
+ *bp++ = '-';
+ while (cp < cpend) {
+ if (cp == cpdec)
+ *bp++ = '.';
+ *bp++ = (char)(*cp++ + '0'); /* ascii dependent? */
+ }
+ *bp = '\0';
+
+ /*
+ * Done!
+ */
+ return buf;
+}
diff --git a/contrib/ntp/libntp/emalloc.c b/contrib/ntp/libntp/emalloc.c
new file mode 100644
index 0000000..0918c9c
--- /dev/null
+++ b/contrib/ntp/libntp/emalloc.c
@@ -0,0 +1,48 @@
+/*
+ * emalloc - return new memory obtained from the system. Belch if none.
+ */
+#include "ntp_types.h"
+#include "ntp_malloc.h"
+#include "ntp_stdlib.h"
+#include "ntp_syslog.h"
+
+#if defined SYS_WINNT && defined DEBUG
+#include <crtdbg.h>
+#endif
+
+#if defined SYS_WINNT && defined DEBUG
+
+void *
+debug_emalloc(
+ u_int size,
+ char *filename,
+ int line
+ )
+{
+ char *mem;
+
+ if ((mem = (char *)_malloc_dbg(size, _NORMAL_BLOCK, filename, line)) == 0) {
+ msyslog(LOG_ERR, "No more memory!");
+ exit(1);
+ }
+ return mem;
+}
+
+#else
+
+void *
+emalloc(
+ u_int size
+ )
+{
+ char *mem;
+
+ if ((mem = (char *)malloc(size)) == 0) {
+ msyslog(LOG_ERR, "No more memory!");
+ exit(1);
+ }
+ return mem;
+}
+
+
+#endif
diff --git a/contrib/ntp/libntp/findconfig.c b/contrib/ntp/libntp/findconfig.c
new file mode 100644
index 0000000..ecf6a4b
--- /dev/null
+++ b/contrib/ntp/libntp/findconfig.c
@@ -0,0 +1,72 @@
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef NEED_HPUX_FINDCONFIG
+#include <string.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/utsname.h>
+#include <unistd.h>
+
+const char *
+FindConfig(
+ const char *base
+ )
+{
+ static char result[BUFSIZ];
+ char hostname[BUFSIZ], *cp;
+ struct stat sbuf;
+ struct utsname unamebuf;
+
+ /* All keyed by initial target being a directory */
+ (void) strcpy(result, base);
+ if (stat(result, &sbuf) == 0) {
+ if (S_ISDIR(sbuf.st_mode)) {
+
+ /* First choice is my hostname */
+ if (gethostname(hostname, BUFSIZ) >= 0) {
+ (void) sprintf(result, "%s/%s", base, hostname);
+ if (stat(result, &sbuf) == 0) {
+ goto outahere;
+ } else {
+
+ /* Second choice is of form default.835 */
+ (void) uname(&unamebuf);
+ if (strncmp(unamebuf.machine, "9000/", 5) == 0)
+ cp = unamebuf.machine + 5;
+ else
+ cp = unamebuf.machine;
+ (void) sprintf(result, "%s/default.%s", base, cp);
+ if (stat(result, &sbuf) == 0) {
+ goto outahere;
+ } else {
+
+ /* Last choice is just default */
+ (void) sprintf(result, "%s/default", base);
+ if (stat(result, &sbuf) == 0) {
+ goto outahere;
+ } else {
+ (void) strcpy(result, "/not/found");
+ }
+ }
+ }
+ }
+ }
+ }
+ outahere:
+ return(result);
+}
+#else
+#include "ntp_stdlib.h"
+
+const char *
+FindConfig(
+ const char *base
+ )
+{
+ return base;
+}
+#endif
diff --git a/contrib/ntp/libntp/fptoa.c b/contrib/ntp/libntp/fptoa.c
new file mode 100644
index 0000000..f0247dd
--- /dev/null
+++ b/contrib/ntp/libntp/fptoa.c
@@ -0,0 +1,25 @@
+/*
+ * fptoa - return an asciized representation of an s_fp number
+ */
+#include "ntp_fp.h"
+#include "ntp_stdlib.h"
+
+char *
+fptoa(
+ s_fp fpv,
+ int ndec
+ )
+{
+ u_fp plusfp;
+ int neg;
+
+ if (fpv < 0) {
+ plusfp = (u_fp)(-fpv);
+ neg = 1;
+ } else {
+ plusfp = (u_fp)fpv;
+ neg = 0;
+ }
+
+ return dofptoa(plusfp, neg, ndec, 0);
+}
diff --git a/contrib/ntp/libntp/fptoms.c b/contrib/ntp/libntp/fptoms.c
new file mode 100644
index 0000000..4d371aa
--- /dev/null
+++ b/contrib/ntp/libntp/fptoms.c
@@ -0,0 +1,24 @@
+/*
+ * fptoms - return an asciized s_fp number in milliseconds
+ */
+#include "ntp_fp.h"
+
+char *
+fptoms(
+ s_fp fpv,
+ int ndec
+ )
+{
+ u_fp plusfp;
+ int neg;
+
+ if (fpv < 0) {
+ plusfp = (u_fp)(-fpv);
+ neg = 1;
+ } else {
+ plusfp = (u_fp)fpv;
+ neg = 0;
+ }
+
+ return dofptoa(plusfp, neg, ndec, 1);
+}
diff --git a/contrib/ntp/libntp/getopt.c b/contrib/ntp/libntp/getopt.c
new file mode 100644
index 0000000..7b344f0
--- /dev/null
+++ b/contrib/ntp/libntp/getopt.c
@@ -0,0 +1,107 @@
+/*
+ * getopt - get option letter from argv
+ *
+ * This is a version of the public domain getopt() implementation by
+ * Henry Spencer, changed for 4.3BSD compatibility (in addition to System V).
+ * It allows rescanning of an option list by setting optind to 0 before
+ * calling, which is why we use it even if the system has its own (in fact,
+ * this one has a unique name so as not to conflict with the system's).
+ * Thanks to Dennis Ferguson for the appropriate modifications.
+ *
+ * This file is in the Public Domain.
+ */
+
+/*LINTLIBRARY*/
+
+#include <stdio.h>
+
+#include "ntp_stdlib.h"
+
+#ifdef lint
+#undef putc
+#define putc fputc
+#endif /* lint */
+
+char *ntp_optarg; /* Global argument pointer. */
+int ntp_optind = 0; /* Global argv index. */
+int ntp_opterr = 1; /* for compatibility, should error be printed? */
+int ntp_optopt; /* for compatibility, option character checked */
+
+static char *scan = NULL; /* Private scan pointer. */
+static const char *prog = "amnesia";
+
+/*
+ * Print message about a bad option.
+ */
+static int
+badopt(
+ const char *mess,
+ int ch
+ )
+{
+ if (ntp_opterr) {
+ fputs(prog, stderr);
+ fputs(mess, stderr);
+ (void) putc(ch, stderr);
+ (void) putc('\n', stderr);
+ }
+ return ('?');
+}
+
+int
+ntp_getopt(
+ int argc,
+ char *argv[],
+ const char *optstring
+ )
+{
+ register char c;
+ register const char *place;
+
+ prog = argv[0];
+ ntp_optarg = NULL;
+
+ if (ntp_optind == 0) {
+ scan = NULL;
+ ntp_optind++;
+ }
+
+ if (scan == NULL || *scan == '\0') {
+ if (ntp_optind >= argc
+ || argv[ntp_optind][0] != '-'
+ || argv[ntp_optind][1] == '\0') {
+ return (EOF);
+ }
+ if (argv[ntp_optind][1] == '-'
+ && argv[ntp_optind][2] == '\0') {
+ ntp_optind++;
+ return (EOF);
+ }
+
+ scan = argv[ntp_optind++]+1;
+ }
+
+ c = *scan++;
+ ntp_optopt = c & 0377;
+ for (place = optstring; place != NULL && *place != '\0'; ++place)
+ if (*place == c)
+ break;
+
+ if (place == NULL || *place == '\0' || c == ':' || c == '?') {
+ return (badopt(": unknown option -", c));
+ }
+
+ place++;
+ if (*place == ':') {
+ if (*scan != '\0') {
+ ntp_optarg = scan;
+ scan = NULL;
+ } else if (ntp_optind >= argc) {
+ return (badopt(": option requires argument -", c));
+ } else {
+ ntp_optarg = argv[ntp_optind++];
+ }
+ }
+
+ return (c & 0377);
+}
diff --git a/contrib/ntp/libntp/gpstolfp.c b/contrib/ntp/libntp/gpstolfp.c
new file mode 100644
index 0000000..cf7b80c
--- /dev/null
+++ b/contrib/ntp/libntp/gpstolfp.c
@@ -0,0 +1,41 @@
+/*
+ * /src/NTP/ntp-4/libntp/gpstolfp.c,v 4.3 1999/02/28 11:42:44 kardel RELEASE_19990228_A
+ *
+ * $Created: Sun Jun 28 16:30:38 1998 $
+ *
+ * Copyright (C) 1998 by Frank Kardel
+ */
+#include "ntp_fp.h"
+
+#define GPSORIGIN (unsigned)(2524953600L) /* NTP origin - GPS origin in seconds */
+#define SECSPERWEEK (unsigned)(604800) /* seconds per week - GPS tells us about weeks */
+#define GPSWRAP 990 /* assume week count less than this in the previous epoch */
+
+void
+gpstolfp(
+ int weeks,
+ int days,
+ unsigned long seconds,
+ l_fp * lfp
+ )
+{
+ if (weeks < GPSWRAP)
+ {
+ weeks += 1024;
+ }
+
+ lfp->l_ui = weeks * SECSPERWEEK + days * 86400 + seconds + GPSORIGIN; /* convert to NTP time */
+ lfp->l_uf = 0;
+}
+
+/*
+ * gpstolfp.c,v
+ * Revision 4.3 1999/02/28 11:42:44 kardel
+ * (GPSWRAP): update GPS rollover to 990 weeks
+ *
+ * Revision 4.2 1998/07/11 10:05:25 kardel
+ * Release 4.0.73d reconcilation
+ *
+ * Revision 4.1 1998/06/28 16:47:15 kardel
+ * added gpstolfp() function
+ */
diff --git a/contrib/ntp/libntp/hextoint.c b/contrib/ntp/libntp/hextoint.c
new file mode 100644
index 0000000..0d774eb
--- /dev/null
+++ b/contrib/ntp/libntp/hextoint.c
@@ -0,0 +1,39 @@
+/*
+ * hextoint - convert an ascii string in hex to an unsigned
+ * long, with error checking
+ */
+#include <ctype.h>
+
+#include "ntp_stdlib.h"
+
+int
+hextoint(
+ const char *str,
+ u_long *ival
+ )
+{
+ register u_long u;
+ register const char *cp;
+
+ cp = str;
+
+ if (*cp == '\0')
+ return 0;
+
+ u = 0;
+ while (*cp != '\0') {
+ if (!isxdigit((int)*cp))
+ return 0;
+ if (u >= 0x10000000)
+ return 0; /* overflow */
+ u <<= 4;
+ if (*cp <= '9') /* very ascii dependent */
+ u += *cp++ - '0';
+ else if (*cp >= 'a')
+ u += *cp++ - 'a' + 10;
+ else
+ u += *cp++ - 'A' + 10;
+ }
+ *ival = u;
+ return 1;
+}
diff --git a/contrib/ntp/libntp/hextolfp.c b/contrib/ntp/libntp/hextolfp.c
new file mode 100644
index 0000000..d0b6243
--- /dev/null
+++ b/contrib/ntp/libntp/hextolfp.c
@@ -0,0 +1,67 @@
+/*
+ * hextolfp - convert an ascii hex string to an l_fp number
+ */
+#include <stdio.h>
+#include <ctype.h>
+
+#include "ntp_fp.h"
+#include "ntp_string.h"
+#include "ntp_stdlib.h"
+
+int
+hextolfp(
+ const char *str,
+ l_fp *lfp
+ )
+{
+ register const char *cp;
+ register const char *cpstart;
+ register u_long dec_i;
+ register u_long dec_f;
+ char *ind = NULL;
+ static const char *digits = "0123456789abcdefABCDEF";
+
+ dec_i = dec_f = 0;
+ cp = str;
+
+ /*
+ * We understand numbers of the form:
+ *
+ * [spaces]8_hex_digits[.]8_hex_digits[spaces|\n|\0]
+ */
+ while (isspace((int)*cp))
+ cp++;
+
+ cpstart = cp;
+ while (*cp != '\0' && (cp - cpstart) < 8 &&
+ (ind = strchr(digits, *cp)) != NULL) {
+ dec_i = dec_i << 4; /* multiply by 16 */
+ dec_i += ((ind - digits) > 15) ? (ind - digits) - 6
+ : (ind - digits);
+ cp++;
+ }
+
+ if ((cp - cpstart) < 8 || ind == NULL)
+ return 0;
+ if (*cp == '.')
+ cp++;
+
+ cpstart = cp;
+ while (*cp != '\0' && (cp - cpstart) < 8 &&
+ (ind = strchr(digits, *cp)) != NULL) {
+ dec_f = dec_f << 4; /* multiply by 16 */
+ dec_f += ((ind - digits) > 15) ? (ind - digits) - 6
+ : (ind - digits);
+ cp++;
+ }
+
+ if ((cp - cpstart) < 8 || ind == NULL)
+ return 0;
+
+ if (*cp != '\0' && !isspace((int)*cp))
+ return 0;
+
+ lfp->l_ui = dec_i;
+ lfp->l_uf = dec_f;
+ return 1;
+}
diff --git a/contrib/ntp/libntp/humandate.c b/contrib/ntp/libntp/humandate.c
new file mode 100644
index 0000000..f663c9e
--- /dev/null
+++ b/contrib/ntp/libntp/humandate.c
@@ -0,0 +1,62 @@
+/*
+ * humandate - convert an NTP (or the current) time to something readable
+ */
+#include <stdio.h>
+#include "time.h"
+#include "ntp_fp.h"
+#include "ntp_unixtime.h" /* includes <sys/time.h> */
+#include "lib_strbuf.h"
+#include "ntp_stdlib.h"
+
+#ifdef TIME_WITH_SYS_TIME
+#include <time.h>
+#endif
+
+static const char *months[] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+static const char *days[] = {
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+};
+
+char *
+humandate(
+ u_long ntptime
+ )
+{
+ char *bp;
+ struct tm *tm;
+ time_t sec;
+
+ LIB_GETBUF(bp);
+
+ sec = ntptime - JAN_1970;
+ tm = localtime(&sec);
+
+ (void) sprintf(bp, "%s, %s %2d %4d %2d:%02d:%02d",
+ days[tm->tm_wday], months[tm->tm_mon], tm->tm_mday,
+ 1900+tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+ return bp;
+}
+
+
+/* This is used in msyslog.c; we don't want to clutter up the log with
+ the year and day of the week, etc.; just the minimal date and time. */
+
+char *
+humanlogtime(void)
+{
+ char *bp;
+ time_t cursec = time((time_t *) 0);
+ struct tm *tm = localtime(&cursec);
+
+ LIB_GETBUF(bp);
+
+ (void) sprintf(bp, "%2d %s %02d:%02d:%02d",
+ tm->tm_mday, months[tm->tm_mon],
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+ return bp;
+}
diff --git a/contrib/ntp/libntp/ieee754io.c b/contrib/ntp/libntp/ieee754io.c
new file mode 100644
index 0000000..4aa9920
--- /dev/null
+++ b/contrib/ntp/libntp/ieee754io.c
@@ -0,0 +1,575 @@
+/*
+ * /src/NTP/ntp-4/libntp/ieee754io.c,v 4.8 1999/02/21 12:17:36 kardel RELEASE_19990228_A
+ *
+ * $Created: Sun Jul 13 09:12:02 1997 $
+ *
+ * Copyright (C) 1997, 1998 by Frank Kardel
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include "l_stdlib.h"
+#include "ntp_stdlib.h"
+#include "ntp_fp.h"
+#include "ieee754io.h"
+
+static unsigned char get_byte P((unsigned char *, offsets_t, int *));
+#ifdef __not_yet__
+static void put_byte P((unsigned char *, offsets_t, int *, unsigned char));
+#endif
+
+#ifdef LIBDEBUG
+
+#include "lib_strbuf.h"
+
+static char *
+fmt_blong(
+ unsigned long val,
+ int cnt
+ )
+{
+ char *buf, *s;
+ int i = cnt;
+
+ val <<= 32 - cnt;
+ LIB_GETBUF(buf);
+ s = buf;
+
+ while (i--)
+ {
+ if (val & 0x80000000)
+ {
+ *s++ = '1';
+ }
+ else
+ {
+ *s++ = '0';
+ }
+ val <<= 1;
+ }
+ *s = '\0';
+ return buf;
+}
+
+static char *
+fmt_flt(
+ unsigned int sign,
+ unsigned long mh,
+ unsigned long ml,
+ unsigned long ch
+ )
+{
+ char *buf;
+
+ LIB_GETBUF(buf);
+ sprintf(buf, "%c %s %s %s", sign ? '-' : '+',
+ fmt_blong(ch, 11),
+ fmt_blong(mh, 20),
+ fmt_blong(ml, 32));
+ return buf;
+}
+
+static char *
+fmt_hex(
+ unsigned char *bufp,
+ int length
+ )
+{
+ char *buf;
+ int i;
+
+ LIB_GETBUF(buf);
+ for (i = 0; i < length; i++)
+ {
+ sprintf(buf+i*2, "%02x", bufp[i]);
+ }
+ return buf;
+}
+
+#endif
+
+static unsigned char
+get_byte(
+ unsigned char *bufp,
+ offsets_t offset,
+ int *fieldindex
+ )
+{
+ unsigned char val;
+
+ val = *(bufp + offset[*fieldindex]);
+#ifdef LIBDEBUG
+ if (debug > 4)
+ printf("fetchieee754: getbyte(0x%08x, %d) = 0x%02x\n", (unsigned int)(bufp)+offset[*fieldindex], *fieldindex, val);
+#endif
+ (*fieldindex)++;
+ return val;
+}
+
+#ifdef __not_yet__
+static void
+put_byte(
+ unsigned char *bufp,
+ offsets_t offsets,
+ int *fieldindex,
+ unsigned char val
+ )
+{
+ *(bufp + offsets[*fieldindex]) = val;
+ (*fieldindex)++;
+}
+#endif
+
+/*
+ * make conversions to and from external IEEE754 formats and internal
+ * NTP FP format.
+ */
+int
+fetch_ieee754(
+ unsigned char **buffpp,
+ int size,
+ l_fp *lfpp,
+ offsets_t offsets
+ )
+{
+ unsigned char *bufp = *buffpp;
+ unsigned int sign;
+ unsigned int bias;
+ unsigned int maxexp;
+ unsigned int mbits;
+ u_long mantissa_low;
+ u_long mantissa_high;
+ u_long characteristic;
+ long exponent;
+#ifdef LIBDEBUG
+ int length;
+#endif
+ unsigned char val;
+ int fieldindex = 0;
+
+ switch (size)
+ {
+ case IEEE_DOUBLE:
+#ifdef LIBDEBUG
+ length = 8;
+#endif
+ mbits = 52;
+ bias = 1023;
+ maxexp = 2047;
+ break;
+
+ case IEEE_SINGLE:
+#ifdef LIBDEBUG
+ length = 4;
+#endif
+ mbits = 23;
+ bias = 127;
+ maxexp = 255;
+ break;
+
+ default:
+ return IEEE_BADCALL;
+ }
+
+ val = get_byte(bufp, offsets, &fieldindex); /* fetch sign byte & first part of characteristic */
+
+ sign = (val & 0x80) != 0;
+ characteristic = (val & 0x7F);
+
+ val = get_byte(bufp, offsets, &fieldindex); /* fetch rest of characteristic and start of mantissa */
+
+ switch (size)
+ {
+ case IEEE_SINGLE:
+ characteristic <<= 1;
+ characteristic |= (val & 0x80) != 0; /* grab last characteristic bit */
+
+ mantissa_high = 0;
+
+ mantissa_low = (val &0x7F) << 16;
+ mantissa_low |= get_byte(bufp, offsets, &fieldindex) << 8;
+ mantissa_low |= get_byte(bufp, offsets, &fieldindex);
+ break;
+
+ case IEEE_DOUBLE:
+ characteristic <<= 4;
+ characteristic |= (val & 0xF0) >> 4; /* grab lower characteristic bits */
+
+ mantissa_high = (val & 0x0F) << 16;
+ mantissa_high |= get_byte(bufp, offsets, &fieldindex) << 8;
+ mantissa_high |= get_byte(bufp, offsets, &fieldindex);
+
+ mantissa_low = get_byte(bufp, offsets, &fieldindex) << 24;
+ mantissa_low |= get_byte(bufp, offsets, &fieldindex) << 16;
+ mantissa_low |= get_byte(bufp, offsets, &fieldindex) << 8;
+ mantissa_low |= get_byte(bufp, offsets, &fieldindex);
+ break;
+
+ default:
+ return IEEE_BADCALL;
+ }
+#ifdef LIBDEBUG
+ if (debug > 4)
+ {
+ double d;
+ float f;
+
+ if (size == IEEE_SINGLE)
+ {
+ int i;
+
+ for (i = 0; i < length; i++)
+ {
+ *((unsigned char *)(&f)+i) = *(*buffpp + offsets[i]);
+ }
+ d = f;
+ }
+ else
+ {
+ int i;
+
+ for (i = 0; i < length; i++)
+ {
+ *((unsigned char *)(&d)+i) = *(*buffpp + offsets[i]);
+ }
+ }
+
+ printf("fetchieee754: FP: %s -> %s -> %e(=%s)\n", fmt_hex(*buffpp, length),
+ fmt_flt(sign, mantissa_high, mantissa_low, characteristic),
+ d, fmt_hex((unsigned char *)&d, length));
+ }
+#endif
+
+ *buffpp += fieldindex;
+
+ /*
+ * detect funny numbers
+ */
+ if (characteristic == maxexp)
+ {
+ /*
+ * NaN or Infinity
+ */
+ if (mantissa_low || mantissa_high)
+ {
+ /*
+ * NaN
+ */
+ return IEEE_NAN;
+ }
+ else
+ {
+ /*
+ * +Inf or -Inf
+ */
+ return sign ? IEEE_NEGINFINITY : IEEE_POSINFINITY;
+ }
+ }
+ else
+ {
+ /*
+ * collect real numbers
+ */
+
+ L_CLR(lfpp);
+
+ /*
+ * check for overflows
+ */
+ exponent = characteristic - bias;
+
+ if (exponent > 31) /* sorry - hardcoded */
+ {
+ /*
+ * overflow only in respect to NTP-FP representation
+ */
+ return sign ? IEEE_NEGOVERFLOW : IEEE_POSOVERFLOW;
+ }
+ else
+ {
+ int frac_offset; /* where the fraction starts */
+
+ frac_offset = mbits - exponent;
+
+ if (characteristic == 0)
+ {
+ /*
+ * de-normalized or tiny number - fits only as 0
+ */
+ return IEEE_OK;
+ }
+ else
+ {
+ /*
+ * adjust for implied 1
+ */
+ if (mbits > 31)
+ mantissa_high |= 1 << (mbits - 32);
+ else
+ mantissa_low |= 1 << mbits;
+
+ /*
+ * take mantissa apart - if only all machine would support
+ * 64 bit operations 8-(
+ */
+ if (frac_offset > mbits)
+ {
+ lfpp->l_ui = 0; /* only fractional number */
+ frac_offset -= mbits + 1; /* will now contain right shift count - 1*/
+ if (mbits > 31)
+ {
+ lfpp->l_uf = mantissa_high << (63 - mbits);
+ lfpp->l_uf |= mantissa_low >> (mbits - 33);
+ lfpp->l_uf >>= frac_offset;
+ }
+ else
+ {
+ lfpp->l_uf = mantissa_low >> frac_offset;
+ }
+ }
+ else
+ {
+ if (frac_offset > 32)
+ {
+ /*
+ * must split in high word
+ */
+ lfpp->l_ui = mantissa_high >> (frac_offset - 32);
+ lfpp->l_uf = (mantissa_high & ((1 << (frac_offset - 32)) - 1)) << (64 - frac_offset);
+ lfpp->l_uf |= mantissa_low >> (frac_offset - 32);
+ }
+ else
+ {
+ /*
+ * must split in low word
+ */
+ lfpp->l_ui = mantissa_high << (32 - frac_offset);
+ lfpp->l_ui |= (mantissa_low >> frac_offset) & ((1 << (32 - frac_offset)) - 1);
+ lfpp->l_uf = (mantissa_low & ((1 << frac_offset) - 1)) << (32 - frac_offset);
+ }
+ }
+
+ /*
+ * adjust for sign
+ */
+ if (sign)
+ {
+ L_NEG(lfpp);
+ }
+
+ return IEEE_OK;
+ }
+ }
+ }
+}
+
+int
+put_ieee754(
+ unsigned char **bufpp,
+ int size,
+ l_fp *lfpp,
+ offsets_t offsets
+ )
+{
+ l_fp outlfp;
+#ifdef LIBDEBUG
+ unsigned int sign;
+ unsigned int bias;
+#endif
+/*unsigned int maxexp;*/
+ int mbits;
+ int msb;
+ u_long mantissa_low = 0;
+ u_long mantissa_high = 0;
+#ifdef LIBDEBUG
+ u_long characteristic = 0;
+ long exponent;
+#endif
+/*int length;*/
+ unsigned long mask;
+
+ outlfp = *lfpp;
+
+ switch (size)
+ {
+ case IEEE_DOUBLE:
+ /*length = 8;*/
+ mbits = 52;
+#ifdef LIBDEBUG
+ bias = 1023;
+#endif
+ /*maxexp = 2047;*/
+ break;
+
+ case IEEE_SINGLE:
+ /*length = 4;*/
+ mbits = 23;
+#ifdef LIBDEBUG
+ bias = 127;
+#endif
+ /*maxexp = 255;*/
+ break;
+
+ default:
+ return IEEE_BADCALL;
+ }
+
+ /*
+ * find sign
+ */
+ if (L_ISNEG(&outlfp))
+ {
+ L_NEG(&outlfp);
+#ifdef LIBDEBUG
+ sign = 1;
+#endif
+ }
+ else
+ {
+#ifdef LIBDEBUG
+ sign = 0;
+#endif
+ }
+
+ if (L_ISZERO(&outlfp))
+ {
+#ifdef LIBDEBUG
+ exponent = mantissa_high = mantissa_low = 0; /* true zero */
+#endif
+ }
+ else
+ {
+ /*
+ * find number of significant integer bits
+ */
+ mask = 0x80000000;
+ if (outlfp.l_ui)
+ {
+ msb = 63;
+ while (mask && ((outlfp.l_ui & mask) == 0))
+ {
+ mask >>= 1;
+ msb--;
+ }
+ }
+ else
+ {
+ msb = 31;
+ while (mask && ((outlfp.l_uf & mask) == 0))
+ {
+ mask >>= 1;
+ msb--;
+ }
+ }
+
+ switch (size)
+ {
+ case IEEE_SINGLE:
+ mantissa_high = 0;
+ if (msb >= 32)
+ {
+ mantissa_low = (outlfp.l_ui & ((1 << (msb - 32)) - 1)) << (mbits - (msb - 32));
+ mantissa_low |= outlfp.l_uf >> (mbits - (msb - 32));
+ }
+ else
+ {
+ mantissa_low = (outlfp.l_uf << (mbits - msb)) & ((1 << mbits) - 1);
+ }
+ break;
+
+ case IEEE_DOUBLE:
+ if (msb >= 32)
+ {
+ mantissa_high = (outlfp.l_ui << (mbits - msb)) & ((1 << (mbits - 32)) - 1);
+ mantissa_high |= outlfp.l_uf >> (32 - (mbits - msb));
+ mantissa_low = (outlfp.l_ui & ((1 << (msb - mbits)) - 1)) << (32 - (msb - mbits));
+ mantissa_low |= outlfp.l_uf >> (msb - mbits);
+ }
+ else
+ {
+ mantissa_high = outlfp.l_uf << (mbits - 32 - msb);
+ mantissa_low = outlfp.l_uf << (mbits - 32);
+ }
+ }
+
+#ifdef LIBDEBUG
+ exponent = msb - 32;
+ characteristic = exponent + bias;
+
+ if (debug > 4)
+ printf("FP: %s\n", fmt_flt(sign, mantissa_high, mantissa_low, characteristic));
+#endif
+ }
+ return IEEE_OK;
+}
+
+
+#if defined(DEBUG) && defined(LIBDEBUG)
+int main(
+ int argc,
+ char **argv
+ )
+{
+ static offsets_t native_off = { 0, 1, 2, 3, 4, 5, 6, 7 };
+ double f = 1.0;
+ double *f_p = &f;
+ l_fp fp;
+
+ if (argc == 2)
+ {
+ if (sscanf(argv[1], "%lf", &f) != 1)
+ {
+ printf("cannot convert %s to a float\n", argv[1]);
+ return 1;
+ }
+ }
+
+ printf("double: %s %s\n", fmt_blong(*(unsigned long *)&f, 32), fmt_blong(*(unsigned long *)((char *)(&f)+4), 32));
+ printf("fetch from %f = %d\n", f, fetch_ieee754((void *)&f_p, IEEE_DOUBLE, &fp, native_off));
+ printf("fp [%s %s] = %s\n", fmt_blong(fp.l_ui, 32), fmt_blong(fp.l_uf, 32), mfptoa(fp.l_ui, fp.l_uf, 15));
+ f_p = &f;
+ put_ieee754((void *)&f_p, IEEE_DOUBLE, &fp, native_off);
+
+ return 0;
+}
+
+#endif
+/*
+ * ieee754io.c,v
+ * Revision 4.8 1999/02/21 12:17:36 kardel
+ * 4.91f reconcilation
+ *
+ * Revision 4.7 1999/02/21 11:26:03 kardel
+ * renamed index to fieldindex to avoid index() name clash
+ *
+ * Revision 4.6 1998/11/15 20:27:52 kardel
+ * Release 4.0.73e13 reconcilation
+ *
+ * Revision 4.5 1998/08/16 19:01:51 kardel
+ * debug information only compile for LIBDEBUG case
+ *
+ * Revision 4.4 1998/08/09 09:39:28 kardel
+ * Release 4.0.73e2 reconcilation
+ *
+ * Revision 4.3 1998/06/13 11:56:19 kardel
+ * disabled putbute() for the time being
+ *
+ * Revision 4.2 1998/06/12 15:16:58 kardel
+ * ansi2knr compatibility
+ *
+ * Revision 4.1 1998/05/24 07:59:56 kardel
+ * conditional debug support
+ *
+ * Revision 4.0 1998/04/10 19:46:29 kardel
+ * Start 4.0 release version numbering
+ *
+ * Revision 1.1 1998/04/10 19:27:46 kardel
+ * initial NTP VERSION 4 integration of PARSE with GPS166 binary support
+ *
+ * Revision 1.1 1997/10/06 21:05:45 kardel
+ * new parse structure
+ *
+ */
diff --git a/contrib/ntp/libntp/inttoa.c b/contrib/ntp/libntp/inttoa.c
new file mode 100644
index 0000000..f270733
--- /dev/null
+++ b/contrib/ntp/libntp/inttoa.c
@@ -0,0 +1,20 @@
+/*
+ * inttoa - return an asciized signed integer
+ */
+#include <stdio.h>
+
+#include "lib_strbuf.h"
+#include "ntp_stdlib.h"
+
+char *
+inttoa(
+ long ival
+ )
+{
+ register char *buf;
+
+ LIB_GETBUF(buf);
+
+ (void) sprintf(buf, "%ld", (long)ival);
+ return buf;
+}
diff --git a/contrib/ntp/libntp/iosignal.c b/contrib/ntp/libntp/iosignal.c
new file mode 100644
index 0000000..c8ec949
--- /dev/null
+++ b/contrib/ntp/libntp/iosignal.c
@@ -0,0 +1,518 @@
+/*
+ * ntp_io.c - input/output routines for ntpd. The socket-opening code
+ * was shamelessly stolen from ntpd.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <signal.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif /* HAVE_SYS_PARAM_H */
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+# include <sys/ioctl.h>
+#endif
+#ifdef HAVE_SYS_SOCKIO_H /* UXPV: SIOC* #defines (Frank Vance <fvance@waii.com>) */
+# include <sys/sockio.h>
+#endif
+#include <arpa/inet.h>
+
+#if _BSDI_VERSION >= 199510
+# include <ifaddrs.h>
+#endif
+/* 98/06/01 */
+#include "ntp_machine.h" /* 98/06/01 */
+#include "ntpd.h"
+#include "ntp_io.h"
+#include "ntp_if.h"
+#include "ntp_stdlib.h"
+#include "iosignal.h"
+
+#if defined(HAVE_SIGNALED_IO)
+static int sigio_block_count = 0;
+extern void input_handler P((l_fp *));
+
+/*
+ * SIGPOLL and SIGIO ROUTINES.
+ */
+
+ /*
+ * Some systems (MOST) define SIGPOLL == SIGIO, others SIGIO == SIGPOLL, and
+ * a few have separate SIGIO and SIGPOLL signals. This code checks for the
+ * SIGIO == SIGPOLL case at compile time.
+ * Do not defined USE_SIGPOLL or USE_SIGIO.
+ * these are interal only to ntp_io.c!
+ */
+# if defined(USE_SIGPOLL)
+# undef USE_SIGPOLL
+# endif
+# if defined(USE_SIGIO)
+# undef USE_SIGIO
+# endif
+
+# if defined(USE_TTY_SIGPOLL) || defined(USE_UDP_SIGPOLL)
+# define USE_SIGPOLL
+# endif
+
+# if !defined(USE_TTY_SIGPOLL) || !defined(USE_UDP_SIGPOLL)
+# define USE_SIGIO
+# endif
+
+# if defined(USE_SIGIO) && defined(USE_SIGPOLL)
+# if SIGIO == SIGPOLL
+# define USE_SIGIO
+# undef USE_SIGPOLL
+# endif /* SIGIO == SIGPOLL */
+# endif /* USE_SIGIO && USE_SIGIO */
+
+
+/*
+ * TTY initialization routines.
+ */
+int
+init_clock_sig(
+ struct refclockio *rio
+ )
+{
+# ifdef USE_TTY_SIGPOLL
+ {
+ /* DO NOT ATTEMPT TO MAKE CLOCK-FD A CTTY: not portable, unreliable */
+ if (ioctl(rio->fd, I_SETSIG, S_INPUT) < 0)
+ {
+ msyslog(LOG_ERR,
+ "init_clock_sig: ioctl(I_SETSIG, S_INPUT) failed: %m");
+ return 1;
+ }
+ return 0;
+ }
+# else
+ /*
+ * Special cases first!
+ */
+ /* Was: defined(SYS_HPUX) */
+# if defined(FIOSSAIOOWN) && defined(FIOSNBIO) && defined(FIOSSAIOSTAT)
+#define CLOCK_DONE
+ {
+ int pgrp, on = 1;
+
+ /* DO NOT ATTEMPT TO MAKE CLOCK-FD A CTTY: not portable, unreliable */
+ pgrp = getpid();
+ if (ioctl(rio->fd, FIOSSAIOOWN, (char *)&pgrp) == -1)
+ {
+ msyslog(LOG_ERR, "ioctl(FIOSSAIOOWN) fails for clock I/O: %m");
+ exit(1);
+ /*NOTREACHED*/
+ }
+
+ /*
+ * set non-blocking, async I/O on the descriptor
+ */
+ if (ioctl(rio->fd, FIOSNBIO, (char *)&on) == -1)
+ {
+ msyslog(LOG_ERR, "ioctl(FIOSNBIO) fails for clock I/O: %m");
+ exit(1);
+ /*NOTREACHED*/
+ }
+
+ if (ioctl(rio->fd, FIOSSAIOSTAT, (char *)&on) == -1)
+ {
+ msyslog(LOG_ERR, "ioctl(FIOSSAIOSTAT) fails for clock I/O: %m");
+ exit(1);
+ /*NOTREACHED*/
+ }
+ return 0;
+ }
+# endif /* SYS_HPUX: FIOSSAIOOWN && FIOSNBIO && FIOSSAIOSTAT */
+ /* Was: defined(SYS_AIX) && !defined(_BSD) */
+# if !defined(_BSD) && defined(_AIX) && defined(FIOASYNC) && defined(FIOSETOWN)
+ /*
+ * SYSV compatibility mode under AIX.
+ */
+#define CLOCK_DONE
+ {
+ int pgrp, on = 1;
+
+ /* DO NOT ATTEMPT TO MAKE CLOCK-FD A CTTY: not portable, unreliable */
+ if (ioctl(rio->fd, FIOASYNC, (char *)&on) == -1)
+ {
+ msyslog(LOG_ERR, "ioctl(FIOASYNC) fails for clock I/O: %m");
+ return 1;
+ }
+ pgrp = -getpid();
+ if (ioctl(rio->fd, FIOSETOWN, (char*)&pgrp) == -1)
+ {
+ msyslog(LOG_ERR, "ioctl(FIOSETOWN) fails for clock I/O: %m");
+ return 1;
+ }
+
+ if (fcntl(rio->fd, F_SETFL, FNDELAY|FASYNC) < 0)
+ {
+ msyslog(LOG_ERR, "fcntl(FNDELAY|FASYNC) fails for clock I/O: %m");
+ return 1;
+ }
+ return 0;
+ }
+# endif /* AIX && !BSD: !_BSD && FIOASYNC && FIOSETOWN */
+# ifndef CLOCK_DONE
+ {
+ /* DO NOT ATTEMPT TO MAKE CLOCK-FD A CTTY: not portable, unreliable */
+# if defined(TIOCSCTTY) && defined(USE_FSETOWNCTTY)
+ /*
+ * there are, however, always exceptions to the rules
+ * one is, that OSF accepts SETOWN on TTY fd's only, iff they are
+ * CTTYs. SunOS and HPUX do not semm to have this restriction.
+ * another question is: how can you do multiple SIGIO from several
+ * ttys (as they all should be CTTYs), wondering...
+ *
+ * kd 95-07-16
+ */
+ if (ioctl(rio->fd, TIOCSCTTY, 0) == -1)
+ {
+ msyslog(LOG_ERR, "ioctl(TIOCSCTTY, 0) fails for clock I/O: %m");
+ return 1;
+ }
+# endif /* TIOCSCTTY && USE_FSETOWNCTTY */
+
+ if (fcntl(rio->fd, F_SETOWN, getpid()) == -1)
+ {
+ msyslog(LOG_ERR, "fcntl(F_SETOWN) fails for clock I/O: %m");
+ return 1;
+ }
+
+ if (fcntl(rio->fd, F_SETFL, FNDELAY|FASYNC) < 0)
+ {
+ msyslog(LOG_ERR,
+ "fcntl(FNDELAY|FASYNC) fails for clock I/O: %m");
+ return 1;
+ }
+ return 0;
+ }
+# endif /* CLOCK_DONE */
+# endif /* !USE_TTY_SIGPOLL */
+}
+
+
+
+void
+init_socket_sig(
+ int fd
+ )
+{
+# ifdef USE_UDP_SIGPOLL
+ {
+ if (ioctl(fd, I_SETSIG, S_INPUT) < 0)
+ {
+ msyslog(LOG_ERR,
+ "init_socket_sig: ioctl(I_SETSIG, S_INPUT) failed: %m");
+ exit(1);
+ }
+ }
+# else /* USE_UDP_SIGPOLL */
+ {
+ int pgrp;
+# ifdef FIOASYNC
+ int on = 1;
+# endif
+
+# if defined(FIOASYNC)
+ if (ioctl(fd, FIOASYNC, (char *)&on) == -1)
+ {
+ msyslog(LOG_ERR, "ioctl(FIOASYNC) fails: %m");
+ exit(1);
+ /*NOTREACHED*/
+ }
+# elif defined(FASYNC)
+ {
+ int flags;
+
+ if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
+ {
+ msyslog(LOG_ERR, "fcntl(F_GETFL) fails: %m");
+ exit(1);
+ /*NOTREACHED*/
+ }
+ if (fcntl(fd, F_SETFL, flags|FASYNC) < 0)
+ {
+ msyslog(LOG_ERR, "fcntl(...|FASYNC) fails: %m");
+ exit(1);
+ /*NOTREACHED*/
+ }
+ }
+# else
+# include "Bletch: Need asynchronous I/O!"
+# endif
+
+# ifdef UDP_BACKWARDS_SETOWN
+ pgrp = -getpid();
+# else
+ pgrp = getpid();
+# endif
+
+# if defined(SIOCSPGRP)
+ if (ioctl(fd, SIOCSPGRP, (char *)&pgrp) == -1)
+ {
+ msyslog(LOG_ERR, "ioctl(SIOCSPGRP) fails: %m");
+ exit(1);
+ /*NOTREACHED*/
+ }
+# elif defined(FIOSETOWN)
+ if (ioctl(fd, FIOSETOWN, (char*)&pgrp) == -1)
+ {
+ msyslog(LOG_ERR, "ioctl(FIOSETOWN) fails: %m");
+ exit(1);
+ /*NOTREACHED*/
+ }
+# elif defined(F_SETOWN)
+ if (fcntl(fd, F_SETOWN, pgrp) == -1)
+ {
+ msyslog(LOG_ERR, "fcntl(F_SETOWN) fails: %m");
+ exit(1);
+ /*NOTREACHED*/
+ }
+# else
+# include "Bletch: Need to set process(group) to receive SIG(IO|POLL)"
+# endif
+ }
+# endif /* USE_UDP_SIGPOLL */
+}
+
+RETSIGTYPE
+sigio_handler(
+ int sig
+ )
+{
+ int saved_errno = errno;
+ l_fp ts;
+
+ get_systime(&ts);
+ (void)input_handler(&ts);
+ errno = saved_errno;
+}
+
+/*
+ * Signal support routines.
+ */
+# ifdef HAVE_SIGACTION
+void
+set_signal(void)
+{
+# ifdef USE_SIGIO
+ (void) signal_no_reset(SIGIO, sigio_handler);
+# endif
+# ifdef USE_SIGPOLL
+ (void) signal_no_reset(SIGPOLL, sigio_handler);
+# endif
+}
+
+void
+block_io_and_alarm(void)
+{
+ sigset_t set;
+
+ if (sigemptyset(&set))
+ msyslog(LOG_ERR, "block_io_and_alarm: sigemptyset() failed: %m");
+# if defined(USE_SIGIO)
+ if (sigaddset(&set, SIGIO))
+ msyslog(LOG_ERR, "block_io_and_alarm: sigaddset(SIGIO) failed: %m");
+# endif
+# if defined(USE_SIGPOLL)
+ if (sigaddset(&set, SIGPOLL))
+ msyslog(LOG_ERR, "block_io_and_alarm: sigaddset(SIGPOLL) failed: %m");
+# endif
+ if (sigaddset(&set, SIGALRM))
+ msyslog(LOG_ERR, "block_io_and_alarm: sigaddset(SIGALRM) failed: %m");
+
+ if (sigprocmask(SIG_BLOCK, &set, NULL))
+ msyslog(LOG_ERR, "block_io_and_alarm: sigprocmask() failed: %m");
+}
+
+void
+block_sigio(void)
+{
+ sigset_t set;
+
+ ++sigio_block_count;
+ if (sigio_block_count > 1)
+ msyslog(LOG_INFO, "block_sigio: sigio_block_count > 1");
+ if (sigio_block_count < 1)
+ msyslog(LOG_INFO, "block_sigio: sigio_block_count < 1");
+
+ if (sigemptyset(&set))
+ msyslog(LOG_ERR, "block_sigio: sigemptyset() failed: %m");
+# if defined(USE_SIGIO)
+ if (sigaddset(&set, SIGIO))
+ msyslog(LOG_ERR, "block_sigio: sigaddset(SIGIO) failed: %m");
+# endif
+# if defined(USE_SIGPOLL)
+ if (sigaddset(&set, SIGPOLL))
+ msyslog(LOG_ERR, "block_sigio: sigaddset(SIGPOLL) failed: %m");
+# endif
+
+ if (sigprocmask(SIG_BLOCK, &set, NULL))
+ msyslog(LOG_ERR, "block_sigio: sigprocmask() failed: %m");
+}
+
+void
+unblock_io_and_alarm(void)
+{
+ sigset_t unset;
+
+ if (sigemptyset(&unset))
+ msyslog(LOG_ERR, "unblock_io_and_alarm: sigemptyset() failed: %m");
+
+# if defined(USE_SIGIO)
+ if (sigaddset(&unset, SIGIO))
+ msyslog(LOG_ERR, "unblock_io_and_alarm: sigaddset(SIGIO) failed: %m");
+# endif
+# if defined(USE_SIGPOLL)
+ if (sigaddset(&unset, SIGPOLL))
+ msyslog(LOG_ERR, "unblock_io_and_alarm: sigaddset(SIGPOLL) failed: %m");
+# endif
+ if (sigaddset(&unset, SIGALRM))
+ msyslog(LOG_ERR, "unblock_io_and_alarm: sigaddset(SIGALRM) failed: %m");
+
+ if (sigprocmask(SIG_UNBLOCK, &unset, NULL))
+ msyslog(LOG_ERR, "unblock_io_and_alarm: sigprocmask() failed: %m");
+}
+
+void
+unblock_sigio(void)
+{
+ sigset_t unset;
+
+ --sigio_block_count;
+ if (sigio_block_count > 0)
+ msyslog(LOG_INFO, "unblock_sigio: sigio_block_count > 0");
+ if (sigio_block_count < 0)
+ msyslog(LOG_INFO, "unblock_sigio: sigio_block_count < 0");
+
+ if (sigemptyset(&unset))
+ msyslog(LOG_ERR, "unblock_sigio: sigemptyset() failed: %m");
+
+# if defined(USE_SIGIO)
+ if (sigaddset(&unset, SIGIO))
+ msyslog(LOG_ERR, "unblock_sigio: sigaddset(SIGIO) failed: %m");
+# endif
+# if defined(USE_SIGPOLL)
+ if (sigaddset(&unset, SIGPOLL))
+ msyslog(LOG_ERR, "unblock_sigio: sigaddset(SIGPOLL) failed: %m");
+# endif
+
+ if (sigprocmask(SIG_UNBLOCK, &unset, NULL))
+ msyslog(LOG_ERR, "unblock_sigio: sigprocmask() failed: %m");
+}
+
+void
+wait_for_signal(void)
+{
+ sigset_t old;
+
+ if (sigprocmask(SIG_UNBLOCK, NULL, &old))
+ msyslog(LOG_ERR, "wait_for_signal: sigprocmask() failed: %m");
+
+# if defined(USE_SIGIO)
+ if (sigdelset(&old, SIGIO))
+ msyslog(LOG_ERR, "wait_for_signal: sigdelset(SIGIO) failed: %m");
+# endif
+# if defined(USE_SIGPOLL)
+ if (sigdelset(&old, SIGPOLL))
+ msyslog(LOG_ERR, "wait_for_signal: sigdelset(SIGPOLL) failed: %m");
+# endif
+ if (sigdelset(&old, SIGALRM))
+ msyslog(LOG_ERR, "wait_for_signal: sigdelset(SIGALRM) failed: %m");
+
+ if (sigsuspend(&old) && (errno != EINTR))
+ msyslog(LOG_ERR, "wait_for_signal: sigsuspend() failed: %m");
+}
+
+# else /* !HAVE_SIGACTION */
+/*
+ * Must be an old bsd system.
+ * We assume there is no SIGPOLL.
+ */
+
+void
+block_io_and_alarm(void)
+{
+ int mask;
+
+ mask = sigmask(SIGIO) | sigmask(SIGALRM);
+ if (sigblock(mask))
+ msyslog(LOG_ERR, "block_io_and_alarm: sigblock() failed: %m");
+}
+
+void
+block_sigio(void)
+{
+ int mask;
+
+ ++sigio_block_count;
+ if (sigio_block_count > 1)
+ msyslog(LOG_INFO, "block_sigio: sigio_block_count > 1");
+ if (sigio_block_count < 1)
+ msyslog(LOG_INFO, "block_sigio: sigio_block_count < 1");
+
+ mask = sigmask(SIGIO);
+ if (sigblock(mask))
+ msyslog(LOG_ERR, "block_sigio: sigblock() failed: %m");
+}
+
+void
+set_signal(void)
+{
+ (void) signal_no_reset(SIGIO, sigio_handler);
+}
+
+void
+unblock_io_and_alarm(void)
+{
+ int mask, omask;
+
+ mask = sigmask(SIGIO) | sigmask(SIGALRM);
+ omask = sigblock(0);
+ omask &= ~mask;
+ (void) sigsetmask(omask);
+}
+
+void
+unblock_sigio(void)
+{
+ int mask, omask;
+
+ --sigio_block_count;
+ if (sigio_block_count > 0)
+ msyslog(LOG_INFO, "unblock_sigio: sigio_block_count > 0");
+ if (sigio_block_count < 0)
+ msyslog(LOG_INFO, "unblock_sigio: sigio_block_count < 0");
+ mask = sigmask(SIGIO);
+ omask = sigblock(0);
+ omask &= ~mask;
+ (void) sigsetmask(omask);
+}
+
+void
+wait_for_signal(void)
+{
+ int mask, omask;
+
+ mask = sigmask(SIGIO) | sigmask(SIGALRM);
+ omask = sigblock(0);
+ omask &= ~mask;
+ if (sigpause(omask) && (errno != EINTR))
+ msyslog(LOG_ERR, "wait_for_signal: sigspause() failed: %m");
+}
+
+# endif /* HAVE_SIGACTION */
+#else
+int NotAnEmptyCompilationUnit;
+#endif
diff --git a/contrib/ntp/libntp/lib_strbuf.c b/contrib/ntp/libntp/lib_strbuf.c
new file mode 100644
index 0000000..690f1ad
--- /dev/null
+++ b/contrib/ntp/libntp/lib_strbuf.c
@@ -0,0 +1,22 @@
+/*
+ * lib_strbuf - library string storage
+ */
+
+#include "lib_strbuf.h"
+
+/*
+ * Storage declarations
+ */
+char lib_stringbuf[LIB_NUMBUFS][LIB_BUFLENGTH];
+int lib_nextbuf;
+int lib_inited = 0;
+
+/*
+ * initialization routine. Might be needed if the code is ROMized.
+ */
+void
+init_lib(void)
+{
+ lib_nextbuf = 0;
+ lib_inited = 1;
+}
diff --git a/contrib/ntp/libntp/lib_strbuf.h b/contrib/ntp/libntp/lib_strbuf.h
new file mode 100644
index 0000000..1a34034
--- /dev/null
+++ b/contrib/ntp/libntp/lib_strbuf.h
@@ -0,0 +1,27 @@
+/*
+ * lib_strbuf.h - definitions for routines which use the common string buffers
+ */
+
+#include <ntp_types.h>
+
+/*
+ * Sizes of things
+ */
+#define LIB_NUMBUFS 20
+#define LIB_BUFLENGTH 80
+
+/*
+ * Macro to get a pointer to the next buffer
+ */
+#define LIB_GETBUF(buf) \
+ do { \
+ if (!lib_inited) \
+ init_lib(); \
+ buf = &lib_stringbuf[lib_nextbuf][0]; \
+ if (++lib_nextbuf >= LIB_NUMBUFS) \
+ lib_nextbuf = 0; \
+ } while (0)
+
+extern char lib_stringbuf[LIB_NUMBUFS][LIB_BUFLENGTH];
+extern int lib_nextbuf;
+extern int lib_inited;
diff --git a/contrib/ntp/libntp/log.c b/contrib/ntp/libntp/log.c
new file mode 100644
index 0000000..e694361
--- /dev/null
+++ b/contrib/ntp/libntp/log.c
@@ -0,0 +1,152 @@
+/* Microsoft Developer Support Copyright (c) 1993 Microsoft Corporation. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <windows.h>
+
+#include "messages.h"
+#include "log.h"
+
+#define PERR(bSuccess, api) {if(!(bSuccess)) printf("%s: Error %d from %s \
+ on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
+
+
+/*********************************************************************
+* FUNCTION: addSourceToRegistry(void) *
+* *
+* PURPOSE: Add a source name key, message DLL name value, and *
+* message type supported value to the registry *
+* *
+* INPUT: source name, path of message DLL *
+* *
+* RETURNS: none *
+*********************************************************************/
+
+void addSourceToRegistry(LPSTR pszAppname, LPSTR pszMsgDLL)
+{
+ HKEY hk; /* registry key handle */
+ DWORD dwData;
+ BOOL bSuccess;
+
+ /* When an application uses the RegisterEventSource or OpenEventLog
+ function to get a handle of an event log, the event loggging service
+ searches for the specified source name in the registry. You can add a
+ new source name to the registry by opening a new registry subkey
+ under the Application key and adding registry values to the new
+ subkey. */
+
+ /* Create a new key for our application */
+ bSuccess = RegCreateKey(HKEY_LOCAL_MACHINE,
+ "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\NTP", &hk);
+ PERR(bSuccess == ERROR_SUCCESS, "RegCreateKey");
+
+ /* Add the Event-ID message-file name to the subkey. */
+ bSuccess = RegSetValueEx(hk, /* subkey handle */
+ "EventMessageFile", /* value name */
+ 0, /* must be zero */
+ REG_EXPAND_SZ, /* value type */
+ (LPBYTE) pszMsgDLL, /* address of value data */
+ strlen(pszMsgDLL) + 1); /* length of value data */
+ PERR(bSuccess == ERROR_SUCCESS, "RegSetValueEx");
+
+ /* Set the supported types flags and addit to the subkey. */
+ dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
+ EVENTLOG_INFORMATION_TYPE;
+ bSuccess = RegSetValueEx(hk, /* subkey handle */
+ "TypesSupported", /* value name */
+ 0, /* must be zero */
+ REG_DWORD, /* value type */
+ (LPBYTE) &dwData, /* address of value data */
+ sizeof(DWORD)); /* length of value data */
+ PERR(bSuccess == ERROR_SUCCESS, "RegSetValueEx");
+ RegCloseKey(hk);
+ return;
+}
+
+/*********************************************************************
+* FUNCTION: reportAnEvent(DWORD dwIdEvent, WORD cStrings, *
+* LPTSTR *ppszStrings); *
+* *
+* PURPOSE: add the event to the event log *
+* *
+* INPUT: the event ID to report in the log, the number of insert *
+* strings, and an array of null-terminated insert strings *
+* *
+* RETURNS: none *
+*********************************************************************/
+
+void reportAnIEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
+{
+ HANDLE hAppLog;
+ BOOL bSuccess;
+
+ /* Get a handle to the Application event log */
+ hAppLog = RegisterEventSource(NULL, /* use local machine */
+ "NTP"); /* source name */
+ PERR(hAppLog, "RegisterEventSource");
+
+ /* Now report the event, which will add this event to the event log */
+ bSuccess = ReportEvent(hAppLog, /* event-log handle */
+ EVENTLOG_INFORMATION_TYPE, /* event type */
+ 0, /* category zero */
+ dwIdEvent, /* event ID */
+ NULL, /* no user SID */
+ cStrings, /* number of substitution strings */
+ 0, /* no binary data */
+ pszStrings, /* string array */
+ NULL); /* address of data */
+ PERR(bSuccess, "ReportEvent");
+ DeregisterEventSource(hAppLog);
+ return;
+}
+
+void reportAnWEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
+{
+ HANDLE hAppLog;
+ BOOL bSuccess;
+
+ /* Get a handle to the Application event log */
+ hAppLog = RegisterEventSource(NULL, /* use local machine */
+ "NTP"); /* source name */
+ PERR(hAppLog, "RegisterEventSource");
+
+ /* Now report the event, which will add this event to the event log */
+ bSuccess = ReportEvent(hAppLog, /* event-log handle */
+ EVENTLOG_WARNING_TYPE, /* event type */
+ 0, /* category zero */
+ dwIdEvent, /* event ID */
+ NULL, /* no user SID */
+ cStrings, /* number of substitution strings */
+ 0, /* no binary data */
+ pszStrings, /* string array */
+ NULL); /* address of data */
+ PERR(bSuccess, "ReportEvent");
+ DeregisterEventSource(hAppLog);
+ return;
+}
+
+void reportAnEEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
+{
+ HANDLE hAppLog;
+ BOOL bSuccess;
+
+ /* Get a handle to the Application event log */
+ hAppLog = RegisterEventSource(NULL, /* use local machine */
+ "NTP"); /* source name */
+ PERR(hAppLog, "RegisterEventSource");
+
+ /* Now report the event, which will add this event to the event log */
+ bSuccess = ReportEvent(hAppLog, /* event-log handle */
+ EVENTLOG_ERROR_TYPE, /* event type */
+ 0, /* category zero */
+ dwIdEvent, /* event ID */
+ NULL, /* no user SID */
+ cStrings, /* number of substitution strings */
+ 0, /* no binary data */
+ pszStrings, /* string array */
+ NULL); /* address of data */
+ PERR(bSuccess, "ReportEvent");
+ DeregisterEventSource(hAppLog);
+ return;
+}
diff --git a/contrib/ntp/libntp/log.h b/contrib/ntp/libntp/log.h
new file mode 100644
index 0000000..99d0e72
--- /dev/null
+++ b/contrib/ntp/libntp/log.h
@@ -0,0 +1,21 @@
+/*
+ * log.h - Used only under Windows NT by msyslog.c
+ *
+ */
+#ifndef WINNT_LOG_H
+#define WINNT_LOG_H
+
+#include <windows.h>
+
+/* function declarations */
+
+void addSourceToRegistry(LPSTR pszAppname, LPSTR pszMsgDLL);
+void reportAnIEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings);
+void reportAnWEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings);
+void reportAnEEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings);
+
+#define MAX_MSG_LENGTH 1024
+#define MSG_ID_MASK 0x0000FFFF
+#define MAX_INSERT_STRS 8
+
+#endif /* WINNT_LOG_H */
diff --git a/contrib/ntp/libntp/machines.c b/contrib/ntp/libntp/machines.c
new file mode 100644
index 0000000..bbcfd54
--- /dev/null
+++ b/contrib/ntp/libntp/machines.c
@@ -0,0 +1,218 @@
+/* machines.c - provide special support for peculiar architectures
+ *
+ * Real bummers unite !
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "ntp_machine.h"
+#include "ntp_syslog.h"
+#include "ntp_stdlib.h"
+#include "ntp_unixtime.h"
+
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef SYS_WINNT
+# include <conio.h>
+#else
+
+#ifdef SYS_VXWORKS
+#include "taskLib.h"
+#include "sysLib.h"
+#include "time.h"
+#include "ntp_syslog.h"
+
+/* some translations to the world of vxWorkings -casey */
+/* first some netdb type things */
+#include "ioLib.h"
+#include <socket.h>
+int h_errno;
+
+struct hostent *gethostbyname(char *name)
+ {
+ struct hostent *host1;
+ h_errno = 0; /* we are always successful!!! */
+ host1 = (struct hostent *) malloc (sizeof(struct hostent));
+ host1->h_name = name;
+ host1->h_addrtype = AF_INET;
+ host1->h_aliases = name;
+ host1->h_length = 4;
+ host1->h_addr_list[0] = (char *)hostGetByName (name);
+ host1->h_addr_list[1] = NULL;
+ return host1;
+ }
+
+struct hostent *gethostbyaddr(char *name, int size, int addr_type)
+ {
+ struct hostent *host1;
+ h_errno = 0; /* we are always successful!!! */
+ host1 = (struct hostent *) malloc (sizeof(struct hostent));
+ host1->h_name = name;
+ host1->h_addrtype = AF_INET;
+ host1->h_aliases = name;
+ host1->h_length = 4;
+ host1->h_addr_list = NULL;
+ return host1;
+ }
+
+struct servent *getservbyname (char *name, char *type)
+ {
+ struct servent *serv1;
+ serv1 = (struct servent *) malloc (sizeof(struct servent));
+ serv1->s_name = "ntp"; /* official service name */
+ serv1->s_aliases = NULL; /* alias list */
+ serv1->s_port = 123; /* port # */
+ serv1->s_proto = "udp"; /* protocol to use */
+ return serv1;
+ }
+
+/* second
+ * vxworks thinks it has insomnia
+ * we have to sleep for number of seconds
+ */
+
+#define CLKRATE sysClkRateGet()
+
+/* I am not sure how valid the granularity is - it is from G. Eger's port */
+#define CLK_GRANULARITY 1 /* Granularity of system clock in usec */
+ /* Used to round down # usecs/tick */
+ /* On a VCOM-100, PIT gets 8 MHz clk, */
+ /* & it prescales by 32, thus 4 usec */
+ /* on mv167, granularity is 1usec anyway*/
+ /* To defeat rounding, set to 1 */
+#define USECS_PER_SEC MILLION /* Microseconds per second */
+#define TICK (((USECS_PER_SEC / CLKRATE) / CLK_GRANULARITY) * CLK_GRANULARITY)
+
+/* emulate unix sleep
+ * casey
+ */
+void sleep(int seconds)
+ {
+ taskDelay(seconds*TICK);
+ }
+/* emulate unix alarm
+ * that pauses and calls SIGALRM after the seconds are up...
+ * so ... taskDelay() fudged for seconds should amount to the same thing.
+ * casey
+ */
+void alarm (int seconds)
+ {
+ sleep(seconds);
+ }
+
+#endif /* SYS_VXWORKS */
+
+#ifdef SYS_PTX /* Does PTX still need this? */
+/*#include <sys/types.h> */
+#include <sys/procstats.h>
+
+int
+gettimeofday(
+ struct timeval *tvp
+ )
+{
+ /*
+ * hi, this is Sequents sneak path to get to a clock
+ * this is also the most logical syscall for such a function
+ */
+ return (get_process_stats(tvp, PS_SELF, (struct procstats *) 0,
+ (struct procstats *) 0));
+}
+#endif /* SYS_PTX */
+
+const char *set_tod_using = "UNKNOWN";
+
+int
+ntp_set_tod(
+ struct timeval *tvp,
+ void *tzp
+ )
+{
+ int rc;
+
+#ifdef HAVE_CLOCK_SETTIME
+ {
+ struct timespec ts;
+
+ /* Convert timeval to timespec */
+ ts.tv_sec = tvp->tv_sec;
+ ts.tv_nsec = 1000 * tvp->tv_usec;
+
+ rc = clock_settime(CLOCK_REALTIME, &ts);
+ if (!rc)
+ {
+ set_tod_using = "clock_settime";
+ return rc;
+ }
+ }
+#endif /* HAVE_CLOCK_SETTIME */
+#ifdef HAVE_SETTIMEOFDAY
+ {
+ rc = SETTIMEOFDAY(tvp, tzp);
+ if (!rc)
+ {
+ set_tod_using = "settimeofday";
+ return rc;
+ }
+ }
+#endif /* HAVE_SETTIMEOFDAY */
+#ifdef HAVE_STIME
+ {
+ long tp = tvp->tv_sec;
+
+ rc = stime(&tp); /* lie as bad as SysVR4 */
+ if (!rc)
+ {
+ set_tod_using = "stime";
+ return rc;
+ }
+ }
+#endif /* HAVE_STIME */
+ set_tod_using = "Failed!";
+ return -1;
+}
+
+#endif /* not SYS_WINNT */
+
+#if defined (SYS_WINNT) || defined (SYS_VXWORKS)
+/* getpass is used in ntpq.c and ntpdc.c */
+
+char *
+getpass(const char * prompt)
+{
+ int c, i;
+ static char password[32];
+#ifdef DEBUG
+ fprintf(stderr, "%s", prompt);
+ fflush(stderr);
+#endif
+ for (i=0; i<sizeof(password)-1 && ((c=_getch())!='\n'); i++) {
+ password[i] = (char) c;
+ }
+ password[i] = '\0';
+
+ return password;
+}
+#endif /* SYS_WINNT */
+
+#if !defined(HAVE_MEMSET)
+void
+ntp_memset(
+ char *a,
+ int x,
+ int c
+ )
+{
+ while (c-- > 0)
+ *a++ = (char) x;
+}
+#endif /*POSIX*/
diff --git a/contrib/ntp/libntp/md5c.c b/contrib/ntp/libntp/md5c.c
new file mode 100644
index 0000000..00b3c6b
--- /dev/null
+++ b/contrib/ntp/libntp/md5c.c
@@ -0,0 +1,350 @@
+/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
+ */
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+ rights reserved.
+
+ License to copy and use this software is granted provided that it
+ is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+ Algorithm" in all material mentioning or referencing this software
+ or this function.
+
+ License is also granted to make and use derivative works provided
+ that such works are identified as "derived from the RSA Data
+ Security, Inc. MD5 Message-Digest Algorithm" in all material
+ mentioning or referencing the derived work.
+
+ RSA Data Security, Inc. makes no representations concerning either
+ the merchantability of this software or the suitability of this
+ software for any particular purpose. It is provided "as is"
+ without express or implied warranty of any kind.
+
+ These notices must be retained in any copies of any part of this
+ documentation and/or software.
+ */
+
+#include "global.h"
+#include "md5.h"
+
+/* Constants for MD5Transform routine.
+ */
+#define S11 7
+#define S12 12
+#define S13 17
+#define S14 22
+#define S21 5
+#define S22 9
+#define S23 14
+#define S24 20
+#define S31 4
+#define S32 11
+#define S33 16
+#define S34 23
+#define S41 6
+#define S42 10
+#define S43 15
+#define S44 21
+
+static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
+static void Encode PROTO_LIST
+ ((unsigned char *, UINT4 *, unsigned int));
+static void Decode PROTO_LIST
+ ((UINT4 *, unsigned char *, unsigned int));
+static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
+static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
+
+static unsigned char PADDING[64] = {
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/* F, G, H and I are basic MD5 functions.
+ */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+/* ROTATE_LEFT rotates x left n bits.
+ */
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+ Rotation is separate from addition to prevent recomputation.
+ */
+#define FF(a, b, c, d, x, s, ac) { \
+ (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define GG(a, b, c, d, x, s, ac) { \
+ (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define HH(a, b, c, d, x, s, ac) { \
+ (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define II(a, b, c, d, x, s, ac) { \
+ (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+
+/* MD5 initialization. Begins an MD5 operation, writing a new context.
+ */
+void
+MD5Init(
+ MD5_CTX *context /* context */
+ )
+{
+ context->count[0] = context->count[1] = 0;
+
+ /* Load magic initialization constants.
+ */
+ context->state[0] = 0x67452301;
+ context->state[1] = 0xefcdab89;
+ context->state[2] = 0x98badcfe;
+ context->state[3] = 0x10325476;
+}
+
+/* MD5 block update operation. Continues an MD5 message-digest
+ operation, processing another message block, and updating the
+ context.
+ */
+void
+MD5Update (
+ MD5_CTX *context, /* context */
+ unsigned char *input, /* input block */
+ unsigned int inputLen /* length of input block */
+ )
+{
+ unsigned int i, index, partLen;
+
+ /* Compute number of bytes mod 64 */
+ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+
+ /* Update number of bits */
+ if ((context->count[0] += ((UINT4)inputLen << 3))
+ < ((UINT4)inputLen << 3))
+ context->count[1]++;
+ context->count[1] += ((UINT4)inputLen >> 29);
+
+ partLen = 64 - index;
+
+ /* Transform as many times as possible.
+ */
+ if (inputLen >= partLen) {
+ MD5_memcpy
+ ((POINTER)&context->buffer[index], (POINTER)input, partLen);
+ MD5Transform (context->state, context->buffer);
+
+ for (i = partLen; i + 63 < inputLen; i += 64)
+ MD5Transform (context->state, &input[i]);
+
+ index = 0;
+ }
+ else
+ i = 0;
+
+ /* Buffer remaining input */
+ MD5_memcpy
+ ((POINTER)&context->buffer[index], (POINTER)&input[i],
+ inputLen-i);
+}
+
+/* MD5 finalization. Ends an MD5 message-digest operation, writing the
+ the message digest and zeroizing the context.
+ */
+void
+MD5Final (
+ unsigned char digest[16], /* message digest */
+ MD5_CTX *context /* context */
+ )
+{
+ unsigned char bits[8];
+ unsigned int index, padLen;
+
+ /* Save number of bits */
+ Encode (bits, context->count, 8);
+
+ /* Pad out to 56 mod 64.
+ */
+ index = (unsigned int)((context->count[0] >> 3) & 0x3f);
+ padLen = (index < 56) ? (56 - index) : (120 - index);
+ MD5Update (context, PADDING, padLen);
+
+ /* Append length (before padding) */
+ MD5Update (context, bits, 8);
+
+ /* Store state in digest */
+ Encode (digest, context->state, 16);
+
+ /* Zeroize sensitive information.
+ */
+ MD5_memset ((POINTER)context, 0, sizeof (*context));
+}
+
+/* MD5 basic transformation. Transforms state based on block.
+ */
+static void
+MD5Transform (
+ UINT4 state[4],
+ unsigned char block[64]
+ )
+{
+ UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+
+ Decode (x, block, 64);
+
+ /* Round 1 */
+ FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
+ FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
+ FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
+ FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
+ FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
+ FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
+ FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
+ FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
+ FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
+ FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
+ FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
+ FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
+ FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
+ FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
+ FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
+ FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
+
+ /* Round 2 */
+ GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
+ GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
+ GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
+ GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
+ GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
+ GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
+ GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
+ GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
+ GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
+ GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
+ GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
+ GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
+ GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
+ GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
+ GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
+ GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
+
+ /* Round 3 */
+ HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
+ HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
+ HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
+ HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
+ HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
+ HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
+ HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
+ HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
+ HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
+ HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
+ HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
+ HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
+ HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
+ HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
+ HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
+ HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
+
+ /* Round 4 */
+ II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
+ II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
+ II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
+ II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
+ II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
+ II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
+ II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
+ II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
+ II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
+ II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
+ II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
+ II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
+ II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
+ II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
+ II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
+ II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
+
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+
+ /* Zeroize sensitive information.
+ */
+ MD5_memset ((POINTER)x, 0, sizeof (x));
+}
+
+/* Encodes input (UINT4) into output (unsigned char). Assumes len is
+ a multiple of 4.
+ */
+static void
+Encode (
+ unsigned char *output,
+ UINT4 *input,
+ unsigned int len
+ )
+{
+ unsigned int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4) {
+ output[j] = (unsigned char)(input[i] & 0xff);
+ output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
+ output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
+ output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
+ }
+}
+
+/* Decodes input (unsigned char) into output (UINT4). Assumes len is
+ a multiple of 4.
+ */
+static void
+Decode (
+ UINT4 *output,
+ unsigned char *input,
+ unsigned int len
+ )
+{
+ unsigned int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4)
+ output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
+ (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
+}
+
+/* Note: Replace "for loop" with standard memcpy if possible.
+ */
+static void
+MD5_memcpy (
+ POINTER output,
+ POINTER input,
+ unsigned int len
+ )
+{
+ unsigned int i;
+
+ for (i = 0; i < len; i++)
+ output[i] = input[i];
+}
+
+/* Note: Replace "for loop" with standard memset if possible.
+ */
+static void
+MD5_memset (
+ POINTER output,
+ int value,
+ unsigned int len
+ )
+{
+ unsigned int i;
+
+ for (i = 0; i < len; i++)
+ ((char *)output)[i] = (char)value;
+}
diff --git a/contrib/ntp/libntp/memmove.c b/contrib/ntp/libntp/memmove.c
new file mode 100644
index 0000000..b5d0868
--- /dev/null
+++ b/contrib/ntp/libntp/memmove.c
@@ -0,0 +1,136 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)bcopy.c 8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifndef HAVE_MEMMOVE
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#include <string.h>
+
+/*
+ * sizeof(word) MUST BE A POWER OF TWO
+ * SO THAT wmask BELOW IS ALL ONES
+ */
+typedef int word; /* "word" used for optimal copy speed */
+
+#define wsize sizeof(word)
+#define wmask (wsize - 1)
+
+/*
+ * Copy a block of memory, handling overlap.
+ * This is the routine that actually implements
+ * (the portable versions of) bcopy, memcpy, and memmove.
+ */
+void *
+memmove(
+ void *dst0,
+ const void *src0,
+ register size_t length
+ )
+{
+ register char *dst = dst0;
+ register const char *src = src0;
+ register size_t t;
+
+ if (length == 0 || dst == src) /* nothing to do */
+ goto done;
+
+ /*
+ * Macros: loop-t-times; and loop-t-times, t>0
+ */
+#define TLOOP(s) if (t) TLOOP1(s)
+#define TLOOP1(s) do { s; } while (--t)
+
+ if ((unsigned long)dst < (unsigned long)src) {
+ /*
+ * Copy forward.
+ */
+ t = (int)src; /* only need low bits */
+ if ((t | (int)dst) & wmask) {
+ /*
+ * Try to align operands. This cannot be done
+ * unless the low bits match.
+ */
+ if ((t ^ (int)dst) & wmask || length < wsize)
+ t = length;
+ else
+ t = wsize - (t & wmask);
+ length -= t;
+ TLOOP1(*dst++ = *src++);
+ }
+ /*
+ * Copy whole words, then mop up any trailing bytes.
+ */
+ t = length / wsize;
+ TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
+ t = length & wmask;
+ TLOOP(*dst++ = *src++);
+ } else {
+ /*
+ * Copy backwards. Otherwise essentially the same.
+ * Alignment works as before, except that it takes
+ * (t&wmask) bytes to align, not wsize-(t&wmask).
+ */
+ src += length;
+ dst += length;
+ t = (int)src;
+ if ((t | (int)dst) & wmask) {
+ if ((t ^ (int)dst) & wmask || length <= wsize)
+ t = length;
+ else
+ t &= wmask;
+ length -= t;
+ TLOOP1(*--dst = *--src);
+ }
+ t = length / wsize;
+ TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
+ t = length & wmask;
+ TLOOP(*--dst = *--src);
+ }
+ done:
+ return (dst0);
+}
+#else
+int memmove_bs;
+#endif
diff --git a/contrib/ntp/libntp/mexit.c b/contrib/ntp/libntp/mexit.c
new file mode 100644
index 0000000..6ae452e
--- /dev/null
+++ b/contrib/ntp/libntp/mexit.c
@@ -0,0 +1,34 @@
+/*
+ * mexit - Used to exit the NTPD daemon
+ *
+ */
+
+#ifdef SYS_WINNT
+#include <stdio.h>
+#include <windows.h>
+
+HANDLE hServDoneEvent = NULL;
+
+void
+service_exit(
+ int status
+ )
+{
+ extern int debug;
+
+ if (debug) /* did not become a service, simply exit */
+ ExitThread((DWORD)status);
+ else {
+ /* service mode, need to have the service_main routine
+ * register with the service control manager that the
+ * service has stopped running, before exiting
+ */
+ if ((status > 0) && (hServDoneEvent != NULL))
+ SetEvent(hServDoneEvent);
+ ExitThread((DWORD)status);
+ }
+}
+
+#else /* not SYS_WINNT */
+int mexit_bs;
+#endif /* not SYS_WINNT */
diff --git a/contrib/ntp/libntp/mfp_mul.c b/contrib/ntp/libntp/mfp_mul.c
new file mode 100644
index 0000000..0c667f7
--- /dev/null
+++ b/contrib/ntp/libntp/mfp_mul.c
@@ -0,0 +1,140 @@
+/*
+ * /src/NTP/ntp-4/libntp/mfp_mul.c,v 4.3 1999/02/21 12:17:37 kardel RELEASE_19990228_A
+ *
+ * $Created: Sat Aug 16 20:35:08 1997 $
+ *
+ * Copyright (C) 1997, 1998 by Frank Kardel
+ */
+#include <stdio.h>
+#include "ntp_stdlib.h"
+#include "ntp_types.h"
+#include "ntp_fp.h"
+
+#define LOW_MASK (u_int32)((1<<(FRACTION_PREC/2))-1)
+#define HIGH_MASK (u_int32)(LOW_MASK << (FRACTION_PREC/2))
+
+void
+mfp_mul(
+ int32 *o_i,
+ u_int32 *o_f,
+ int32 a_i,
+ u_int32 a_f,
+ int32 b_i,
+ u_int32 b_f
+ )
+{
+ int32 i, j;
+ u_int32 f;
+ u_long a[4]; /* operand a */
+ u_long b[4]; /* operand b */
+ u_long c[4]; /* result c */
+
+ int neg = 0;
+
+ if (a_i < 0) /* examine sign situation */
+ {
+ neg = 1;
+ M_NEG(a_i, a_f);
+ }
+
+ if (b_i < 0) /* examine sign situation */
+ {
+ neg = !neg;
+ M_NEG(b_i, b_f);
+ }
+
+ a[0] = a_f & LOW_MASK; /* prepare a operand */
+ a[1] = (a_f & HIGH_MASK) >> (FRACTION_PREC/2);
+ a[2] = a_i & LOW_MASK;
+ a[3] = (a_i & HIGH_MASK) >> (FRACTION_PREC/2);
+
+ b[0] = b_f & LOW_MASK; /* prepare b operand */
+ b[1] = (b_f & HIGH_MASK) >> (FRACTION_PREC/2);
+ b[2] = b_i & LOW_MASK;
+ b[3] = (b_i & HIGH_MASK) >> (FRACTION_PREC/2);
+
+ c[0] = c[1] = c[2] = c[3] = 0;
+
+ for (i = 0; i < 4; i++) /* we do assume 32 * 32 = 64 bit multiplication */
+ for (j = 0; j < 4; j++)
+ {
+ u_long result_low, result_high;
+
+ result_low = (u_long)a[i] * (u_long)b[j]; /* partial product */
+
+ if ((i+j) & 1) /* splits across two result registers */
+ {
+ result_high = result_low >> (FRACTION_PREC/2);
+ result_low <<= FRACTION_PREC/2;
+ }
+ else
+ { /* stays in a result register - except for overflows */
+ result_high = 0;
+ }
+
+ if (((c[(i+j)/2] >> 1) + (result_low >> 1)) & (u_int32)((unsigned)1<<(FRACTION_PREC - 1)))
+ result_high++; /* propagate overflows */
+
+ c[(i+j)/2] += result_low; /* add up partial products */
+
+ if (((c[(i+j+1)/2] >> 1) + (result_high >> 1)) & (u_int32)((unsigned)1<<(FRACTION_PREC - 1)))
+ c[1+(i+j)/2]++; /* propagate overflows */
+
+ c[(i+j+1)/2] += result_high;
+ }
+
+#ifdef DEBUG
+ if (debug > 6)
+ printf("mfp_mul: 0x%04lx%04lx%04lx%04lx * 0x%04lx%04lx%04lx%04lx = 0x%08lx%08lx%08lx%08lx\n",
+ a[3], a[2], a[1], a[0], b[3], b[2], b[1], b[0], c[3], c[2], c[1], c[0]);
+#endif
+
+ if (c[3]) /* overflow */
+ {
+ i = ((unsigned)1 << (FRACTION_PREC-1)) - 1;
+ f = ~(unsigned)0;
+ }
+ else
+ { /* take produkt - discarding extra precision */
+ i = c[2];
+ f = c[1];
+ }
+
+ if (neg) /* recover sign */
+ {
+ M_NEG(i, f);
+ }
+
+ *o_i = i;
+ *o_f = f;
+
+#ifdef DEBUG
+ if (debug > 6)
+ printf("mfp_mul: %s * %s => %s\n",
+ mfptoa((u_long)a_i, a_f, 6),
+ mfptoa((u_long)b_i, b_f, 6),
+ mfptoa((u_long)i, f, 6));
+#endif
+}
+
+/*
+ * mfp_mul.c,v
+ * Revision 4.3 1999/02/21 12:17:37 kardel
+ * 4.91f reconcilation
+ *
+ * Revision 4.2 1998/12/20 23:45:28 kardel
+ * fix types and warnings
+ *
+ * Revision 4.1 1998/05/24 07:59:57 kardel
+ * conditional debug support
+ *
+ * Revision 4.0 1998/04/10 19:46:38 kardel
+ * Start 4.0 release version numbering
+ *
+ * Revision 1.1 1998/04/10 19:27:47 kardel
+ * initial NTP VERSION 4 integration of PARSE with GPS166 binary support
+ *
+ * Revision 1.1 1997/10/06 21:05:46 kardel
+ * new parse structure
+ *
+ */
diff --git a/contrib/ntp/libntp/mfptoa.c b/contrib/ntp/libntp/mfptoa.c
new file mode 100644
index 0000000..8257b6c
--- /dev/null
+++ b/contrib/ntp/libntp/mfptoa.c
@@ -0,0 +1,23 @@
+/*
+ * mfptoa - Return an asciized representation of a signed long fp number
+ */
+#include "ntp_fp.h"
+#include "ntp_stdlib.h"
+
+char *
+mfptoa(
+ u_long fpi,
+ u_long fpf,
+ int ndec
+ )
+{
+ int isneg;
+
+ if (M_ISNEG(fpi, fpf)) {
+ isneg = 1;
+ M_NEG(fpi, fpf);
+ } else
+ isneg = 0;
+
+ return dolfptoa(fpi, fpf, isneg, ndec, 0);
+}
diff --git a/contrib/ntp/libntp/mfptoms.c b/contrib/ntp/libntp/mfptoms.c
new file mode 100644
index 0000000..10afb51
--- /dev/null
+++ b/contrib/ntp/libntp/mfptoms.c
@@ -0,0 +1,23 @@
+/*
+ * mfptoms - Return an asciized signed long fp number in milliseconds
+ */
+#include "ntp_fp.h"
+#include "ntp_stdlib.h"
+
+char *
+mfptoms(
+ u_long fpi,
+ u_long fpf,
+ int ndec
+ )
+{
+ int isneg;
+
+ if (M_ISNEG(fpi, fpf)) {
+ isneg = 1;
+ M_NEG(fpi, fpf);
+ } else
+ isneg = 0;
+
+ return dolfptoa(fpi, fpf, isneg, ndec, 1);
+}
diff --git a/contrib/ntp/libntp/mktime.c b/contrib/ntp/libntp/mktime.c
new file mode 100644
index 0000000..c752690
--- /dev/null
+++ b/contrib/ntp/libntp/mktime.c
@@ -0,0 +1,282 @@
+/*
+ * Copyright (c) 1987, 1989 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Arthur David Olson of the National Cancer Institute.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+
+/*static char *sccsid = "from: @(#)ctime.c 5.26 (Berkeley) 2/23/91";*/
+/*static char *rcsid = "mktime.c,v 1.1.1.3 1998/11/15 19:23:34 kardel RELEASE_19990228_A";*/
+
+/*
+ * This implementation of mktime is lifted straight from the NetBSD (BSD 4.4)
+ * version. I modified it slightly to divorce it from the internals of the
+ * ctime library. Thus this version can't use details of the internal
+ * timezone state file to figure out strange unnormalized struct tm values,
+ * as might result from someone doing date math on the tm struct then passing
+ * it to mktime.
+ *
+ * It just does as well as it can at normalizing the tm input, then does a
+ * binary search of the time space using the system's localtime() function.
+ *
+ * The original binary search was defective in that it didn't consider the
+ * setting of tm_isdst when comparing tm values, causing the search to be
+ * flubbed for times near the dst/standard time changeover. The original
+ * code seems to make up for this by grubbing through the timezone info
+ * whenever the binary search barfed. Since I don't have that luxury in
+ * portable code, I have to take care of tm_isdst in the comparison routine.
+ * This requires knowing how many minutes offset dst is from standard time.
+ *
+ * So, if you live somewhere in the world where dst is not 60 minutes offset,
+ * and your vendor doesn't supply mktime(), you'll have to edit this variable
+ * by hand. Sorry about that.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifndef DSTMINUTES
+#define DSTMINUTES 60
+#endif
+
+#define FALSE 0
+#define TRUE 1
+
+/* some constants from tzfile.h */
+#define SECSPERMIN 60
+#define MINSPERHOUR 60
+#define HOURSPERDAY 24
+#define DAYSPERWEEK 7
+#define DAYSPERNYEAR 365
+#define DAYSPERLYEAR 366
+#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
+#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY)
+#define MONSPERYEAR 12
+#define TM_YEAR_BASE 1900
+#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+#include <time.h>
+
+extern time_t time();
+
+static int mon_lengths[2][MONSPERYEAR] = {
+ { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+};
+
+static int year_lengths[2] = {
+ DAYSPERNYEAR, DAYSPERLYEAR
+};
+
+/*
+** Adapted from code provided by Robert Elz, who writes:
+** The "best" way to do mktime I think is based on an idea of Bob
+** Kridle's (so its said...) from a long time ago. (mtxinu!kridle now).
+** It does a binary search of the time_t space. Since time_t's are
+** just 32 bits, its a max of 32 iterations (even at 64 bits it
+** would still be very reasonable).
+*/
+
+#ifndef WRONG
+#define WRONG (-1)
+#endif /* !defined WRONG */
+
+static void
+normalize(
+ int * tensptr,
+ int * unitsptr,
+ int base
+ )
+{
+ if (*unitsptr >= base) {
+ *tensptr += *unitsptr / base;
+ *unitsptr %= base;
+ } else if (*unitsptr < 0) {
+ --*tensptr;
+ *unitsptr += base;
+ if (*unitsptr < 0) {
+ *tensptr -= 1 + (-*unitsptr) / base;
+ *unitsptr = base - (-*unitsptr) % base;
+ }
+ }
+}
+
+static struct tm *
+mkdst(
+ struct tm * tmp
+ )
+{
+ /* jds */
+ static struct tm tmbuf;
+
+ tmbuf = *tmp;
+ tmbuf.tm_isdst = 1;
+ tmbuf.tm_min += DSTMINUTES;
+ normalize(&tmbuf.tm_hour, &tmbuf.tm_min, MINSPERHOUR);
+ return &tmbuf;
+}
+
+static int
+tmcomp(
+ register struct tm * atmp,
+ register struct tm * btmp
+ )
+{
+ register int result;
+
+ /* compare down to the same day */
+
+ if ((result = (atmp->tm_year - btmp->tm_year)) == 0 &&
+ (result = (atmp->tm_mon - btmp->tm_mon)) == 0)
+ result = (atmp->tm_mday - btmp->tm_mday);
+
+ if(result != 0)
+ return result;
+
+ /* get rid of one-sided dst bias */
+
+ if(atmp->tm_isdst == 1 && !btmp->tm_isdst)
+ btmp = mkdst(btmp);
+ else if(btmp->tm_isdst == 1 && !atmp->tm_isdst)
+ atmp = mkdst(atmp);
+
+ /* compare the rest of the way */
+
+ if ((result = (atmp->tm_hour - btmp->tm_hour)) == 0 &&
+ (result = (atmp->tm_min - btmp->tm_min)) == 0)
+ result = atmp->tm_sec - btmp->tm_sec;
+ return result;
+}
+
+
+static time_t
+time2(
+ struct tm * tmp,
+ int * okayp
+ )
+{
+ register int dir;
+ register int bits;
+ register int i;
+ register int saved_seconds;
+ time_t t;
+ struct tm yourtm, mytm;
+
+ *okayp = FALSE;
+ yourtm = *tmp;
+ if (yourtm.tm_sec >= SECSPERMIN + 2 || yourtm.tm_sec < 0)
+ normalize(&yourtm.tm_min, &yourtm.tm_sec, SECSPERMIN);
+ normalize(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR);
+ normalize(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY);
+ normalize(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR);
+ while (yourtm.tm_mday <= 0) {
+ --yourtm.tm_year;
+ yourtm.tm_mday +=
+ year_lengths[isleap(yourtm.tm_year + TM_YEAR_BASE)];
+ }
+ for ( ; ; ) {
+ i = mon_lengths[isleap(yourtm.tm_year +
+ TM_YEAR_BASE)][yourtm.tm_mon];
+ if (yourtm.tm_mday <= i)
+ break;
+ yourtm.tm_mday -= i;
+ if (++yourtm.tm_mon >= MONSPERYEAR) {
+ yourtm.tm_mon = 0;
+ ++yourtm.tm_year;
+ }
+ }
+ saved_seconds = yourtm.tm_sec;
+ yourtm.tm_sec = 0;
+ /*
+ ** Calculate the number of magnitude bits in a time_t
+ ** (this works regardless of whether time_t is
+ ** signed or unsigned, though lint complains if unsigned).
+ */
+ for (bits = 0, t = 1; t > 0; ++bits, t <<= 1)
+ ;
+ /*
+ ** If time_t is signed, then 0 is the median value,
+ ** if time_t is unsigned, then 1 << bits is median.
+ */
+ t = (t < 0) ? 0 : ((time_t) 1 << bits);
+ for ( ; ; ) {
+ mytm = *localtime(&t);
+ dir = tmcomp(&mytm, &yourtm);
+ if (dir != 0) {
+ if (bits-- < 0)
+ return WRONG;
+ if (bits < 0)
+ --t;
+ else if (dir > 0)
+ t -= (time_t) 1 << bits;
+ else t += (time_t) 1 << bits;
+ continue;
+ }
+ if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst)
+ break;
+
+ return WRONG;
+ }
+ t += saved_seconds;
+ *tmp = *localtime(&t);
+ *okayp = TRUE;
+ return t;
+}
+
+static time_t
+time1(
+ struct tm * tmp
+ )
+{
+ register time_t t;
+ int okay;
+
+ if (tmp->tm_isdst > 1)
+ tmp->tm_isdst = 1;
+ t = time2(tmp, &okay);
+ if (okay || tmp->tm_isdst < 0)
+ return t;
+
+ return WRONG;
+}
+
+time_t
+mktime(
+ struct tm * tmp
+ )
+{
+ return time1(tmp);
+}
diff --git a/contrib/ntp/libntp/modetoa.c b/contrib/ntp/libntp/modetoa.c
new file mode 100644
index 0000000..405aef8
--- /dev/null
+++ b/contrib/ntp/libntp/modetoa.c
@@ -0,0 +1,34 @@
+/*
+ * modetoa - return an asciized mode
+ */
+#include <stdio.h>
+
+#include "lib_strbuf.h"
+#include "ntp_stdlib.h"
+
+const char *
+modetoa(
+ int mode
+ )
+{
+ char *bp;
+ static const char *modestrings[] = {
+ "unspec",
+ "sym_active",
+ "sym_passive",
+ "client",
+ "server",
+ "broadcast",
+ "control",
+ "private",
+ "bclient",
+ };
+
+ if (mode < 0 || mode >= (sizeof modestrings)/sizeof(char *)) {
+ LIB_GETBUF(bp);
+ (void)sprintf(bp, "mode#%d", mode);
+ return bp;
+ }
+
+ return modestrings[mode];
+}
diff --git a/contrib/ntp/libntp/mstolfp.c b/contrib/ntp/libntp/mstolfp.c
new file mode 100644
index 0000000..e4e909d
--- /dev/null
+++ b/contrib/ntp/libntp/mstolfp.c
@@ -0,0 +1,100 @@
+/*
+ * mstolfp - convert an ascii string in milliseconds to an l_fp number
+ */
+#include <stdio.h>
+#include <ctype.h>
+
+#include "ntp_fp.h"
+#include "ntp_stdlib.h"
+
+int
+mstolfp(
+ const char *str,
+ l_fp *lfp
+ )
+{
+ register const char *cp;
+ register char *bp;
+ register const char *cpdec;
+ char buf[100];
+
+ /*
+ * We understand numbers of the form:
+ *
+ * [spaces][-][digits][.][digits][spaces|\n|\0]
+ *
+ * This is one enormous hack. Since I didn't feel like
+ * rewriting the decoding routine for milliseconds, what
+ * is essentially done here is to make a copy of the string
+ * with the decimal moved over three places so the seconds
+ * decoding routine can be used.
+ */
+ bp = buf;
+ cp = str;
+ while (isspace((int)*cp))
+ cp++;
+
+ if (*cp == '-') {
+ *bp++ = '-';
+ cp++;
+ }
+
+ if (*cp != '.' && !isdigit((int)*cp))
+ return 0;
+
+
+ /*
+ * Search forward for the decimal point or the end of the string.
+ */
+ cpdec = cp;
+ while (isdigit((int)*cpdec))
+ cpdec++;
+
+ /*
+ * Found something. If we have more than three digits copy the
+ * excess over, else insert a leading 0.
+ */
+ if ((cpdec - cp) > 3) {
+ do {
+ *bp++ = (char)*cp++;
+ } while ((cpdec - cp) > 3);
+ } else {
+ *bp++ = '0';
+ }
+
+ /*
+ * Stick the decimal in. If we've got less than three digits in
+ * front of the millisecond decimal we insert the appropriate number
+ * of zeros.
+ */
+ *bp++ = '.';
+ if ((cpdec - cp) < 3) {
+ register int i = 3 - (cpdec - cp);
+
+ do {
+ *bp++ = '0';
+ } while (--i > 0);
+ }
+
+ /*
+ * Copy the remainder up to the millisecond decimal. If cpdec
+ * is pointing at a decimal point, copy in the trailing number too.
+ */
+ while (cp < cpdec)
+ *bp++ = (char)*cp++;
+
+ if (*cp == '.') {
+ cp++;
+ while (isdigit((int)*cp))
+ *bp++ = (char)*cp++;
+ }
+ *bp = '\0';
+
+ /*
+ * Check to make sure the string is properly terminated. If
+ * so, give the buffer to the decoding routine.
+ */
+ if (*cp != '\0' && !isspace((int)*cp))
+ return 0;
+ return atolfp(buf, lfp);
+}
diff --git a/contrib/ntp/libntp/msutotsf.c b/contrib/ntp/libntp/msutotsf.c
new file mode 100644
index 0000000..eb3babe
--- /dev/null
+++ b/contrib/ntp/libntp/msutotsf.c
@@ -0,0 +1,35 @@
+/*
+ * msutotsf - tables for converting from a subsecond millisecond value
+ * to a time stamp fraction.
+ */
+#include <sys/types.h>
+
+#include "ntp_types.h"
+
+/*
+ * Index each of these tables with five bits of the (less than) 10
+ * bit millisecond value. Note that the tables are rounded (not
+ * truncated). The error in the result will thus be +-1 low order
+ * bit in the time stamp fraction.
+ */
+u_long msutotsflo[32] = {
+ 0x00000000, 0x00418937, 0x0083126f, 0x00c49ba6,
+ 0x010624dd, 0x0147ae14, 0x0189374c, 0x01cac083,
+ 0x020c49ba, 0x024dd2f2, 0x028f5c29, 0x02d0e560,
+ 0x03126e98, 0x0353f7cf, 0x03958106, 0x03d70a3d,
+ 0x04189375, 0x045a1cac, 0x049ba5e3, 0x04dd2f1b,
+ 0x051eb852, 0x05604189, 0x05a1cac1, 0x05e353f8,
+ 0x0624dd2f, 0x06666666, 0x06a7ef9e, 0x06e978d5,
+ 0x072b020c, 0x076c8b44, 0x07ae147b, 0x07ef9db2
+};
+
+u_long msutotsfhi[32] = {
+ 0x00000000, 0x083126e9, 0x10624dd3, 0x189374bc,
+ 0x20c49ba6, 0x28f5c28f, 0x3126e979, 0x39581062,
+ 0x4189374c, 0x49ba5e35, 0x51eb851f, 0x5a1cac08,
+ 0x624dd2f2, 0x6a7ef9db, 0x72b020c5, 0x7ae147ae,
+ 0x83126e98, 0x8b439581, 0x9374bc6a, 0x9ba5e354,
+ 0xa3d70a3d, 0xac083127, 0xb4395810, 0xbc6a7efa,
+ 0xc49ba5e3, 0xcccccccd, 0xd4fdf3b6, 0xdd2f1aa0,
+ 0xe5604189, 0xed916873, 0xf5c28f5c, 0xfdf3b646
+};
diff --git a/contrib/ntp/libntp/msyslog.c b/contrib/ntp/libntp/msyslog.c
new file mode 100644
index 0000000..dfb1627
--- /dev/null
+++ b/contrib/ntp/libntp/msyslog.c
@@ -0,0 +1,170 @@
+/*
+ * msyslog - either send a message to the terminal or print it on
+ * the standard output.
+ *
+ * Converted to use varargs, much better ... jks
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include <stdio.h>
+
+#include "ntp_types.h"
+#include "ntp_string.h"
+#include "ntp_stdlib.h"
+#include "ntp_syslog.h"
+
+#ifdef SYS_WINNT
+# include "..\ports\winnt\libntp\log.h"
+# include "..\ports\winnt\libntp\messages.h"
+#endif
+
+int syslogit = 1;
+
+FILE *syslog_file = NULL;
+
+u_long ntp_syslogmask = ~ (u_long) 0;
+
+#ifdef SYS_WINNT
+HANDLE hEventSource;
+LPTSTR lpszStrings[1];
+static WORD event_type[] = {
+ EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE, EVENTLOG_ERROR_TYPE,
+ EVENTLOG_WARNING_TYPE,
+ EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE, EVENTLOG_INFORMATION_TYPE,
+};
+#endif /* SYS_WINNT */
+extern char *progname;
+
+#if defined(__STDC__) || defined(HAVE_STDARG_H)
+void msyslog(int level, const char *fmt, ...)
+#else /* defined(__STDC__) || defined(HAVE_STDARG_H) */
+ /*VARARGS*/
+ void msyslog(va_alist)
+ va_dcl
+#endif /* defined(__STDC__) || defined(HAVE_STDARG_H) */
+{
+#if defined(__STDC__) || defined(HAVE_STDARG_H)
+#else
+ int level;
+ const char *fmt;
+#endif
+ va_list ap;
+ char buf[1025], nfmt[256];
+#if !defined(VMS)
+ char xerr[50];
+#endif
+ register int c;
+ register char *n, *prog;
+ register const char *f;
+#ifdef CHAR_SYS_ERRLIST
+ extern int sys_nerr;
+ extern char *sys_errlist[];
+#endif
+ int olderrno;
+ char *err;
+
+#if defined(__STDC__) || defined(HAVE_STDARG_H)
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+
+ level = va_arg(ap, int);
+ fmt = va_arg(ap, char *);
+#endif
+
+ olderrno = errno;
+ n = nfmt;
+ f = fmt;
+ while ((c = *f++) != '\0' && c != '\n' && n < &nfmt[252]) {
+ if (c != '%') {
+ *n++ = c;
+ continue;
+ }
+ if ((c = *f++) != 'm') {
+ *n++ = '%';
+ *n++ = c;
+ continue;
+ }
+ err = 0;
+#if !defined(VMS) && !defined(SYS_WINNT) && !defined (SYS_VXWORKS)
+ if ((unsigned)olderrno > sys_nerr)
+ sprintf((char *)(err = xerr), "error %d", olderrno);
+ else
+ err = (char*)sys_errlist[olderrno];
+#elif defined(VMS) || defined (SYS_VXWORKS)
+ err = strerror(olderrno);
+#else /* SYS_WINNT */
+ err = xerr;
+ FormatMessage(
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
+ (LPTSTR) err,
+ sizeof(xerr),
+ NULL);
+
+#endif /* VMS && SYS_WINNT */
+ if ((n + strlen(err)) < &nfmt[254]) {
+ strcpy(n, err);
+ n += strlen(err);
+ }
+ }
+#if !defined(VMS)
+ if (!syslogit)
+#endif /* VMS */
+ *n++ = '\n';
+ *n = '\0';
+
+ vsprintf(buf, nfmt, ap);
+#if !defined(VMS) && !defined (SYS_VXWORKS)
+ if (syslogit)
+#ifndef SYS_WINNT
+ syslog(level, "%s", buf);
+#else
+ {
+ lpszStrings[0] = buf;
+
+ switch (event_type[level])
+ {
+ case EVENTLOG_ERROR_TYPE:
+ reportAnEEvent(NTP_ERROR,1,lpszStrings);
+ break;
+ case EVENTLOG_INFORMATION_TYPE:
+ reportAnIEvent(NTP_INFO,1,lpszStrings);
+ break;
+ case EVENTLOG_WARNING_TYPE:
+ reportAnWEvent(NTP_WARNING,1,lpszStrings);
+ break;
+ } /* switch end */
+
+ }
+#endif /* SYS_WINNT */
+ else
+#endif /* VMS && SYS_VXWORKS*/
+ {
+ FILE *out_file = syslog_file ? syslog_file
+ : level <= LOG_ERR ? stderr : stdout;
+ /* syslog() provides the timestamp, so if we're not using
+ syslog, we must provide it. */
+ prog = strrchr(progname, '/');
+ if (prog == NULL)
+ prog = progname;
+ else
+ prog++;
+ (void) fprintf(out_file, "%s ", humanlogtime ());
+ (void) fprintf(out_file, "%s[%d]: %s", prog, (int)getpid(), buf);
+ fflush (out_file);
+ }
+ va_end(ap);
+}
diff --git a/contrib/ntp/libntp/netof.c b/contrib/ntp/libntp/netof.c
new file mode 100644
index 0000000..df7657e
--- /dev/null
+++ b/contrib/ntp/libntp/netof.c
@@ -0,0 +1,25 @@
+/*
+ * netof - return the net address part of an ip address
+ * (zero out host part)
+ */
+#include <stdio.h>
+
+#include "ntp_fp.h"
+#include "ntp_stdlib.h"
+
+u_int32
+netof(
+ u_int32 num
+ )
+{
+ register u_int32 netnum;
+
+ netnum = num;
+ if(IN_CLASSC(netnum))
+ netnum &= IN_CLASSC_NET;
+ else if (IN_CLASSB(netnum))
+ netnum &= IN_CLASSB_NET;
+ else /* treat all other like class A */
+ netnum &= IN_CLASSA_NET;
+ return netnum;
+}
diff --git a/contrib/ntp/libntp/numtoa.c b/contrib/ntp/libntp/numtoa.c
new file mode 100644
index 0000000..de95118
--- /dev/null
+++ b/contrib/ntp/libntp/numtoa.c
@@ -0,0 +1,24 @@
+/*
+ * numtoa - return asciized network numbers store in local array space
+ */
+#include <stdio.h>
+
+#include "ntp_fp.h"
+#include "lib_strbuf.h"
+#include "ntp_stdlib.h"
+
+char *
+numtoa(
+ u_int32 num
+ )
+{
+ register u_int32 netnum;
+ register char *buf;
+
+ netnum = ntohl(num);
+ LIB_GETBUF(buf);
+ (void) sprintf(buf, "%lu.%lu.%lu.%lu", ((u_long)netnum >> 24) & 0xff,
+ ((u_long)netnum >> 16) & 0xff, ((u_long)netnum >> 8) & 0xff,
+ (u_long)netnum & 0xff);
+ return buf;
+}
diff --git a/contrib/ntp/libntp/numtohost.c b/contrib/ntp/libntp/numtohost.c
new file mode 100644
index 0000000..4e53092
--- /dev/null
+++ b/contrib/ntp/libntp/numtohost.c
@@ -0,0 +1,39 @@
+/*
+ * numtohost - convert network number to host name.
+ */
+#include <netdb.h>
+
+#include "ntp_fp.h"
+#include "ntp_stdlib.h"
+#include "lib_strbuf.h"
+
+#define LOOPBACKNET 0x7f000000
+#define LOOPBACKHOST 0x7f000001
+#define LOOPBACKNETMASK 0xff000000
+
+char *
+numtohost(
+ u_int32 netnum
+ )
+{
+ char *bp;
+ struct hostent *hp;
+
+ /*
+ * This is really gross, but saves lots of hanging looking for
+ * hostnames for the radio clocks. Don't bother looking up
+ * addresses on the loopback network except for the loopback
+ * host itself.
+ */
+ if ((((ntohl(netnum) & LOOPBACKNETMASK) == LOOPBACKNET)
+ && (ntohl(netnum) != LOOPBACKHOST))
+ || ((hp = gethostbyaddr((char *)&netnum, sizeof netnum, AF_INET))
+ == 0))
+ return numtoa(netnum);
+
+ LIB_GETBUF(bp);
+
+ bp[LIB_BUFLENGTH-1] = '\0';
+ (void) strncpy(bp, hp->h_name, LIB_BUFLENGTH-1);
+ return bp;
+}
diff --git a/contrib/ntp/libntp/octtoint.c b/contrib/ntp/libntp/octtoint.c
new file mode 100644
index 0000000..f792b2b
--- /dev/null
+++ b/contrib/ntp/libntp/octtoint.c
@@ -0,0 +1,35 @@
+/*
+ * octtoint - convert an ascii string in octal to an unsigned
+ * long, with error checking
+ */
+#include <stdio.h>
+#include <ctype.h>
+
+#include "ntp_stdlib.h"
+
+int
+octtoint(
+ const char *str,
+ u_long *ival
+ )
+{
+ register u_long u;
+ register const char *cp;
+
+ cp = str;
+
+ if (*cp == '\0')
+ return 0;
+
+ u = 0;
+ while (*cp != '\0') {
+ if (!isdigit((int)*cp) || *cp == '8' || *cp == '9')
+ return 0;
+ if (u >= 0x20000000)
+ return 0; /* overflow */
+ u <<= 3;
+ u += *cp++ - '0'; /* ascii dependent */
+ }
+ *ival = u;
+ return 1;
+}
diff --git a/contrib/ntp/libntp/prettydate.c b/contrib/ntp/libntp/prettydate.c
new file mode 100644
index 0000000..291c17c
--- /dev/null
+++ b/contrib/ntp/libntp/prettydate.c
@@ -0,0 +1,72 @@
+/*
+ * prettydate - convert a time stamp to something readable
+ */
+#include <stdio.h>
+
+#include "ntp_fp.h"
+#include "ntp_unixtime.h" /* includes <sys/time.h> */
+#include "lib_strbuf.h"
+#include "ntp_stdlib.h"
+
+#ifndef TM_IN_SYS_TIME
+#include <time.h>
+#endif
+
+static const char *months[] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+static const char *days[] = {
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+};
+
+char *
+prettydate(
+ l_fp *ts
+ )
+{
+ char *bp;
+ struct tm *tm;
+ time_t sec;
+ u_long msec;
+
+ LIB_GETBUF(bp);
+
+ sec = ts->l_ui - JAN_1970;
+ msec = ts->l_uf / 4294967; /* fract / (2 ** 32 / 1000) */
+
+ tm = localtime(&sec);
+
+ (void) sprintf(bp, "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03lu",
+ (u_long)ts->l_ui, (u_long)ts->l_uf, days[tm->tm_wday],
+ months[tm->tm_mon], tm->tm_mday, 1900 + tm->tm_year,
+ tm->tm_hour,tm->tm_min, tm->tm_sec, msec);
+
+ return bp;
+}
+
+char *
+gmprettydate(
+ l_fp *ts
+ )
+{
+ char *bp;
+ struct tm *tm;
+ time_t sec;
+ u_long msec;
+
+ LIB_GETBUF(bp);
+
+ sec = ts->l_ui - JAN_1970;
+ msec = ts->l_uf / 4294967; /* fract / (2 ** 32 / 1000) */
+
+ tm = gmtime(&sec);
+
+ (void) sprintf(bp, "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03lu UTC",
+ (u_long)ts->l_ui, (u_long)ts->l_uf, days[tm->tm_wday],
+ months[tm->tm_mon], tm->tm_mday, 1900 + tm->tm_year,
+ tm->tm_hour,tm->tm_min, tm->tm_sec, msec);
+
+ return bp;
+}
diff --git a/contrib/ntp/libntp/ranny.c b/contrib/ntp/libntp/ranny.c
new file mode 100644
index 0000000..fa555f5
--- /dev/null
+++ b/contrib/ntp/libntp/ranny.c
@@ -0,0 +1,82 @@
+/*
+ * Random number generator is:
+ *
+ * Copyright 1988 by Rayan S. Zachariassen, all rights reserved.
+ * This will be free software, but only when it is finished.
+ *
+ * Used in ntp by permission of the author. If copyright is
+ * annoying to you, read no further. Instead, look up the reference,
+ * write me an equivalent to this and send it back to me.
+ */
+
+/*
+ * Random number generator; see Knuth Vol 2. 2nd ed. p.27 (section 3.2.2)
+ */
+#include "ntp_stdlib.h"
+
+extern time_t time P((time_t *loc));
+
+/*
+ * 55 random numbers, not all even. Note we don't initialize ran_y
+ * directly since I have had thoughts of putting this in an EPROM
+ */
+static time_t ran_y[55];
+
+static time_t init_ran_y[55] = {
+ 1860909544, 231033423, 437666411, 1349655137, 2014584962,
+ 504613712, 656256107, 1246027206, 573713775, 643466871,
+ 540235388, 1630565153, 443649364, 729302839, 1933991552,
+ 944681982, 949111118, 406212522, 1065063137, 1712954727,
+ 73280612, 787623973, 1874130997, 801658492, 73395958,
+ 739165367, 596047144, 490055249, 1131094323, 662727104,
+ 483614097, 844520219, 893760527, 921280508, 46691708,
+ 760861842, 1425894220, 702947816, 2006889048, 1999607995,
+ 1346414687, 399640789, 1482689501, 1790064052, 1128943628,
+ 1269197405, 587262386, 2078054746, 1675409928, 1652325524,
+ 1643525825, 1748690540, 292465849, 1370173174, 402865384
+};
+
+static int ran_j;
+static int ran_k;
+
+
+/*
+ * ranp2 - return a random integer in the range 0 .. (1 << m) - 1
+ */
+u_long
+ranp2(
+ int m
+ )
+{
+ time_t r;
+
+ ran_y[ran_k] += ran_y[ran_j]; /* overflow does a mod */
+ r = ran_y[ran_k];
+ if (ran_k-- == 0)
+ ran_k = 54;
+ if (ran_j-- == 0)
+ ran_j = 54;
+ return (u_long)(r & ((1 << m ) - 1));
+}
+
+/*
+ * init_random - do initialization of random number routine
+ */
+void
+init_random(void)
+{
+ register int i;
+ register time_t now;
+
+ ran_j = 23;
+ ran_k = 54;
+
+ /*
+ * Randomize the seed array some more. The time of day
+ * should be initialized by now.
+ */
+ now = time((time_t *)0) | 01;
+
+ for (i = 0; i < 55; ++i)
+ ran_y[i] = now * init_ran_y[i]; /* overflow does a mod */
+}
diff --git a/contrib/ntp/libntp/recvbuff.c b/contrib/ntp/libntp/recvbuff.c
new file mode 100644
index 0000000..37166a4
--- /dev/null
+++ b/contrib/ntp/libntp/recvbuff.c
@@ -0,0 +1,277 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include "ntp_machine.h"
+#include "ntp_fp.h"
+#include "ntp_stdlib.h"
+#include "ntp_syslog.h"
+#include "ntp_io.h"
+#include "recvbuff.h"
+#include "iosignal.h"
+
+/*
+ * Memory allocation
+ */
+static u_long volatile full_recvbufs; /* number of recvbufs on fulllist */
+static u_long volatile free_recvbufs; /* number of recvbufs on freelist */
+static u_long volatile total_recvbufs; /* total recvbufs currently in use */
+static u_long volatile lowater_adds; /* number of times we have added memory */
+
+static struct recvbuf *volatile freelist; /* free buffers */
+static struct recvbuf *volatile fulllist; /* lifo buffers with data */
+static struct recvbuf *volatile beginlist; /* fifo buffers with data */
+
+#if defined(HAVE_IO_COMPLETION_PORT)
+static HANDLE fulldatabufferevent;
+static CRITICAL_SECTION RecvCritSection;
+# define RECV_BLOCK_IO() EnterCriticalSection(&RecvCritSection)
+# define RECV_UNBLOCK_IO() LeaveCriticalSection(&RecvCritSection)
+#else
+# define RECV_BLOCK_IO()
+# define RECV_UNBLOCK_IO()
+#endif
+
+u_long
+free_recvbuffs (void)
+{
+ return free_recvbufs;
+}
+
+u_long
+full_recvbuffs (void)
+{
+ return free_recvbufs;
+}
+
+u_long
+total_recvbuffs (void)
+{
+ return free_recvbufs;
+}
+
+u_long
+lowater_additions(void)
+{
+ return lowater_adds;
+}
+
+static void
+initialise_buffer(struct recvbuf *buff)
+{
+ memset((char *) buff, 0, sizeof(struct recvbuf));
+
+#if defined HAVE_IO_COMPLETION_PORT
+ buff->iocompletioninfo.overlapped.hEvent = CreateEvent(NULL, FALSE,FALSE, NULL);
+ buff->wsabuff.len = RX_BUFF_SIZE;
+ buff->wsabuff.buf = (char *) buff->recv_buffer;
+#endif
+}
+
+static void
+create_buffers(void)
+{
+ register struct recvbuf *buf;
+ int i;
+ buf = (struct recvbuf *)
+ emalloc(RECV_INC*sizeof(struct recvbuf));
+ for (i = 0; i < RECV_INC; i++)
+ {
+ initialise_buffer(buf);
+ buf->next = (struct recvbuf *) freelist;
+ freelist = buf;
+ buf++;
+ }
+
+ free_recvbufs += RECV_INC;
+ total_recvbufs += RECV_INC;
+ lowater_adds++;
+}
+
+void
+init_recvbuff(int nbufs)
+{
+ register struct recvbuf *buf;
+ int i;
+
+ /*
+ * Init buffer free list and stat counters
+ */
+ freelist = 0;
+
+ buf = (struct recvbuf *)
+ emalloc(nbufs*sizeof(struct recvbuf));
+ for (i = 0; i < nbufs; i++)
+ {
+ initialise_buffer(buf);
+ buf->next = (struct recvbuf *) freelist;
+ freelist = buf;
+ buf++;
+ }
+
+ fulllist = 0;
+ free_recvbufs = total_recvbufs = nbufs;
+ full_recvbufs = lowater_adds = 0;
+
+#if defined(HAVE_IO_COMPLETION_PORT)
+ InitializeCriticalSection(&RecvCritSection);
+ fulldatabufferevent = CreateEvent(NULL, FALSE,FALSE, NULL);
+#endif
+
+}
+
+#if defined(HAVE_IO_COMPLETION_PORT)
+
+/* Return the new full buffer event handle . This handle is
+ * signalled when a recv buffer is placed in the full list.
+ */
+HANDLE
+get_recv_buff_event()
+{
+ return fulldatabufferevent;
+}
+#endif
+
+/*
+ * getrecvbufs - get receive buffers which have data in them
+ *
+ *
+ */
+
+struct recvbuf *
+getrecvbufs(void)
+{
+ struct recvbuf *rb = NULL; /* nothing has arrived */;
+
+ RECV_BLOCK_IO();
+ if (full_recvbufs == 0)
+ {
+#ifdef DEBUG
+ if (debug > 4)
+ printf("getrecvbufs called, no action here\n");
+#endif
+ }
+ else {
+
+ /*
+ * Get the fulllist chain and mark it empty
+ */
+#ifdef DEBUG
+ if (debug > 4)
+ printf("getrecvbufs returning %ld buffers\n", full_recvbufs);
+#endif
+ rb = beginlist;
+ fulllist = 0;
+ full_recvbufs = 0;
+
+ /*
+ * Check to see if we're below the low water mark.
+ */
+ if (free_recvbufs <= RECV_LOWAT)
+ {
+ if (total_recvbufs >= RECV_TOOMANY)
+ msyslog(LOG_ERR, "too many recvbufs allocated (%ld)",
+ total_recvbufs);
+ else
+ {
+ create_buffers();
+ }
+ }
+ }
+ RECV_UNBLOCK_IO();
+
+ /*
+ * Return the chain
+ */
+ return rb;
+}
+
+/*
+ * freerecvbuf - make a single recvbuf available for reuse
+ */
+void
+freerecvbuf(
+ struct recvbuf *rb
+ )
+{
+ RECV_BLOCK_IO();
+ BLOCKIO();
+ rb->next = (struct recvbuf *) freelist;
+ freelist = rb;
+ free_recvbufs++;
+ UNBLOCKIO();
+ RECV_UNBLOCK_IO();
+}
+
+
+void
+add_full_recv_buffer(
+ struct recvbuf *rb
+ )
+{
+ RECV_BLOCK_IO();
+ if (full_recvbufs == 0)
+ {
+ beginlist = rb;
+ rb->next = 0;
+ }
+ else
+ {
+ rb->next = fulllist->next;
+ fulllist->next = rb;
+ }
+ fulllist = rb;
+ full_recvbufs++;
+
+#if defined(HAVE_IO_COMPLETION_PORT)
+ if (!SetEvent(fulldatabufferevent)) {
+ msyslog(LOG_ERR, "Can't set receive buffer event");
+ }
+#endif
+ RECV_UNBLOCK_IO();
+}
+
+struct recvbuf *
+get_free_recv_buffer(void)
+{
+ struct recvbuf * buffer = NULL;
+ RECV_BLOCK_IO();
+ if (free_recvbufs <= RECV_LOWAT)
+ {
+ if (total_recvbufs >= RECV_TOOMANY) {
+ msyslog(LOG_ERR, "too many recvbufs allocated (%ld)",
+ total_recvbufs);
+ }
+ else
+ {
+ create_buffers();
+ }
+ }
+
+ if (free_recvbufs > 0)
+ {
+ buffer = freelist;
+ freelist = buffer->next;
+ buffer->next = NULL;
+ --free_recvbufs;
+ }
+
+ RECV_UNBLOCK_IO();
+ return buffer;
+}
+
+struct recvbuf *
+get_full_recv_buffer(void)
+{
+ struct recvbuf * buffer = NULL;
+ RECV_BLOCK_IO();
+ if (full_recvbufs > 0) {
+ --full_recvbufs;
+ buffer = beginlist;
+ beginlist = buffer->next;
+ buffer->next = NULL;
+ }
+ RECV_UNBLOCK_IO();
+ return buffer;
+}
diff --git a/contrib/ntp/libntp/refnumtoa.c b/contrib/ntp/libntp/refnumtoa.c
new file mode 100644
index 0000000..a102015
--- /dev/null
+++ b/contrib/ntp/libntp/refnumtoa.c
@@ -0,0 +1,31 @@
+/*
+ * refnumtoa - return asciized refclock addresses stored in local array space
+ */
+#include <stdio.h>
+
+#include "ntp_fp.h"
+#include "lib_strbuf.h"
+#include "ntp_stdlib.h"
+
+char *
+refnumtoa(
+ u_int32 num
+ )
+{
+ register u_int32 netnum;
+ register char *buf;
+ register const char *rclock;
+
+ netnum = ntohl(num);
+
+ LIB_GETBUF(buf);
+
+ rclock = clockname((int)((u_long)netnum >> 8) & 0xff);
+
+ if (rclock != NULL)
+ (void)sprintf(buf, "%s(%lu)", rclock, (u_long)netnum & 0xff);
+ else
+ (void)sprintf(buf, "REFCLK(%lu,%lu)",
+ ((u_long)netnum >> 8) & 0xff, (u_long)netnum & 0xff);
+ return buf;
+}
diff --git a/contrib/ntp/libntp/statestr.c b/contrib/ntp/libntp/statestr.c
new file mode 100644
index 0000000..7dd6009
--- /dev/null
+++ b/contrib/ntp/libntp/statestr.c
@@ -0,0 +1,271 @@
+/*
+ * pretty printing of status information
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "ntp_stdlib.h"
+#include "ntp_fp.h"
+#include "ntp.h"
+#include "lib_strbuf.h"
+#include "ntp_refclock.h"
+#include "ntp_control.h"
+#include "ntp_string.h"
+
+/*
+ * Structure for turning various constants into a readable string.
+ */
+struct codestring {
+ int code;
+ const char *string;
+};
+
+/*
+ * Leap values
+ */
+static
+struct codestring leap_codes[] = {
+ { LEAP_NOWARNING, "leap_none" },
+ { LEAP_ADDSECOND, "leap_add_sec" },
+ { LEAP_DELSECOND, "leap_del_sec" },
+ { LEAP_NOTINSYNC, "sync_alarm" },
+ { -1, "leap" }
+};
+
+/*
+ * Clock source
+ */
+static
+struct codestring sync_codes[] = {
+ { CTL_SST_TS_UNSPEC, "sync_unspec" },
+ { CTL_SST_TS_ATOM, "sync_atomic" },
+ { CTL_SST_TS_LF, "sync_lf_clock" },
+ { CTL_SST_TS_HF, "sync_hf_clock" },
+ { CTL_SST_TS_UHF, "sync_uhf_clock" },
+ { CTL_SST_TS_LOCAL, "sync_local_proto" },
+ { CTL_SST_TS_NTP, "sync_ntp" },
+ { CTL_SST_TS_UDPTIME, "sync_udp/time" },
+ { CTL_SST_TS_WRSTWTCH, "sync_wristwatch" },
+ { CTL_SST_TS_TELEPHONE, "sync_telephone" },
+ { -1, "sync" }
+};
+
+
+/*
+ * Peer selection
+ */
+static
+struct codestring select_codes[] = {
+ { CTL_PST_SEL_REJECT, "selreject" },
+ { CTL_PST_SEL_SANE, "sel_falsetick" },
+ { CTL_PST_SEL_CORRECT, "sel_excess" },
+ { CTL_PST_SEL_SELCAND, "sel_outlyer" },
+ { CTL_PST_SEL_SYNCCAND, "sel_candidat" },
+ { CTL_PST_SEL_DISTSYSPEER, "sel_selected" },
+ { CTL_PST_SEL_SYSPEER, "sel_sys.peer" },
+ { CTL_PST_SEL_PPS, "sel_pps.peer" },
+ { -1, "sel" }
+};
+
+
+/*
+ * Clock status
+ */
+static
+struct codestring clock_codes[] = {
+ { CTL_CLK_OKAY, "clk_okay" },
+ { CTL_CLK_NOREPLY, "clk_noreply" },
+ { CTL_CLK_BADFORMAT, "clk_badformat" },
+ { CTL_CLK_FAULT, "clk_fault" },
+ { CTL_CLK_PROPAGATION, "clk_badsignal" },
+ { CTL_CLK_BADDATE, "clk_baddate" },
+ { CTL_CLK_BADTIME, "clk_badtime" },
+ { -1, "clk" }
+};
+
+
+/*
+ * System Events
+ */
+static
+struct codestring sys_codes[] = {
+ { EVNT_UNSPEC, "event_unspec" },
+ { EVNT_SYSRESTART, "event_restart" },
+ { EVNT_SYSFAULT, "event_fault" },
+ { EVNT_SYNCCHG, "event_sync_chg" },
+ { EVNT_PEERSTCHG, "event_peer/strat_chg" },
+ { EVNT_CLOCKRESET, "event_clock_reset" },
+ { EVNT_BADDATETIM, "event_bad_date" },
+ { EVNT_CLOCKEXCPT, "event_clock_excptn" },
+ { -1, "event" }
+};
+
+/*
+ * Peer Events
+ */
+static
+struct codestring peer_codes[] = {
+ { EVNT_UNSPEC, "event_unspec" },
+ { EVNT_PEERIPERR & ~PEER_EVENT, "event_ip_err" },
+ { EVNT_PEERAUTH & ~PEER_EVENT, "event_authen" },
+ { EVNT_UNREACH & ~PEER_EVENT, "event_unreach" },
+ { EVNT_REACH & ~PEER_EVENT, "event_reach" },
+ { EVNT_PEERCLOCK & ~PEER_EVENT, "event_peer_clock" },
+#if 0
+ { EVNT_PEERSTRAT & ~PEER_EVENT, "event_stratum_chg" },
+#endif
+ { -1, "event" }
+};
+
+/* Forwards */
+static const char *getcode P((int, struct codestring *));
+static const char *getevents P((int));
+
+/*
+ * getcode - return string corresponding to code
+ */
+static const char *
+getcode(
+ int code,
+ struct codestring *codetab
+ )
+{
+ static char buf[30];
+
+ while (codetab->code != -1) {
+ if (codetab->code == code)
+ return codetab->string;
+ codetab++;
+ }
+ (void) sprintf(buf, "%s_%d", codetab->string, code);
+ return buf;
+}
+
+/*
+ * getevents - return a descriptive string for the event count
+ */
+static const char *
+getevents(
+ int cnt
+ )
+{
+ static char buf[20];
+
+ if (cnt == 0)
+ return "no events";
+ (void) sprintf(buf, "%d event%s", cnt, (cnt==1) ? "" : "s");
+ return buf;
+}
+
+/*
+ * statustoa - return a descriptive string for a peer status
+ */
+char *
+statustoa(
+ int type,
+ int st
+ )
+{
+ char *cb;
+ u_char pst;
+
+ LIB_GETBUF(cb);
+
+ switch (type) {
+ case TYPE_SYS:
+ (void)strcpy(cb, getcode(CTL_SYS_LI(st), leap_codes));
+ (void)strcat(cb, ", ");
+ (void)strcat(cb, getcode(CTL_SYS_SOURCE(st) & ~CTL_SST_TS_PPS, sync_codes));
+ if (CTL_SYS_SOURCE(st) & CTL_SST_TS_PPS)
+ (void)strcat(cb, "/PPS");
+ (void)strcat(cb, ", ");
+ (void)strcat(cb, getevents(CTL_SYS_NEVNT(st)));
+ (void)strcat(cb, ", ");
+ (void)strcat(cb, getcode(CTL_SYS_EVENT(st), sys_codes));
+ break;
+
+ case TYPE_PEER:
+ /*
+ * Handcraft the bits
+ */
+ pst = (u_char) CTL_PEER_STATVAL(st);
+ if (!(pst & CTL_PST_REACH)) {
+ (void)strcpy(cb, "unreach");
+ } else {
+ (void)strcpy(cb, "reach");
+
+ }
+ if (pst & CTL_PST_CONFIG)
+ (void)strcat(cb, ", conf");
+ if (pst & CTL_PST_AUTHENABLE) {
+ if (!(pst & CTL_PST_REACH) || (pst & CTL_PST_AUTHENTIC))
+ (void)strcat(cb, ", auth");
+ else
+ (void)strcat(cb, ", unauth");
+ }
+
+ /*
+ * Now the codes
+ */
+ if ((pst & 0x7) != CTL_PST_SEL_REJECT) {
+ (void)strcat(cb, ", ");
+ (void)strcat(cb, getcode(pst & 0x7, select_codes));
+ }
+ (void)strcat(cb, ", ");
+ (void)strcat(cb, getevents(CTL_PEER_NEVNT(st)));
+ if (CTL_PEER_EVENT(st) != EVNT_UNSPEC) {
+ (void)strcat(cb, ", ");
+ (void)strcat(cb, getcode(CTL_PEER_EVENT(st),
+ peer_codes));
+ }
+ break;
+
+ case TYPE_CLOCK:
+ (void)strcpy(cb, getcode(((st)>>8) & 0xff, clock_codes));
+ (void)strcat(cb, ", last_");
+ (void)strcat(cb, getcode((st) & 0xff, clock_codes));
+ break;
+ }
+ return cb;
+}
+
+const char *
+eventstr(
+ int num
+ )
+{
+ return getcode(num & ~PEER_EVENT, (num & PEER_EVENT) ? peer_codes : sys_codes);
+}
+
+const char *
+ceventstr(
+ int num
+ )
+{
+ return getcode(num, clock_codes);
+}
+
+const char *
+sysstatstr(
+ int status
+ )
+{
+ return statustoa(TYPE_SYS, status);
+}
+
+const char *
+peerstatstr(
+ int status
+ )
+{
+ return statustoa(TYPE_PEER, status);
+}
+
+const char *
+clockstatstr(
+ int status
+ )
+{
+ return statustoa(TYPE_CLOCK, status);
+}
diff --git a/contrib/ntp/libntp/strerror.c b/contrib/ntp/libntp/strerror.c
new file mode 100644
index 0000000..a07bcd6
--- /dev/null
+++ b/contrib/ntp/libntp/strerror.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley. The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static const char sccsid[] = "@(#)strerror.c 5.1 (Berkeley) 4/9/89";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <string.h>
+
+char *
+strerror(
+ int errnum
+ )
+{
+ extern int sys_nerr;
+ extern char *sys_errlist[];
+ static char ebuf[20];
+
+ if ((unsigned int)errnum < sys_nerr)
+ return(sys_errlist[errnum]);
+ (void)sprintf(ebuf, "Unknown error: %d", errnum);
+ return(ebuf);
+}
diff --git a/contrib/ntp/libntp/syssignal.c b/contrib/ntp/libntp/syssignal.c
new file mode 100644
index 0000000..50c65b7
--- /dev/null
+++ b/contrib/ntp/libntp/syssignal.c
@@ -0,0 +1,123 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <signal.h>
+
+#include "ntp_syslog.h"
+#include "ntp_stdlib.h"
+
+#ifdef HAVE_SIGACTION
+
+void
+signal_no_reset(
+#if defined(__STDC__) || defined(HAVE_STDARG_H)
+ int sig,
+ void (*func) (int)
+#else
+ sig, func
+#endif
+ )
+#if defined(__STDC__) || defined(HAVE_STDARG_H)
+#else
+ int sig;
+ void (*func) P((int));
+#endif
+{
+ int n;
+ struct sigaction vec;
+
+ vec.sa_handler = func;
+ sigemptyset(&vec.sa_mask);
+#if 0
+#ifdef SA_RESTART
+ vec.sa_flags = SA_RESTART;
+#else
+ vec.sa_flags = 0;
+#endif
+#else
+ vec.sa_flags = 0;
+#endif
+
+ while (1)
+ {
+ struct sigaction ovec;
+
+ n = sigaction(sig, &vec, &ovec);
+ if (n == -1 && errno == EINTR) continue;
+ if (ovec.sa_flags
+#ifdef SA_RESTART
+ && ovec.sa_flags != SA_RESTART
+#endif
+ )
+ msyslog(LOG_DEBUG, "signal_no_reset: signal %d had flags %x",
+ sig, ovec.sa_flags);
+ break;
+ }
+ if (n == -1) {
+ perror("sigaction");
+ exit(1);
+ }
+}
+
+#elif HAVE_SIGVEC
+
+void
+signal_no_reset(
+ int sig,
+ RETSIGTYPE (*func) (int)
+ )
+{
+ struct sigvec sv;
+ int n;
+
+ bzero((char *) &sv, sizeof(sv));
+ sv.sv_handler = func;
+ n = sigvec(sig, &sv, (struct sigvec *)NULL);
+ if (n == -1) {
+ perror("sigvec");
+ exit(1);
+ }
+}
+
+#elif HAVE_SIGSET
+
+void
+signal_no_reset(
+ int sig,
+ RETSIGTYPE (*func) (int)
+ )
+{
+ int n;
+
+ n = sigset(sig, func);
+ if (n == -1) {
+ perror("sigset");
+ exit(1);
+ }
+}
+
+#else
+
+/* Beware! This implementation resets the signal to SIG_DFL */
+void
+signal_no_reset(
+ int sig,
+ RETSIGTYPE (*func) (int)
+ )
+{
+#ifdef SIG_ERR
+ if (SIG_ERR == signal(sig, func)) {
+#else
+ int n;
+ n = signal(sig, func);
+ if (n == -1) {
+#endif
+ perror("signal");
+ exit(1);
+ }
+}
+
+#endif
diff --git a/contrib/ntp/libntp/systime.c b/contrib/ntp/libntp/systime.c
new file mode 100644
index 0000000..5e50fc5
--- /dev/null
+++ b/contrib/ntp/libntp/systime.c
@@ -0,0 +1,404 @@
+/*
+ * systime -- routines to fiddle a UNIX clock.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#ifdef HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
+#ifdef HAVE_UTMP_H
+# include <utmp.h>
+#endif /* HAVE_UTMP_H */
+#ifdef HAVE_UTMPX_H
+# include <utmpx.h>
+#endif /* HAVE_UTMPX_H */
+
+#include "ntp_machine.h"
+#include "ntp_fp.h"
+#include "ntp_syslog.h"
+#include "ntp_unixtime.h"
+#include "ntp_stdlib.h"
+
+#if defined SYS_WINNT
+#include "ntp_timer.h"
+extern DWORD units_per_tick;
+static long last_Adj = 0;
+#endif
+
+int systime_10ms_ticks = 0; /* adj sysclock in 10ms increments */
+
+#define MAXFREQ 500e-6
+
+/*
+ * These routines (init_systime, get_systime, step_systime, adj_systime)
+ * implement an interface between the (more or less) system independent
+ * bits of NTP and the peculiarities of dealing with the Unix system
+ * clock.
+ */
+double sys_residual = 0; /* residual from previous adjustment */
+double sys_maxfreq = MAXFREQ; /* max frequency correction */
+
+
+/*
+ * get_systime - return the system time in timestamp format biased by
+ * the current time offset.
+ */
+void
+get_systime(
+ l_fp *now
+ )
+{
+#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK)
+ struct timespec ts;
+#else
+ struct timeval tv;
+#endif
+ double dtemp;
+
+ /*
+ * We use nanosecond time if we can get it. Watch out for
+ * rounding wiggles, which may overflow the fraction.
+ */
+#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK)
+# ifdef HAVE_CLOCK_GETTIME
+ (void) clock_gettime(CLOCK_REALTIME, &ts);
+# else
+ (void) getclock(TIMEOFDAY, &ts);
+# endif
+ now->l_i = ts.tv_sec + JAN_1970;
+ dtemp = ts.tv_nsec * FRAC / 1e9;
+ if (dtemp >= FRAC)
+ now->l_i++;
+ now->l_uf = (u_int32)dtemp;
+#else /* HAVE_CLOCK_GETTIME */
+ (void) GETTIMEOFDAY(&tv, (struct timezone *)0);
+ now->l_i = tv.tv_sec + JAN_1970;
+
+ if (systime_10ms_ticks) {
+ /* fake better than 10ms resolution by interpolating
+ accumulated residual (in adj_systime(), see below) */
+ dtemp = tv.tv_usec / 1e6;
+ if (sys_residual < 5000e-6 && sys_residual > -5000e-6) {
+ dtemp += sys_residual;
+ if (dtemp < 0) {
+ now->l_i--;
+ dtemp++;
+ }
+ }
+ dtemp *= FRAC;
+ } else {
+ dtemp = tv.tv_usec * FRAC / 1e6;
+ }
+
+ if (dtemp >= FRAC)
+ now->l_i++;
+ now->l_uf = (u_int32)dtemp;
+#endif /* HAVE_CLOCK_GETTIME */
+
+}
+
+
+/*
+ * adj_systime - called once every second to make system time adjustments.
+ * Returns 1 if okay, 0 if trouble.
+ */
+int
+adj_systime(
+ double now
+ )
+{
+ double dtemp;
+ struct timeval adjtv;
+ u_char isneg = 0;
+#if !defined SYS_WINNT && !defined SYS_CYGWIN32
+ struct timeval oadjtv;
+#else
+ int rc;
+ long dwTimeAdjustment;
+#endif
+
+ /*
+ * Add the residual from the previous adjustment to the new
+ * adjustment, bound and round.
+ */
+ dtemp = sys_residual + now;
+ sys_residual = 0;
+ if (dtemp < 0) {
+ isneg = 1;
+ dtemp = -dtemp;
+ }
+
+ if (systime_10ms_ticks) {
+ /* accumulate changes until we have enough to adjust a tick */
+ if (dtemp < 5000e-6) {
+ if (isneg) sys_residual = -dtemp;
+ else sys_residual = dtemp;
+ dtemp = 0;
+ } else {
+ if (isneg) sys_residual = 10000e-6 - dtemp;
+ else sys_residual = dtemp - 10000e-6;
+ dtemp = 10000e-6;
+ }
+ } else {
+ if (dtemp > sys_maxfreq)
+ dtemp = sys_maxfreq;
+ }
+
+#ifdef SYS_WINNT
+ dtemp = dtemp * 1000000.0;
+#else
+ dtemp = dtemp * 1e6 + .5;
+#endif
+ if (isneg)
+ dtemp = -dtemp;
+ adjtv.tv_sec = 0;
+ adjtv.tv_usec = (int32)dtemp;
+
+#if defined SYS_WINNT || defined SYS_CYGWIN32
+ /* dtemp is in micro seconds. NT uses 100 ns units,
+ * so a unit change in dwTimeAdjustment corresponds
+ * to slewing 10 ppm.
+ * Calculate the number of 100ns units to add,
+ * and leave the remainder in dtemp */
+ dwTimeAdjustment = dtemp / 10;
+ dtemp += (double) -dwTimeAdjustment * 10.0;
+ dwTimeAdjustment += units_per_tick;
+
+ /* only adjust the clock if adjustment changes */
+ if (last_Adj != dwTimeAdjustment) {
+ last_Adj = dwTimeAdjustment;
+# ifdef DEBUG
+ if (debug > 1)
+ printf("SetSystemTimeAdjustment( %ld)\n", dwTimeAdjustment);
+# endif
+ rc = !SetSystemTimeAdjustment(dwTimeAdjustment, FALSE);
+ }
+ else rc = 0;
+ if (rc)
+#else
+ /*
+ * Here we do the actual adjustment. If for some reason the adjtime()
+ * call fails, like it is not implemented or something like that,
+ * we honk to the log. If the previous adjustment did not complete,
+ * we correct the residual offset.
+ */
+ /* casey - we need a posix type thang here */
+ if (adjtime(&adjtv, &oadjtv) < 0)
+#endif /* SYS_WINNT */
+ {
+ msyslog(LOG_ERR, "Can't adjust time: %m");
+ return 0;
+ }
+ else {
+#if !defined (SYS_WINNT) && !defined (SYS_CYGWIN32)
+ sys_residual += oadjtv.tv_usec / 1e6;
+#else
+ sys_residual = dtemp / 1000000.0;
+#endif /* SYS_WINNT */
+ }
+#ifdef DEBUG
+ if (debug > 6)
+ printf("adj_systime: adj %.9f -> remaining residual %.9f\n", now, sys_residual);
+#endif
+ return 1;
+}
+
+
+/*
+ * step_systime - step the system clock.
+ */
+int
+step_systime(
+ double now
+ )
+{
+ struct timeval timetv, adjtv, oldtimetv;
+ int isneg = 0;
+ double dtemp;
+#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK)
+ struct timespec ts;
+#endif
+
+ dtemp = sys_residual + now;
+ if (dtemp < 0) {
+ isneg = 1;
+ dtemp = - dtemp;
+ adjtv.tv_sec = (int32)dtemp;
+ adjtv.tv_usec = (u_int32)((dtemp - (double)adjtv.tv_sec) *
+ 1e6 + .5);
+ } else {
+ adjtv.tv_sec = (int32)dtemp;
+ adjtv.tv_usec = (u_int32)((dtemp - (double)adjtv.tv_sec) *
+ 1e6 + .5);
+ }
+#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK)
+#ifdef HAVE_CLOCK_GETTIME
+ (void) clock_gettime(CLOCK_REALTIME, &ts);
+#else
+ (void) getclock(TIMEOFDAY, &ts);
+#endif
+ timetv.tv_sec = ts.tv_sec;
+ timetv.tv_usec = ts.tv_nsec / 1000;
+#else /* not HAVE_GETCLOCK */
+ (void) GETTIMEOFDAY(&timetv, (struct timezone *)0);
+#endif /* not HAVE_GETCLOCK */
+
+ oldtimetv = timetv;
+
+#ifdef DEBUG
+ if (debug)
+ printf("step_systime: step %.6f residual %.6f\n", now, sys_residual);
+#endif
+ if (isneg) {
+ timetv.tv_sec -= adjtv.tv_sec;
+ timetv.tv_usec -= adjtv.tv_usec;
+ if (timetv.tv_usec < 0) {
+ timetv.tv_sec--;
+ timetv.tv_usec += 1000000;
+ }
+ } else {
+ timetv.tv_sec += adjtv.tv_sec;
+ timetv.tv_usec += adjtv.tv_usec;
+ if (timetv.tv_usec >= 1000000) {
+ timetv.tv_sec++;
+ timetv.tv_usec -= 1000000;
+ }
+ }
+ if (ntp_set_tod(&timetv, (struct timezone *)0) != 0) {
+ msyslog(LOG_ERR, "Can't set time of day: %m");
+ return (0);
+ }
+ sys_residual = 0;
+
+#ifdef NEED_HPUX_ADJTIME
+ /*
+ * CHECKME: is this correct when called by ntpdate?????
+ */
+ _clear_adjtime();
+#endif
+
+ /*
+ * FreeBSD, for example, has:
+ * struct utmp {
+ * char ut_line[UT_LINESIZE];
+ * char ut_name[UT_NAMESIZE];
+ * char ut_host[UT_HOSTSIZE];
+ * long ut_time;
+ * };
+ * and appends line="|", name="date", host="", time for the OLD
+ * and appends line="{", name="date", host="", time for the NEW
+ * to _PATH_WTMP .
+ *
+ * Some OSes have utmp, some have utmpx.
+ */
+
+ /*
+ * Write old and new time entries in utmp and wtmp if step adjustment
+ * is greater than one second.
+ *
+ * This might become even Uglier...
+ */
+ if (oldtimetv.tv_sec != timetv.tv_sec)
+ {
+#ifdef HAVE_UTMP_H
+ struct utmp ut;
+#endif
+#ifdef HAVE_UTMPX_H
+ struct utmpx utx;
+#endif
+
+#ifdef HAVE_UTMP_H
+ memset((char *)&ut, 0, sizeof(ut));
+#endif
+#ifdef HAVE_UTMPX_H
+ memset((char *)&utx, 0, sizeof(utx));
+#endif
+
+ /* UTMP */
+
+#ifdef UPDATE_UTMP
+# ifdef HAVE_PUTUTLINE
+ ut.ut_type = OLD_TIME;
+ (void)strcpy(ut.ut_line, OTIME_MSG);
+ ut.ut_time = oldtimetv.tv_sec;
+ pututline(&ut);
+ setutent();
+ ut.ut_type = NEW_TIME;
+ (void)strcpy(ut.ut_line, NTIME_MSG);
+ ut.ut_time = timetv.tv_sec;
+ pututline(&ut);
+ endutent();
+# else /* not HAVE_PUTUTLINE */
+# endif /* not HAVE_PUTUTLINE */
+#endif /* UPDATE_UTMP */
+
+ /* UTMPX */
+
+#ifdef UPDATE_UTMPX
+# ifdef HAVE_PUTUTXLINE
+ utx.ut_type = OLD_TIME;
+ (void)strcpy(utx.ut_line, OTIME_MSG);
+ utx.ut_tv = oldtimetv;
+ pututxline(&utx);
+ setutxent();
+ utx.ut_type = NEW_TIME;
+ (void)strcpy(utx.ut_line, NTIME_MSG);
+ utx.ut_tv = timetv;
+ pututxline(&utx);
+ endutxent();
+# else /* not HAVE_PUTUTXLINE */
+# endif /* not HAVE_PUTUTXLINE */
+#endif /* UPDATE_UTMPX */
+
+ /* WTMP */
+
+#ifdef UPDATE_WTMP
+# ifdef HAVE_PUTUTLINE
+ utmpname(WTMP_FILE);
+ ut.ut_type = OLD_TIME;
+ (void)strcpy(ut.ut_line, OTIME_MSG);
+ ut.ut_time = oldtimetv.tv_sec;
+ pututline(&ut);
+ ut.ut_type = NEW_TIME;
+ (void)strcpy(ut.ut_line, NTIME_MSG);
+ ut.ut_time = timetv.tv_sec;
+ pututline(&ut);
+ endutent();
+# else /* not HAVE_PUTUTLINE */
+# endif /* not HAVE_PUTUTLINE */
+#endif /* UPDATE_WTMP */
+
+ /* WTMPX */
+
+#ifdef UPDATE_WTMPX
+# ifdef HAVE_PUTUTXLINE
+ utx.ut_type = OLD_TIME;
+ utx.ut_tv = oldtimetv;
+ (void)strcpy(utx.ut_line, OTIME_MSG);
+# ifdef HAVE_UPDWTMPX
+ updwtmpx(WTMPX_FILE, &utx);
+# else /* not HAVE_UPDWTMPX */
+# endif /* not HAVE_UPDWTMPX */
+# else /* not HAVE_PUTUTXLINE */
+# endif /* not HAVE_PUTUTXLINE */
+# ifdef HAVE_PUTUTXLINE
+ utx.ut_type = NEW_TIME;
+ utx.ut_tv = timetv;
+ (void)strcpy(utx.ut_line, NTIME_MSG);
+# ifdef HAVE_UPDWTMPX
+ updwtmpx(WTMPX_FILE, &utx);
+# else /* not HAVE_UPDWTMPX */
+# endif /* not HAVE_UPDWTMPX */
+# else /* not HAVE_PUTUTXLINE */
+# endif /* not HAVE_PUTUTXLINE */
+#endif /* UPDATE_WTMPX */
+
+ }
+ return (1);
+}
diff --git a/contrib/ntp/libntp/tsftomsu.c b/contrib/ntp/libntp/tsftomsu.c
new file mode 100644
index 0000000..5926aab
--- /dev/null
+++ b/contrib/ntp/libntp/tsftomsu.c
@@ -0,0 +1,38 @@
+/*
+ * tsftomsu - convert from a time stamp fraction to milliseconds
+ */
+#include "ntp_fp.h"
+#include "ntp_stdlib.h"
+
+int
+tsftomsu(
+ u_long tsf,
+ int round
+ )
+{
+ register long val_ui, val_uf;
+ register long tmp_ui, tmp_uf;
+ register int i;
+
+ /*
+ * Essentially, multiply by 10 three times in l_fp form.
+ * The integral part is the milliseconds.
+ */
+ val_ui = 0;
+ val_uf = tsf;
+ for (i = 3; i > 0; i--) {
+ M_LSHIFT(val_ui, val_uf);
+ tmp_ui = val_ui;
+ tmp_uf = val_uf;
+ M_LSHIFT(val_ui, val_uf);
+ M_LSHIFT(val_ui, val_uf);
+ M_ADD(val_ui, val_uf, tmp_ui, tmp_uf);
+ }
+
+ /*
+ * Round the value if need be, then return it.
+ */
+ if (round && (val_uf & 0x80000000))
+ val_ui++;
+ return (int)val_ui;
+}
diff --git a/contrib/ntp/libntp/tstotv.c b/contrib/ntp/libntp/tstotv.c
new file mode 100644
index 0000000..be4bdd4
--- /dev/null
+++ b/contrib/ntp/libntp/tstotv.c
@@ -0,0 +1,135 @@
+/*
+ * tstotv - tables for converting from NTP time stamps to struct timeval
+ */
+
+#include "ntp_types.h"
+
+/*
+ * Tables to convert from a time stamp fraction to usecs. Note that
+ * the units of these tables are actually (usec<<3). We carry three
+ * guard bits so that the result can be properly truncated (or rounded)
+ * to be correct to the least significant bit.
+ *
+ * These tables are rounded.
+ */
+
+long tstoushi[256] = {
+ 0x000000, 0x007a12, 0x00f424, 0x016e36,
+ 0x01e848, 0x02625a, 0x02dc6c, 0x03567e,
+ 0x03d090, 0x044aa2, 0x04c4b4, 0x053ec6,
+ 0x05b8d8, 0x0632ea, 0x06acfc, 0x07270e,
+ 0x07a120, 0x081b32, 0x089544, 0x090f56,
+ 0x098968, 0x0a037a, 0x0a7d8c, 0x0af79e,
+ 0x0b71b0, 0x0bebc2, 0x0c65d4, 0x0cdfe6,
+ 0x0d59f8, 0x0dd40a, 0x0e4e1c, 0x0ec82e,
+ 0x0f4240, 0x0fbc52, 0x103664, 0x10b076,
+ 0x112a88, 0x11a49a, 0x121eac, 0x1298be,
+ 0x1312d0, 0x138ce2, 0x1406f4, 0x148106,
+ 0x14fb18, 0x15752a, 0x15ef3c, 0x16694e,
+ 0x16e360, 0x175d72, 0x17d784, 0x185196,
+ 0x18cba8, 0x1945ba, 0x19bfcc, 0x1a39de,
+ 0x1ab3f0, 0x1b2e02, 0x1ba814, 0x1c2226,
+ 0x1c9c38, 0x1d164a, 0x1d905c, 0x1e0a6e,
+ 0x1e8480, 0x1efe92, 0x1f78a4, 0x1ff2b6,
+ 0x206cc8, 0x20e6da, 0x2160ec, 0x21dafe,
+ 0x225510, 0x22cf22, 0x234934, 0x23c346,
+ 0x243d58, 0x24b76a, 0x25317c, 0x25ab8e,
+ 0x2625a0, 0x269fb2, 0x2719c4, 0x2793d6,
+ 0x280de8, 0x2887fa, 0x29020c, 0x297c1e,
+ 0x29f630, 0x2a7042, 0x2aea54, 0x2b6466,
+ 0x2bde78, 0x2c588a, 0x2cd29c, 0x2d4cae,
+ 0x2dc6c0, 0x2e40d2, 0x2ebae4, 0x2f34f6,
+ 0x2faf08, 0x30291a, 0x30a32c, 0x311d3e,
+ 0x319750, 0x321162, 0x328b74, 0x330586,
+ 0x337f98, 0x33f9aa, 0x3473bc, 0x34edce,
+ 0x3567e0, 0x35e1f2, 0x365c04, 0x36d616,
+ 0x375028, 0x37ca3a, 0x38444c, 0x38be5e,
+ 0x393870, 0x39b282, 0x3a2c94, 0x3aa6a6,
+ 0x3b20b8, 0x3b9aca, 0x3c14dc, 0x3c8eee,
+ 0x3d0900, 0x3d8312, 0x3dfd24, 0x3e7736,
+ 0x3ef148, 0x3f6b5a, 0x3fe56c, 0x405f7e,
+ 0x40d990, 0x4153a2, 0x41cdb4, 0x4247c6,
+ 0x42c1d8, 0x433bea, 0x43b5fc, 0x44300e,
+ 0x44aa20, 0x452432, 0x459e44, 0x461856,
+ 0x469268, 0x470c7a, 0x47868c, 0x48009e,
+ 0x487ab0, 0x48f4c2, 0x496ed4, 0x49e8e6,
+ 0x4a62f8, 0x4add0a, 0x4b571c, 0x4bd12e,
+ 0x4c4b40, 0x4cc552, 0x4d3f64, 0x4db976,
+ 0x4e3388, 0x4ead9a, 0x4f27ac, 0x4fa1be,
+ 0x501bd0, 0x5095e2, 0x510ff4, 0x518a06,
+ 0x520418, 0x527e2a, 0x52f83c, 0x53724e,
+ 0x53ec60, 0x546672, 0x54e084, 0x555a96,
+ 0x55d4a8, 0x564eba, 0x56c8cc, 0x5742de,
+ 0x57bcf0, 0x583702, 0x58b114, 0x592b26,
+ 0x59a538, 0x5a1f4a, 0x5a995c, 0x5b136e,
+ 0x5b8d80, 0x5c0792, 0x5c81a4, 0x5cfbb6,
+ 0x5d75c8, 0x5defda, 0x5e69ec, 0x5ee3fe,
+ 0x5f5e10, 0x5fd822, 0x605234, 0x60cc46,
+ 0x614658, 0x61c06a, 0x623a7c, 0x62b48e,
+ 0x632ea0, 0x63a8b2, 0x6422c4, 0x649cd6,
+ 0x6516e8, 0x6590fa, 0x660b0c, 0x66851e,
+ 0x66ff30, 0x677942, 0x67f354, 0x686d66,
+ 0x68e778, 0x69618a, 0x69db9c, 0x6a55ae,
+ 0x6acfc0, 0x6b49d2, 0x6bc3e4, 0x6c3df6,
+ 0x6cb808, 0x6d321a, 0x6dac2c, 0x6e263e,
+ 0x6ea050, 0x6f1a62, 0x6f9474, 0x700e86,
+ 0x708898, 0x7102aa, 0x717cbc, 0x71f6ce,
+ 0x7270e0, 0x72eaf2, 0x736504, 0x73df16,
+ 0x745928, 0x74d33a, 0x754d4c, 0x75c75e,
+ 0x764170, 0x76bb82, 0x773594, 0x77afa6,
+ 0x7829b8, 0x78a3ca, 0x791ddc, 0x7997ee
+};
+
+long tstousmid[256] = {
+ 0x0000, 0x007a, 0x00f4, 0x016e, 0x01e8, 0x0262, 0x02dc, 0x0356,
+ 0x03d1, 0x044b, 0x04c5, 0x053f, 0x05b9, 0x0633, 0x06ad, 0x0727,
+ 0x07a1, 0x081b, 0x0895, 0x090f, 0x0989, 0x0a03, 0x0a7e, 0x0af8,
+ 0x0b72, 0x0bec, 0x0c66, 0x0ce0, 0x0d5a, 0x0dd4, 0x0e4e, 0x0ec8,
+ 0x0f42, 0x0fbc, 0x1036, 0x10b0, 0x112b, 0x11a5, 0x121f, 0x1299,
+ 0x1313, 0x138d, 0x1407, 0x1481, 0x14fb, 0x1575, 0x15ef, 0x1669,
+ 0x16e3, 0x175d, 0x17d8, 0x1852, 0x18cc, 0x1946, 0x19c0, 0x1a3a,
+ 0x1ab4, 0x1b2e, 0x1ba8, 0x1c22, 0x1c9c, 0x1d16, 0x1d90, 0x1e0a,
+ 0x1e84, 0x1eff, 0x1f79, 0x1ff3, 0x206d, 0x20e7, 0x2161, 0x21db,
+ 0x2255, 0x22cf, 0x2349, 0x23c3, 0x243d, 0x24b7, 0x2531, 0x25ac,
+ 0x2626, 0x26a0, 0x271a, 0x2794, 0x280e, 0x2888, 0x2902, 0x297c,
+ 0x29f6, 0x2a70, 0x2aea, 0x2b64, 0x2bde, 0x2c59, 0x2cd3, 0x2d4d,
+ 0x2dc7, 0x2e41, 0x2ebb, 0x2f35, 0x2faf, 0x3029, 0x30a3, 0x311d,
+ 0x3197, 0x3211, 0x328b, 0x3306, 0x3380, 0x33fa, 0x3474, 0x34ee,
+ 0x3568, 0x35e2, 0x365c, 0x36d6, 0x3750, 0x37ca, 0x3844, 0x38be,
+ 0x3938, 0x39b3, 0x3a2d, 0x3aa7, 0x3b21, 0x3b9b, 0x3c15, 0x3c8f,
+ 0x3d09, 0x3d83, 0x3dfd, 0x3e77, 0x3ef1, 0x3f6b, 0x3fe5, 0x405f,
+ 0x40da, 0x4154, 0x41ce, 0x4248, 0x42c2, 0x433c, 0x43b6, 0x4430,
+ 0x44aa, 0x4524, 0x459e, 0x4618, 0x4692, 0x470c, 0x4787, 0x4801,
+ 0x487b, 0x48f5, 0x496f, 0x49e9, 0x4a63, 0x4add, 0x4b57, 0x4bd1,
+ 0x4c4b, 0x4cc5, 0x4d3f, 0x4db9, 0x4e34, 0x4eae, 0x4f28, 0x4fa2,
+ 0x501c, 0x5096, 0x5110, 0x518a, 0x5204, 0x527e, 0x52f8, 0x5372,
+ 0x53ec, 0x5466, 0x54e1, 0x555b, 0x55d5, 0x564f, 0x56c9, 0x5743,
+ 0x57bd, 0x5837, 0x58b1, 0x592b, 0x59a5, 0x5a1f, 0x5a99, 0x5b13,
+ 0x5b8d, 0x5c08, 0x5c82, 0x5cfc, 0x5d76, 0x5df0, 0x5e6a, 0x5ee4,
+ 0x5f5e, 0x5fd8, 0x6052, 0x60cc, 0x6146, 0x61c0, 0x623a, 0x62b5,
+ 0x632f, 0x63a9, 0x6423, 0x649d, 0x6517, 0x6591, 0x660b, 0x6685,
+ 0x66ff, 0x6779, 0x67f3, 0x686d, 0x68e7, 0x6962, 0x69dc, 0x6a56,
+ 0x6ad0, 0x6b4a, 0x6bc4, 0x6c3e, 0x6cb8, 0x6d32, 0x6dac, 0x6e26,
+ 0x6ea0, 0x6f1a, 0x6f94, 0x700f, 0x7089, 0x7103, 0x717d, 0x71f7,
+ 0x7271, 0x72eb, 0x7365, 0x73df, 0x7459, 0x74d3, 0x754d, 0x75c7,
+ 0x7641, 0x76bc, 0x7736, 0x77b0, 0x782a, 0x78a4, 0x791e, 0x7998
+};
+
+long tstouslo[128] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
+ 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
+ 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e,
+ 0x1f, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
+ 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
+ 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x33, 0x34,
+ 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c,
+ 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44,
+ 0x45, 0x46, 0x47, 0x48, 0x48, 0x49, 0x4a, 0x4b,
+ 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
+ 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b,
+ 0x5c, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62,
+ 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a,
+ 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x71,
+ 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79
+};
diff --git a/contrib/ntp/libntp/tvtoa.c b/contrib/ntp/libntp/tvtoa.c
new file mode 100644
index 0000000..6bc72ac
--- /dev/null
+++ b/contrib/ntp/libntp/tvtoa.c
@@ -0,0 +1,38 @@
+/*
+ * tvtoa - return an asciized representation of a struct timeval
+ */
+#include <stdio.h>
+#include <sys/time.h>
+
+#include "lib_strbuf.h"
+#if defined(VMS)
+#include "ntp_fp.h"
+#endif /* VMS */
+#include "ntp_stdlib.h"
+#include "ntp_unixtime.h"
+
+char *
+tvtoa(
+ const struct timeval *tv
+ )
+{
+ register char *buf;
+ register u_long sec;
+ register u_long usec;
+ register int isneg;
+
+ if (tv->tv_sec < 0 || tv->tv_usec < 0) {
+ sec = -tv->tv_sec;
+ usec = -tv->tv_usec;
+ isneg = 1;
+ } else {
+ sec = tv->tv_sec;
+ usec = tv->tv_usec;
+ isneg = 0;
+ }
+
+ LIB_GETBUF(buf);
+
+ (void) sprintf(buf, "%s%lu.%06lu", (isneg?"-":""), sec, usec);
+ return buf;
+}
diff --git a/contrib/ntp/libntp/tvtots.c b/contrib/ntp/libntp/tvtots.c
new file mode 100644
index 0000000..0bd2b69
--- /dev/null
+++ b/contrib/ntp/libntp/tvtots.c
@@ -0,0 +1,159 @@
+/*
+ * tvtots - tables for converting from Unix struct timeval's to
+ * NTP time stamp format.
+ */
+#include <sys/types.h>
+
+#include "ntp_types.h"
+
+/*
+ * Tables to calculate time stamp fractions from usecs. The entries
+ * in these tables are offset into using each of the two low order
+ * bytes plus the next 4 bits in a usec value (from a struct timeval).
+ * These are summed to produce the time stamp fraction.
+ *
+ * Note that these tables are rounded (not truncated) to the nearest
+ * low order bit in the fraction. The timestamp computed should be
+ * +- 1.5 low order bits.
+ */
+
+u_long ustotslo[256] = {
+ 0x00000000, 0x000010c7, 0x0000218e, 0x00003255,
+ 0x0000431c, 0x000053e3, 0x000064aa, 0x00007571,
+ 0x00008638, 0x000096ff, 0x0000a7c6, 0x0000b88d,
+ 0x0000c954, 0x0000da1b, 0x0000eae2, 0x0000fba9,
+ 0x00010c6f, 0x00011d36, 0x00012dfd, 0x00013ec4,
+ 0x00014f8b, 0x00016052, 0x00017119, 0x000181e0,
+ 0x000192a7, 0x0001a36e, 0x0001b435, 0x0001c4fc,
+ 0x0001d5c3, 0x0001e68a, 0x0001f751, 0x00020818,
+ 0x000218df, 0x000229a6, 0x00023a6d, 0x00024b34,
+ 0x00025bfb, 0x00026cc2, 0x00027d89, 0x00028e50,
+ 0x00029f17, 0x0002afde, 0x0002c0a5, 0x0002d16c,
+ 0x0002e233, 0x0002f2fa, 0x000303c0, 0x00031487,
+ 0x0003254e, 0x00033615, 0x000346dc, 0x000357a3,
+ 0x0003686a, 0x00037931, 0x000389f8, 0x00039abf,
+ 0x0003ab86, 0x0003bc4d, 0x0003cd14, 0x0003dddb,
+ 0x0003eea2, 0x0003ff69, 0x00041030, 0x000420f7,
+ 0x000431be, 0x00044285, 0x0004534c, 0x00046413,
+ 0x000474da, 0x000485a1, 0x00049668, 0x0004a72f,
+ 0x0004b7f6, 0x0004c8bd, 0x0004d984, 0x0004ea4b,
+ 0x0004fb12, 0x00050bd8, 0x00051c9f, 0x00052d66,
+ 0x00053e2d, 0x00054ef4, 0x00055fbb, 0x00057082,
+ 0x00058149, 0x00059210, 0x0005a2d7, 0x0005b39e,
+ 0x0005c465, 0x0005d52c, 0x0005e5f3, 0x0005f6ba,
+ 0x00060781, 0x00061848, 0x0006290f, 0x000639d6,
+ 0x00064a9d, 0x00065b64, 0x00066c2b, 0x00067cf2,
+ 0x00068db9, 0x00069e80, 0x0006af47, 0x0006c00e,
+ 0x0006d0d5, 0x0006e19c, 0x0006f263, 0x00070329,
+ 0x000713f0, 0x000724b7, 0x0007357e, 0x00074645,
+ 0x0007570c, 0x000767d3, 0x0007789a, 0x00078961,
+ 0x00079a28, 0x0007aaef, 0x0007bbb6, 0x0007cc7d,
+ 0x0007dd44, 0x0007ee0b, 0x0007fed2, 0x00080f99,
+ 0x00082060, 0x00083127, 0x000841ee, 0x000852b5,
+ 0x0008637c, 0x00087443, 0x0008850a, 0x000895d1,
+ 0x0008a698, 0x0008b75f, 0x0008c826, 0x0008d8ed,
+ 0x0008e9b4, 0x0008fa7b, 0x00090b41, 0x00091c08,
+ 0x00092ccf, 0x00093d96, 0x00094e5d, 0x00095f24,
+ 0x00096feb, 0x000980b2, 0x00099179, 0x0009a240,
+ 0x0009b307, 0x0009c3ce, 0x0009d495, 0x0009e55c,
+ 0x0009f623, 0x000a06ea, 0x000a17b1, 0x000a2878,
+ 0x000a393f, 0x000a4a06, 0x000a5acd, 0x000a6b94,
+ 0x000a7c5b, 0x000a8d22, 0x000a9de9, 0x000aaeb0,
+ 0x000abf77, 0x000ad03e, 0x000ae105, 0x000af1cc,
+ 0x000b0292, 0x000b1359, 0x000b2420, 0x000b34e7,
+ 0x000b45ae, 0x000b5675, 0x000b673c, 0x000b7803,
+ 0x000b88ca, 0x000b9991, 0x000baa58, 0x000bbb1f,
+ 0x000bcbe6, 0x000bdcad, 0x000bed74, 0x000bfe3b,
+ 0x000c0f02, 0x000c1fc9, 0x000c3090, 0x000c4157,
+ 0x000c521e, 0x000c62e5, 0x000c73ac, 0x000c8473,
+ 0x000c953a, 0x000ca601, 0x000cb6c8, 0x000cc78f,
+ 0x000cd856, 0x000ce91d, 0x000cf9e4, 0x000d0aaa,
+ 0x000d1b71, 0x000d2c38, 0x000d3cff, 0x000d4dc6,
+ 0x000d5e8d, 0x000d6f54, 0x000d801b, 0x000d90e2,
+ 0x000da1a9, 0x000db270, 0x000dc337, 0x000dd3fe,
+ 0x000de4c5, 0x000df58c, 0x000e0653, 0x000e171a,
+ 0x000e27e1, 0x000e38a8, 0x000e496f, 0x000e5a36,
+ 0x000e6afd, 0x000e7bc4, 0x000e8c8b, 0x000e9d52,
+ 0x000eae19, 0x000ebee0, 0x000ecfa7, 0x000ee06e,
+ 0x000ef135, 0x000f01fb, 0x000f12c2, 0x000f2389,
+ 0x000f3450, 0x000f4517, 0x000f55de, 0x000f66a5,
+ 0x000f776c, 0x000f8833, 0x000f98fa, 0x000fa9c1,
+ 0x000fba88, 0x000fcb4f, 0x000fdc16, 0x000fecdd,
+ 0x000ffda4, 0x00100e6b, 0x00101f32, 0x00102ff9,
+ 0x001040c0, 0x00105187, 0x0010624e, 0x00107315,
+ 0x001083dc, 0x001094a3, 0x0010a56a, 0x0010b631,
+};
+
+u_long ustotsmid[256] = {
+ 0x00000000, 0x0010c6f8, 0x00218def, 0x003254e7,
+ 0x00431bde, 0x0053e2d6, 0x0064a9ce, 0x007570c5,
+ 0x008637bd, 0x0096feb4, 0x00a7c5ac, 0x00b88ca4,
+ 0x00c9539b, 0x00da1a93, 0x00eae18a, 0x00fba882,
+ 0x010c6f7a, 0x011d3671, 0x012dfd69, 0x013ec460,
+ 0x014f8b58, 0x01605250, 0x01711947, 0x0181e03f,
+ 0x0192a736, 0x01a36e2e, 0x01b43526, 0x01c4fc1d,
+ 0x01d5c315, 0x01e68a0c, 0x01f75104, 0x020817fc,
+ 0x0218def3, 0x0229a5eb, 0x023a6ce3, 0x024b33da,
+ 0x025bfad2, 0x026cc1c9, 0x027d88c1, 0x028e4fb9,
+ 0x029f16b0, 0x02afdda8, 0x02c0a49f, 0x02d16b97,
+ 0x02e2328f, 0x02f2f986, 0x0303c07e, 0x03148775,
+ 0x03254e6d, 0x03361565, 0x0346dc5c, 0x0357a354,
+ 0x03686a4b, 0x03793143, 0x0389f83b, 0x039abf32,
+ 0x03ab862a, 0x03bc4d21, 0x03cd1419, 0x03dddb11,
+ 0x03eea208, 0x03ff6900, 0x04102ff7, 0x0420f6ef,
+ 0x0431bde7, 0x044284de, 0x04534bd6, 0x046412cd,
+ 0x0474d9c5, 0x0485a0bd, 0x049667b4, 0x04a72eac,
+ 0x04b7f5a3, 0x04c8bc9b, 0x04d98393, 0x04ea4a8a,
+ 0x04fb1182, 0x050bd879, 0x051c9f71, 0x052d6669,
+ 0x053e2d60, 0x054ef458, 0x055fbb4f, 0x05708247,
+ 0x0581493f, 0x05921036, 0x05a2d72e, 0x05b39e25,
+ 0x05c4651d, 0x05d52c15, 0x05e5f30c, 0x05f6ba04,
+ 0x060780fb, 0x061847f3, 0x06290eeb, 0x0639d5e2,
+ 0x064a9cda, 0x065b63d2, 0x066c2ac9, 0x067cf1c1,
+ 0x068db8b8, 0x069e7fb0, 0x06af46a8, 0x06c00d9f,
+ 0x06d0d497, 0x06e19b8e, 0x06f26286, 0x0703297e,
+ 0x0713f075, 0x0724b76d, 0x07357e64, 0x0746455c,
+ 0x07570c54, 0x0767d34b, 0x07789a43, 0x0789613a,
+ 0x079a2832, 0x07aaef2a, 0x07bbb621, 0x07cc7d19,
+ 0x07dd4410, 0x07ee0b08, 0x07fed200, 0x080f98f7,
+ 0x08205fef, 0x083126e6, 0x0841edde, 0x0852b4d6,
+ 0x08637bcd, 0x087442c5, 0x088509bc, 0x0895d0b4,
+ 0x08a697ac, 0x08b75ea3, 0x08c8259b, 0x08d8ec92,
+ 0x08e9b38a, 0x08fa7a82, 0x090b4179, 0x091c0871,
+ 0x092ccf68, 0x093d9660, 0x094e5d58, 0x095f244f,
+ 0x096feb47, 0x0980b23e, 0x09917936, 0x09a2402e,
+ 0x09b30725, 0x09c3ce1d, 0x09d49514, 0x09e55c0c,
+ 0x09f62304, 0x0a06e9fb, 0x0a17b0f3, 0x0a2877ea,
+ 0x0a393ee2, 0x0a4a05da, 0x0a5accd1, 0x0a6b93c9,
+ 0x0a7c5ac1, 0x0a8d21b8, 0x0a9de8b0, 0x0aaeafa7,
+ 0x0abf769f, 0x0ad03d97, 0x0ae1048e, 0x0af1cb86,
+ 0x0b02927d, 0x0b135975, 0x0b24206d, 0x0b34e764,
+ 0x0b45ae5c, 0x0b567553, 0x0b673c4b, 0x0b780343,
+ 0x0b88ca3a, 0x0b999132, 0x0baa5829, 0x0bbb1f21,
+ 0x0bcbe619, 0x0bdcad10, 0x0bed7408, 0x0bfe3aff,
+ 0x0c0f01f7, 0x0c1fc8ef, 0x0c308fe6, 0x0c4156de,
+ 0x0c521dd5, 0x0c62e4cd, 0x0c73abc5, 0x0c8472bc,
+ 0x0c9539b4, 0x0ca600ab, 0x0cb6c7a3, 0x0cc78e9b,
+ 0x0cd85592, 0x0ce91c8a, 0x0cf9e381, 0x0d0aaa79,
+ 0x0d1b7171, 0x0d2c3868, 0x0d3cff60, 0x0d4dc657,
+ 0x0d5e8d4f, 0x0d6f5447, 0x0d801b3e, 0x0d90e236,
+ 0x0da1a92d, 0x0db27025, 0x0dc3371d, 0x0dd3fe14,
+ 0x0de4c50c, 0x0df58c03, 0x0e0652fb, 0x0e1719f3,
+ 0x0e27e0ea, 0x0e38a7e2, 0x0e496ed9, 0x0e5a35d1,
+ 0x0e6afcc9, 0x0e7bc3c0, 0x0e8c8ab8, 0x0e9d51b0,
+ 0x0eae18a7, 0x0ebedf9f, 0x0ecfa696, 0x0ee06d8e,
+ 0x0ef13486, 0x0f01fb7d, 0x0f12c275, 0x0f23896c,
+ 0x0f345064, 0x0f45175c, 0x0f55de53, 0x0f66a54b,
+ 0x0f776c42, 0x0f88333a, 0x0f98fa32, 0x0fa9c129,
+ 0x0fba8821, 0x0fcb4f18, 0x0fdc1610, 0x0fecdd08,
+ 0x0ffda3ff, 0x100e6af7, 0x101f31ee, 0x102ff8e6,
+ 0x1040bfde, 0x105186d5, 0x10624dcd, 0x107314c4,
+ 0x1083dbbc, 0x1094a2b4, 0x10a569ab, 0x10b630a3,
+};
+
+u_long ustotshi[16] = {
+ 0x00000000, 0x10c6f79a, 0x218def35, 0x3254e6cf,
+ 0x431bde6a, 0x53e2d604, 0x64a9cd9f, 0x7570c539,
+ 0x8637bcd3, 0x96feb46e, 0xa7c5ac08, 0xb88ca3a3,
+ 0xc9539b3d, 0xda1a92d7, 0xeae18a72, 0xfba8820c,
+};
diff --git a/contrib/ntp/libntp/uglydate.c b/contrib/ntp/libntp/uglydate.c
new file mode 100644
index 0000000..fcd3d9f
--- /dev/null
+++ b/contrib/ntp/libntp/uglydate.c
@@ -0,0 +1,50 @@
+/*
+ * uglydate - convert a time stamp to something barely readable
+ * The string returned is 37 characters long.
+ */
+#include <stdio.h>
+
+#include "ntp_fp.h"
+#include "ntp_unixtime.h"
+#include "lib_strbuf.h"
+#include "ntp_stdlib.h"
+#ifndef TM_IN_SYS_TIME
+#include <time.h>
+#endif
+
+char *
+uglydate(
+ l_fp *ts
+ )
+{
+ char *bp;
+ char *timep;
+ struct tm *tm;
+ time_t sec;
+ long msec;
+ int year;
+
+ timep = ulfptoa(ts, 6); /* returns max 17 characters */
+ LIB_GETBUF(bp);
+ sec = ts->l_ui - JAN_1970;
+ msec = ts->l_uf / 4294967; /* fract / (2**32/1000) */
+ tm = gmtime(&sec);
+ if (ts->l_ui == 0) {
+ /*
+ * Probably not a real good thing to do. Oh, well.
+ */
+ year = 0;
+ tm->tm_yday = 0;
+ tm->tm_hour = 0;
+ tm->tm_min = 0;
+ tm->tm_sec = 0;
+ } else {
+ year = tm->tm_year;
+ while (year >= 100)
+ year -= 100;
+ }
+ (void) sprintf(bp, "%17s %02d:%03d:%02d:%02d:%02d.%03ld",
+ timep, year, tm->tm_yday, tm->tm_hour, tm->tm_min,
+ tm->tm_sec, msec);
+ return bp;
+}
diff --git a/contrib/ntp/libntp/uinttoa.c b/contrib/ntp/libntp/uinttoa.c
new file mode 100644
index 0000000..be48ea5
--- /dev/null
+++ b/contrib/ntp/libntp/uinttoa.c
@@ -0,0 +1,20 @@
+/*
+ * uinttoa - return an asciized unsigned integer
+ */
+#include <stdio.h>
+
+#include "lib_strbuf.h"
+#include "ntp_stdlib.h"
+
+char *
+uinttoa(
+ u_long uval
+ )
+{
+ register char *buf;
+
+ LIB_GETBUF(buf);
+
+ (void) sprintf(buf, "%lu", (u_long)uval);
+ return buf;
+}
diff --git a/contrib/ntp/libntp/utvtoa.c b/contrib/ntp/libntp/utvtoa.c
new file mode 100644
index 0000000..79d14ef
--- /dev/null
+++ b/contrib/ntp/libntp/utvtoa.c
@@ -0,0 +1,26 @@
+/*
+ * utvtoa - return an asciized representation of an unsigned struct timeval
+ */
+#include <stdio.h>
+#include <sys/time.h>
+
+#include "lib_strbuf.h"
+#if defined(VMS)
+#include "ntp_fp.h"
+#endif
+#include "ntp_stdlib.h"
+#include "ntp_unixtime.h"
+
+char *
+utvtoa(
+ const struct timeval *tv
+ )
+{
+ register char *buf;
+
+ LIB_GETBUF(buf);
+
+ (void) sprintf(buf, "%lu.%06lu", (u_long)tv->tv_sec,
+ (u_long)tv->tv_usec);
+ return buf;
+}
diff --git a/contrib/ntp/libntp/ymd2yd.c b/contrib/ntp/libntp/ymd2yd.c
new file mode 100644
index 0000000..796ce40
--- /dev/null
+++ b/contrib/ntp/libntp/ymd2yd.c
@@ -0,0 +1,37 @@
+/*
+ * ymd2yd - compute the date in the year from y/m/d
+ */
+
+#include "ntp_fp.h"
+#include "ntp_unixtime.h"
+#include "ntp_stdlib.h"
+
+/*
+ * Tables to compute the day of year from yyyymmdd timecode.
+ * Viva la leap.
+ */
+static int day1tab[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+static int day2tab[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+
+int
+ymd2yd(
+ int y,
+ int m,
+ int d
+ )
+{
+ int i, *t;
+
+ if (m < 1 || m > 12 || d < 1)
+ return (-1);
+
+ if (((y%4 == 0) && (y%100 != 0)) || (y%400 == 0))
+ t = day2tab; /* leap year */
+ else
+ t = day1tab; /* not a leap year */
+ if (d > t[m - 1])
+ return (-1);
+ for (i = 0; i < m - 1; i++)
+ d += t[i];
+ return d;
+}
OpenPOWER on IntegriCloud