summaryrefslogtreecommitdiffstats
path: root/libntp
diff options
context:
space:
mode:
Diffstat (limited to 'libntp')
-rw-r--r--libntp/Makefile.am35
-rw-r--r--libntp/Makefile.in1212
-rw-r--r--libntp/README5
-rw-r--r--libntp/a_md5encrypt.c104
-rw-r--r--libntp/adjtime.c323
-rw-r--r--libntp/adjtimex.c15
-rw-r--r--libntp/atoint.c50
-rw-r--r--libntp/atolfp.c118
-rw-r--r--libntp/atouint.c35
-rw-r--r--libntp/audio.c481
-rw-r--r--libntp/authencrypt.c97
-rw-r--r--libntp/authkeys.c488
-rw-r--r--libntp/authparity.c66
-rw-r--r--libntp/authreadkeys.c162
-rw-r--r--libntp/authusekey.c47
-rw-r--r--libntp/binio.c128
-rw-r--r--libntp/buftvtots.c106
-rw-r--r--libntp/caljulian.c115
-rw-r--r--libntp/calleapwhen.c59
-rw-r--r--libntp/caltontp.c42
-rw-r--r--libntp/calyearstart.c22
-rw-r--r--libntp/clocktime.c132
-rw-r--r--libntp/clocktypes.c118
-rw-r--r--libntp/decodenetnum.c40
-rw-r--r--libntp/dofptoa.c118
-rw-r--r--libntp/dolfptoa.c162
-rw-r--r--libntp/emalloc.c48
-rw-r--r--libntp/findconfig.c72
-rw-r--r--libntp/fptoa.c25
-rw-r--r--libntp/fptoms.c24
-rw-r--r--libntp/getopt.c107
-rw-r--r--libntp/gpstolfp.c41
-rw-r--r--libntp/hextoint.c39
-rw-r--r--libntp/hextolfp.c67
-rw-r--r--libntp/humandate.c63
-rw-r--r--libntp/icom.c324
-rw-r--r--libntp/ieee754io.c575
-rw-r--r--libntp/inttoa.c20
-rw-r--r--libntp/iosignal.c544
-rw-r--r--libntp/lib_strbuf.c23
-rw-r--r--libntp/lib_strbuf.h27
-rw-r--r--libntp/log.c161
-rw-r--r--libntp/log.h21
-rw-r--r--libntp/machines.c525
-rw-r--r--libntp/md5c.c354
-rw-r--r--libntp/memmove.c140
-rw-r--r--libntp/mfp_mul.c140
-rw-r--r--libntp/mfptoa.c23
-rw-r--r--libntp/mfptoms.c23
-rw-r--r--libntp/mktime.c306
-rw-r--r--libntp/modetoa.c34
-rw-r--r--libntp/mstolfp.c100
-rw-r--r--libntp/msutotsf.c35
-rw-r--r--libntp/msyslog.c207
-rw-r--r--libntp/netof.c48
-rw-r--r--libntp/ntp_rfc2553.c331
-rw-r--r--libntp/numtoa.c24
-rw-r--r--libntp/numtohost.c39
-rw-r--r--libntp/octtoint.c35
-rw-r--r--libntp/prettydate.c68
-rw-r--r--libntp/random.c482
-rw-r--r--libntp/ranny.c82
-rw-r--r--libntp/recvbuff.c259
-rw-r--r--libntp/refnumtoa.c36
-rw-r--r--libntp/snprintf.c62
-rw-r--r--libntp/socktoa.c48
-rw-r--r--libntp/socktohost.c32
-rw-r--r--libntp/statestr.c303
-rw-r--r--libntp/strdup.c28
-rw-r--r--libntp/strerror.c48
-rw-r--r--libntp/strstr.c52
-rw-r--r--libntp/syssignal.c133
-rw-r--r--libntp/systime.c521
-rw-r--r--libntp/systime_s.c2
-rw-r--r--libntp/tsftomsu.c38
-rw-r--r--libntp/tstotv.c135
-rw-r--r--libntp/tvtoa.c39
-rw-r--r--libntp/tvtots.c159
-rw-r--r--libntp/uglydate.c48
-rw-r--r--libntp/uinttoa.c20
-rw-r--r--libntp/utvtoa.c26
-rw-r--r--libntp/ymd2yd.c37
82 files changed, 11483 insertions, 0 deletions
diff --git a/libntp/Makefile.am b/libntp/Makefile.am
new file mode 100644
index 0000000..75b5505
--- /dev/null
+++ b/libntp/Makefile.am
@@ -0,0 +1,35 @@
+#AUTOMAKE_OPTIONS = ../ansi2knr no-dependencies
+AUTOMAKE_OPTIONS = ../util/ansi2knr
+noinst_LIBRARIES = libntp.a @MAKE_LIBNTPSIM@
+EXTRA_LIBRARIES = libntpsim.a
+libntp_a_SRCS = a_md5encrypt.c adjtime.c atoint.c atolfp.c atouint.c \
+ audio.c authkeys.c authreadkeys.c authusekey.c binio.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 gpstolfp.c hextoint.c \
+ hextolfp.c humandate.c icom.c ieee754io.c inttoa.c iosignal.c \
+ lib_strbuf.c machines.c md5c.c memmove.c mfp_mul.c mfptoa.c \
+ mfptoms.c mktime.c modetoa.c mstolfp.c msutotsf.c msyslog.c netof.c \
+ ntp_rfc2553.c numtoa.c numtohost.c octtoint.c prettydate.c \
+ ranny.c recvbuff.c refnumtoa.c snprintf.c socktoa.c socktohost.c \
+ statestr.c strdup.c strerror.c strstr.c \
+ syssignal.c tsftomsu.c tstotv.c tvtoa.c tvtots.c \
+ uglydate.c uinttoa.c utvtoa.c ymd2yd.c \
+ $(srcdir)/../libisc/assertions.c $(srcdir)/../libisc/error.c \
+ $(srcdir)/../libisc/interfaceiter.c $(srcdir)/../libisc/lib.c \
+ $(srcdir)/../libisc/mem.c $(srcdir)/../libisc/msgcat.c \
+ $(srcdir)/../libisc/net.c $(srcdir)/../libisc/isc_strerror.c \
+ $(srcdir)/../libisc/inet_ntop.c
+libntp_a_SOURCES = systime.c $(libntp_a_SRCS)
+libntpsim_a_SOURCES = systime_s.c $(libntp_a_SRCS)
+EXTRA_libntp_a_SOURCES = adjtimex.c log.c random.c
+INCLUDES = -I$(top_srcdir)/include -I../include
+ETAGS_ARGS = Makefile.am
+
+noinst_HEADERS = lib_strbuf.h log.h
+
+../include/des.h:
+ touch ../include/des.h
+
+EXTRA_DIST = README
+
diff --git a/libntp/Makefile.in b/libntp/Makefile.in
new file mode 100644
index 0000000..1565b0b
--- /dev/null
+++ b/libntp/Makefile.in
@@ -0,0 +1,1212 @@
+# Makefile.in generated by automake 1.7.7 from Makefile.am.
+# @configure_input@
+
+# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+# Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+top_builddir = ..
+
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = @INSTALL@
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+target_triplet = @target@
+ACLOCAL = @ACLOCAL@
+AMDEP_FALSE = @AMDEP_FALSE@
+AMDEP_TRUE = @AMDEP_TRUE@
+AMTAR = @AMTAR@
+ARLIB_DIR = @ARLIB_DIR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CHUTEST = @CHUTEST@
+CLKTEST = @CLKTEST@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DCFD = @DCFD@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EF_LIBS = @EF_LIBS@
+EF_PROGS = @EF_PROGS@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LCRYPTO = @LCRYPTO@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBPARSE = @LIBPARSE@
+LIBS = @LIBS@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MAKE_ADJTIMED = @MAKE_ADJTIMED@
+MAKE_CHECK_Y2K = @MAKE_CHECK_Y2K@
+MAKE_LIBNTPSIM = @MAKE_LIBNTPSIM@
+MAKE_LIBPARSE = @MAKE_LIBPARSE@
+MAKE_LIBPARSE_KERNEL = @MAKE_LIBPARSE_KERNEL@
+MAKE_NTPDSIM = @MAKE_NTPDSIM@
+MAKE_NTPTIME = @MAKE_NTPTIME@
+MAKE_NTP_KEYGEN = @MAKE_NTP_KEYGEN@
+MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@
+MAKE_SNTP = @MAKE_SNTP@
+MAKE_TICKADJ = @MAKE_TICKADJ@
+MAKE_TIMETRIM = @MAKE_TIMETRIM@
+OBJEXT = @OBJEXT@
+OPENSSL = @OPENSSL@
+OPENSSL_INC = @OPENSSL_INC@
+OPENSSL_LIB = @OPENSSL_LIB@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_PERL = @PATH_PERL@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PATH_SH = @PATH_SH@
+PROPDELAY = @PROPDELAY@
+RANLIB = @RANLIB@
+READLINE_LIBS = @READLINE_LIBS@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+TESTDCF = @TESTDCF@
+U = @U@
+VERSION = @VERSION@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_RANLIB = @ac_ct_RANLIB@
+ac_ct_STRIP = @ac_ct_STRIP@
+am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
+am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+datadir = @datadir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+oldincludedir = @oldincludedir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+subdirs = @subdirs@
+sysconfdir = @sysconfdir@
+target = @target@
+target_alias = @target_alias@
+target_cpu = @target_cpu@
+target_os = @target_os@
+target_vendor = @target_vendor@
+
+#AUTOMAKE_OPTIONS = ../ansi2knr no-dependencies
+AUTOMAKE_OPTIONS = ../util/ansi2knr
+noinst_LIBRARIES = libntp.a @MAKE_LIBNTPSIM@
+EXTRA_LIBRARIES = libntpsim.a
+libntp_a_SRCS = a_md5encrypt.c adjtime.c atoint.c atolfp.c atouint.c \
+ audio.c authkeys.c authreadkeys.c authusekey.c binio.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 gpstolfp.c hextoint.c \
+ hextolfp.c humandate.c icom.c ieee754io.c inttoa.c iosignal.c \
+ lib_strbuf.c machines.c md5c.c memmove.c mfp_mul.c mfptoa.c \
+ mfptoms.c mktime.c modetoa.c mstolfp.c msutotsf.c msyslog.c netof.c \
+ ntp_rfc2553.c numtoa.c numtohost.c octtoint.c prettydate.c \
+ ranny.c recvbuff.c refnumtoa.c snprintf.c socktoa.c socktohost.c \
+ statestr.c strdup.c strerror.c strstr.c \
+ syssignal.c tsftomsu.c tstotv.c tvtoa.c tvtots.c \
+ uglydate.c uinttoa.c utvtoa.c ymd2yd.c \
+ $(srcdir)/../libisc/assertions.c $(srcdir)/../libisc/error.c \
+ $(srcdir)/../libisc/interfaceiter.c $(srcdir)/../libisc/lib.c \
+ $(srcdir)/../libisc/mem.c $(srcdir)/../libisc/msgcat.c \
+ $(srcdir)/../libisc/net.c $(srcdir)/../libisc/isc_strerror.c \
+ $(srcdir)/../libisc/inet_ntop.c
+
+libntp_a_SOURCES = systime.c $(libntp_a_SRCS)
+libntpsim_a_SOURCES = systime_s.c $(libntp_a_SRCS)
+EXTRA_libntp_a_SOURCES = adjtimex.c log.c random.c
+INCLUDES = -I$(top_srcdir)/include -I../include
+ETAGS_ARGS = Makefile.am
+
+noinst_HEADERS = lib_strbuf.h log.h
+
+EXTRA_DIST = README
+subdir = libntp
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+LIBRARIES = $(noinst_LIBRARIES)
+
+libntp_a_AR = $(AR) cru
+libntp_a_LIBADD =
+am__objects_1 = a_md5encrypt$U.$(OBJEXT) adjtime$U.$(OBJEXT) \
+ atoint$U.$(OBJEXT) atolfp$U.$(OBJEXT) atouint$U.$(OBJEXT) \
+ audio$U.$(OBJEXT) authkeys$U.$(OBJEXT) authreadkeys$U.$(OBJEXT) \
+ authusekey$U.$(OBJEXT) binio$U.$(OBJEXT) buftvtots$U.$(OBJEXT) \
+ caljulian$U.$(OBJEXT) calleapwhen$U.$(OBJEXT) \
+ caltontp$U.$(OBJEXT) calyearstart$U.$(OBJEXT) \
+ clocktime$U.$(OBJEXT) clocktypes$U.$(OBJEXT) \
+ decodenetnum$U.$(OBJEXT) dofptoa$U.$(OBJEXT) \
+ dolfptoa$U.$(OBJEXT) emalloc$U.$(OBJEXT) findconfig$U.$(OBJEXT) \
+ fptoa$U.$(OBJEXT) fptoms$U.$(OBJEXT) getopt$U.$(OBJEXT) \
+ gpstolfp$U.$(OBJEXT) hextoint$U.$(OBJEXT) hextolfp$U.$(OBJEXT) \
+ humandate$U.$(OBJEXT) icom$U.$(OBJEXT) ieee754io$U.$(OBJEXT) \
+ inttoa$U.$(OBJEXT) iosignal$U.$(OBJEXT) lib_strbuf$U.$(OBJEXT) \
+ machines$U.$(OBJEXT) md5c$U.$(OBJEXT) memmove$U.$(OBJEXT) \
+ mfp_mul$U.$(OBJEXT) mfptoa$U.$(OBJEXT) mfptoms$U.$(OBJEXT) \
+ mktime$U.$(OBJEXT) modetoa$U.$(OBJEXT) mstolfp$U.$(OBJEXT) \
+ msutotsf$U.$(OBJEXT) msyslog$U.$(OBJEXT) netof$U.$(OBJEXT) \
+ ntp_rfc2553$U.$(OBJEXT) numtoa$U.$(OBJEXT) \
+ numtohost$U.$(OBJEXT) octtoint$U.$(OBJEXT) \
+ prettydate$U.$(OBJEXT) ranny$U.$(OBJEXT) recvbuff$U.$(OBJEXT) \
+ refnumtoa$U.$(OBJEXT) snprintf$U.$(OBJEXT) socktoa$U.$(OBJEXT) \
+ socktohost$U.$(OBJEXT) statestr$U.$(OBJEXT) strdup$U.$(OBJEXT) \
+ strerror$U.$(OBJEXT) strstr$U.$(OBJEXT) syssignal$U.$(OBJEXT) \
+ tsftomsu$U.$(OBJEXT) tstotv$U.$(OBJEXT) tvtoa$U.$(OBJEXT) \
+ tvtots$U.$(OBJEXT) uglydate$U.$(OBJEXT) uinttoa$U.$(OBJEXT) \
+ utvtoa$U.$(OBJEXT) ymd2yd$U.$(OBJEXT) assertions$U.$(OBJEXT) \
+ error$U.$(OBJEXT) interfaceiter$U.$(OBJEXT) lib$U.$(OBJEXT) \
+ mem$U.$(OBJEXT) msgcat$U.$(OBJEXT) net$U.$(OBJEXT) \
+ isc_strerror$U.$(OBJEXT) inet_ntop$U.$(OBJEXT)
+am_libntp_a_OBJECTS = systime$U.$(OBJEXT) $(am__objects_1)
+libntp_a_OBJECTS = $(am_libntp_a_OBJECTS)
+libntpsim_a_AR = $(AR) cru
+libntpsim_a_LIBADD =
+am_libntpsim_a_OBJECTS = systime_s$U.$(OBJEXT) $(am__objects_1)
+libntpsim_a_OBJECTS = $(am_libntpsim_a_OBJECTS)
+
+DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/a_md5encrypt$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/adjtime$U.Po ./$(DEPDIR)/adjtimex$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/assertions$U.Po ./$(DEPDIR)/atoint$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/atolfp$U.Po ./$(DEPDIR)/atouint$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/audio$U.Po ./$(DEPDIR)/authkeys$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/authreadkeys$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/authusekey$U.Po ./$(DEPDIR)/binio$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/buftvtots$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/caljulian$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/calleapwhen$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/caltontp$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/calyearstart$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/clocktime$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/clocktypes$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/decodenetnum$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/dofptoa$U.Po ./$(DEPDIR)/dolfptoa$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/emalloc$U.Po ./$(DEPDIR)/error$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/findconfig$U.Po ./$(DEPDIR)/fptoa$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/fptoms$U.Po ./$(DEPDIR)/getopt$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/gpstolfp$U.Po ./$(DEPDIR)/hextoint$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/hextolfp$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/humandate$U.Po ./$(DEPDIR)/icom$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/ieee754io$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/inet_ntop$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/interfaceiter$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/inttoa$U.Po ./$(DEPDIR)/iosignal$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/isc_strerror$U.Po ./$(DEPDIR)/lib$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/lib_strbuf$U.Po ./$(DEPDIR)/log$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/machines$U.Po ./$(DEPDIR)/md5c$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/mem$U.Po ./$(DEPDIR)/memmove$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/mfp_mul$U.Po ./$(DEPDIR)/mfptoa$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/mfptoms$U.Po ./$(DEPDIR)/mktime$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/modetoa$U.Po ./$(DEPDIR)/msgcat$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/mstolfp$U.Po ./$(DEPDIR)/msutotsf$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/msyslog$U.Po ./$(DEPDIR)/net$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/netof$U.Po ./$(DEPDIR)/ntp_rfc2553$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/numtoa$U.Po ./$(DEPDIR)/numtohost$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/octtoint$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/prettydate$U.Po ./$(DEPDIR)/random$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/ranny$U.Po ./$(DEPDIR)/recvbuff$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/refnumtoa$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/snprintf$U.Po ./$(DEPDIR)/socktoa$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/socktohost$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/statestr$U.Po ./$(DEPDIR)/strdup$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/strerror$U.Po ./$(DEPDIR)/strstr$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/syssignal$U.Po ./$(DEPDIR)/systime$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/systime_s$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/tsftomsu$U.Po ./$(DEPDIR)/tstotv$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/tvtoa$U.Po ./$(DEPDIR)/tvtots$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/uglydate$U.Po ./$(DEPDIR)/uinttoa$U.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/utvtoa$U.Po ./$(DEPDIR)/ymd2yd$U.Po
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+DIST_SOURCES = $(libntp_a_SOURCES) $(EXTRA_libntp_a_SOURCES) \
+ $(libntpsim_a_SOURCES)
+HEADERS = $(noinst_HEADERS)
+
+DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/Makefile.in \
+ Makefile.am
+SOURCES = $(libntp_a_SOURCES) $(EXTRA_libntp_a_SOURCES) $(libntpsim_a_SOURCES)
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .o .obj
+$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu libntp/Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
+
+AR = ar
+
+clean-noinstLIBRARIES:
+ -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
+libntp.a: $(libntp_a_OBJECTS) $(libntp_a_DEPENDENCIES)
+ -rm -f libntp.a
+ $(libntp_a_AR) libntp.a $(libntp_a_OBJECTS) $(libntp_a_LIBADD)
+ $(RANLIB) libntp.a
+libntpsim.a: $(libntpsim_a_OBJECTS) $(libntpsim_a_DEPENDENCIES)
+ -rm -f libntpsim.a
+ $(libntpsim_a_AR) libntpsim.a $(libntpsim_a_OBJECTS) $(libntpsim_a_LIBADD)
+ $(RANLIB) libntpsim.a
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT) core *.core
+
+distclean-compile:
+ -rm -f *.tab.c
+
+ANSI2KNR = ../util/ansi2knr
+../util/ansi2knr:
+ cd ../util && $(MAKE) $(AM_MAKEFLAGS) ansi2knr
+
+mostlyclean-kr:
+ -test "$U" = "" || rm -f *_.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/a_md5encrypt$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/adjtime$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/adjtimex$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/assertions$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atoint$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atolfp$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/atouint$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audio$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/authkeys$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/authreadkeys$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/authusekey$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/binio$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buftvtots$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/caljulian$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/calleapwhen$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/caltontp$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/calyearstart$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clocktime$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clocktypes$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/decodenetnum$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dofptoa$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dolfptoa$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/emalloc$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/error$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/findconfig$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fptoa$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fptoms$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gpstolfp$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hextoint$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hextolfp$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/humandate$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/icom$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ieee754io$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inet_ntop$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/interfaceiter$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inttoa$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iosignal$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isc_strerror$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lib$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lib_strbuf$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/machines$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md5c$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mem$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memmove$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mfp_mul$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mfptoa$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mfptoms$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mktime$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/modetoa$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msgcat$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mstolfp$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msutotsf$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msyslog$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/net$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netof$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_rfc2553$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/numtoa$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/numtohost$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/octtoint$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/prettydate$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/random$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ranny$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/recvbuff$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/refnumtoa$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snprintf$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socktoa$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socktohost$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/statestr$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strdup$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strerror$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strstr$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/syssignal$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/systime$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/systime_s$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsftomsu$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tstotv$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tvtoa$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tvtots$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uglydate$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uinttoa$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utvtoa$U.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ymd2yd$U.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
+@am__fastdepCC_TRUE@ -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
+
+.c.obj:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
+@am__fastdepCC_TRUE@ -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`
+
+assertions_.o: assertions_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT assertions_.o -MD -MP -MF "$(DEPDIR)/assertions_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o assertions_.o `test -f 'assertions_.c' || echo '$(srcdir)/'`assertions_.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/assertions_.Tpo" "$(DEPDIR)/assertions_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/assertions_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='assertions_.c' object='assertions_.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/assertions_.Po' tmpdepfile='$(DEPDIR)/assertions_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o assertions_.o `test -f 'assertions_.c' || echo '$(srcdir)/'`assertions_.c
+
+assertions_.obj: assertions_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT assertions_.obj -MD -MP -MF "$(DEPDIR)/assertions_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o assertions_.obj `if test -f 'assertions_.c'; then $(CYGPATH_W) 'assertions_.c'; else $(CYGPATH_W) '$(srcdir)/assertions_.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/assertions_.Tpo" "$(DEPDIR)/assertions_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/assertions_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='assertions_.c' object='assertions_.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/assertions_.Po' tmpdepfile='$(DEPDIR)/assertions_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o assertions_.obj `if test -f 'assertions_.c'; then $(CYGPATH_W) 'assertions_.c'; else $(CYGPATH_W) '$(srcdir)/assertions_.c'; fi`
+
+assertions.o: $(srcdir)/../libisc/assertions.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT assertions.o -MD -MP -MF "$(DEPDIR)/assertions.Tpo" \
+@am__fastdepCC_TRUE@ -c -o assertions.o `test -f '$(srcdir)/../libisc/assertions.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/assertions.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/assertions.Tpo" "$(DEPDIR)/assertions.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/assertions.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/assertions.c' object='assertions.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/assertions.Po' tmpdepfile='$(DEPDIR)/assertions.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o assertions.o `test -f '$(srcdir)/../libisc/assertions.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/assertions.c
+
+assertions.obj: $(srcdir)/../libisc/assertions.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT assertions.obj -MD -MP -MF "$(DEPDIR)/assertions.Tpo" \
+@am__fastdepCC_TRUE@ -c -o assertions.obj `if test -f '$(srcdir)/../libisc/assertions.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/assertions.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/assertions.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/assertions.Tpo" "$(DEPDIR)/assertions.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/assertions.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/assertions.c' object='assertions.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/assertions.Po' tmpdepfile='$(DEPDIR)/assertions.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o assertions.obj `if test -f '$(srcdir)/../libisc/assertions.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/assertions.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/assertions.c'; fi`
+
+error_.o: error_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT error_.o -MD -MP -MF "$(DEPDIR)/error_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o error_.o `test -f 'error_.c' || echo '$(srcdir)/'`error_.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/error_.Tpo" "$(DEPDIR)/error_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/error_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='error_.c' object='error_.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/error_.Po' tmpdepfile='$(DEPDIR)/error_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o error_.o `test -f 'error_.c' || echo '$(srcdir)/'`error_.c
+
+error_.obj: error_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT error_.obj -MD -MP -MF "$(DEPDIR)/error_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o error_.obj `if test -f 'error_.c'; then $(CYGPATH_W) 'error_.c'; else $(CYGPATH_W) '$(srcdir)/error_.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/error_.Tpo" "$(DEPDIR)/error_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/error_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='error_.c' object='error_.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/error_.Po' tmpdepfile='$(DEPDIR)/error_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o error_.obj `if test -f 'error_.c'; then $(CYGPATH_W) 'error_.c'; else $(CYGPATH_W) '$(srcdir)/error_.c'; fi`
+
+error.o: $(srcdir)/../libisc/error.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT error.o -MD -MP -MF "$(DEPDIR)/error.Tpo" \
+@am__fastdepCC_TRUE@ -c -o error.o `test -f '$(srcdir)/../libisc/error.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/error.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/error.Tpo" "$(DEPDIR)/error.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/error.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/error.c' object='error.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/error.Po' tmpdepfile='$(DEPDIR)/error.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o error.o `test -f '$(srcdir)/../libisc/error.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/error.c
+
+error.obj: $(srcdir)/../libisc/error.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT error.obj -MD -MP -MF "$(DEPDIR)/error.Tpo" \
+@am__fastdepCC_TRUE@ -c -o error.obj `if test -f '$(srcdir)/../libisc/error.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/error.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/error.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/error.Tpo" "$(DEPDIR)/error.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/error.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/error.c' object='error.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/error.Po' tmpdepfile='$(DEPDIR)/error.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o error.obj `if test -f '$(srcdir)/../libisc/error.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/error.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/error.c'; fi`
+
+interfaceiter_.o: interfaceiter_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interfaceiter_.o -MD -MP -MF "$(DEPDIR)/interfaceiter_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o interfaceiter_.o `test -f 'interfaceiter_.c' || echo '$(srcdir)/'`interfaceiter_.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/interfaceiter_.Tpo" "$(DEPDIR)/interfaceiter_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/interfaceiter_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='interfaceiter_.c' object='interfaceiter_.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/interfaceiter_.Po' tmpdepfile='$(DEPDIR)/interfaceiter_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o interfaceiter_.o `test -f 'interfaceiter_.c' || echo '$(srcdir)/'`interfaceiter_.c
+
+interfaceiter_.obj: interfaceiter_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interfaceiter_.obj -MD -MP -MF "$(DEPDIR)/interfaceiter_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o interfaceiter_.obj `if test -f 'interfaceiter_.c'; then $(CYGPATH_W) 'interfaceiter_.c'; else $(CYGPATH_W) '$(srcdir)/interfaceiter_.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/interfaceiter_.Tpo" "$(DEPDIR)/interfaceiter_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/interfaceiter_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='interfaceiter_.c' object='interfaceiter_.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/interfaceiter_.Po' tmpdepfile='$(DEPDIR)/interfaceiter_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o interfaceiter_.obj `if test -f 'interfaceiter_.c'; then $(CYGPATH_W) 'interfaceiter_.c'; else $(CYGPATH_W) '$(srcdir)/interfaceiter_.c'; fi`
+
+interfaceiter.o: $(srcdir)/../libisc/interfaceiter.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interfaceiter.o -MD -MP -MF "$(DEPDIR)/interfaceiter.Tpo" \
+@am__fastdepCC_TRUE@ -c -o interfaceiter.o `test -f '$(srcdir)/../libisc/interfaceiter.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/interfaceiter.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/interfaceiter.Tpo" "$(DEPDIR)/interfaceiter.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/interfaceiter.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/interfaceiter.c' object='interfaceiter.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/interfaceiter.Po' tmpdepfile='$(DEPDIR)/interfaceiter.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o interfaceiter.o `test -f '$(srcdir)/../libisc/interfaceiter.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/interfaceiter.c
+
+interfaceiter.obj: $(srcdir)/../libisc/interfaceiter.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT interfaceiter.obj -MD -MP -MF "$(DEPDIR)/interfaceiter.Tpo" \
+@am__fastdepCC_TRUE@ -c -o interfaceiter.obj `if test -f '$(srcdir)/../libisc/interfaceiter.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/interfaceiter.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/interfaceiter.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/interfaceiter.Tpo" "$(DEPDIR)/interfaceiter.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/interfaceiter.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/interfaceiter.c' object='interfaceiter.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/interfaceiter.Po' tmpdepfile='$(DEPDIR)/interfaceiter.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o interfaceiter.obj `if test -f '$(srcdir)/../libisc/interfaceiter.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/interfaceiter.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/interfaceiter.c'; fi`
+
+lib_.o: lib_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lib_.o -MD -MP -MF "$(DEPDIR)/lib_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o lib_.o `test -f 'lib_.c' || echo '$(srcdir)/'`lib_.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lib_.Tpo" "$(DEPDIR)/lib_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/lib_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='lib_.c' object='lib_.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/lib_.Po' tmpdepfile='$(DEPDIR)/lib_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lib_.o `test -f 'lib_.c' || echo '$(srcdir)/'`lib_.c
+
+lib_.obj: lib_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lib_.obj -MD -MP -MF "$(DEPDIR)/lib_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o lib_.obj `if test -f 'lib_.c'; then $(CYGPATH_W) 'lib_.c'; else $(CYGPATH_W) '$(srcdir)/lib_.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lib_.Tpo" "$(DEPDIR)/lib_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/lib_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='lib_.c' object='lib_.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/lib_.Po' tmpdepfile='$(DEPDIR)/lib_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lib_.obj `if test -f 'lib_.c'; then $(CYGPATH_W) 'lib_.c'; else $(CYGPATH_W) '$(srcdir)/lib_.c'; fi`
+
+lib.o: $(srcdir)/../libisc/lib.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lib.o -MD -MP -MF "$(DEPDIR)/lib.Tpo" \
+@am__fastdepCC_TRUE@ -c -o lib.o `test -f '$(srcdir)/../libisc/lib.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/lib.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lib.Tpo" "$(DEPDIR)/lib.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/lib.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/lib.c' object='lib.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/lib.Po' tmpdepfile='$(DEPDIR)/lib.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lib.o `test -f '$(srcdir)/../libisc/lib.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/lib.c
+
+lib.obj: $(srcdir)/../libisc/lib.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lib.obj -MD -MP -MF "$(DEPDIR)/lib.Tpo" \
+@am__fastdepCC_TRUE@ -c -o lib.obj `if test -f '$(srcdir)/../libisc/lib.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/lib.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/lib.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lib.Tpo" "$(DEPDIR)/lib.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/lib.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/lib.c' object='lib.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/lib.Po' tmpdepfile='$(DEPDIR)/lib.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lib.obj `if test -f '$(srcdir)/../libisc/lib.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/lib.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/lib.c'; fi`
+
+mem_.o: mem_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mem_.o -MD -MP -MF "$(DEPDIR)/mem_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o mem_.o `test -f 'mem_.c' || echo '$(srcdir)/'`mem_.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/mem_.Tpo" "$(DEPDIR)/mem_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/mem_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='mem_.c' object='mem_.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/mem_.Po' tmpdepfile='$(DEPDIR)/mem_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mem_.o `test -f 'mem_.c' || echo '$(srcdir)/'`mem_.c
+
+mem_.obj: mem_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mem_.obj -MD -MP -MF "$(DEPDIR)/mem_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o mem_.obj `if test -f 'mem_.c'; then $(CYGPATH_W) 'mem_.c'; else $(CYGPATH_W) '$(srcdir)/mem_.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/mem_.Tpo" "$(DEPDIR)/mem_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/mem_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='mem_.c' object='mem_.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/mem_.Po' tmpdepfile='$(DEPDIR)/mem_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mem_.obj `if test -f 'mem_.c'; then $(CYGPATH_W) 'mem_.c'; else $(CYGPATH_W) '$(srcdir)/mem_.c'; fi`
+
+mem.o: $(srcdir)/../libisc/mem.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mem.o -MD -MP -MF "$(DEPDIR)/mem.Tpo" \
+@am__fastdepCC_TRUE@ -c -o mem.o `test -f '$(srcdir)/../libisc/mem.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/mem.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/mem.Tpo" "$(DEPDIR)/mem.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/mem.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/mem.c' object='mem.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/mem.Po' tmpdepfile='$(DEPDIR)/mem.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mem.o `test -f '$(srcdir)/../libisc/mem.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/mem.c
+
+mem.obj: $(srcdir)/../libisc/mem.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mem.obj -MD -MP -MF "$(DEPDIR)/mem.Tpo" \
+@am__fastdepCC_TRUE@ -c -o mem.obj `if test -f '$(srcdir)/../libisc/mem.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/mem.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/mem.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/mem.Tpo" "$(DEPDIR)/mem.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/mem.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/mem.c' object='mem.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/mem.Po' tmpdepfile='$(DEPDIR)/mem.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mem.obj `if test -f '$(srcdir)/../libisc/mem.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/mem.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/mem.c'; fi`
+
+msgcat_.o: msgcat_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT msgcat_.o -MD -MP -MF "$(DEPDIR)/msgcat_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o msgcat_.o `test -f 'msgcat_.c' || echo '$(srcdir)/'`msgcat_.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/msgcat_.Tpo" "$(DEPDIR)/msgcat_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/msgcat_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='msgcat_.c' object='msgcat_.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/msgcat_.Po' tmpdepfile='$(DEPDIR)/msgcat_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o msgcat_.o `test -f 'msgcat_.c' || echo '$(srcdir)/'`msgcat_.c
+
+msgcat_.obj: msgcat_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT msgcat_.obj -MD -MP -MF "$(DEPDIR)/msgcat_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o msgcat_.obj `if test -f 'msgcat_.c'; then $(CYGPATH_W) 'msgcat_.c'; else $(CYGPATH_W) '$(srcdir)/msgcat_.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/msgcat_.Tpo" "$(DEPDIR)/msgcat_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/msgcat_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='msgcat_.c' object='msgcat_.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/msgcat_.Po' tmpdepfile='$(DEPDIR)/msgcat_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o msgcat_.obj `if test -f 'msgcat_.c'; then $(CYGPATH_W) 'msgcat_.c'; else $(CYGPATH_W) '$(srcdir)/msgcat_.c'; fi`
+
+msgcat.o: $(srcdir)/../libisc/msgcat.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT msgcat.o -MD -MP -MF "$(DEPDIR)/msgcat.Tpo" \
+@am__fastdepCC_TRUE@ -c -o msgcat.o `test -f '$(srcdir)/../libisc/msgcat.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/msgcat.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/msgcat.Tpo" "$(DEPDIR)/msgcat.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/msgcat.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/msgcat.c' object='msgcat.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/msgcat.Po' tmpdepfile='$(DEPDIR)/msgcat.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o msgcat.o `test -f '$(srcdir)/../libisc/msgcat.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/msgcat.c
+
+msgcat.obj: $(srcdir)/../libisc/msgcat.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT msgcat.obj -MD -MP -MF "$(DEPDIR)/msgcat.Tpo" \
+@am__fastdepCC_TRUE@ -c -o msgcat.obj `if test -f '$(srcdir)/../libisc/msgcat.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/msgcat.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/msgcat.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/msgcat.Tpo" "$(DEPDIR)/msgcat.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/msgcat.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/msgcat.c' object='msgcat.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/msgcat.Po' tmpdepfile='$(DEPDIR)/msgcat.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o msgcat.obj `if test -f '$(srcdir)/../libisc/msgcat.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/msgcat.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/msgcat.c'; fi`
+
+net_.o: net_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT net_.o -MD -MP -MF "$(DEPDIR)/net_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o net_.o `test -f 'net_.c' || echo '$(srcdir)/'`net_.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/net_.Tpo" "$(DEPDIR)/net_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/net_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='net_.c' object='net_.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/net_.Po' tmpdepfile='$(DEPDIR)/net_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o net_.o `test -f 'net_.c' || echo '$(srcdir)/'`net_.c
+
+net_.obj: net_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT net_.obj -MD -MP -MF "$(DEPDIR)/net_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o net_.obj `if test -f 'net_.c'; then $(CYGPATH_W) 'net_.c'; else $(CYGPATH_W) '$(srcdir)/net_.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/net_.Tpo" "$(DEPDIR)/net_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/net_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='net_.c' object='net_.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/net_.Po' tmpdepfile='$(DEPDIR)/net_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o net_.obj `if test -f 'net_.c'; then $(CYGPATH_W) 'net_.c'; else $(CYGPATH_W) '$(srcdir)/net_.c'; fi`
+
+net.o: $(srcdir)/../libisc/net.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT net.o -MD -MP -MF "$(DEPDIR)/net.Tpo" \
+@am__fastdepCC_TRUE@ -c -o net.o `test -f '$(srcdir)/../libisc/net.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/net.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/net.Tpo" "$(DEPDIR)/net.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/net.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/net.c' object='net.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/net.Po' tmpdepfile='$(DEPDIR)/net.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o net.o `test -f '$(srcdir)/../libisc/net.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/net.c
+
+net.obj: $(srcdir)/../libisc/net.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT net.obj -MD -MP -MF "$(DEPDIR)/net.Tpo" \
+@am__fastdepCC_TRUE@ -c -o net.obj `if test -f '$(srcdir)/../libisc/net.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/net.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/net.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/net.Tpo" "$(DEPDIR)/net.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/net.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/net.c' object='net.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/net.Po' tmpdepfile='$(DEPDIR)/net.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o net.obj `if test -f '$(srcdir)/../libisc/net.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/net.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/net.c'; fi`
+
+isc_strerror_.o: isc_strerror_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT isc_strerror_.o -MD -MP -MF "$(DEPDIR)/isc_strerror_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o isc_strerror_.o `test -f 'isc_strerror_.c' || echo '$(srcdir)/'`isc_strerror_.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/isc_strerror_.Tpo" "$(DEPDIR)/isc_strerror_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/isc_strerror_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='isc_strerror_.c' object='isc_strerror_.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/isc_strerror_.Po' tmpdepfile='$(DEPDIR)/isc_strerror_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o isc_strerror_.o `test -f 'isc_strerror_.c' || echo '$(srcdir)/'`isc_strerror_.c
+
+isc_strerror_.obj: isc_strerror_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT isc_strerror_.obj -MD -MP -MF "$(DEPDIR)/isc_strerror_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o isc_strerror_.obj `if test -f 'isc_strerror_.c'; then $(CYGPATH_W) 'isc_strerror_.c'; else $(CYGPATH_W) '$(srcdir)/isc_strerror_.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/isc_strerror_.Tpo" "$(DEPDIR)/isc_strerror_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/isc_strerror_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='isc_strerror_.c' object='isc_strerror_.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/isc_strerror_.Po' tmpdepfile='$(DEPDIR)/isc_strerror_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o isc_strerror_.obj `if test -f 'isc_strerror_.c'; then $(CYGPATH_W) 'isc_strerror_.c'; else $(CYGPATH_W) '$(srcdir)/isc_strerror_.c'; fi`
+
+isc_strerror.o: $(srcdir)/../libisc/isc_strerror.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT isc_strerror.o -MD -MP -MF "$(DEPDIR)/isc_strerror.Tpo" \
+@am__fastdepCC_TRUE@ -c -o isc_strerror.o `test -f '$(srcdir)/../libisc/isc_strerror.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/isc_strerror.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/isc_strerror.Tpo" "$(DEPDIR)/isc_strerror.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/isc_strerror.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/isc_strerror.c' object='isc_strerror.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/isc_strerror.Po' tmpdepfile='$(DEPDIR)/isc_strerror.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o isc_strerror.o `test -f '$(srcdir)/../libisc/isc_strerror.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/isc_strerror.c
+
+isc_strerror.obj: $(srcdir)/../libisc/isc_strerror.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT isc_strerror.obj -MD -MP -MF "$(DEPDIR)/isc_strerror.Tpo" \
+@am__fastdepCC_TRUE@ -c -o isc_strerror.obj `if test -f '$(srcdir)/../libisc/isc_strerror.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/isc_strerror.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/isc_strerror.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/isc_strerror.Tpo" "$(DEPDIR)/isc_strerror.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/isc_strerror.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/isc_strerror.c' object='isc_strerror.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/isc_strerror.Po' tmpdepfile='$(DEPDIR)/isc_strerror.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o isc_strerror.obj `if test -f '$(srcdir)/../libisc/isc_strerror.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/isc_strerror.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/isc_strerror.c'; fi`
+
+inet_ntop_.o: inet_ntop_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_ntop_.o -MD -MP -MF "$(DEPDIR)/inet_ntop_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o inet_ntop_.o `test -f 'inet_ntop_.c' || echo '$(srcdir)/'`inet_ntop_.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/inet_ntop_.Tpo" "$(DEPDIR)/inet_ntop_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/inet_ntop_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='inet_ntop_.c' object='inet_ntop_.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/inet_ntop_.Po' tmpdepfile='$(DEPDIR)/inet_ntop_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o inet_ntop_.o `test -f 'inet_ntop_.c' || echo '$(srcdir)/'`inet_ntop_.c
+
+inet_ntop_.obj: inet_ntop_.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_ntop_.obj -MD -MP -MF "$(DEPDIR)/inet_ntop_.Tpo" \
+@am__fastdepCC_TRUE@ -c -o inet_ntop_.obj `if test -f 'inet_ntop_.c'; then $(CYGPATH_W) 'inet_ntop_.c'; else $(CYGPATH_W) '$(srcdir)/inet_ntop_.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/inet_ntop_.Tpo" "$(DEPDIR)/inet_ntop_.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/inet_ntop_.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='inet_ntop_.c' object='inet_ntop_.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/inet_ntop_.Po' tmpdepfile='$(DEPDIR)/inet_ntop_.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o inet_ntop_.obj `if test -f 'inet_ntop_.c'; then $(CYGPATH_W) 'inet_ntop_.c'; else $(CYGPATH_W) '$(srcdir)/inet_ntop_.c'; fi`
+
+inet_ntop.o: $(srcdir)/../libisc/inet_ntop.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_ntop.o -MD -MP -MF "$(DEPDIR)/inet_ntop.Tpo" \
+@am__fastdepCC_TRUE@ -c -o inet_ntop.o `test -f '$(srcdir)/../libisc/inet_ntop.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/inet_ntop.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/inet_ntop.Tpo" "$(DEPDIR)/inet_ntop.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/inet_ntop.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/inet_ntop.c' object='inet_ntop.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/inet_ntop.Po' tmpdepfile='$(DEPDIR)/inet_ntop.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o inet_ntop.o `test -f '$(srcdir)/../libisc/inet_ntop.c' || echo '$(srcdir)/'`$(srcdir)/../libisc/inet_ntop.c
+
+inet_ntop.obj: $(srcdir)/../libisc/inet_ntop.c
+@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT inet_ntop.obj -MD -MP -MF "$(DEPDIR)/inet_ntop.Tpo" \
+@am__fastdepCC_TRUE@ -c -o inet_ntop.obj `if test -f '$(srcdir)/../libisc/inet_ntop.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/inet_ntop.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/inet_ntop.c'; fi`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/inet_ntop.Tpo" "$(DEPDIR)/inet_ntop.Po"; \
+@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/inet_ntop.Tpo"; exit 1; \
+@am__fastdepCC_TRUE@ fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(srcdir)/../libisc/inet_ntop.c' object='inet_ntop.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/inet_ntop.Po' tmpdepfile='$(DEPDIR)/inet_ntop.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o inet_ntop.obj `if test -f '$(srcdir)/../libisc/inet_ntop.c'; then $(CYGPATH_W) '$(srcdir)/../libisc/inet_ntop.c'; else $(CYGPATH_W) '$(srcdir)/$(srcdir)/../libisc/inet_ntop.c'; fi`
+a_md5encrypt_.c: a_md5encrypt.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+adjtime_.c: adjtime.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+adjtimex_.c: adjtimex.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/adjtimex.c; then echo $(srcdir)/adjtimex.c; else echo adjtimex.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+assertions_.c: $(srcdir)/../libisc/assertions.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/$(srcdir)/../libisc/assertions.c; then echo $(srcdir)/$(srcdir)/../libisc/assertions.c; else echo $(srcdir)/../libisc/assertions.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+atoint_.c: atoint.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+atolfp_.c: atolfp.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+atouint_.c: atouint.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+audio_.c: audio.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/audio.c; then echo $(srcdir)/audio.c; else echo audio.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+authkeys_.c: authkeys.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+authreadkeys_.c: authreadkeys.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+authusekey_.c: authusekey.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+binio_.c: binio.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+buftvtots_.c: buftvtots.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+caljulian_.c: caljulian.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+calleapwhen_.c: calleapwhen.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+caltontp_.c: caltontp.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+calyearstart_.c: calyearstart.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+clocktime_.c: clocktime.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+clocktypes_.c: clocktypes.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+decodenetnum_.c: decodenetnum.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+dofptoa_.c: dofptoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+dolfptoa_.c: dolfptoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+emalloc_.c: emalloc.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+error_.c: $(srcdir)/../libisc/error.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/$(srcdir)/../libisc/error.c; then echo $(srcdir)/$(srcdir)/../libisc/error.c; else echo $(srcdir)/../libisc/error.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+findconfig_.c: findconfig.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+fptoa_.c: fptoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+fptoms_.c: fptoms.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+getopt_.c: getopt.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+gpstolfp_.c: gpstolfp.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+hextoint_.c: hextoint.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+hextolfp_.c: hextolfp.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+humandate_.c: humandate.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+icom_.c: icom.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/icom.c; then echo $(srcdir)/icom.c; else echo icom.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+ieee754io_.c: ieee754io.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+inet_ntop_.c: $(srcdir)/../libisc/inet_ntop.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/$(srcdir)/../libisc/inet_ntop.c; then echo $(srcdir)/$(srcdir)/../libisc/inet_ntop.c; else echo $(srcdir)/../libisc/inet_ntop.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+interfaceiter_.c: $(srcdir)/../libisc/interfaceiter.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/$(srcdir)/../libisc/interfaceiter.c; then echo $(srcdir)/$(srcdir)/../libisc/interfaceiter.c; else echo $(srcdir)/../libisc/interfaceiter.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+inttoa_.c: inttoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+iosignal_.c: iosignal.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+isc_strerror_.c: $(srcdir)/../libisc/isc_strerror.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/$(srcdir)/../libisc/isc_strerror.c; then echo $(srcdir)/$(srcdir)/../libisc/isc_strerror.c; else echo $(srcdir)/../libisc/isc_strerror.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+lib_.c: $(srcdir)/../libisc/lib.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/$(srcdir)/../libisc/lib.c; then echo $(srcdir)/$(srcdir)/../libisc/lib.c; else echo $(srcdir)/../libisc/lib.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+lib_strbuf_.c: lib_strbuf.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+log_.c: log.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/log.c; then echo $(srcdir)/log.c; else echo log.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+machines_.c: machines.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+md5c_.c: md5c.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+mem_.c: $(srcdir)/../libisc/mem.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/$(srcdir)/../libisc/mem.c; then echo $(srcdir)/$(srcdir)/../libisc/mem.c; else echo $(srcdir)/../libisc/mem.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+memmove_.c: memmove.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+mfp_mul_.c: mfp_mul.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+mfptoa_.c: mfptoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+mfptoms_.c: mfptoms.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+mktime_.c: mktime.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+modetoa_.c: modetoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+msgcat_.c: $(srcdir)/../libisc/msgcat.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/$(srcdir)/../libisc/msgcat.c; then echo $(srcdir)/$(srcdir)/../libisc/msgcat.c; else echo $(srcdir)/../libisc/msgcat.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+mstolfp_.c: mstolfp.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+msutotsf_.c: msutotsf.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+msyslog_.c: msyslog.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+net_.c: $(srcdir)/../libisc/net.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/$(srcdir)/../libisc/net.c; then echo $(srcdir)/$(srcdir)/../libisc/net.c; else echo $(srcdir)/../libisc/net.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+netof_.c: netof.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+ntp_rfc2553_.c: ntp_rfc2553.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntp_rfc2553.c; then echo $(srcdir)/ntp_rfc2553.c; else echo ntp_rfc2553.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+numtoa_.c: numtoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+numtohost_.c: numtohost.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+octtoint_.c: octtoint.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+prettydate_.c: prettydate.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+random_.c: random.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/random.c; then echo $(srcdir)/random.c; else echo random.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+ranny_.c: ranny.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+recvbuff_.c: recvbuff.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+refnumtoa_.c: refnumtoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+snprintf_.c: snprintf.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/snprintf.c; then echo $(srcdir)/snprintf.c; else echo snprintf.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+socktoa_.c: socktoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/socktoa.c; then echo $(srcdir)/socktoa.c; else echo socktoa.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+socktohost_.c: socktohost.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/socktohost.c; then echo $(srcdir)/socktohost.c; else echo socktohost.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+statestr_.c: statestr.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+strdup_.c: strdup.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/strdup.c; then echo $(srcdir)/strdup.c; else echo strdup.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+strerror_.c: strerror.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+strstr_.c: strstr.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/strstr.c; then echo $(srcdir)/strstr.c; else echo strstr.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+syssignal_.c: syssignal.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+systime_.c: systime.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+systime_s_.c: systime_s.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/systime_s.c; then echo $(srcdir)/systime_s.c; else echo systime_s.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@
+tsftomsu_.c: tsftomsu.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+tstotv_.c: tstotv.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+tvtoa_.c: tvtoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+tvtots_.c: tvtots.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+uglydate_.c: uglydate.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+uinttoa_.c: uinttoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+utvtoa_.c: utvtoa.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+ymd2yd_.c: ymd2yd.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(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) > $@ || rm -f $@
+a_md5encrypt_.$(OBJEXT) adjtime_.$(OBJEXT) adjtimex_.$(OBJEXT) \
+assertions_.$(OBJEXT) atoint_.$(OBJEXT) atolfp_.$(OBJEXT) \
+atouint_.$(OBJEXT) audio_.$(OBJEXT) authkeys_.$(OBJEXT) \
+authreadkeys_.$(OBJEXT) authusekey_.$(OBJEXT) binio_.$(OBJEXT) \
+buftvtots_.$(OBJEXT) caljulian_.$(OBJEXT) calleapwhen_.$(OBJEXT) \
+caltontp_.$(OBJEXT) calyearstart_.$(OBJEXT) clocktime_.$(OBJEXT) \
+clocktypes_.$(OBJEXT) decodenetnum_.$(OBJEXT) dofptoa_.$(OBJEXT) \
+dolfptoa_.$(OBJEXT) emalloc_.$(OBJEXT) error_.$(OBJEXT) \
+findconfig_.$(OBJEXT) fptoa_.$(OBJEXT) fptoms_.$(OBJEXT) \
+getopt_.$(OBJEXT) gpstolfp_.$(OBJEXT) hextoint_.$(OBJEXT) \
+hextolfp_.$(OBJEXT) humandate_.$(OBJEXT) icom_.$(OBJEXT) \
+ieee754io_.$(OBJEXT) inet_ntop_.$(OBJEXT) interfaceiter_.$(OBJEXT) \
+inttoa_.$(OBJEXT) iosignal_.$(OBJEXT) isc_strerror_.$(OBJEXT) \
+lib_.$(OBJEXT) lib_strbuf_.$(OBJEXT) log_.$(OBJEXT) machines_.$(OBJEXT) \
+md5c_.$(OBJEXT) mem_.$(OBJEXT) memmove_.$(OBJEXT) mfp_mul_.$(OBJEXT) \
+mfptoa_.$(OBJEXT) mfptoms_.$(OBJEXT) mktime_.$(OBJEXT) \
+modetoa_.$(OBJEXT) msgcat_.$(OBJEXT) mstolfp_.$(OBJEXT) \
+msutotsf_.$(OBJEXT) msyslog_.$(OBJEXT) net_.$(OBJEXT) netof_.$(OBJEXT) \
+ntp_rfc2553_.$(OBJEXT) numtoa_.$(OBJEXT) numtohost_.$(OBJEXT) \
+octtoint_.$(OBJEXT) prettydate_.$(OBJEXT) random_.$(OBJEXT) \
+ranny_.$(OBJEXT) recvbuff_.$(OBJEXT) refnumtoa_.$(OBJEXT) \
+snprintf_.$(OBJEXT) socktoa_.$(OBJEXT) socktohost_.$(OBJEXT) \
+statestr_.$(OBJEXT) strdup_.$(OBJEXT) strerror_.$(OBJEXT) \
+strstr_.$(OBJEXT) syssignal_.$(OBJEXT) systime_.$(OBJEXT) \
+systime_s_.$(OBJEXT) tsftomsu_.$(OBJEXT) tstotv_.$(OBJEXT) \
+tvtoa_.$(OBJEXT) tvtots_.$(OBJEXT) uglydate_.$(OBJEXT) \
+uinttoa_.$(OBJEXT) utvtoa_.$(OBJEXT) ymd2yd_.$(OBJEXT) : $(ANSI2KNR)
+uninstall-info-am:
+
+ETAGS = etags
+ETAGSFLAGS =
+
+CTAGS = ctags
+CTAGSFLAGS =
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ mkid -fID $$unique
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(ETAGS_ARGS)$$tags$$unique" \
+ || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique
+
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(CTAGS_ARGS)$$tags$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$tags $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+
+top_distdir = ..
+distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
+ list='$(DISTFILES)'; for file in $$list; do \
+ case $$file in \
+ $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
+ $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
+ esac; \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+ dir="/$$dir"; \
+ $(mkinstalldirs) "$(distdir)$$dir"; \
+ else \
+ dir=''; \
+ fi; \
+ if test -d $$d/$$file; then \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LIBRARIES) $(HEADERS)
+
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-exec-am:
+
+install-info: install-info-am
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic mostlyclean-kr
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-info-am
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-noinstLIBRARIES ctags distclean distclean-compile \
+ distclean-generic distclean-tags distdir dvi dvi-am info \
+ info-am install install-am install-data install-data-am \
+ install-exec install-exec-am install-info install-info-am \
+ install-man install-strip installcheck installcheck-am \
+ installdirs maintainer-clean maintainer-clean-generic \
+ mostlyclean mostlyclean-compile mostlyclean-generic \
+ mostlyclean-kr pdf pdf-am ps ps-am tags uninstall uninstall-am \
+ uninstall-info-am
+
+
+../include/des.h:
+ touch ../include/des.h
+# 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/libntp/README b/libntp/README
new file mode 100644
index 0000000..fac7185
--- /dev/null
+++ b/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/libntp/a_md5encrypt.c b/libntp/a_md5encrypt.c
new file mode 100644
index 0000000..42513ef
--- /dev/null
+++ b/libntp/a_md5encrypt.c
@@ -0,0 +1,104 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "ntp_fp.h"
+#include "ntp_string.h"
+#include "ntp_stdlib.h"
+
+/* Disable the openssl md5 includes, because they'd clash with ours. */
+/* #define NO_MD5 */
+/* #define OPENSSL_NO_MD5 */
+#undef OPENSSL
+
+#include "ntp.h"
+#include "global.h"
+#include "ntp_md5.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 md5;
+ u_char digest[16];
+
+ /*
+ * MD5 with key identifier concatenated with packet.
+ */
+ MD5Init(&md5);
+ MD5Update(&md5, key, (u_int)cache_keylen);
+ MD5Update(&md5, (u_char *)pkt, (u_int)length);
+ MD5Final(digest, &md5);
+ memmove((u_char *)pkt + length + 4, digest, 16);
+ return (16 + 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 md5;
+ u_char digest[16];
+
+ /*
+ * MD5 with key identifier concatenated with packet.
+ */
+ MD5Init(&md5);
+ MD5Update(&md5, key, (u_int)cache_keylen);
+ MD5Update(&md5, (u_char *)pkt, (u_int)length);
+ MD5Final(digest, &md5);
+ if (size != 16 + 4)
+ return (0);
+ return (!memcmp(digest, (char *)pkt + length + 4, 16));
+}
+
+/*
+ * Calculate the reference id from the address. If it is an IPv4
+ * address, use it as is. If it is an IPv6 address, do a md5 on
+ * it and use the bottom 4 bytes.
+ */
+u_int32
+addr2refid(struct sockaddr_storage *addr)
+{
+ MD5_CTX md5;
+ u_char digest[16];
+ u_int32 addr_refid;
+
+ if (addr->ss_family == AF_INET)
+ return (GET_INADDR(*addr));
+
+ MD5Init(&md5);
+ MD5Update(&md5, (u_char *)&GET_INADDR6(*addr),
+ sizeof(struct in6_addr));
+ MD5Final(digest, &md5);
+ memcpy(&addr_refid, digest, 4);
+ return (htonl(addr_refid));
+}
diff --git a/libntp/adjtime.c b/libntp/adjtime.c
new file mode 100644
index 0000000..f041450
--- /dev/null
+++ b/libntp/adjtime.c
@@ -0,0 +1,323 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef MPE
+/*
+ * MPE lacks adjtime(), so we define our own. But note that time slewing has
+ * a sub-second accuracy bug documented in SR 5003462838 which prevents ntpd
+ * from being able to maintain clock synch. Because of the bug, this adjtime()
+ * implementation as used by ntpd has a side-effect of screwing up the hardware
+ * PDC clock, which will need to be reset with a reboot.
+ *
+ * This problem affects all versions of MPE at the time of this writing (when
+ * MPE/iX 7.0 is the most current). It only causes bad things to happen when
+ * doing continuous clock synchronization with ntpd; note that you CAN run ntpd
+ * with "disable ntp" in ntp.conf if you wish to provide a time server.
+ *
+ * The one-time clock adjustment functionality of ntpdate and ntp_timeset can
+ * be used without screwing up the PDC clock.
+ *
+ */
+#include <time.h>
+
+int adjtime(struct timeval *delta, struct timeval *olddelta);
+
+int adjtime(struct timeval *delta, struct timeval *olddelta)
+
+{
+/* Documented, supported MPE system intrinsics. */
+
+extern void GETPRIVMODE(void);
+extern void GETUSERMODE(void);
+
+/* Undocumented, unsupported MPE internal functions. */
+
+extern long long current_correction_usecs(void);
+extern long long get_time(void);
+extern void get_time_change_info(long long *, char *, char *);
+extern long long pdc_time(int *);
+extern void set_time_correction(long long, int, int);
+extern long long ticks_to_micro(long long);
+
+long long big_sec, big_usec, new_correction = 0LL;
+long long prev_correction;
+
+if (delta != NULL) {
+ /* Adjustment required. Convert delta to 64-bit microseconds. */
+ big_sec = (long)delta->tv_sec;
+ big_usec = delta->tv_usec;
+ new_correction = (big_sec * 1000000LL) + big_usec;
+}
+
+GETPRIVMODE();
+
+/* Determine how much of a previous correction (if any) we're interrupting. */
+prev_correction = current_correction_usecs();
+
+if (delta != NULL) {
+ /* Adjustment required. */
+
+#if 0
+ /* Speculative code disabled until bug SR 5003462838 is fixed. This bug
+ prevents accurate time slewing, and indeed renders ntpd inoperable. */
+
+ if (prev_correction != 0LL) {
+ /* A previous adjustment did not complete. Since the PDC UTC clock was
+ immediately jumped at the start of the previous adjustment, we must
+ explicitly reset it to the value of the MPE local time clock minus the
+ time zone offset. */
+
+ char pwf_since_boot, recover_pwf_time;
+ long long offset_ticks, offset_usecs, pdc_usecs_current, pdc_usecs_wanted;
+ int hpe_status;
+
+ get_time_change_info(&offset_ticks, &pwf_since_boot, &recover_pwf_time);
+ offset_usecs = ticks_to_micro(offset_ticks);
+ pdc_usecs_wanted = get_time() - offset_usecs;
+ pdc_usecs_current = pdc_time(&hpe_status);
+ if (hpe_status == 0)
+ /* Force new PDC time by starting an extra correction. */
+ set_time_correction(pdc_usecs_wanted - pdc_usecs_current,0,1);
+ }
+#endif /* 0 */
+
+ /* Immediately jump the PDC time to the new value, and then initiate a
+ gradual MPE time correction slew. */
+ set_time_correction(new_correction,0,1);
+}
+
+GETUSERMODE();
+
+if (olddelta != NULL) {
+ /* Caller wants to know remaining amount of previous correction. */
+ (long)olddelta->tv_sec = prev_correction / 1000000LL;
+ olddelta->tv_usec = prev_correction % 1000000LL;
+}
+
+return 0;
+}
+#endif /* MPE */
+
+#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
+# if NEED_QNX_ADJTIME
+/*
+ * Emulate adjtime() using QNX ClockAdjust().
+ * Chris Burghart <burghart@atd.ucar.edu>, 11/2001
+ *
+ * This is a *very* simple implementation of adjtime() for QNX.
+ * ClockAdjust() is used to tweak the system clock by about +- 1/10
+ * of its current clock period per tick until the desired delta is
+ * achieved.
+ */
+# include <math.h>
+# include <stdio.h>
+# include <sys/neutrino.h>
+# include <sys/time.h>
+
+# include <ntp_stdlib.h>
+
+int
+adjtime (struct timeval *delta, struct timeval *olddelta)
+{
+ double delta_nsec;
+ double delta_nsec_old;
+ struct _clockadjust adj;
+ struct _clockadjust oldadj;
+ /*
+ * How many nanoseconds are we adjusting?
+ */
+ delta_nsec = delta->tv_sec * 1e9 + delta->tv_usec * 1000;
+ /*
+ * Build the adjust structure and call ClockAdjust()
+ */
+ if (delta_nsec != 0)
+ {
+ struct _clockperiod period;
+ long count;
+ long increment;
+
+ /*
+ * Get the current clock period (nanoseconds)
+ */
+ if (ClockPeriod (CLOCK_REALTIME, 0, &period, 0) < 0)
+ return -1;
+
+ /*
+ * Set the adjust increment to approximately 1/10 timer period per
+ * clock tick.
+ */
+ count = 1 + (long)(fabs(10 * delta_nsec / period.nsec));
+ increment = (long)(delta_nsec / count);
+
+ adj.tick_nsec_inc = increment;
+ adj.tick_count = count;
+ }
+ else
+ {
+ adj.tick_nsec_inc = 0;
+ adj.tick_count = 0;
+ }
+
+ if (ClockAdjust (CLOCK_REALTIME, &adj, &oldadj) < 0)
+ return -1;
+
+ /*
+ * Build olddelta
+ */
+ delta_nsec_old = oldadj.tick_count * oldadj.tick_nsec_inc;
+ olddelta->tv_sec = (int)(delta_nsec_old / 1e9);
+ olddelta->tv_usec = (int)((delta_nsec_old - 1.0e9 * olddelta->tv_sec) /
+ 1000);
+
+ return 0;
+}
+# else /* no special adjtime() needed */
+int adjtime_bs;
+# endif
+#endif
diff --git a/libntp/adjtimex.c b/libntp/adjtimex.c
new file mode 100644
index 0000000..03e9d79
--- /dev/null
+++ b/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/libntp/atoint.c b/libntp/atoint.c
new file mode 100644
index 0000000..46cd96d
--- /dev/null
+++ b/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/libntp/atolfp.c b/libntp/atolfp.c
new file mode 100644
index 0000000..ff50947
--- /dev/null
+++ b/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/libntp/atouint.c b/libntp/atouint.c
new file mode 100644
index 0000000..c25e3a0
--- /dev/null
+++ b/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/libntp/audio.c b/libntp/audio.c
new file mode 100644
index 0000000..65a6063
--- /dev/null
+++ b/libntp/audio.c
@@ -0,0 +1,481 @@
+/*
+ * audio.c - audio interface for reference clock audio drivers
+ */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if defined(HAVE_SYS_AUDIOIO_H) || defined(HAVE_SUN_AUDIOIO_H) || \
+ defined(HAVE_SYS_SOUNDCARD_H) || defined(HAVE_MACHINE_SOUNDCARD_H)
+
+#include "audio.h"
+#include "ntp_stdlib.h"
+#include "ntp_syslog.h"
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#include <stdio.h>
+#include "ntp_string.h"
+
+#ifdef HAVE_SYS_AUDIOIO_H
+# include <sys/audioio.h>
+#endif /* HAVE_SYS_AUDIOIO_H */
+
+#ifdef HAVE_SUN_AUDIOIO_H
+# include <sys/ioccom.h>
+# include <sun/audioio.h>
+#endif /* HAVE_SUN_AUDIOIO_H */
+
+#ifdef HAVE_SYS_IOCTL_H
+# include <sys/ioctl.h>
+#endif /* HAVE_SYS_IOCTL_H */
+
+#include <fcntl.h>
+
+#ifdef HAVE_MACHINE_SOUNDCARD_H
+# include <machine/soundcard.h>
+# define PCM_STYLE_SOUND
+#else
+# ifdef HAVE_SYS_SOUNDCARD_H
+# include <sys/soundcard.h>
+# define PCM_STYLE_SOUND
+# endif
+#endif
+
+#ifdef PCM_STYLE_SOUND
+# include <ctype.h>
+#endif
+
+/*
+ * Global variables
+ */
+#ifdef HAVE_SYS_AUDIOIO_H
+static struct audio_device device; /* audio device ident */
+#endif /* HAVE_SYS_AUDIOIO_H */
+#ifdef PCM_STYLE_SOUND
+# define INIT_FILE "/etc/ntp.audio"
+int agc = SOUND_MIXER_WRITE_RECLEV; /* or IGAIN or LINE */
+int monitor = SOUND_MIXER_WRITE_VOLUME; /* or OGAIN */
+int devmask = 0;
+int recmask = 0;
+char cf_c_dev[100], cf_i_dev[100], cf_agc[100], cf_monitor[100];
+
+const char *m_names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
+#else /* not PCM_STYLE_SOUND */
+static struct audio_info info; /* audio device info */
+#endif /* not PCM_STYLE_SOUND */
+static int ctl_fd; /* audio control file descriptor */
+
+#ifdef PCM_STYLE_SOUND
+static void audio_config_read P((int, char **, char **));
+static int mixer_name P((const char *, int));
+
+
+int
+mixer_name(
+ const char *m_name,
+ int m_mask
+ )
+{
+ int i;
+
+ for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i)
+ if (((1 << i) & m_mask)
+ && !strcmp(m_names[i], m_name))
+ break;
+
+ return (SOUND_MIXER_NRDEVICES == i)
+ ? -1
+ : i
+ ;
+}
+
+
+/*
+ * Check:
+ *
+ * /etc/ntp.audio# where # is the unit number
+ * /etc/ntp.audio.# where # is the unit number
+ * /etc/ntp.audio
+ *
+ * for contents of the form:
+ *
+ * idev /dev/input_device
+ * cdev /dev/control_device
+ * agc pcm_input_device {igain,line,line1,...}
+ * monitor pcm_monitor_device {ogain,...}
+ *
+ * The device names for the "agc" and "monitor" keywords
+ * can be found by running either the "mixer" program or the
+ * util/audio-pcm program.
+ *
+ * Great hunks of this subroutine were swiped from refclock_oncore.c
+ */
+static void
+audio_config_read(
+ int unit,
+ char **c_dev, /* Control device */
+ char **i_dev /* input device */
+ )
+{
+ FILE *fd;
+ char device[20], line[100], ab[100];
+
+ sprintf(device, "%s%d", INIT_FILE, unit);
+ if ((fd = fopen(device, "r")) == NULL) {
+ printf("audio_config_read: <%s> NO\n", device);
+ sprintf(device, "%s.%d", INIT_FILE, unit);
+ if ((fd = fopen(device, "r")) == NULL) {
+ printf("audio_config_read: <%s> NO\n", device);
+ sprintf(device, "%s.%d", INIT_FILE, unit);
+ if ((fd = fopen(device, "r")) == NULL) {
+ printf("audio_config_read: <%s> NO\n", device);
+ return;
+ }
+ }
+ }
+ printf("audio_config_read: reading <%s>\n", device);
+ while (fgets(line, sizeof line, fd)) {
+ char *cp, *cc, *ca;
+ int i;
+
+ /* Remove comments */
+ if ((cp = strchr(line, '#')))
+ *cp = '\0';
+
+ /* Remove any trailing spaces */
+ for (i = strlen(line);
+ i > 0 && isascii((int)line[i - 1]) && isspace((int)line[i - 1]);
+ )
+ line[--i] = '\0';
+
+ /* Remove leading space */
+ for (cc = line; *cc && isascii((int)*cc) && isspace((int)*cc); cc++)
+ continue;
+
+ /* Stop if nothing left */
+ if (!*cc)
+ continue;
+
+ /* Uppercase the command and find the arg */
+ for (ca = cc; *ca; ca++) {
+ if (isascii((int)*ca)) {
+ if (islower((int)*ca)) {
+ *ca = toupper(*ca);
+ } else if (isspace((int)*ca) || (*ca == '='))
+ break;
+ }
+ }
+
+ /* Remove space (and possible =) leading the arg */
+ for (; *ca && isascii((int)*ca) && (isspace((int)*ca) || (*ca == '=')); ca++)
+ continue;
+
+ if (!strncmp(cc, "IDEV", (size_t) 4)) {
+ sscanf(ca, "%s", ab);
+ strcpy(cf_i_dev, ab);
+ printf("idev <%s>\n", ab);
+ } else if (!strncmp(cc, "CDEV", (size_t) 4)) {
+ sscanf(ca, "%s", ab);
+ strcpy(cf_c_dev, ab);
+ printf("cdev <%s>\n", ab);
+ } else if (!strncmp(cc, "AGC", (size_t) 3)) {
+ sscanf(ca, "%s", ab);
+ strcpy(cf_agc, ab);
+ printf("agc <%s> %d\n", ab, i);
+ } else if (!strncmp(cc, "MONITOR", (size_t) 7)) {
+ sscanf(ca, "%s", ab);
+ strcpy(cf_monitor, ab);
+ printf("monitor <%s> %d\n", ab, mixer_name(ab, -1));
+ }
+ }
+ fclose(fd);
+ return;
+}
+#endif /* PCM_STYLE_SOUND */
+
+/*
+ * audio_init - open and initialize audio device
+ *
+ * This code works with SunOS 4.x, Solaris 2.x, and PCM; however, it is
+ * believed generic and applicable to other systems with a minor twid
+ * or two. All it does is open the device, set the buffer size (Solaris
+ * only), preset the gain and set the input port. It assumes that the
+ * codec sample rate (8000 Hz), precision (8 bits), number of channels
+ * (1) and encoding (ITU-T G.711 mu-law companded) have been set by
+ * default.
+ */
+int
+audio_init(
+ char *dname, /* device name */
+ int bufsiz, /* buffer size */
+ int unit /* device unit (0-3) */
+ )
+{
+#ifdef PCM_STYLE_SOUND
+# define ACTL_DEV "/dev/mixer%d"
+ char actl_dev[30];
+# ifdef HAVE_STRUCT_SND_SIZE
+ struct snd_size s_size;
+# endif
+# ifdef AIOGFMT
+ snd_chan_param s_c_p;
+# endif
+#endif
+ int fd;
+ int rval;
+ char *actl =
+#ifdef PCM_STYLE_SOUND
+ actl_dev
+#else
+ "/dev/audioctl"
+#endif
+ ;
+
+#ifdef PCM_STYLE_SOUND
+ (void)sprintf(actl_dev, ACTL_DEV, unit);
+
+ audio_config_read(unit, &actl, &dname);
+ /* If we have values for cf_c_dev or cf_i_dev, use them. */
+ if (*cf_c_dev)
+ dname = cf_c_dev;
+ if (*cf_i_dev)
+ actl = cf_i_dev;
+#endif
+
+ /*
+ * Open audio device. Do not complain if not there.
+ */
+ fd = open(dname, O_RDWR | O_NONBLOCK, 0777);
+ if (fd < 0)
+ return (fd);
+
+ /*
+ * Open audio control device.
+ */
+ ctl_fd = open(actl, O_RDWR);
+ if (ctl_fd < 0) {
+ msyslog(LOG_ERR, "audio_init: invalid control device <%s>\n", actl);
+ close(fd);
+ return(ctl_fd);
+ }
+
+ /*
+ * Set audio device parameters.
+ */
+#ifdef PCM_STYLE_SOUND
+ printf("audio_init: <%s> bufsiz %d\n", dname, bufsiz);
+ rval = fd;
+
+# ifdef HAVE_STRUCT_SND_SIZE
+ if (ioctl(fd, AIOGSIZE, &s_size) == -1)
+ printf("audio_init: AIOGSIZE: %s\n", strerror(errno));
+ else
+ printf("audio_init: orig: play_size %d, rec_size %d\n",
+ s_size.play_size, s_size.rec_size);
+
+ s_size.play_size = s_size.rec_size = bufsiz;
+ printf("audio_init: want: play_size %d, rec_size %d\n",
+ s_size.play_size, s_size.rec_size);
+
+ if (ioctl(fd, AIOSSIZE, &s_size) == -1)
+ printf("audio_init: AIOSSIZE: %s\n", strerror(errno));
+ else
+ printf("audio_init: set: play_size %d, rec_size %d\n",
+ s_size.play_size, s_size.rec_size);
+# endif /* HAVE_STRUCT_SND_SIZE */
+
+# ifdef AIOGFMT
+ if (ioctl(fd, AIOGFMT, &s_c_p) == -1)
+ printf("audio_init: AIOGFMT: %s\n", strerror(errno));
+ else
+ printf("audio_init: play_rate %lu, rec_rate %lu, play_format %#lx, rec_format %#lx\n",
+ s_c_p.play_rate, s_c_p.rec_rate, s_c_p.play_format, s_c_p.rec_format);
+# endif
+
+ /* Grab the device and record masks */
+
+ if (ioctl(ctl_fd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1)
+ printf("SOUND_MIXER_READ_DEVMASK: %s\n", strerror(errno));
+ if (ioctl(ctl_fd, SOUND_MIXER_READ_RECMASK, &recmask) == -1)
+ printf("SOUND_MIXER_READ_RECMASK: %s\n", strerror(errno));
+
+ /* validate and set any specified config file stuff */
+ if (*cf_agc) {
+ int i;
+
+ i = mixer_name(cf_agc, recmask);
+ if (i >= 0)
+ agc = MIXER_WRITE(i);
+ else
+ printf("input %s not in recmask %#x\n",
+ cf_agc, recmask);
+ }
+
+ if (*cf_monitor) {
+ int i;
+
+ /* devmask */
+ i = mixer_name(cf_monitor, devmask);
+ if (i >= 0)
+ monitor = MIXER_WRITE(i);
+ else
+ printf("monitor %s not in devmask %#x\n",
+ cf_monitor, devmask);
+ }
+
+#else /* not PCM_STYLE_SOUND */
+ AUDIO_INITINFO(&info);
+ info.play.gain = AUDIO_MAX_GAIN;
+ info.play.port = AUDIO_SPEAKER;
+# ifdef HAVE_SYS_AUDIOIO_H
+ info.record.buffer_size = bufsiz;
+# endif /* HAVE_SYS_AUDIOIO_H */
+ rval = ioctl(ctl_fd, (int)AUDIO_SETINFO, (char *)&info);
+ if (rval < 0) {
+ msyslog(LOG_ERR, "audio: invalid control device parameters\n");
+ close(ctl_fd);
+ close(fd);
+ return(rval);
+ }
+ rval = fd;
+#endif /* not PCM_STYLE_SOUND */
+ return (rval);
+}
+
+
+/*
+ * audio_gain - adjust codec gains and port
+ */
+int
+audio_gain(
+ int gain, /* volume level (gain) 0-255 */
+ int mongain, /* input to output mix (monitor gain) 0-255 */
+ int port /* selected I/O port: 1 mic/2 line in */
+ )
+{
+ int rval;
+ static int o_mongain = -1;
+ static int o_port = -1;
+
+#ifdef PCM_STYLE_SOUND
+ int l, r;
+
+ rval = 0;
+
+ r = l = 100 * gain / 255; /* Normalize to 0-100 */
+# ifdef DEBUG
+ if (debug > 1)
+ printf("audio_gain: gain %d/%d\n", gain, l);
+# endif
+ /* figure out what channel(s) to use. just nuke right for now. */
+ r = 0 ; /* setting to zero nicely mutes the channel */
+
+ l |= r << 8;
+ if (port == 2) {
+ rval = ioctl(ctl_fd, SOUND_MIXER_WRITE_LINE, &l);
+ } else {
+ rval = ioctl(ctl_fd, SOUND_MIXER_WRITE_MIC, &l);
+ }
+ if (rval == -1) {
+ printf("audio_gain: agc write: %s\n", strerror(errno));
+ return (rval);
+ }
+
+ if (o_mongain != mongain) {
+ r = l = 100 * mongain / 255; /* Normalize to 0-100 */
+# ifdef DEBUG
+ if (debug > 1)
+ printf("audio_gain: mongain %d/%d\n", mongain, l);
+# endif
+ l |= r << 8;
+ rval = ioctl(ctl_fd, SOUND_MIXER_WRITE_VOLUME, &l);
+ if (rval == -1) {
+ printf("audio_gain: mongain write: %s\n",
+ strerror(errno));
+ return (rval);
+ }
+ o_mongain = mongain;
+ }
+
+ if (o_port != port) {
+# ifdef DEBUG
+ if (debug > 1)
+ printf("audio_gain: port %d\n", port);
+# endif
+ l = (1 << ((port == 2) ? SOUND_MIXER_LINE : SOUND_MIXER_MIC));
+ rval = ioctl(ctl_fd, SOUND_MIXER_WRITE_RECSRC, &l);
+ if (rval == -1) {
+ printf("SOUND_MIXER_WRITE_RECSRC: %s\n",
+ strerror(errno));
+ return (rval);
+ }
+# ifdef DEBUG
+ if (debug > 1) {
+ if (ioctl(ctl_fd, SOUND_MIXER_READ_RECSRC, &l) == -1)
+ printf("SOUND_MIXER_WRITE_RECSRC: %s\n",
+ strerror(errno));
+ else
+ printf("audio_gain: recsrc is %d\n", l);
+ }
+# endif
+ o_port = port;
+ }
+#else /* not PCM_STYLE_SOUND */
+ ioctl(ctl_fd, (int)AUDIO_GETINFO, (char *)&info);
+ info.record.encoding = AUDIO_ENCODING_ULAW;
+ info.record.error = 0;
+ info.record.gain = gain;
+ if (o_mongain != mongain)
+ o_mongain = info.monitor_gain = mongain;
+ if (o_port != port)
+ o_port = info.record.port = port;
+ rval = ioctl(ctl_fd, (int)AUDIO_SETINFO, (char *)&info);
+ if (rval < 0) {
+ msyslog(LOG_ERR, "audio_gain: %m");
+ return (rval);
+ }
+ rval = info.record.error;
+#endif /* not PCM_STYLE_SOUND */
+ return (rval);
+}
+
+
+/*
+ * audio_show - display audio parameters
+ *
+ * This code doesn't really do anything, except satisfy curiousity and
+ * verify the ioctl's work.
+ */
+void
+audio_show(void)
+{
+#ifdef PCM_STYLE_SOUND
+ int recsrc = 0;
+
+ printf("audio_show: ctl_fd %d\n", ctl_fd);
+ if (ioctl(ctl_fd, SOUND_MIXER_READ_RECSRC, &recsrc) == -1)
+ printf("SOUND_MIXER_READ_RECSRC: %s\n", strerror(errno));
+
+#else /* not PCM_STYLE_SOUND */
+# ifdef HAVE_SYS_AUDIOIO_H
+ ioctl(ctl_fd, (int)AUDIO_GETDEV, &device);
+ printf("audio: name %s, version %s, config %s\n",
+ device.name, device.version, device.config);
+# endif /* HAVE_SYS_AUDIOIO_H */
+ ioctl(ctl_fd, (int)AUDIO_GETINFO, (char *)&info);
+ printf(
+ "audio: rate %d, chan %d, prec %d, code %d, gain %d, mon %d, port %d\n",
+ info.record.sample_rate, info.record.channels,
+ info.record.precision, info.record.encoding,
+ info.record.gain, info.monitor_gain, info.record.port);
+ printf(
+ "audio: samples %d, eof %d, pause %d, error %d, waiting %d, balance %d\n",
+ info.record.samples, info.record.eof,
+ info.record.pause, info.record.error,
+ info.record.waiting, info.record.balance);
+#endif /* not PCM_STYLE_SOUND */
+}
+#else
+int audio_bs;
+#endif /* HAVE_{SYS_AUDIOIO,SUN_AUDIOIO,MACHINE_SOUNDCARD,SYS_SOUNDCARD}_H */
diff --git a/libntp/authencrypt.c b/libntp/authencrypt.c
new file mode 100644
index 0000000..075afe0
--- /dev/null
+++ b/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/libntp/authkeys.c b/libntp/authkeys.c
new file mode 100644
index 0000000..1c95444
--- /dev/null
+++ b/libntp/authkeys.c
@@ -0,0 +1,488 @@
+/*
+ * 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 */
+ u_char MD5_key[32]; /* MD5 key */
+ } k;
+ keyid_t keyid; /* key identifier */
+ u_short flags; /* flags that wave */
+ u_long lifetime; /* remaining lifetime */
+ int keylen; /* key length */
+};
+
+#define KEY_TRUSTED 0x001 /* this key is trusted */
+#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.
+ */
+keyid_t 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(
+ keyid_t 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(
+ keyid_t 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(
+ keyid_t 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;
+ if (sk->flags & KEY_MD5) {
+ cache_key = sk->k.MD5_key;
+ cache_keylen = sk->keylen;
+ return (1);
+ }
+ return (0);
+}
+
+
+/*
+ * auth_moremem - get some more free key structures
+ */
+int
+auth_moremem(void)
+{
+ struct savekey *sk;
+ int i;
+
+ sk = (struct savekey *)calloc(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(
+ keyid_t keyno,
+ u_long trust
+ )
+{
+ struct savekey *sk;
+
+#ifdef DEBUG
+ if (debug > 2)
+ printf("authtrust: keyid %08x life %lu\n", 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(
+ keyid_t 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);
+}
+
+
+void
+MD5auth_setkey(
+ keyid_t 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;
+}
+
+/*
+ * 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 lose info as to which keys are trusted.
+ */
+ if (sk->flags & KEY_TRUSTED) {
+ skp = &(sk->next);
+ memset(&sk->k, 0, sizeof(sk->k));
+ sk->lifetime = 0;
+ sk->keylen = 0;
+ 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(
+ keyid_t 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] = htonl(keyno);
+ if (keyno == 0) {
+ return (4);
+ }
+ if (!authhavekey(keyno))
+ return (0);
+
+ if (cache_flags & KEY_MD5)
+ return (MD5authencrypt(cache_key, pkt, length));
+
+ return (0);
+}
+
+/*
+ * authdecrypt - verify message authenticator
+ *
+ * Returns one if authenticator valid, zero if invalid or key not found.
+ */
+int
+authdecrypt(
+ keyid_t 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 (0);
+
+ if (!authhavekey(keyno) || size < 4)
+ return (0);
+
+ if (cache_flags & KEY_MD5)
+ return (MD5authdecrypt(cache_key, pkt, length, size));
+
+ return (0);
+}
diff --git a/libntp/authparity.c b/libntp/authparity.c
new file mode 100644
index 0000000..ea5eac0
--- /dev/null
+++ b/libntp/authparity.c
@@ -0,0 +1,66 @@
+/*
+ * auth_parity - set parity on a key/check for odd parity
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef DES
+#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);
+}
+#else
+int authparity_bs;
+#endif /* DES */
diff --git a/libntp/authreadkeys.c b/libntp/authreadkeys.c
new file mode 100644
index 0000000..22020f3
--- /dev/null
+++ b/libntp/authreadkeys.c
@@ -0,0 +1,162 @@
+/*
+ * 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_syslog.h"
+#include "ntp_stdlib.h"
+
+/*
+ * Arbitrary long string of ASCII characters.
+ */
+#define KEY_TYPE_MD5 4
+
+/* 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) {
+ case 'M':
+ case 'm':
+ keytype = KEY_TYPE_MD5; break;
+ 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) {
+ 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;
+ }
+ }
+ }
+ (void) fclose(fp);
+ return 1;
+}
diff --git a/libntp/authusekey.c b/libntp/authusekey.c
new file mode 100644
index 0000000..40dd373
--- /dev/null
+++ b/libntp/authusekey.c
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+#define KEY_TYPE_MD5 4
+
+int
+authusekey(
+ keyid_t keyno,
+ int keytype,
+ const u_char *str
+ )
+{
+ const u_char *cp;
+ int len;
+
+ cp = str;
+ len = strlen((const char *)cp);
+ if (len == 0)
+ return 0;
+
+ switch(keytype) {
+ case KEY_TYPE_MD5:
+ MD5auth_setkey(keyno, str, (int)strlen((const char *)str));
+ break;
+
+ default:
+ /* Oh, well */
+ return 0;
+ }
+
+ return 1;
+}
diff --git a/libntp/binio.c b/libntp/binio.c
new file mode 100644
index 0000000..bbaf06f
--- /dev/null
+++ b/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)++) = (unsigned char) (val & 0xFF);
+ *((*bufpp)++) = (unsigned char) ((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)++) = (unsigned char)(val & 0xFF);
+ *((*bufpp)++) = (unsigned char)((val >> 8) & 0xFF);
+ *((*bufpp)++) = (unsigned char)((val >> 16) & 0xFF);
+ *((*bufpp)++) = (unsigned char)((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)++) = (unsigned char)((val >> 8) & 0xFF);
+ *((*bufpp)++) = (unsigned char)( 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)++) = (unsigned char)((val >> 24) & 0xFF);
+ *((*bufpp)++) = (unsigned char)((val >> 16) & 0xFF);
+ *((*bufpp)++) = (unsigned char)((val >> 8 ) & 0xFF);
+ *((*bufpp)++) = (unsigned char)( 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/libntp/buftvtots.c b/libntp/buftvtots.c
new file mode 100644
index 0000000..1944233
--- /dev/null
+++ b/libntp/buftvtots.c
@@ -0,0 +1,106 @@
+/*
+ * 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;
+ struct timeval tv;
+
+#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;
+
+ if (sizeof(tv.tv_sec) == 8) {
+ 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;
+
+ if (sizeof(tv.tv_usec) == 8) {
+ 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;
+
+ if (sizeof(tv.tv_usec) == 8) {
+ 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;
+
+ if (sizeof (tv.tv_sec) == 8) {
+ 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/libntp/caljulian.c b/libntp/caljulian.c
new file mode 100644
index 0000000..c3b5e67
--- /dev/null
+++ b/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 = (u_char) monthday;
+ }
+}
diff --git a/libntp/calleapwhen.c b/libntp/calleapwhen.c
new file mode 100644
index 0000000..c954901
--- /dev/null
+++ b/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/libntp/caltontp.c b/libntp/caltontp.c
new file mode 100644
index 0000000..9ec1064
--- /dev/null
+++ b/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/libntp/calyearstart.c b/libntp/calyearstart.c
new file mode 100644
index 0000000..0f7ca4f
--- /dev/null
+++ b/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/libntp/clocktime.c b/libntp/clocktime.c
new file mode 100644
index 0000000..371859c
--- /dev/null
+++ b/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/libntp/clocktypes.c b/libntp/clocktypes.c
new file mode 100644
index 0000000..928851f
--- /dev/null
+++ b/libntp/clocktypes.c
@@ -0,0 +1,118 @@
+/*
+ * 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_SPECTRACOM, "Spectracom (generic) Receivers (4)",
+ "SPECTRACOM" },
+ { REFCLK_TRUETIME, "TrueTime (generic) Receivers (5)",
+ "TRUETIME" },
+ { REFCLK_IRIG_AUDIO, "IRIG Audio Decoder (6)",
+ "IRIG_AUDIO" },
+ { REFCLK_CHU_AUDIO, "CHU Audio Demodulator/Decoder (7)",
+ "CHU_AUDIO" },
+ { 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 (33)",
+ "DUMBCLOCK" },
+ { REFCLK_ULINK, "Ultralink M320 WWVB receiver (34)",
+ "ULINK_M320"},
+ { REFCLK_PCF, "Conrad parallel port radio clock (35)",
+ "PCF"},
+ { REFCLK_WWV_AUDIO, "WWV/H Audio Demodulator/Decoder (36)",
+ "WWV_AUDIO"},
+ { REFCLK_FG, "Forum Graphic GPS Dating Station (37)",
+ "GPS_FG"},
+ { REFCLK_HOPF_SERIAL, "hopf Elektronic serial line receiver (38)",
+ "HOPF_S"},
+ { REFCLK_HOPF_PCI, "hopf Elektronic PCI receiver (39)",
+ "HOPF_P"},
+ { REFCLK_JJY, "JJY receiver (40)",
+ "JJY"},
+ { REFCLK_TT560, "TrueTime 560 IRIG-B decoder (41)",
+ "TT_IRIG"},
+ { REFCLK_ZYFER, "Zyfer GPStarplus receiver (42)",
+ "GPS_ZYFER" },
+ { REFCLK_RIPENCC, "RIPE NCC Trimble driver (43)",
+ "GPS_RIPENCC" },
+ { REFCLK_NEOCLOCK4X, "NeoClock4X DCF77 / TDF receiver (44)",
+ "NEOCLK4X"},
+ { -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/libntp/decodenetnum.c b/libntp/decodenetnum.c
new file mode 100644
index 0000000..4accf4a
--- /dev/null
+++ b/libntp/decodenetnum.c
@@ -0,0 +1,40 @@
+/*
+ * 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 <netdb.h>
+
+#include "ntp_stdlib.h"
+
+int
+decodenetnum(
+ const char *num,
+ struct sockaddr_storage *netnum
+ )
+{
+ struct addrinfo hints, *ai = NULL;
+ register int err, i;
+ register const char *cp;
+ char name[80];
+
+ cp = num;
+
+ if (*cp == '[') {
+ cp++;
+ for (i = 0; *cp != ']'; cp++, i++)
+ name[i] = *cp;
+ name[i] = '\0';
+ num = name;
+ }
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_flags = AI_NUMERICHOST;
+ err = getaddrinfo(num, NULL, &hints, &ai);
+ if (err != 0)
+ return 0;
+ memcpy(netnum, (struct sockaddr_storage *)ai->ai_addr, ai->ai_addrlen);
+ freeaddrinfo(ai);
+ return 1;
+}
diff --git a/libntp/dofptoa.c b/libntp/dofptoa.c
new file mode 100644
index 0000000..0f96909
--- /dev/null
+++ b/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,
+ short 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 = (u_short) (sv/ten);
+ *(--cp) = (u_char)(tmp - ((sv<<3) + (sv<<1)));
+ } while (sv != 0);
+ }
+
+ /*
+ * Figure out how much of the fraction to do
+ */
+ if (msec) {
+ dec = (short)(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/libntp/dolfptoa.c b/libntp/dolfptoa.c
new file mode 100644
index 0000000..7c92a30
--- /dev/null
+++ b/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,
+ short 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 = (u_short) (swork/sten);
+ stmp = (u_short)(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/libntp/emalloc.c b/libntp/emalloc.c
new file mode 100644
index 0000000..2fe4c38
--- /dev/null
+++ b/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_syslog.h"
+#include "ntp_stdlib.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, "Exiting: No more memory!");
+ exit(1);
+ }
+ return mem;
+}
+
+#else
+
+void *
+emalloc(
+ u_int size
+ )
+{
+ char *mem;
+
+ if ((mem = (char *)malloc(size)) == 0) {
+ msyslog(LOG_ERR, "Exiting: No more memory!");
+ exit(1);
+ }
+ return mem;
+}
+
+
+#endif
diff --git a/libntp/findconfig.c b/libntp/findconfig.c
new file mode 100644
index 0000000..ecf6a4b
--- /dev/null
+++ b/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/libntp/fptoa.c b/libntp/fptoa.c
new file mode 100644
index 0000000..025ad21
--- /dev/null
+++ b/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,
+ short 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/libntp/fptoms.c b/libntp/fptoms.c
new file mode 100644
index 0000000..0bfca55
--- /dev/null
+++ b/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,
+ short 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/libntp/getopt.c b/libntp/getopt.c
new file mode 100644
index 0000000..7b344f0
--- /dev/null
+++ b/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/libntp/gpstolfp.c b/libntp/gpstolfp.c
new file mode 100644
index 0000000..c424784
--- /dev/null
+++ b/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 ULONG_CONST(2524953600) /* 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/libntp/hextoint.c b/libntp/hextoint.c
new file mode 100644
index 0000000..0d774eb
--- /dev/null
+++ b/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/libntp/hextolfp.c b/libntp/hextolfp.c
new file mode 100644
index 0000000..d0b6243
--- /dev/null
+++ b/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/libntp/humandate.c b/libntp/humandate.c
new file mode 100644
index 0000000..52f5af1
--- /dev/null
+++ b/libntp/humandate.c
@@ -0,0 +1,63 @@
+/*
+ * humandate - convert an NTP (or the current) time to something readable
+ */
+#include <stdio.h>
+#include "ntp_fp.h"
+#include "ntp_unixtime.h" /* includes <sys/time.h> and <time.h> */
+#include "lib_strbuf.h"
+#include "ntp_stdlib.h"
+
+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;
+
+ sec = ntptime - JAN_1970;
+ tm = localtime(&sec);
+
+ if (!tm)
+ return "--- --- -- ---- --:--:--";
+
+ LIB_GETBUF(bp);
+
+ (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);
+
+ if (!tm)
+ return "-- --- --:--:--";
+
+ 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/libntp/icom.c b/libntp/icom.c
new file mode 100644
index 0000000..5c1a9a3
--- /dev/null
+++ b/libntp/icom.c
@@ -0,0 +1,324 @@
+/*
+ * Program to control ICOM radios
+ *
+ * This is a ripoff of the utility routines in the ICOM software
+ * distribution. The only function provided is to load the radio
+ * frequency. All other parameters must be manually set before use.
+ */
+#include "icom.h"
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "ntp_tty.h"
+#include "l_stdlib.h"
+
+/*
+ * Scraps
+ */
+#define BMAX 50 /* max command length */
+#define DICOM /dev/icom/ /* ICOM port link */
+
+/*
+ * FSA definitions
+ */
+#define S_IDLE 0 /* idle */
+#define S_HDR 1 /* header */
+#define S_TX 2 /* address */
+#define S_DATA 3 /* data */
+#define S_ERROR 4 /* error */
+
+/*
+ * Local function prototypes
+ */
+static void doublefreq P((double, u_char *, int));
+static int sndpkt P((int, int, u_char *, u_char *));
+static int sndoctet P((int, int));
+static int rcvoctet P((int));
+
+/*
+ * Local variables
+ */
+static int flags; /* trace flags */
+static int state; /* fsa state */
+
+
+/*
+ * icom_freq(fd, ident, freq) - load radio frequency
+ */
+int
+icom_freq( /* returns 0 (ok), EIO (error) */
+ int fd, /* file descriptor */
+ int ident, /* ICOM radio identifier */
+ double freq /* frequency (MHz) */
+ )
+{
+ u_char cmd[BMAX], rsp[BMAX];
+ int temp;
+ cmd[0] = V_SFREQ;
+ if (ident == IC735)
+ temp = 4;
+ else
+ temp = 5;
+ doublefreq(freq * 1e6, &cmd[1], temp);
+ temp = sndpkt(fd, ident, cmd, rsp);
+ if (temp < 1 || rsp[0] != ACK)
+ return (EIO);
+ return (0);
+}
+
+
+/*
+ * doublefreq(freq, y, len) - double to ICOM frequency with padding
+ */
+static void
+doublefreq( /* returns void */
+ double freq, /* frequency */
+ u_char *x, /* radio frequency */
+ int len /* length (octets) */
+ )
+{
+ int i;
+ char s1[11];
+ char *y;
+
+ sprintf(s1, " %10.0f", freq);
+ y = s1 + 10;
+ i = 0;
+ while (*y != ' ') {
+ x[i] = *y-- & 0x0f;
+ x[i] = x[i] | ((*y-- & 0x0f) << 4);
+ i++;
+ }
+ for (; i < len; i++)
+ x[i] = 0;
+ x[i] = FI;
+}
+
+
+/*
+ * Packet routines
+ *
+ * These routines send a packet and receive the response. If an error
+ * (collision) occurs on transmit, the packet is resent. If an error
+ * occurs on receive (timeout), all input to the terminating FI is
+ * discarded and the packet is resent. If the maximum number of retries
+ * is not exceeded, the program returns the number of octets in the user
+ * buffer; otherwise, it returns zero.
+ *
+ * ICOM frame format
+ *
+ * Frames begin with a two-octet preamble PR-PR followyd by the
+ * transceiver address RE, controller address TX, control code CN, zero
+ * or more data octets DA (depending on command), and terminator FI.
+ * Since the bus is bidirectional, every octet output is echoed on
+ * input. Every valid frame sent is answered with a frame in the same
+ * format, but with the RE and TX fields interchanged. The CN field is
+ * set to NAK if an error has occurred. Otherwise, the data are returned
+ * in this and following DA octets. If no data are returned, the CN
+ * octet is set to ACK.
+ *
+ * +------+------+------+------+------+--//--+------+
+ * | PR | PR | RE | TX | CN | DA | FI |
+ * +------+------+------+------+------+--//--+------+
+ */
+/*
+ * icom_open() - open and initialize serial interface
+ *
+ * This routine opens the serial interface for raw transmission; that
+ * is, character-at-a-time, no stripping, checking or monkeying with the
+ * bits. For Unix, an input operation ends either with the receipt of a
+ * character or a 0.5-s timeout.
+ */
+int
+icom_init(
+ char *device, /* device name/link */
+ int speed, /* line speed */
+ int trace /* trace flags */ )
+{
+ TTY ttyb;
+ int fd;
+
+ flags = trace;
+ fd = open(device, O_RDWR, 0777);
+ if (fd < 0)
+ return (fd);
+ tcgetattr(fd, &ttyb);
+ ttyb.c_iflag = 0; /* input modes */
+ ttyb.c_oflag = 0; /* output modes */
+ ttyb.c_cflag = IBAUD|CS8|CREAD|CLOCAL; /* control modes */
+ ttyb.c_lflag = 0; /* local modes */
+ ttyb.c_cc[VMIN] = 0; /* min chars */
+ ttyb.c_cc[VTIME] = 5; /* receive timeout */
+ cfsetispeed(&ttyb, (u_int)speed);
+ cfsetospeed(&ttyb, (u_int)speed);
+ tcsetattr(fd, TCSANOW, &ttyb);
+ return (fd);
+}
+
+
+/*
+ * sndpkt(r, x, y) - send packet and receive response
+ *
+ * This routine sends a command frame, which consists of all except the
+ * preamble octets PR-PR. It then listens for the response frame and
+ * returns the payload to the caller. The routine checks for correct
+ * response header format; that is, the length of the response vector
+ * returned to the caller must be at least 2 and the RE and TX octets
+ * must be interchanged; otherwise, the operation is retried up to
+ * the number of times specified in a global variable.
+ *
+ * The trace function, which is enabled by the P_TRACE bit of the global
+ * flags variable, prints all characters received or echoed on the bus
+ * preceded by a T (transmit) or R (receive). The P_ERMSG bit of the
+ * flags variable enables printing of bus error messages.
+ *
+ * Note that the first octet sent is a PAD in order to allow time for
+ * the radio to flush its receive buffer after sending the previous
+ * response. Even with this precaution, some of the older radios
+ * occasionally fail to receive a command and it has to be sent again.
+ */
+static int
+sndpkt( /* returns octet count */
+ int fd, /* file descriptor */
+ int r, /* radio address */
+ u_char *cmd, /* command vector */
+ u_char *rsp /* response vector */
+ )
+{
+ int i, j, temp;
+
+ (void)tcflush(fd, TCIOFLUSH);
+ for (i = 0; i < RETRY; i++) {
+ state = S_IDLE;
+
+ /*
+ * Transmit packet.
+ */
+ if (flags & P_TRACE)
+ printf("icom T:");
+ sndoctet(fd, PAD); /* send header */
+ sndoctet(fd, PR);
+ sndoctet(fd, PR);
+ sndoctet(fd, r);
+ sndoctet(fd, TX);
+ for (j = 0; j < BMAX; j++) { /* send body */
+ if (sndoctet(fd, cmd[j]) == FI)
+ break;
+ }
+ while (rcvoctet(fd) != FI); /* purge echos */
+ if (cmd[0] == V_FREQT || cmd[0] == V_MODET)
+ return (0); /* shortcut for broadcast */
+
+ /*
+ * Receive packet. First, delete all characters
+ * preceeding a PR, then discard all PRs. Check that the
+ * RE and TX fields are correctly interchanged, then
+ * copy the remaining data and FI to the user buffer.
+ */
+ if (flags & P_TRACE)
+ printf("\nicom R:");
+ j = 0;
+ while ((temp = rcvoctet(fd)) != FI) {
+ switch (state) {
+
+ case S_IDLE:
+ if (temp != PR)
+ continue;
+ state = S_HDR;
+ break;
+
+ case S_HDR:
+ if (temp == PR) {
+ continue;
+ } else if (temp != TX) {
+ if (flags & P_ERMSG)
+ printf(
+ "icom: TX error\n");
+ state = S_ERROR;
+ }
+ state = S_TX;
+ break;
+
+ case S_TX:
+ if (temp != r) {
+ if (flags & P_ERMSG)
+ printf(
+ "icom: RE error\n");
+ state = S_ERROR;
+ }
+ state = S_DATA;
+ break;
+
+ case S_DATA:
+ if (j >= BMAX ) {
+ if (flags & P_ERMSG)
+ printf(
+ "icom: buffer overrun\n");
+ state = S_ERROR;
+ j = 0;
+ }
+ rsp[j++] = (u_char)temp;
+ break;
+
+ case S_ERROR:
+ break;
+ }
+ }
+ if (flags & P_TRACE)
+ printf("\n");
+ if (j > 0) {
+ rsp[j++] = FI;
+ return (j);
+ }
+ }
+ if (flags & P_ERMSG)
+ printf("icom: retries exceeded\n");
+ return (0);
+}
+
+
+/*
+ * Interface routines
+ *
+ * These routines read and write octets on the bus. In case of receive
+ * timeout a FI code is returned. In case of output collision (echo
+ * does not match octet sent), the remainder of the collision frame
+ * (including the trailing FI) is discarded.
+ */
+/*
+ * sndoctet(fd, x) - send octet
+ */
+static int
+sndoctet( /* returns octet */
+ int fd, /* file descriptor */
+ int x /* octet */
+ )
+{
+ u_char y;
+
+ y = (u_char)x;
+ write(fd, &y, 1);
+ return (x);
+}
+
+
+/*
+ * rcvoctet(fd) - receive octet
+ */
+static int
+rcvoctet( /* returns octet */
+ int fd /* file descriptor */
+ )
+{
+ u_char y;
+
+ if (read(fd, &y, 1) < 1)
+ y = FI; /* come here if timeout */
+ if (flags & P_TRACE && y != PAD)
+ printf(" %02x", y);
+ return (y);
+}
+
+/* end program */
diff --git a/libntp/ieee754io.c b/libntp/ieee754io.c
new file mode 100644
index 0000000..979fed9
--- /dev/null
+++ b/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;
+ 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/libntp/inttoa.c b/libntp/inttoa.c
new file mode 100644
index 0000000..f270733
--- /dev/null
+++ b/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/libntp/iosignal.c b/libntp/iosignal.c
new file mode 100644
index 0000000..bcad890
--- /dev/null
+++ b/libntp/iosignal.c
@@ -0,0 +1,544 @@
+/*
+ * iosignal.c - input/output routines for ntpd. The socket-opening code
+ * was shamelessly stolen from ntpd.
+ */
+
+#include "ntp_machine.h"
+#include "ntpd.h"
+#include "ntp_io.h"
+#include "ntp_if.h"
+#include "ntp_stdlib.h"
+#include "iosignal.h"
+
+#include <stdio.h>
+#include <signal.h>
+#ifdef HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif /* HAVE_SYS_PARAM_H */
+#ifdef HAVE_SYS_IOCTL_H
+# include <sys/ioctl.h>
+#endif
+
+#include <arpa/inet.h>
+
+#if _BSDI_VERSION >= 199510
+# include <ifaddrs.h>
+#endif
+
+#if defined(HAVE_SIGNALED_IO)
+static int sigio_block_count = 0;
+# if defined(HAVE_SIGACTION)
+/*
+ * If sigaction() is used for signal handling and a signal is
+ * pending then the kernel blocks the signal before it calls
+ * the signal handler.
+ *
+ * The variable below is used to take care that the SIGIO signal
+ * is not unintentionally unblocked inside the sigio_handler()
+ * if the handler executes a piece of code that is normally
+ * bracketed by BLOCKIO()/UNBLOCKIO() calls.
+ */
+static int sigio_handler_active = 0;
+# endif
+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 define USE_SIGPOLL or USE_SIGIO.
+ * these are interal only to iosignal.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
+
+# ifdef __QNXNTO__
+# include <fcntl.h>
+# include <unix.h>
+# define FNDELAY O_NDELAY
+# 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);
+
+# if defined(HAVE_SIGACTION)
+ sigio_handler_active++;
+ if (sigio_handler_active != 1) /* This should never happen! */
+ msyslog(LOG_ERR, "sigio_handler: sigio_handler_active != 1");
+# endif
+
+ (void)input_handler(&ts);
+
+# if defined(HAVE_SIGACTION)
+ sigio_handler_active--;
+ if (sigio_handler_active != 0) /* This should never happen! */
+ msyslog(LOG_ERR, "sigio_handler: sigio_handler_active != 0");
+# endif
+
+ 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)
+{
+ if ( sigio_handler_active == 0 ) /* not called from within signal handler */
+ {
+ 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)
+{
+ if ( sigio_handler_active == 0 ) /* not called from within signal handler */
+ {
+ 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/libntp/lib_strbuf.c b/libntp/lib_strbuf.c
new file mode 100644
index 0000000..315070f
--- /dev/null
+++ b/libntp/lib_strbuf.c
@@ -0,0 +1,23 @@
+/*
+ * lib_strbuf - library string storage
+ */
+
+#include "ntp_stdlib.h"
+#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/libntp/lib_strbuf.h b/libntp/lib_strbuf.h
new file mode 100644
index 0000000..1a34034
--- /dev/null
+++ b/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/libntp/log.c b/libntp/log.c
new file mode 100644
index 0000000..991b498
--- /dev/null
+++ b/libntp/log.c
@@ -0,0 +1,161 @@
+/* Microsoft Developer Support Copyright (c) 1993 Microsoft Corporation. */
+
+/* Skip asynch rpc inclusion */
+#ifndef __RPCASYNC_H__
+#define __RPCASYNC_H__
+#endif
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.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(LPSTR pszAppname, LPSTR pszMsgDLL) *
+* *
+* 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;
+ char regarray[200];
+ char *lpregarray = regarray;
+
+ /* 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. */
+
+ strcpy(lpregarray, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\");
+ strcat(lpregarray, pszAppname);
+
+ /* Create a new key for our application */
+ bSuccess = RegCreateKey(HKEY_LOCAL_MACHINE,lpregarray, &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/libntp/log.h b/libntp/log.h
new file mode 100644
index 0000000..99d0e72
--- /dev/null
+++ b/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/libntp/machines.c b/libntp/machines.c
new file mode 100644
index 0000000..9e318bf
--- /dev/null
+++ b/libntp/machines.c
@@ -0,0 +1,525 @@
+/* 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_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef SYS_WINNT
+int _getch(void); /* Declare the one function rather than 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 */
+
+#ifdef MPE
+/* This is a substitute for bind() that if called for an AF_INET socket
+port less than 1024, GETPRIVMODE() and GETUSERMODE() calls will be done. */
+
+#undef bind
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/un.h>
+
+extern void GETPRIVMODE(void);
+extern void GETUSERMODE(void);
+
+int __ntp_mpe_bind(int s, void *addr, int addrlen);
+
+int __ntp_mpe_bind(int s, void *addr, int addrlen) {
+ int priv = 0;
+ int result;
+
+if (addrlen == sizeof(struct sockaddr_in)) { /* AF_INET */
+ if (((struct sockaddr_in *)addr)->sin_port > 0 &&
+ ((struct sockaddr_in *)addr)->sin_port < 1024) {
+ priv = 1;
+ GETPRIVMODE();
+ }
+/* ((struct sockaddr_in *)addr)->sin_addr.s_addr = 0; */
+ result = bind(s,addr,addrlen);
+ if (priv == 1) GETUSERMODE();
+} else /* AF_UNIX */
+ result = bind(s,addr,addrlen);
+
+return result;
+}
+
+/*
+ * MPE stupidly requires sfcntl() to be used on sockets instead of fcntl(),
+ * so we define a wrapper to analyze the file descriptor and call the correct
+ * function.
+ */
+
+#undef fcntl
+#include <errno.h>
+#include <fcntl.h>
+
+int __ntp_mpe_fcntl(int fd, int cmd, int arg);
+
+int __ntp_mpe_fcntl(int fd, int cmd, int arg) {
+ int len;
+ struct sockaddr sa;
+
+ extern int sfcntl(int, int, int);
+
+ len = sizeof sa;
+ if (getsockname(fd, &sa, &len) == -1) {
+ if (errno == EAFNOSUPPORT) /* AF_UNIX socket */
+ return sfcntl(fd, cmd, arg);
+ if (errno == ENOTSOCK) /* file or pipe */
+ return fcntl(fd, cmd, arg);
+ return (-1); /* unknown getsockname() failure */
+ } else /* AF_INET socket */
+ return sfcntl(fd, cmd, arg);
+}
+
+/*
+ * Setitimer emulation support. Note that we implement this using alarm(),
+ * and since alarm() only delivers one signal, we must re-enable the alarm
+ * by enabling our own SIGALRM setitimer_mpe_handler routine to be called
+ * before the real handler routine and re-enable the alarm at that time.
+ *
+ * Note that this solution assumes that sigaction(SIGALRM) is called before
+ * calling setitimer(). If it should ever to become necessary to support
+ * sigaction(SIGALRM) after calling setitimer(), it will be necessary to trap
+ * those sigaction() calls.
+ */
+
+#include <limits.h>
+#include <signal.h>
+
+/*
+ * Some global data that needs to be shared between setitimer() and
+ * setitimer_mpe_handler().
+ */
+
+struct {
+ unsigned long current_msec; /* current alarm() value in effect */
+ unsigned long interval_msec; /* next alarm() value from setitimer */
+ unsigned long value_msec; /* first alarm() value from setitimer */
+ struct itimerval current_itimerval; /* current itimerval in effect */
+ struct sigaction oldact; /* SIGALRM state saved by setitimer */
+} setitimer_mpe_ctx = { 0, 0, 0 };
+
+/*
+ * Undocumented, unsupported function to do alarm() in milliseconds.
+ */
+
+extern unsigned int px_alarm(unsigned long, int *);
+
+/*
+ * The SIGALRM handler routine enabled by setitimer(). Re-enable the alarm or
+ * restore the original SIGALRM setting if no more alarms are needed. Then
+ * call the original SIGALRM handler (if any).
+ */
+
+static RETSIGTYPE setitimer_mpe_handler(int sig)
+{
+int alarm_hpe_status;
+
+/* Update the new current alarm value */
+
+setitimer_mpe_ctx.current_msec = setitimer_mpe_ctx.interval_msec;
+
+if (setitimer_mpe_ctx.interval_msec > 0) {
+ /* Additional intervals needed; re-arm the alarm timer */
+ px_alarm(setitimer_mpe_ctx.interval_msec,&alarm_hpe_status);
+} else {
+ /* No more intervals, so restore previous original SIGALRM handler */
+ sigaction(SIGALRM, &setitimer_mpe_ctx.oldact, NULL);
+}
+
+/* Call the original SIGALRM handler if it is a function and not just a flag */
+
+if (setitimer_mpe_ctx.oldact.sa_handler != SIG_DFL &&
+ setitimer_mpe_ctx.oldact.sa_handler != SIG_ERR &&
+ setitimer_mpe_ctx.oldact.sa_handler != SIG_IGN)
+ (*setitimer_mpe_ctx.oldact.sa_handler)(SIGALRM);
+
+}
+
+/*
+ * Our implementation of setitimer().
+ */
+
+int
+setitimer(int which, struct itimerval *value,
+ struct itimerval *ovalue)
+{
+
+int alarm_hpe_status;
+unsigned long remaining_msec, value_msec, interval_msec;
+struct sigaction newact;
+
+/*
+ * Convert the initial interval to milliseconds
+ */
+
+if (value->it_value.tv_sec > (UINT_MAX / 1000))
+ value_msec = UINT_MAX;
+else
+ value_msec = value->it_value.tv_sec * 1000;
+
+value_msec += value->it_value.tv_usec / 1000;
+
+/*
+ * Convert the reset interval to milliseconds
+ */
+
+if (value->it_interval.tv_sec > (UINT_MAX / 1000))
+ interval_msec = UINT_MAX;
+else
+ interval_msec = value->it_interval.tv_sec * 1000;
+
+interval_msec += value->it_interval.tv_usec / 1000;
+
+if (value_msec > 0 && interval_msec > 0) {
+ /*
+ * We'll be starting an interval timer that will be repeating, so we need to
+ * insert our own SIGALRM signal handler to schedule the repeats.
+ */
+
+ /* Read the current SIGALRM action */
+
+ if (sigaction(SIGALRM, NULL, &setitimer_mpe_ctx.oldact) < 0) {
+ fprintf(stderr,"MPE setitimer old handler failed, errno=%d\n",errno);
+ return -1;
+ }
+
+ /* Initialize the new action to call our SIGALRM handler instead */
+
+ newact.sa_handler = &setitimer_mpe_handler;
+ newact.sa_mask = setitimer_mpe_ctx.oldact.sa_mask;
+ newact.sa_flags = setitimer_mpe_ctx.oldact.sa_flags;
+
+ if (sigaction(SIGALRM, &newact, NULL) < 0) {
+ fprintf(stderr,"MPE setitimer new handler failed, errno=%d\n",errno);
+ return -1;
+ }
+}
+
+/*
+ * Return previous itimerval if desired
+ */
+
+if (ovalue != NULL) *ovalue = setitimer_mpe_ctx.current_itimerval;
+
+/*
+ * Save current parameters for later usage
+ */
+
+setitimer_mpe_ctx.current_itimerval = *value;
+setitimer_mpe_ctx.current_msec = value_msec;
+setitimer_mpe_ctx.value_msec = value_msec;
+setitimer_mpe_ctx.interval_msec = interval_msec;
+
+/*
+ * Schedule the first alarm
+ */
+
+remaining_msec = px_alarm(value_msec, &alarm_hpe_status);
+if (alarm_hpe_status == 0)
+ return (0);
+else
+ return (-1);
+}
+
+/*
+ * MPE lacks gettimeofday(), so we define our own.
+ */
+
+int gettimeofday(struct timeval *tvp)
+
+{
+/* Documented, supported MPE functions. */
+extern void GETPRIVMODE(void);
+extern void GETUSERMODE(void);
+
+/* Undocumented, unsupported MPE functions. */
+extern long long get_time(void);
+extern void get_time_change_info(long long *, char *, char *);
+extern long long ticks_to_micro(long long);
+
+char pwf_since_boot, recover_pwf_time;
+long long mpetime, offset_ticks, offset_usec;
+
+GETPRIVMODE();
+mpetime = get_time(); /* MPE local time usecs since Jan 1 1970 */
+get_time_change_info(&offset_ticks, &pwf_since_boot, &recover_pwf_time);
+offset_usec = ticks_to_micro(offset_ticks); /* UTC offset usecs */
+GETUSERMODE();
+
+mpetime = mpetime - offset_usec; /* Convert from local time to UTC */
+tvp->tv_sec = mpetime / 1000000LL;
+tvp->tv_usec = mpetime % 1000000LL;
+
+return 0;
+}
+
+/*
+ * MPE lacks settimeofday(), so we define our own.
+ */
+
+#define HAVE_SETTIMEOFDAY
+
+int settimeofday(struct timeval *tvp)
+
+{
+/* Documented, supported MPE functions. */
+extern void GETPRIVMODE(void);
+extern void GETUSERMODE(void);
+
+/* Undocumented, unsupported MPE functions. */
+extern void get_time_change_info(long long *, char *, char *);
+extern void initialize_system_time(long long, int);
+extern void set_time_correction(long long, int, int);
+extern long long ticks_to_micro(long long);
+
+char pwf_since_boot, recover_pwf_time;
+long long big_sec, big_usec, mpetime, offset_ticks, offset_usec;
+
+big_sec = tvp->tv_sec;
+big_usec = tvp->tv_usec;
+mpetime = (big_sec * 1000000LL) + big_usec; /* Desired UTC microseconds */
+
+GETPRIVMODE();
+set_time_correction(0LL,0,0); /* Cancel previous time correction, if any */
+get_time_change_info(&offset_ticks, &pwf_since_boot, &recover_pwf_time);
+offset_usec = ticks_to_micro(offset_ticks); /* UTC offset microseconds */
+mpetime = mpetime + offset_usec; /* Convert from UTC to local time */
+initialize_system_time(mpetime,1);
+GETUSERMODE();
+
+return 0;
+}
+#endif /* MPE */
+
+const char *set_tod_using = "UNKNOWN";
+
+int
+ntp_set_tod(
+ struct timeval *tvp,
+ void *tzp
+ )
+{
+ int rc = -1;
+
+#ifdef DEBUG
+ if (debug)
+ printf("In ntp_set_tod\n");
+#endif
+
+#ifdef HAVE_CLOCK_SETTIME
+ if (rc) {
+ struct timespec ts;
+
+ set_tod_using = "clock_settime";
+ /* Convert timeval to timespec */
+ ts.tv_sec = tvp->tv_sec;
+ ts.tv_nsec = 1000 * tvp->tv_usec;
+
+ errno = 0;
+ rc = clock_settime(CLOCK_REALTIME, &ts);
+#ifdef DEBUG
+ if (debug) {
+ printf("ntp_set_tod: %s: %d: %s\n",
+ set_tod_using, rc, strerror(errno));
+ }
+#endif
+ }
+#endif /* HAVE_CLOCK_SETTIME */
+#ifdef HAVE_SETTIMEOFDAY
+ if (rc) {
+ struct timeval adjtv;
+
+ set_tod_using = "settimeofday";
+ /*
+ * Some broken systems don't reset adjtime() when the
+ * clock is stepped.
+ */
+ adjtv.tv_sec = adjtv.tv_usec = 0;
+ adjtime(&adjtv, NULL);
+ rc = SETTIMEOFDAY(tvp, tzp);
+#ifdef DEBUG
+ if (debug) {
+ printf("ntp_set_tod: %s: %d: %s\n",
+ set_tod_using, rc, strerror(errno));
+ }
+#endif
+ }
+#endif /* HAVE_SETTIMEOFDAY */
+#ifdef HAVE_STIME
+ if (rc) {
+ long tp = tvp->tv_sec;
+
+ set_tod_using = "stime";
+ rc = stime(&tp); /* lie as bad as SysVR4 */
+#ifdef DEBUG
+ if (debug) {
+ printf("ntp_set_tod: %s: %d: %s\n",
+ set_tod_using, rc, strerror(errno));
+ }
+#endif
+ }
+#endif /* HAVE_STIME */
+ if (rc)
+ set_tod_using = "Failed!";
+#ifdef DEBUG
+ if (debug) {
+ printf("ntp_set_tod: Final result: %s: %d: %s\n",
+ set_tod_using, rc, strerror(errno));
+ }
+#endif
+ return rc;
+}
+
+#endif /* not SYS_WINNT */
+
+#if defined (SYS_WINNT) || defined (SYS_VXWORKS) || defined(MPE)
+/* 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' && c!='\r'); 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/libntp/md5c.c b/libntp/md5c.c
new file mode 100644
index 0000000..07eec6c
--- /dev/null
+++ b/libntp/md5c.c
@@ -0,0 +1,354 @@
+/* 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"
+#ifndef HAVE_MD5INIT
+#include "ntp_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, idx, partLen;
+
+ /* Compute number of bytes mod 64 */
+ idx = (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 - idx;
+
+ /* Transform as many times as possible.
+ */
+ if (inputLen >= partLen) {
+ MD5_memcpy
+ ((POINTER)&context->buffer[idx], (POINTER)input, partLen);
+ MD5Transform (context->state, context->buffer);
+
+ for (i = partLen; i + 63 < inputLen; i += 64)
+ MD5Transform (context->state, &input[i]);
+
+ idx = 0;
+ }
+ else
+ i = 0;
+
+ /* Buffer remaining input */
+ MD5_memcpy
+ ((POINTER)&context->buffer[idx], (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 idx, padLen;
+
+ /* Save number of bits */
+ Encode (bits, context->count, 8);
+
+ /* Pad out to 56 mod 64.
+ */
+ idx = (unsigned int)((context->count[0] >> 3) & 0x3f);
+ padLen = (idx < 56) ? (56 - idx) : (120 - idx);
+ 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;
+}
+#else
+int md5_bs;
+#endif
diff --git a/libntp/memmove.c b/libntp/memmove.c
new file mode 100644
index 0000000..8ccc4b1
--- /dev/null
+++ b/libntp/memmove.c
@@ -0,0 +1,140 @@
+/*-
+ * 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>
+
+#include "l_stdlib.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 = *(const 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 = *(const word *)src);
+ t = length & wmask;
+ TLOOP(*--dst = *--src);
+ }
+ done:
+ return (dst0);
+}
+#else
+int memmove_bs;
+#endif
diff --git a/libntp/mfp_mul.c b/libntp/mfp_mul.c
new file mode 100644
index 0000000..0c667f7
--- /dev/null
+++ b/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/libntp/mfptoa.c b/libntp/mfptoa.c
new file mode 100644
index 0000000..6450b2c
--- /dev/null
+++ b/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,
+ short 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/libntp/mfptoms.c b/libntp/mfptoms.c
new file mode 100644
index 0000000..d2bfd71
--- /dev/null
+++ b/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,
+ short 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/libntp/mktime.c b/libntp/mktime.c
new file mode 100644
index 0000000..7f8290f
--- /dev/null
+++ b/libntp/mktime.c
@@ -0,0 +1,306 @@
+/*
+ * 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.
+ */
+
+#include "ntp_machine.h"
+
+#if !HAVE_MKTIME || !HAVE_TIMEGM
+
+#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)
+
+extern time_t time P((time_t *));
+
+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,
+ int usezn
+ )
+{
+ 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 ( ; ; ) {
+ if (usezn)
+ mytm = *localtime(&t);
+ else
+ mytm = *gmtime(&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;
+ if (usezn)
+ *tmp = *localtime(&t);
+ else
+ *tmp = *gmtime(&t);
+ *okayp = TRUE;
+ return t;
+}
+#else
+int mktime_bs;
+#endif /* !HAVE_MKTIME || !HAVE_TIMEGM */
+
+#if !HAVE_MKTIME
+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, 1);
+ if (okay || tmp->tm_isdst < 0)
+ return t;
+
+ return WRONG;
+}
+
+time_t
+mktime(
+ struct tm * tmp
+ )
+{
+ return time1(tmp);
+}
+#endif /* !HAVE_MKTIME */
+
+#if !HAVE_TIMEGM
+time_t
+timegm(
+ struct tm * tmp
+ )
+{
+ register time_t t;
+ int okay;
+
+ tmp->tm_isdst = 0;
+ t = time2(tmp, &okay, 0);
+ if (okay || tmp->tm_isdst < 0)
+ return t;
+
+ return WRONG;
+}
+#endif /* !HAVE_TIMEGM */
diff --git a/libntp/modetoa.c b/libntp/modetoa.c
new file mode 100644
index 0000000..405aef8
--- /dev/null
+++ b/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/libntp/mstolfp.c b/libntp/mstolfp.c
new file mode 100644
index 0000000..e4e909d
--- /dev/null
+++ b/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/libntp/msutotsf.c b/libntp/msutotsf.c
new file mode 100644
index 0000000..eb3babe
--- /dev/null
+++ b/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/libntp/msyslog.c b/libntp/msyslog.c
new file mode 100644
index 0000000..f0e8872
--- /dev/null
+++ b/libntp/msyslog.c
@@ -0,0 +1,207 @@
+/*
+ * 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_syslog.h"
+#include "ntp_stdlib.h"
+
+#ifdef SYS_WINNT
+# include <stdarg.h>
+# 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
+static char separator = '\\';
+#else
+static char separator = '/';
+#endif /* SYS_WINNT */
+extern char *progname;
+
+/* Declare the local functions */
+void addto_syslog P((int, char *));
+void format_errmsg P((char *, int, const char *, int));
+
+
+/*
+ * This routine adds the contents of a buffer to the log
+ */
+void
+addto_syslog(int level, char * buf)
+{
+ char *prog;
+ FILE *out_file = syslog_file;
+
+#if !defined(VMS) && !defined (SYS_VXWORKS)
+ if (syslogit)
+ syslog(level, "%s", buf);
+ else
+#endif /* VMS && SYS_VXWORKS*/
+ {
+ 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, separator);
+ 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);
+ }
+#if DEBUG
+ if (debug && out_file != stdout && out_file != stderr)
+ printf("addto_syslog: %s\n", buf);
+#endif
+}
+void
+format_errmsg(char *nfmt, int lennfmt, const char *fmt, int errval)
+{
+ register char c;
+ register char *n;
+ register const char *f;
+
+ char *err;
+
+ n = nfmt;
+ f = fmt;
+ while ((c = *f++) != '\0' && n < (nfmt+lennfmt - 2)) {
+ if (c != '%') {
+ *n++ = c;
+ continue;
+ }
+ if ((c = *f++) != 'm') {
+ *n++ = '%';
+ *n++ = c;
+ continue;
+ }
+ err = 0;
+ err = strerror(errval);
+ /* Make sure we have enough space for the error message */
+ if ((n + strlen(err)) < (nfmt + lennfmt -2)) {
+ strcpy(n, err);
+ n += strlen(err);
+ }
+ }
+#if !defined(VMS)
+ if (!syslogit)
+#endif /* VMS */
+ *n++ = '\n';
+ *n = '\0';
+}
+
+/*
+ * The externally called functions are defined here
+ * but share the internal function above to fetch
+ * any error message strings, This is done so that we can
+ * have two different functions to perform the logging
+ * since Windows gets it's error information from different
+ * places depending on whether or not it's network I/O.
+ * msyslog() is for general use while netsyslog() is for
+ * network I/O functions. They are virtually identical
+ * in implementation.
+ */
+
+#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];
+
+ /*
+ * Save the error value as soon as possible
+ */
+#ifdef SYS_WINNT
+ int errval = GetLastError();
+#else
+ int errval = errno;
+#endif
+
+#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
+ format_errmsg(nfmt, sizeof(nfmt), fmt, errval);
+
+ vsnprintf(buf, sizeof(buf), nfmt, ap);
+ addto_syslog(level, buf);
+ va_end(ap);
+}
+#if defined(__STDC__) || defined(HAVE_STDARG_H)
+void netsyslog(int level, const char *fmt, ...)
+#else /* defined(__STDC__) || defined(HAVE_STDARG_H) */
+ /*VARARGS*/
+ void netsyslog(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];
+
+ /*
+ * Save the error value as soon as possible
+ */
+#ifdef SYS_WINNT
+ int errval = WSAGetLastError();
+#else
+ int errval = errno;
+#endif
+
+#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
+ format_errmsg(nfmt, sizeof(nfmt), fmt, errval);
+
+ vsnprintf(buf, sizeof(buf), nfmt, ap);
+ addto_syslog(level, buf);
+ va_end(ap);
+}
diff --git a/libntp/netof.c b/libntp/netof.c
new file mode 100644
index 0000000..fd57568
--- /dev/null
+++ b/libntp/netof.c
@@ -0,0 +1,48 @@
+/*
+ * netof - return the net address part of an ip address in a sockaddr_storage structure
+ * (zero out host part)
+ */
+#include <stdio.h>
+
+#include "ntp_fp.h"
+#include "ntp_stdlib.h"
+#include "ntp.h"
+
+#define NUM_NETOF_BUFS 10
+static struct sockaddr_storage ssbuf[NUM_NETOF_BUFS];
+static int next_ssbuf = 0;
+
+struct sockaddr_storage*
+netof(
+ struct sockaddr_storage* hostaddr
+ )
+{
+ register u_int32 netnum;
+ struct sockaddr_storage *netaddr;
+
+ netaddr = &ssbuf[next_ssbuf++];
+ if (next_ssbuf == NUM_NETOF_BUFS)
+ next_ssbuf = 0;
+ memcpy(netaddr, hostaddr, sizeof(struct sockaddr_storage));
+
+ if(netaddr->ss_family == AF_INET) {
+ netnum = ((struct sockaddr_in*)netaddr)->sin_addr.s_addr;
+
+ /*
+ * We live in a modern CIDR world where the basement nets, which
+ * used to be class A, are now probably associated with each
+ * host address. So, for class-A nets, all bits are significant.
+ */
+ if(IN_CLASSC(netnum))
+ netnum &= IN_CLASSC_NET;
+ else if (IN_CLASSB(netnum))
+ netnum &= IN_CLASSB_NET;
+ ((struct sockaddr_in*)netaddr)->sin_addr.s_addr = netnum;
+ }
+ else if(netaddr->ss_family == AF_INET6) {
+ /* Here we put 0 at the local link address so we get net address */
+ memset(&((struct sockaddr_in6*)netaddr)->sin6_addr.s6_addr[8], 0, 8*sizeof(u_char));
+ }
+
+ return netaddr;
+}
diff --git a/libntp/ntp_rfc2553.c b/libntp/ntp_rfc2553.c
new file mode 100644
index 0000000..2788630
--- /dev/null
+++ b/libntp/ntp_rfc2553.c
@@ -0,0 +1,331 @@
+/*
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1982, 1986, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Compatability shims with the rfc2553 API to simplify ntp.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <ctype.h>
+#include <sys/socket.h>
+#include "ntp_rfc2553.h"
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#include <netdb.h>
+
+#include "ntpd.h"
+#include "ntp_malloc.h"
+#include "ntp_stdlib.h"
+#include "ntp_string.h"
+
+#ifndef HAVE_IPV6
+
+#if defined(SYS_WINNT)
+/* XXX This is the preferred way, but for some reason the SunOS compiler
+ * does not like it.
+ */
+const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
+#else
+const struct in6_addr in6addr_any;
+#endif
+
+static char *ai_errlist[] = {
+ "Success",
+ "Address family for hostname not supported", /* EAI_ADDRFAMILY */
+ "Temporary failure in name resolution", /* EAI_AGAIN */
+ "Invalid value for ai_flags", /* EAI_BADFLAGS */
+ "Non-recoverable failure in name resolution", /* EAI_FAIL */
+ "ai_family not supported", /* EAI_FAMILY */
+ "Memory allocation failure", /* EAI_MEMORY */
+ "No address associated with hostname", /* EAI_NODATA */
+ "hostname nor servname provided, or not known", /* EAI_NONAME */
+ "servname not supported for ai_socktype", /* EAI_SERVICE */
+ "ai_socktype not supported", /* EAI_SOCKTYPE */
+ "System error returned in errno", /* EAI_SYSTEM */
+ "Invalid value for hints", /* EAI_BADHINTS */
+ "Resolved protocol is unknown", /* EAI_PROTOCOL */
+ "Unknown error", /* EAI_MAX */
+};
+
+static int ipv4_aton P((const char *, struct sockaddr_storage *));
+static int do_nodename P((const char *nodename, struct addrinfo *ai,
+ const struct addrinfo *hints));
+
+int
+getaddrinfo (const char *nodename, const char *servname,
+ const struct addrinfo *hints, struct addrinfo **res)
+{
+ int rval;
+ struct addrinfo *ai;
+ struct sockaddr_in *sockin;
+
+ ai = calloc(sizeof(struct addrinfo), 1);
+ if (ai == NULL)
+ return (EAI_MEMORY);
+
+ if (nodename != NULL) {
+ rval = do_nodename(nodename, ai, hints);
+ if (rval != 0) {
+ freeaddrinfo(ai);
+ return (rval);
+ }
+ }
+ if (nodename == NULL && hints != NULL) {
+ ai->ai_addr = calloc(sizeof(struct sockaddr_storage), 1);
+ if (ai->ai_addr == NULL) {
+ freeaddrinfo(ai);
+ return (EAI_MEMORY);
+ }
+ ai->ai_family = AF_INET;
+ ai->ai_addrlen = sizeof(struct sockaddr_storage);
+ sockin = (struct sockaddr_in *)ai->ai_addr;
+ sockin->sin_family = AF_INET;
+ sockin->sin_addr.s_addr = htonl(INADDR_ANY);
+#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR
+ ai->ai_addr->sa_len = SOCKLEN(ai->ai_addr);
+#endif
+ }
+ if (servname != NULL) {
+ ai->ai_family = AF_INET;
+ ai->ai_socktype = SOCK_DGRAM;
+ if (strcmp(servname, "ntp") != 0) {
+ freeaddrinfo(ai);
+ return (EAI_SERVICE);
+ }
+ sockin = (struct sockaddr_in *)ai->ai_addr;
+ sockin->sin_port = htons(NTP_PORT);
+ }
+ *res = ai;
+ return (0);
+}
+
+void
+freeaddrinfo(struct addrinfo *ai)
+{
+ if (ai->ai_canonname != NULL)
+ free(ai->ai_canonname);
+ if (ai->ai_addr != NULL)
+ free(ai->ai_addr);
+ free(ai);
+}
+
+int
+getnameinfo (const struct sockaddr *sa, u_int salen, char *host,
+ size_t hostlen, char *serv, size_t servlen, int flags)
+{
+ struct hostent *hp;
+
+ if (sa->sa_family != AF_INET)
+ return (EAI_FAMILY);
+ hp = gethostbyaddr(
+ (const char *)&((const struct sockaddr_in *)sa)->sin_addr,
+ 4, AF_INET);
+ if (hp == NULL) {
+ if (h_errno == TRY_AGAIN)
+ return (EAI_AGAIN);
+ else
+ return (EAI_FAIL);
+ }
+ if (host != NULL) {
+ strncpy(host, hp->h_name, hostlen);
+ host[hostlen] = '\0';
+ }
+ return (0);
+}
+
+char *
+gai_strerror(int ecode)
+{
+ if (ecode < 0 || ecode > EAI_MAX)
+ ecode = EAI_MAX;
+ return ai_errlist[ecode];
+}
+
+static int
+do_nodename(
+ const char *nodename,
+ struct addrinfo *ai,
+ const struct addrinfo *hints)
+{
+ struct hostent *hp;
+ struct sockaddr_in *sockin;
+
+ ai->ai_addr = calloc(sizeof(struct sockaddr_storage), 1);
+ if (ai->ai_addr == NULL)
+ return (EAI_MEMORY);
+
+ if (hints != NULL && hints->ai_flags & AI_NUMERICHOST) {
+ if (ipv4_aton(nodename,
+ (struct sockaddr_storage *)ai->ai_addr) == 1) {
+ ai->ai_family = AF_INET;
+ ai->ai_addrlen = sizeof(struct sockaddr_in);
+ return (0);
+ }
+ return (EAI_NONAME);
+ }
+ hp = gethostbyname(nodename);
+ if (hp == NULL) {
+ if (h_errno == TRY_AGAIN)
+ return (EAI_AGAIN);
+ else {
+ if (ipv4_aton(nodename,
+ (struct sockaddr_storage *)ai->ai_addr) == 1) {
+ ai->ai_family = AF_INET;
+ ai->ai_addrlen = sizeof(struct sockaddr_in);
+ return (0);
+ }
+ return (EAI_FAIL);
+ }
+ }
+ ai->ai_family = hp->h_addrtype;
+ ai->ai_addrlen = sizeof(struct sockaddr);
+ sockin = (struct sockaddr_in *)ai->ai_addr;
+ memcpy(&sockin->sin_addr, hp->h_addr, hp->h_length);
+ ai->ai_addr->sa_family = hp->h_addrtype;
+#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR
+ ai->ai_addr->sa_len = sizeof(struct sockaddr);
+#endif
+ if (hints != NULL && hints->ai_flags & AI_CANONNAME) {
+ ai->ai_canonname = malloc(strlen(hp->h_name) + 1);
+ if (ai->ai_canonname == NULL)
+ return (EAI_MEMORY);
+ strcpy(ai->ai_canonname, hp->h_name);
+ }
+ return (0);
+}
+
+/*
+ * ipv4_aton - return a net number (this is crude, but careful)
+ */
+static int
+ipv4_aton(
+ const char *num,
+ struct sockaddr_storage *saddr
+ )
+{
+ const char *cp;
+ char *bp;
+ int i;
+ int temp;
+ char buf[80]; /* will core dump on really stupid stuff */
+ u_int32 netnum;
+ struct sockaddr_in *addr;
+
+ cp = num;
+ netnum = 0;
+ for (i = 0; i < 4; i++) {
+ bp = buf;
+ while (isdigit((int)*cp))
+ *bp++ = *cp++;
+ if (bp == buf)
+ break;
+
+ if (i < 3) {
+ if (*cp++ != '.')
+ break;
+ } else if (*cp != '\0')
+ break;
+
+ *bp = '\0';
+ temp = atoi(buf);
+ if (temp > 255)
+ break;
+ netnum <<= 8;
+ netnum += temp;
+#ifdef DEBUG
+ if (debug > 3)
+ printf("ipv4_aton %s step %d buf %s temp %d netnum %lu\n",
+ num, i, buf, temp, (u_long)netnum);
+#endif
+ }
+
+ if (i < 4) {
+#ifdef DEBUG
+ if (debug > 3)
+ printf(
+ "ipv4_aton: \"%s\" invalid host number, line ignored\n",
+ num);
+#endif
+ return (0);
+ }
+
+ /*
+ * make up socket address. Clear it out for neatness.
+ */
+ memset((void *)saddr, 0, sizeof(struct sockaddr_storage));
+ addr = (struct sockaddr_in *)saddr;
+ addr->sin_family = AF_INET;
+ addr->sin_port = htons(NTP_PORT);
+ addr->sin_addr.s_addr = htonl(netnum);
+#ifdef DEBUG
+ if (debug > 1)
+ printf("ipv4_aton given %s, got %s.\n", num, ntoa(saddr));
+#endif
+ return (1);
+}
+#endif /* !HAVE_IPV6 */
diff --git a/libntp/numtoa.c b/libntp/numtoa.c
new file mode 100644
index 0000000..de95118
--- /dev/null
+++ b/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/libntp/numtohost.c b/libntp/numtohost.c
new file mode 100644
index 0000000..4e53092
--- /dev/null
+++ b/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/libntp/octtoint.c b/libntp/octtoint.c
new file mode 100644
index 0000000..f792b2b
--- /dev/null
+++ b/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/libntp/prettydate.c b/libntp/prettydate.c
new file mode 100644
index 0000000..9710c84
--- /dev/null
+++ b/libntp/prettydate.c
@@ -0,0 +1,68 @@
+/*
+ * 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"
+
+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/libntp/random.c b/libntp/random.c
new file mode 100644
index 0000000..7136857
--- /dev/null
+++ b/libntp/random.c
@@ -0,0 +1,482 @@
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ *
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)random.c 8.2 (Berkeley) 5/19/95";
+#endif /* LIBC_SCCS and not lint */
+
+#include "config.h"
+#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>
+
+/*
+ * random.c:
+ *
+ * An improved random number generation package. In addition to the standard
+ * rand()/srand() like interface, this package also has a special state info
+ * interface. The initstate() routine is called with a seed, an array of
+ * bytes, and a count of how many bytes are being passed in; this array is
+ * then initialized to contain information for random number generation with
+ * that much state information. Good sizes for the amount of state
+ * information are 32, 64, 128, and 256 bytes. The state can be switched by
+ * calling the setstate() routine with the same array as was initiallized
+ * with initstate(). By default, the package runs with 128 bytes of state
+ * information and generates far better random numbers than a linear
+ * congruential generator. If the amount of state information is less than
+ * 32 bytes, a simple linear congruential R.N.G. is used.
+ *
+ * Internally, the state information is treated as an array of longs; the
+ * zeroeth element of the array is the type of R.N.G. being used (small
+ * integer); the remainder of the array is the state information for the
+ * R.N.G. Thus, 32 bytes of state information will give 7 longs worth of
+ * state information, which will allow a degree seven polynomial. (Note:
+ * the zeroeth word of state information also has some other information
+ * stored in it -- see setstate() for details).
+ *
+ * The random number generation technique is a linear feedback shift register
+ * approach, employing trinomials (since there are fewer terms to sum up that
+ * way). In this approach, the least significant bit of all the numbers in
+ * the state table will act as a linear feedback shift register, and will
+ * have period 2^deg - 1 (where deg is the degree of the polynomial being
+ * used, assuming that the polynomial is irreducible and primitive). The
+ * higher order bits will have longer periods, since their values are also
+ * influenced by pseudo-random carries out of the lower bits. The total
+ * period of the generator is approximately deg*(2**deg - 1); thus doubling
+ * the amount of state information has a vast influence on the period of the
+ * generator. Note: the deg*(2**deg - 1) is an approximation only good for
+ * large deg, when the period of the shift register is the dominant factor.
+ * With deg equal to seven, the period is actually much longer than the
+ * 7*(2**7 - 1) predicted by this formula.
+ *
+ * Modified 28 December 1994 by Jacob S. Rosenberg.
+ * The following changes have been made:
+ * All references to the type u_int have been changed to unsigned long.
+ * All references to type int have been changed to type long. Other
+ * cleanups have been made as well. A warning for both initstate and
+ * setstate has been inserted to the effect that on Sparc platforms
+ * the 'arg_state' variable must be forced to begin on word boundaries.
+ * This can be easily done by casting a long integer array to char *.
+ * The overall logic has been left STRICTLY alone. This software was
+ * tested on both a VAX and Sun SpacsStation with exactly the same
+ * results. The new version and the original give IDENTICAL results.
+ * The new version is somewhat faster than the original. As the
+ * documentation says: "By default, the package runs with 128 bytes of
+ * state information and generates far better random numbers than a linear
+ * congruential generator. If the amount of state information is less than
+ * 32 bytes, a simple linear congruential R.N.G. is used." For a buffer of
+ * 128 bytes, this new version runs about 19 percent faster and for a 16
+ * byte buffer it is about 5 percent faster.
+ */
+
+/*
+ * For each of the currently supported random number generators, we have a
+ * break value on the amount of state information (you need at least this
+ * many bytes of state info to support this random number generator), a degree
+ * for the polynomial (actually a trinomial) that the R.N.G. is based on, and
+ * the separation between the two lower order coefficients of the trinomial.
+ */
+#define TYPE_0 0 /* linear congruential */
+#define BREAK_0 8
+#define DEG_0 0
+#define SEP_0 0
+
+#define TYPE_1 1 /* x**7 + x**3 + 1 */
+#define BREAK_1 32
+#define DEG_1 7
+#define SEP_1 3
+
+#define TYPE_2 2 /* x**15 + x + 1 */
+#define BREAK_2 64
+#define DEG_2 15
+#define SEP_2 1
+
+#define TYPE_3 3 /* x**31 + x**3 + 1 */
+#define BREAK_3 128
+#define DEG_3 31
+#define SEP_3 3
+
+#define TYPE_4 4 /* x**63 + x + 1 */
+#define BREAK_4 256
+#define DEG_4 63
+#define SEP_4 1
+
+/*
+ * Array versions of the above information to make code run faster --
+ * relies on fact that TYPE_i == i.
+ */
+#define MAX_TYPES 5 /* max number of types above */
+
+static long degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
+static long seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
+
+/*
+ * Initially, everything is set up as if from:
+ *
+ * initstate(1, randtbl, 128);
+ *
+ * Note that this initialization takes advantage of the fact that srandom()
+ * advances the front and rear pointers 10*rand_deg times, and hence the
+ * rear pointer which starts at 0 will also end up at zero; thus the zeroeth
+ * element of the state information, which contains info about the current
+ * position of the rear pointer is just
+ *
+ * MAX_TYPES * (rptr - state) + TYPE_3 == TYPE_3.
+ */
+
+static long randtbl[DEG_3 + 1] = {
+ TYPE_3,
+#ifdef USE_WEAK_SEEDING
+/* Historic implementation compatibility */
+/* The random sequences do not vary much with the seed */
+ 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, 0xdf0a6fb5,
+ 0xf103bc02, 0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd,
+ 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88,
+ 0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc,
+ 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, 0x8999220b,
+ 0x27fb47b9,
+#else /* !USE_WEAK_SEEDING */
+ 0x991539b1, 0x16a5bce3, 0x6774a4cd, 0x3e01511e, 0x4e508aaa, 0x61048c05,
+ 0xf5500617, 0x846b7115, 0x6a19892c, 0x896a97af, 0xdb48f936, 0x14898454,
+ 0x37ffd106, 0xb58bff9c, 0x59e17104, 0xcf918a49, 0x09378c83, 0x52c7a471,
+ 0x8d293ea9, 0x1f4fc301, 0xc3db71be, 0x39b44e1c, 0xf8a44ef9, 0x4c8b80b1,
+ 0x19edc328, 0x87bf4bdd, 0xc9b240e5, 0xe9ee4b1b, 0x4382aee7, 0x535b6b41,
+ 0xf3bec5da
+#endif /* !USE_WEAK_SEEDING */
+};
+
+/*
+ * fptr and rptr are two pointers into the state info, a front and a rear
+ * pointer. These two pointers are always rand_sep places aparts, as they
+ * cycle cyclically through the state information. (Yes, this does mean we
+ * could get away with just one pointer, but the code for random() is more
+ * efficient this way). The pointers are left positioned as they would be
+ * from the call
+ *
+ * initstate(1, randtbl, 128);
+ *
+ * (The position of the rear pointer, rptr, is really 0 (as explained above
+ * in the initialization of randtbl) because the state table pointer is set
+ * to point to randtbl[1] (as explained below).
+ */
+static long *fptr = &randtbl[SEP_3 + 1];
+static long *rptr = &randtbl[1];
+
+/*
+ * The following things are the pointer to the state information table, the
+ * type of the current generator, the degree of the current polynomial being
+ * used, and the separation between the two pointers. Note that for efficiency
+ * of random(), we remember the first location of the state information, not
+ * the zeroeth. Hence it is valid to access state[-1], which is used to
+ * store the type of the R.N.G. Also, we remember the last location, since
+ * this is more efficient than indexing every time to find the address of
+ * the last element to see if the front and rear pointers have wrapped.
+ */
+static long *state = &randtbl[1];
+static long rand_type = TYPE_3;
+static long rand_deg = DEG_3;
+static long rand_sep = SEP_3;
+static long *end_ptr = &randtbl[DEG_3 + 1];
+
+static inline long good_rand P((long));
+long random P((void));
+
+static inline long
+good_rand (
+ register long x
+ )
+{
+#ifdef USE_WEAK_SEEDING
+/*
+ * Historic implementation compatibility.
+ * The random sequences do not vary much with the seed,
+ * even with overflowing.
+ */
+ return (1103515245 * x + 12345);
+#else /* !USE_WEAK_SEEDING */
+/*
+ * Compute x = (7^5 * x) mod (2^31 - 1)
+ * wihout overflowing 31 bits:
+ * (2^31 - 1) = 127773 * (7^5) + 2836
+ * From "Random number generators: good ones are hard to find",
+ * Park and Miller, Communications of the ACM, vol. 31, no. 10,
+ * October 1988, p. 1195.
+ */
+ register long hi, lo;
+
+ hi = x / 127773;
+ lo = x % 127773;
+ x = 16807 * lo - 2836 * hi;
+ if (x <= 0)
+ x += 0x7fffffff;
+ return (x);
+#endif /* !USE_WEAK_SEEDING */
+}
+
+/*
+ * srandom:
+ *
+ * Initialize the random number generator based on the given seed. If the
+ * type is the trivial no-state-information type, just remember the seed.
+ * Otherwise, initializes state[] based on the given "seed" via a linear
+ * congruential generator. Then, the pointers are set to known locations
+ * that are exactly rand_sep places apart. Lastly, it cycles the state
+ * information a given number of times to get rid of any initial dependencies
+ * introduced by the L.C.R.N.G. Note that the initialization of randtbl[]
+ * for default usage relies on values produced by this routine.
+ */
+void
+srandom(
+ unsigned long x
+ )
+{
+ register long i;
+
+ if (rand_type == TYPE_0)
+ state[0] = x;
+ else {
+ state[0] = x;
+ for (i = 1; i < rand_deg; i++)
+ state[i] = good_rand(state[i - 1]);
+ fptr = &state[rand_sep];
+ rptr = &state[0];
+ for (i = 0; i < 10 * rand_deg; i++)
+ (void)random();
+ }
+}
+
+/*
+ * srandomdev:
+ *
+ * Many programs choose the seed value in a totally predictable manner.
+ * This often causes problems. We seed the generator using the much more
+ * secure urandom(4) interface. Note that this particular seeding
+ * procedure can generate states which are impossible to reproduce by
+ * calling srandom() with any value, since the succeeding terms in the
+ * state buffer are no longer derived from the LC algorithm applied to
+ * a fixed seed.
+ */
+void
+srandomdev( void )
+{
+ struct timeval tv;
+ unsigned long junk; /* Purposely used uninitialized */
+
+ gettimeofday(&tv, NULL);
+ srandom(getpid() ^ tv.tv_sec ^ tv.tv_usec ^ junk);
+ return;
+}
+
+/*
+ * initstate:
+ *
+ * Initialize the state information in the given array of n bytes for future
+ * random number generation. Based on the number of bytes we are given, and
+ * the break values for the different R.N.G.'s, we choose the best (largest)
+ * one we can and set things up for it. srandom() is then called to
+ * initialize the state information.
+ *
+ * Note that on return from srandom(), we set state[-1] to be the type
+ * multiplexed with the current value of the rear pointer; this is so
+ * successive calls to initstate() won't lose this information and will be
+ * able to restart with setstate().
+ *
+ * Note: the first thing we do is save the current state, if any, just like
+ * setstate() so that it doesn't matter when initstate is called.
+ *
+ * Returns a pointer to the old state.
+ *
+ * Note: The Sparc platform requires that arg_state begin on a long
+ * word boundary; otherwise a bus error will occur. Even so, lint will
+ * complain about mis-alignment, but you should disregard these messages.
+ */
+char *
+initstate(
+ unsigned long seed, /* seed for R.N.G. */
+ char *arg_state, /* pointer to state array */
+ long n /* # bytes of state info */
+ )
+{
+ register char *ostate = (char *)(&state[-1]);
+ register long *long_arg_state = (long *) arg_state;
+
+ if (rand_type == TYPE_0)
+ state[-1] = rand_type;
+ else
+ state[-1] = MAX_TYPES * (rptr - state) + rand_type;
+ if (n < BREAK_0) {
+ (void)fprintf(stderr,
+ "random: not enough state (%ld bytes); ignored.\n", n);
+ return(0);
+ }
+ if (n < BREAK_1) {
+ rand_type = TYPE_0;
+ rand_deg = DEG_0;
+ rand_sep = SEP_0;
+ } else if (n < BREAK_2) {
+ rand_type = TYPE_1;
+ rand_deg = DEG_1;
+ rand_sep = SEP_1;
+ } else if (n < BREAK_3) {
+ rand_type = TYPE_2;
+ rand_deg = DEG_2;
+ rand_sep = SEP_2;
+ } else if (n < BREAK_4) {
+ rand_type = TYPE_3;
+ rand_deg = DEG_3;
+ rand_sep = SEP_3;
+ } else {
+ rand_type = TYPE_4;
+ rand_deg = DEG_4;
+ rand_sep = SEP_4;
+ }
+ state = (long *) (long_arg_state + 1); /* first location */
+ end_ptr = &state[rand_deg]; /* must set end_ptr before srandom */
+ srandom(seed);
+ if (rand_type == TYPE_0)
+ long_arg_state[0] = rand_type;
+ else
+ long_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type;
+ return(ostate);
+}
+
+/*
+ * setstate:
+ *
+ * Restore the state from the given state array.
+ *
+ * Note: it is important that we also remember the locations of the pointers
+ * in the current state information, and restore the locations of the pointers
+ * from the old state information. This is done by multiplexing the pointer
+ * location into the zeroeth word of the state information.
+ *
+ * Note that due to the order in which things are done, it is OK to call
+ * setstate() with the same state as the current state.
+ *
+ * Returns a pointer to the old state information.
+ *
+ * Note: The Sparc platform requires that arg_state begin on a long
+ * word boundary; otherwise a bus error will occur. Even so, lint will
+ * complain about mis-alignment, but you should disregard these messages.
+ */
+char *
+setstate(
+ char *arg_state /* pointer to state array */
+ )
+{
+ register long *new_state = (long *) arg_state;
+ register long type = new_state[0] % MAX_TYPES;
+ register long rear = new_state[0] / MAX_TYPES;
+ char *ostate = (char *)(&state[-1]);
+
+ if (rand_type == TYPE_0)
+ state[-1] = rand_type;
+ else
+ state[-1] = MAX_TYPES * (rptr - state) + rand_type;
+ switch(type) {
+ case TYPE_0:
+ case TYPE_1:
+ case TYPE_2:
+ case TYPE_3:
+ case TYPE_4:
+ rand_type = type;
+ rand_deg = degrees[type];
+ rand_sep = seps[type];
+ break;
+ default:
+ (void)fprintf(stderr,
+ "random: state info corrupted; not changed.\n");
+ }
+ state = (long *) (new_state + 1);
+ if (rand_type != TYPE_0) {
+ rptr = &state[rear];
+ fptr = &state[(rear + rand_sep) % rand_deg];
+ }
+ end_ptr = &state[rand_deg]; /* set end_ptr too */
+ return(ostate);
+}
+
+/*
+ * random:
+ *
+ * If we are using the trivial TYPE_0 R.N.G., just do the old linear
+ * congruential bit. Otherwise, we do our fancy trinomial stuff, which is
+ * the same in all the other cases due to all the global variables that have
+ * been set up. The basic operation is to add the number at the rear pointer
+ * into the one at the front pointer. Then both pointers are advanced to
+ * the next location cyclically in the table. The value returned is the sum
+ * generated, reduced to 31 bits by throwing away the "least random" low bit.
+ *
+ * Note: the code takes advantage of the fact that both the front and
+ * rear pointers can't wrap on the same call by not testing the rear
+ * pointer if the front one has wrapped.
+ *
+ * Returns a 31-bit random number.
+ */
+long
+random( void )
+{
+ register long i;
+ register long *f, *r;
+
+ if (rand_type == TYPE_0) {
+ i = state[0];
+ state[0] = i = (good_rand(i)) & 0x7fffffff;
+ } else {
+ /*
+ * Use local variables rather than static variables for speed.
+ */
+ f = fptr; r = rptr;
+ *f += *r;
+ i = (*f >> 1) & 0x7fffffff; /* chucking least random bit */
+ if (++f >= end_ptr) {
+ f = state;
+ ++r;
+ }
+ else if (++r >= end_ptr) {
+ r = state;
+ }
+
+ fptr = f; rptr = r;
+ }
+ return(i);
+}
diff --git a/libntp/ranny.c b/libntp/ranny.c
new file mode 100644
index 0000000..fa555f5
--- /dev/null
+++ b/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/libntp/recvbuff.c b/libntp/recvbuff.c
new file mode 100644
index 0000000..35c7e23
--- /dev/null
+++ b/libntp/recvbuff.c
@@ -0,0 +1,259 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include "ntp_machine.h"
+#include "ntp_fp.h"
+#include "ntp_syslog.h"
+#include "ntp_stdlib.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 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);
+#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++;
+
+ 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/libntp/refnumtoa.c b/libntp/refnumtoa.c
new file mode 100644
index 0000000..7c5d96e
--- /dev/null
+++ b/libntp/refnumtoa.c
@@ -0,0 +1,36 @@
+/*
+ * 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(
+ struct sockaddr_storage* num
+ )
+{
+ register u_int32 netnum;
+ register char *buf;
+ register const char *rclock;
+
+ LIB_GETBUF(buf);
+
+ if(num->ss_family == AF_INET) {
+ netnum = ntohl(((struct sockaddr_in*)num)->sin_addr.s_addr);
+ 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);
+
+ }
+ else {
+ (void)sprintf(buf, "refclock address type not implemented yet, use IPv4 refclock address.");
+ }
+ return buf;
+}
diff --git a/libntp/snprintf.c b/libntp/snprintf.c
new file mode 100644
index 0000000..7588b84
--- /dev/null
+++ b/libntp/snprintf.c
@@ -0,0 +1,62 @@
+#include <config.h>
+
+#if !HAVE_SNPRINTF
+#include <sys/types.h>
+
+#ifdef __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+#include <stdio.h>
+
+#include "l_stdlib.h"
+
+#ifdef __STDC__
+int snprintf(char *str, size_t n, const char *fmt, ...)
+#else
+int snprintf(str, n, fmt, va_alist)
+ char *str;
+ size_t n;
+ const char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+ int rval;
+#ifdef VSPRINTF_CHARSTAR
+ char *rp;
+#endif
+#ifdef __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+#ifdef VSPRINTF_CHARSTAR
+ rp = vsprintf(str, fmt, ap);
+ va_end(ap);
+ return (strlen(rp));
+#else
+ rval = vsprintf(str, fmt, ap);
+ va_end(ap);
+ return (rval);
+#endif
+}
+
+int
+vsnprintf(
+ char *str,
+ size_t n,
+ const char *fmt,
+ va_list ap
+ )
+{
+#ifdef VSPRINTF_CHARSTAR
+ return (strlen(vsprintf(str, fmt, ap)));
+#else
+ return (vsprintf(str, fmt, ap));
+#endif
+}
+#else
+int snprintf_bs;
+#endif
diff --git a/libntp/socktoa.c b/libntp/socktoa.c
new file mode 100644
index 0000000..34de784
--- /dev/null
+++ b/libntp/socktoa.c
@@ -0,0 +1,48 @@
+/*
+ * socktoa - return a numeric host name from a sockaddr_storage structure
+ */
+
+#include <config.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <netinet/in.h>
+
+#include <arpa/inet.h>
+
+#ifdef ISC_PLATFORM_NEEDNTOP
+#include <isc/net.h>
+#endif
+
+#include <stdio.h>
+
+#include "ntp_fp.h"
+#include "lib_strbuf.h"
+#include "ntp_stdlib.h"
+#include "ntp.h"
+
+char *
+socktoa(
+ struct sockaddr_storage* sock
+ )
+{
+ register char *buffer;
+
+ LIB_GETBUF(buffer);
+
+ if (sock == NULL) printf("null");
+
+ switch(sock->ss_family) {
+
+ case AF_INET :
+ inet_ntop(AF_INET, &GET_INADDR(*sock), buffer,
+ LIB_BUFLENGTH);
+ break;
+
+ case AF_INET6 :
+ inet_ntop(AF_INET6, &GET_INADDR6(*sock), buffer,
+ LIB_BUFLENGTH);
+ }
+ return buffer;
+}
diff --git a/libntp/socktohost.c b/libntp/socktohost.c
new file mode 100644
index 0000000..7a3b30f
--- /dev/null
+++ b/libntp/socktohost.c
@@ -0,0 +1,32 @@
+/*
+ * socktoa - return a numeric host name from a sockaddr_storage structure
+ */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <netinet/in.h>
+
+#include <arpa/inet.h>
+
+#include <stdio.h>
+
+#include "ntp_fp.h"
+#include "lib_strbuf.h"
+#include "ntp_stdlib.h"
+#include "ntp.h"
+
+
+char *
+socktohost(
+ struct sockaddr_storage* sock
+ )
+{
+ register char *buffer;
+
+ LIB_GETBUF(buffer);
+ if (getnameinfo((struct sockaddr *)sock, SOCKLEN(sock), buffer,
+ LIB_BUFLENGTH /* NI_MAXHOST*/, NULL, 0, 0))
+ return stoa(sock);
+
+ return buffer;
+}
diff --git a/libntp/statestr.c b/libntp/statestr.c
new file mode 100644
index 0000000..3acc5c9
--- /dev/null
+++ b/libntp/statestr.c
@@ -0,0 +1,303 @@
+/*
+ * 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" }
+};
+
+#ifdef OPENSSL
+/*
+ * Crypto events
+ */
+static
+struct codestring crypto_codes[] = {
+ { XEVNT_OK & ~CRPT_EVENT, "success" },
+ { XEVNT_LEN & ~CRPT_EVENT, "bad_field_format_or_length" },
+ { XEVNT_TSP & ~CRPT_EVENT, "bad_timestamp" },
+ { XEVNT_FSP & ~CRPT_EVENT, "bad_filestamp" },
+ { XEVNT_PUB & ~CRPT_EVENT, "bad_procedure_or_data" },
+ { XEVNT_MD & ~CRPT_EVENT, "unsupported_digest_type" },
+ { XEVNT_KEY & ~CRPT_EVENT, "unsupported_identity_type" },
+ { XEVNT_SGL & ~CRPT_EVENT, "bad_signature_length" },
+ { XEVNT_SIG & ~CRPT_EVENT, "signature_not_verified" },
+ { XEVNT_VFY & ~CRPT_EVENT, "certificate not verified" },
+ { XEVNT_PER & ~CRPT_EVENT, "certificate_expired" },
+ { XEVNT_CKY & ~CRPT_EVENT, "bad_or_missing_cookie" },
+ { XEVNT_DAT & ~CRPT_EVENT, "bad_or_missing_leapsecond_table" },
+ { XEVNT_CRT & ~CRPT_EVENT, "bad_or_missing_certificate" },
+ { XEVNT_ID & ~CRPT_EVENT, "bad or missing identification" },
+ { -1, "crypto" }
+};
+#endif /* OPENSSL */
+
+/* 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
+ )
+{
+ if (num & PEER_EVENT)
+ return (getcode(num & ~PEER_EVENT, peer_codes));
+#ifdef OPENSSL
+ else if (num & CRPT_EVENT)
+ return (getcode(num & ~CRPT_EVENT, crypto_codes));
+#endif /* OPENSSL */
+ else
+ return (getcode(num, 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/libntp/strdup.c b/libntp/strdup.c
new file mode 100644
index 0000000..2e26ba7
--- /dev/null
+++ b/libntp/strdup.c
@@ -0,0 +1,28 @@
+#include "ntp_malloc.h"
+
+#if !HAVE_STRDUP
+
+#define NULL 0
+
+char *strdup(const char *s);
+
+char *
+strdup(
+ const char *s
+ )
+{
+ char *cp;
+
+ if (s) {
+ cp = (char *) malloc((unsigned) (strlen(s)+1));
+ if (cp) {
+ (void) strcpy(cp, s);
+ }
+ } else {
+ cp = (char *) NULL;
+ }
+ return(cp);
+}
+#else
+int strdup_bs;
+#endif
diff --git a/libntp/strerror.c b/libntp/strerror.c
new file mode 100644
index 0000000..9d8ae8e
--- /dev/null
+++ b/libntp/strerror.c
@@ -0,0 +1,48 @@
+#include <config.h>
+
+#if !HAVE_STRERROR
+/*
+ * 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>
+
+#include "l_stdlib.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);
+}
+#else
+int strerror_bs;
+#endif
diff --git a/libntp/strstr.c b/libntp/strstr.c
new file mode 100644
index 0000000..a4deb87
--- /dev/null
+++ b/libntp/strstr.c
@@ -0,0 +1,52 @@
+#include <config.h>
+
+#if !HAVE_STRSTR
+
+/*
+ * Amanda, The Advanced Maryland Automatic Network Disk Archiver
+ * Copyright (c) 1991-1998 University of Maryland at College Park
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of U.M. not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. U.M. makes no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: James da Silva, Systems Design and Analysis Group
+ * Computer Science Department
+ * University of Maryland at College Park
+ */
+/*
+ * $Id$
+ *
+ * replacement for missing ANSI-C strstr function
+ */
+
+char *strstr(a, b)
+char *a, *b;
+{
+ int alen, blen, i;
+
+ alen = strlen(a);
+ blen = strlen(b);
+
+ for(i=0; i <= alen-blen; i++, a++)
+ if(strncmp(a, b, blen) == 0) return a;
+
+ return NULL;
+}
+#else
+int strstr_bs;
+#endif
diff --git a/libntp/syssignal.c b/libntp/syssignal.c
new file mode 100644
index 0000000..6ec4c4c
--- /dev/null
+++ b/libntp/syssignal.c
@@ -0,0 +1,133 @@
+#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
+
+#ifdef SA_RESTART
+/* Added for PPS clocks on Solaris 7 which get EINTR errors */
+# ifdef SIGPOLL
+ if (sig == SIGPOLL) vec.sa_flags = SA_RESTART;
+# endif
+# ifdef SIGIO
+ if (sig == SIGIO) vec.sa_flags = SA_RESTART;
+# endif
+#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/libntp/systime.c b/libntp/systime.c
new file mode 100644
index 0000000..ac6aa98
--- /dev/null
+++ b/libntp/systime.c
@@ -0,0 +1,521 @@
+/*
+ * systime -- routines to fiddle a UNIX clock.
+ *
+ * ATTENTION: Get approval from Dave Mills on all changes to this file!
+ *
+ */
+#include "ntp_machine.h"
+#include "ntp_fp.h"
+#include "ntp_syslog.h"
+#include "ntp_unixtime.h"
+#include "ntp_stdlib.h"
+
+#ifdef SIM
+#include "ntpsim.h"
+#endif /*SIM */
+
+#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 */
+
+/*
+ * These routines (get_systime, step_systime, adj_systime) implement an
+ * interface between the system independent NTP clock and the Unix
+ * system clock in various architectures and operating systems.
+ *
+ * Time is a precious quantity in these routines and every effort is
+ * made to minimize errors by always rounding toward zero and amortizing
+ * adjustment residues. By default the adjustment quantum is 1 us for
+ * the usual Unix tickadj() system call, but this can be increased if
+ * necessary by a configuration command. For instance, when the
+ * adjtime() quantum is a clock tick for a 100-Hz clock, the quantum
+ * should be 10 ms.
+ */
+double sys_tick = 1e-6; /* tickadj() quantum (s) */
+double sys_residual = 0; /* adjustment residue (s) */
+
+#ifndef SIM
+
+/*
+ * get_systime - return system time in NTP timestamp format.
+ */
+void
+get_systime(
+ l_fp *now /* system time */
+ )
+{
+ double dtemp;
+
+#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK)
+ struct timespec ts; /* seconds and nanoseconds */
+
+ /*
+ * Convert Unix clock from seconds and nanoseconds to seconds.
+ */
+# ifdef HAVE_CLOCK_GETTIME
+ clock_gettime(CLOCK_REALTIME, &ts);
+# else
+ getclock(TIMEOFDAY, &ts);
+# endif
+ now->l_i = ts.tv_sec + JAN_1970;
+ dtemp = ts.tv_nsec / 1e9;
+
+#else /* HAVE_CLOCK_GETTIME || HAVE_GETCLOCK */
+ struct timeval tv; /* seconds and microseconds */
+
+ /*
+ * Convert Unix clock from seconds and microseconds to seconds.
+ */
+ GETTIMEOFDAY(&tv, NULL);
+ now->l_i = tv.tv_sec + JAN_1970;
+ dtemp = tv.tv_usec / 1e6;
+
+#endif /* HAVE_CLOCK_GETTIME || HAVE_GETCLOCK */
+
+ /*
+ * Renormalize to seconds past 1900 and fraction.
+ */
+ dtemp += sys_residual;
+ if (dtemp >= 1) {
+ dtemp -= 1;
+ now->l_i++;
+ } else if (dtemp < -1) {
+ dtemp += 1;
+ now->l_i--;
+ }
+ dtemp *= FRAC;
+ now->l_uf = (u_int32)dtemp;
+}
+
+
+/*
+ * adj_systime - adjust system time by the argument.
+ */
+#if !defined SYS_WINNT
+int /* 0 okay, 1 error */
+adj_systime(
+ double now /* adjustment (s) */
+ )
+{
+ struct timeval adjtv; /* new adjustment */
+ struct timeval oadjtv; /* residual adjustment */
+ double dtemp;
+ long ticks;
+ int isneg = 0;
+
+ /*
+ * Most Unix adjtime() implementations adjust the system clock
+ * in microsecond quanta, but some adjust in 10-ms quanta. We
+ * carefully round the adjustment to the nearest quantum, then
+ * adjust in quanta and keep the residue for later.
+ */
+ dtemp = now + sys_residual;
+ if (dtemp < 0) {
+ isneg = 1;
+ dtemp = -dtemp;
+ }
+ adjtv.tv_sec = (long)dtemp;
+ dtemp -= adjtv.tv_sec;
+ ticks = (long)(dtemp / sys_tick + .5);
+ adjtv.tv_usec = (long)(ticks * sys_tick * 1e6);
+ dtemp -= adjtv.tv_usec / 1e6;
+ sys_residual = dtemp;
+
+ /*
+ * Convert to signed seconds and microseconds for the Unix
+ * adjtime() system call. Note we purposely lose the adjtime()
+ * leftover.
+ */
+ if (isneg) {
+ adjtv.tv_sec = -adjtv.tv_sec;
+ adjtv.tv_usec = -adjtv.tv_usec;
+ }
+ if (adjtime(&adjtv, &oadjtv) < 0) {
+ msyslog(LOG_ERR, "adj_systime: %m");
+ return (0);
+ }
+ return (1);
+}
+#endif
+
+
+/*
+ * 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, NULL) != 0) {
+ msyslog(LOG_ERR, "step-systime: %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);
+}
+
+#else /* SIM */
+/*
+ * Clock routines for the simulator - Harish Nair, with help
+ */
+/*
+ * get_systime - return the system time in NTP timestamp format
+ */
+void
+get_systime(
+ l_fp *now /* current system time in l_fp */ )
+{
+ /*
+ * To fool the code that determines the local clock precision,
+ * we advance the clock a minimum of 200 nanoseconds on every
+ * clock read. This is appropriate for a typical modern machine
+ * with nanosecond clocks. Note we make no attempt here to
+ * simulate reading error, since the error is so small. This may
+ * change when the need comes to implement picosecond clocks.
+ */
+ if (ntp_node.ntp_time == ntp_node.last_time)
+ ntp_node.ntp_time += 200e-9;
+ ntp_node.last_time = ntp_node.ntp_time;
+ DTOLFP(ntp_node.ntp_time, now);
+}
+
+
+/*
+ * adj_systime - advance or retard the system clock exactly like the
+ * real thng.
+ */
+int /* always succeeds */
+adj_systime(
+ double now /* time adjustment (s) */
+ )
+{
+ struct timeval adjtv; /* new adjustment */
+ double dtemp;
+ long ticks;
+ int isneg = 0;
+
+ /*
+ * Most Unix adjtime() implementations adjust the system clock
+ * in microsecond quanta, but some adjust in 10-ms quanta. We
+ * carefully round the adjustment to the nearest quantum, then
+ * adjust in quanta and keep the residue for later.
+ */
+ dtemp = now + sys_residual;
+ if (dtemp < 0) {
+ isneg = 1;
+ dtemp = -dtemp;
+ }
+ adjtv.tv_sec = (long)dtemp;
+ dtemp -= adjtv.tv_sec;
+ ticks = (long)(dtemp / sys_tick + .5);
+ adjtv.tv_usec = (long)(ticks * sys_tick * 1e6);
+ dtemp -= adjtv.tv_usec / 1e6;
+ sys_residual = dtemp;
+
+ /*
+ * Convert to signed seconds and microseconds for the Unix
+ * adjtime() system call. Note we purposely lose the adjtime()
+ * leftover.
+ */
+ if (isneg) {
+ adjtv.tv_sec = -adjtv.tv_sec;
+ adjtv.tv_usec = -adjtv.tv_usec;
+ sys_residual = -sys_residual;
+ }
+
+ /*
+ * We went to all the trouble just to be sure the emulation is
+ * precise. We now return to our regularly scheduled concert.
+ */
+ ntp_node.clk_time -= adjtv.tv_sec + adjtv.tv_usec / 1e6;
+ return (1);
+}
+
+
+/*
+ * step_systime - step the system clock. We are religious here.
+ */
+int /* always succeeds */
+step_systime(
+ double now /* step adjustment (s) */
+ )
+{
+ ntp_node.adj = now;
+ return (1);
+}
+
+/*
+ * node_clock - update the clocks
+ */
+int /* always succeeds */
+node_clock(
+ Node *n, /* global node pointer */
+ double t /* node time */
+ )
+{
+ double dtemp;
+
+ /*
+ * Advance client clock (ntp_time). Advance server clock
+ * (clk_time) adjusted for systematic and random frequency
+ * errors. The random error is a random walk computed as the
+ * integral of samples from a Gaussian distribution.
+ */
+ dtemp = t - n->ntp_time;
+ n->time = t;
+ n->ntp_time += dtemp;
+ n->ferr += gauss(0, dtemp * n->fnse);
+ n->clk_time += dtemp * (1 + n->ferr);
+
+ /*
+ * Perform the adjtime() function. If the adjustment completed
+ * in the previous interval, amortize the entire amount; if not,
+ * carry the leftover to the next interval.
+ */
+ dtemp *= n->slew;
+ if (dtemp < fabs(n->adj)) {
+ if (n->adj < 0) {
+ n->adj += dtemp;
+ n->ntp_time -= dtemp;
+ } else {
+ n->adj -= dtemp;
+ n->ntp_time += dtemp;
+ }
+ } else {
+ n->ntp_time += n->adj;
+ n->adj = 0;
+ }
+ return (0);
+}
+
+
+/*
+ * gauss() - returns samples from a gaussion distribution
+ */
+double /* Gaussian sample */
+gauss(
+ double m, /* sample mean */
+ double s /* sample standard deviation (sigma) */
+ )
+{
+ double q1, q2;
+
+ /*
+ * Roll a sample from a Gaussian distribution with mean m and
+ * standard deviation s. For m = 0, s = 1, mean(y) = 0,
+ * std(y) = 1.
+ */
+ if (s == 0)
+ return (m);
+ while ((q1 = drand48()) == 0);
+ q2 = drand48();
+ return (m + s * sqrt(-2. * log(q1)) * cos(2. * PI * q2));
+}
+
+
+/*
+ * poisson() - returns samples from a network delay distribution
+ */
+double /* delay sample (s) */
+poisson(
+ double m, /* fixed propagation delay (s) */
+ double s /* exponential parameter (mu) */
+ )
+{
+ double q1;
+
+ /*
+ * Roll a sample from a composite distribution with propagation
+ * delay m and exponential distribution time with parameter s.
+ * For m = 0, s = 1, mean(y) = std(y) = 1.
+ */
+ if (s == 0)
+ return (m);
+ while ((q1 = drand48()) == 0);
+ return (m - s * log(q1 * s));
+}
+#endif /* SIM */
diff --git a/libntp/systime_s.c b/libntp/systime_s.c
new file mode 100644
index 0000000..8762122
--- /dev/null
+++ b/libntp/systime_s.c
@@ -0,0 +1,2 @@
+#define SIM
+#include "systime.c"
diff --git a/libntp/tsftomsu.c b/libntp/tsftomsu.c
new file mode 100644
index 0000000..5926aab
--- /dev/null
+++ b/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/libntp/tstotv.c b/libntp/tstotv.c
new file mode 100644
index 0000000..be4bdd4
--- /dev/null
+++ b/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/libntp/tvtoa.c b/libntp/tvtoa.c
new file mode 100644
index 0000000..19d4a94
--- /dev/null
+++ b/libntp/tvtoa.c
@@ -0,0 +1,39 @@
+/*
+ * tvtoa - return an asciized representation of a struct timeval
+ */
+
+#include "lib_strbuf.h"
+
+#if defined(VMS)
+# include "ntp_fp.h"
+#endif /* VMS */
+#include "ntp_stdlib.h"
+#include "ntp_unixtime.h"
+
+#include <stdio.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/libntp/tvtots.c b/libntp/tvtots.c
new file mode 100644
index 0000000..0bd2b69
--- /dev/null
+++ b/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/libntp/uglydate.c b/libntp/uglydate.c
new file mode 100644
index 0000000..676a5fd
--- /dev/null
+++ b/libntp/uglydate.c
@@ -0,0 +1,48 @@
+/*
+ * 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"
+
+
+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/libntp/uinttoa.c b/libntp/uinttoa.c
new file mode 100644
index 0000000..be48ea5
--- /dev/null
+++ b/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/libntp/utvtoa.c b/libntp/utvtoa.c
new file mode 100644
index 0000000..a441c49
--- /dev/null
+++ b/libntp/utvtoa.c
@@ -0,0 +1,26 @@
+/*
+ * utvtoa - return an asciized representation of an unsigned struct timeval
+ */
+#include <stdio.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/libntp/ymd2yd.c b/libntp/ymd2yd.c
new file mode 100644
index 0000000..796ce40
--- /dev/null
+++ b/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