diff options
author | roberto <roberto@FreeBSD.org> | 2004-07-20 15:01:56 +0000 |
---|---|---|
committer | roberto <roberto@FreeBSD.org> | 2004-07-20 15:01:56 +0000 |
commit | 118e757284cbb8fc4f43a713e892b41504b50a5f (patch) | |
tree | 528d12dda44ebdc3ffcc38050f159ac553a69c17 /contrib/ntp/ntpdc | |
parent | a85d9ae25e8e8696677bc30feb6eaf7fc150e529 (diff) | |
download | FreeBSD-src-118e757284cbb8fc4f43a713e892b41504b50a5f.zip FreeBSD-src-118e757284cbb8fc4f43a713e892b41504b50a5f.tar.gz |
Virgin import of ntpd 4.2.0
Diffstat (limited to 'contrib/ntp/ntpdc')
-rw-r--r-- | contrib/ntp/ntpdc/Makefile.am | 40 | ||||
-rw-r--r-- | contrib/ntp/ntpdc/Makefile.in | 340 | ||||
-rw-r--r-- | contrib/ntp/ntpdc/layout.std | 417 | ||||
-rwxr-xr-x | contrib/ntp/ntpdc/nl.pl | 37 | ||||
-rw-r--r-- | contrib/ntp/ntpdc/nl.pl.in | 37 | ||||
-rw-r--r-- | contrib/ntp/ntpdc/nl_in.c | 3 | ||||
-rw-r--r-- | contrib/ntp/ntpdc/ntpdc-layout.c | 21 | ||||
-rw-r--r-- | contrib/ntp/ntpdc/ntpdc.c | 400 | ||||
-rw-r--r-- | contrib/ntp/ntpdc/ntpdc.h | 11 | ||||
-rw-r--r-- | contrib/ntp/ntpdc/ntpdc_ops.c | 972 |
10 files changed, 1820 insertions, 458 deletions
diff --git a/contrib/ntp/ntpdc/Makefile.am b/contrib/ntp/ntpdc/Makefile.am index ba0626f..f7a4d2a 100644 --- a/contrib/ntp/ntpdc/Makefile.am +++ b/contrib/ntp/ntpdc/Makefile.am @@ -1,21 +1,45 @@ #AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies AUTOMAKE_OPTIONS = ../util/ansi2knr -bin_PROGRAMS = ntpdc -INCLUDES = -I$(top_srcdir)/include +bin_PROGRAMS= ntpdc +EXTRA_PROGRAMS= ntpdc-layout +EXTRA_DATA= check-layout +BUILT_SOURCES= maybe-layout +INCLUDES= -I$(top_srcdir)/include # LDADD might need RESLIB and ADJLIB -LDADD = version.o ../libntp/libntp.a @LIBRSAREF@ -DISTCLEANFILES = .version version.c -noinst_HEADERS = ntpdc.h -#EXTRA_DIST = ntpdc.mak -ETAGS_ARGS = Makefile.am +ntpdc_LDADD= version.o ../libntp/libntp.a @READLINE_LIBS@ +# ntpdc-layout doesn't need any additional libraries at all +ntpdc_layout_LDADD= +DISTCLEANFILES= .version version.c +CLEANFILES= check-layout layout.here nl.c ntpdc-layout +noinst_HEADERS= ntpdc.h +EXTRA_DIST= nl_in.c nl.pl layout.std +ETAGS_ARGS= Makefile.am ntpdc_SOURCES = ntpdc.c ntpdc_ops.c +maybe-layout: + @case "${PATH_PERL}" in \ + /*) ${MAKE} check-layout ;; \ + esac + +ntpdc-layout.o: nl.c + +layout.here: ntpdc-layout + ./ntpdc-layout > $@ + +check-layout: ntpdc-layout layout.std layout.here + cmp $(srcdir)/layout.std layout.here && echo stamp > $@ + $(PROGRAMS): $(LDADD) ../libntp/libntp.a: cd ../libntp && $(MAKE) -version.o: $(ntpdc_OBJECTS) ../libntp/libntp.a @LIBRSAREF@ Makefile +version.o: $(ntpdc_OBJECTS) ../libntp/libntp.a Makefile $(top_srcdir)/version env CSET=`cat $(top_srcdir)/version` $(top_builddir)/scripts/mkver ntpdc $(COMPILE) -c version.c + +# I ran nl_in.c (attached, to be installed into ntpdc) through +# $(CC) -E nl_in.c | nl.pl > nl.c +nl.c: nl_in.c nl.pl + $(CC) -E $(DEFAULT_INCLUDES) $(INCLUDES) $(CPPFLAGS) $(srcdir)/nl_in.c | ./nl.pl > nl.c diff --git a/contrib/ntp/ntpdc/Makefile.in b/contrib/ntp/ntpdc/Makefile.in index 4c722e3..8ad0e05 100644 --- a/contrib/ntp/ntpdc/Makefile.in +++ b/contrib/ntp/ntpdc/Makefile.in @@ -1,6 +1,7 @@ -# Makefile.in generated automatically by automake 1.5 from Makefile.am. +# Makefile.in generated by automake 1.7.7 from Makefile.am. +# @configure_input@ -# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +# 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, @@ -13,82 +14,79 @@ @SET_MAKE@ -#AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies - -SHELL = @SHELL@ - srcdir = @srcdir@ top_srcdir = @top_srcdir@ VPATH = @srcdir@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ - -bindir = @bindir@ -sbindir = @sbindir@ -libexecdir = @libexecdir@ -datadir = @datadir@ -sysconfdir = @sysconfdir@ -sharedstatedir = @sharedstatedir@ -localstatedir = @localstatedir@ -libdir = @libdir@ -infodir = @infodir@ -mandir = @mandir@ -includedir = @includedir@ -oldincludedir = /usr/include pkgdatadir = $(datadir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ top_builddir = .. -ACLOCAL = @ACLOCAL@ -AUTOCONF = @AUTOCONF@ -AUTOMAKE = @AUTOMAKE@ -AUTOHEADER = @AUTOHEADER@ - +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ +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@ +transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : -build_alias = @build_alias@ build_triplet = @build@ -host_alias = @host_alias@ host_triplet = @host@ -target_alias = @target_alias@ target_triplet = @target@ +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ AMTAR = @AMTAR@ -AUTOKEY = @AUTOKEY@ +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@ -LIBRSAREF = @LIBRSAREF@ +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_LIBRSAREF = @MAKE_LIBRSAREF@ +MAKE_NTPDSIM = @MAKE_NTPDSIM@ MAKE_NTPTIME = @MAKE_NTPTIME@ -MAKE_NTP_GENKEYS = @MAKE_NTP_GENKEYS@ +MAKE_NTP_KEYGEN = @MAKE_NTP_KEYGEN@ MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@ +MAKE_SNTP = @MAKE_SNTP@ MAKE_TICKADJ = @MAKE_TICKADJ@ MAKE_TIMETRIM = @MAKE_TIMETRIM@ OBJEXT = @OBJEXT@ @@ -96,63 +94,119 @@ 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@ -RSADIR = @RSADIR@ -RSAOBJS = @RSAOBJS@ -RSAREF = @RSAREF@ -RSASRCS = @RSASRCS@ +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 = ../util/ansi2knr no-dependencies AUTOMAKE_OPTIONS = ../util/ansi2knr bin_PROGRAMS = ntpdc +EXTRA_PROGRAMS = ntpdc-layout +EXTRA_DATA = check-layout +BUILT_SOURCES = maybe-layout INCLUDES = -I$(top_srcdir)/include # LDADD might need RESLIB and ADJLIB -LDADD = version.o ../libntp/libntp.a @LIBRSAREF@ +ntpdc_LDADD = version.o ../libntp/libntp.a @READLINE_LIBS@ +# ntpdc-layout doesn't need any additional libraries at all +ntpdc_layout_LDADD = DISTCLEANFILES = .version version.c +CLEANFILES = check-layout layout.here nl.c ntpdc-layout noinst_HEADERS = ntpdc.h -#EXTRA_DIST = ntpdc.mak +EXTRA_DIST = nl_in.c nl.pl layout.std ETAGS_ARGS = Makefile.am ntpdc_SOURCES = ntpdc.c ntpdc_ops.c subdir = ntpdc +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = +CONFIG_CLEAN_FILES = nl.pl +EXTRA_PROGRAMS = ntpdc-layout$(EXEEXT) bin_PROGRAMS = ntpdc$(EXEEXT) PROGRAMS = $(bin_PROGRAMS) am_ntpdc_OBJECTS = ntpdc$U.$(OBJEXT) ntpdc_ops$U.$(OBJEXT) ntpdc_OBJECTS = $(am_ntpdc_OBJECTS) -ntpdc_LDADD = $(LDADD) ntpdc_DEPENDENCIES = version.o ../libntp/libntp.a ntpdc_LDFLAGS = +ntpdc_layout_SOURCES = ntpdc-layout.c +ntpdc_layout_OBJECTS = ntpdc-layout$U.$(OBJEXT) +ntpdc_layout_DEPENDENCIES = +ntpdc_layout_LDFLAGS = -DEFS = @DEFS@ DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) -CPPFLAGS = @CPPFLAGS@ -LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ depcomp = $(SHELL) $(top_srcdir)/depcomp -@AMDEP_TRUE@DEP_FILES = $(DEPDIR)/ntpdc$U.Po $(DEPDIR)/ntpdc_ops$U.Po +am__depfiles_maybe = depfiles +@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/ntpdc$U.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/ntpdc-layout$U.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/ntpdc_ops$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 = $(ntpdc_SOURCES) +DIST_SOURCES = $(ntpdc_SOURCES) ntpdc-layout.c HEADERS = $(noinst_HEADERS) -DIST_COMMON = README $(noinst_HEADERS) Makefile.am Makefile.in -SOURCES = $(ntpdc_SOURCES) +DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/Makefile.in \ + Makefile.am nl.pl.in +SOURCES = $(ntpdc_SOURCES) ntpdc-layout.c -all: all-am +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: .SUFFIXES: .c .o .obj @@ -160,9 +214,10 @@ $(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) cd $(top_srcdir) && \ $(AUTOMAKE) --gnu ntpdc/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) && \ - CONFIG_HEADERS= CONFIG_LINKS= \ - CONFIG_FILES=$(subdir)/$@ $(SHELL) ./config.status + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) +nl.pl: $(top_builddir)/config.status nl.pl.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) $(mkinstalldirs) $(DESTDIR)$(bindir) @@ -170,16 +225,16 @@ install-binPROGRAMS: $(bin_PROGRAMS) p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ if test -f $$p \ ; then \ - f=`echo $$p1|sed '$(transform);s/$$/$(EXEEXT)/'`; \ - echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/$$f"; \ - $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/$$f; \ + f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f"; \ + $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f || exit 1; \ else :; fi; \ done uninstall-binPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(bin_PROGRAMS)'; for p in $$list; do \ - f=`echo $$p|sed 's/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ + f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ echo " rm -f $(DESTDIR)$(bindir)/$$f"; \ rm -f $(DESTDIR)$(bindir)/$$f; \ done @@ -189,6 +244,9 @@ clean-binPROGRAMS: ntpdc$(EXEEXT): $(ntpdc_OBJECTS) $(ntpdc_DEPENDENCIES) @rm -f ntpdc$(EXEEXT) $(LINK) $(ntpdc_LDFLAGS) $(ntpdc_OBJECTS) $(ntpdc_LDADD) $(LIBS) +ntpdc-layout$(EXEEXT): $(ntpdc_layout_OBJECTS) $(ntpdc_layout_DEPENDENCIES) + @rm -f ntpdc-layout$(EXEEXT) + $(LINK) $(ntpdc_layout_LDFLAGS) $(ntpdc_layout_OBJECTS) $(ntpdc_layout_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) core *.core @@ -201,80 +259,122 @@ ANSI2KNR = ../util/ansi2knr cd ../util && $(MAKE) $(AM_MAKEFLAGS) ansi2knr mostlyclean-kr: - -rm -f *_.c - -@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/ntpdc$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/ntpdc_ops$U.Po@am__quote@ + -test "$U" = "" || rm -f *_.c -distclean-depend: - -rm -rf $(DEPDIR) +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpdc$U.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpdc-layout$U.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpdc_ops$U.Po@am__quote@ .c.o: -@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ -@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ - $(COMPILE) -c `test -f $< || echo '$(srcdir)/'`$< +@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: -@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ -@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ - $(COMPILE) -c `cygpath -w $<` -CCDEPMODE = @CCDEPMODE@ +@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` ntpdc_.c: ntpdc.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntpdc.c; then echo $(srcdir)/ntpdc.c; else echo ntpdc.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > ntpdc_.c || rm -f ntpdc_.c + $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntpdc.c; then echo $(srcdir)/ntpdc.c; else echo ntpdc.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ +ntpdc-layout_.c: ntpdc-layout.c $(ANSI2KNR) + $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntpdc-layout.c; then echo $(srcdir)/ntpdc-layout.c; else echo ntpdc-layout.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ ntpdc_ops_.c: ntpdc_ops.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntpdc_ops.c; then echo $(srcdir)/ntpdc_ops.c; else echo ntpdc_ops.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > ntpdc_ops_.c || rm -f ntpdc_ops_.c -ntpdc_.$(OBJEXT) ntpdc_ops_.$(OBJEXT) : $(ANSI2KNR) + $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntpdc_ops.c; then echo $(srcdir)/ntpdc_ops.c; else echo ntpdc_ops.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ +ntpdc_.$(OBJEXT) ntpdc-layout_.$(OBJEXT) ntpdc_ops_.$(OBJEXT) : \ +$(ANSI2KNR) uninstall-info-am: +ETAGS = etags +ETAGSFLAGS = + +CTAGS = ctags +CTAGSFLAGS = + tags: TAGS ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(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 $(LISP) + mkid -fID $$unique TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) tags=; \ here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(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; }'`; \ - test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ - || etags $(ETAGS_ARGS) $$tags $$unique $(LISP) + 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=`CDPATH=: && cd $(top_builddir) && pwd` \ + here=`$(am__cd) $(top_builddir) && pwd` \ && cd $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) $$here distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH - + -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) - @for file in $(DISTFILES); do \ - if test -f $$file; then d=.; else d=$(srcdir); fi; \ + @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 \ - $(mkinstalldirs) "$(distdir)/$$dir"; \ + dir="/$$dir"; \ + $(mkinstalldirs) "$(distdir)$$dir"; \ + else \ + dir=''; \ fi; \ if test -d $$d/$$file; then \ - cp -pR $$d/$$file $(distdir) \ - || exit 1; \ + 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 \ @@ -282,13 +382,14 @@ distdir: $(DISTFILES) fi; \ done check-am: all-am -check: check-am +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am all-am: Makefile $(PROGRAMS) $(HEADERS) installdirs: $(mkinstalldirs) $(DESTDIR)$(bindir) - -install: install-am +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am @@ -299,27 +400,32 @@ install-am: all-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: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: - -rm -f Makefile $(CONFIG_CLEAN_FILES) stamp-h stamp-h[0-9]* + -rm -f $(CONFIG_CLEAN_FILES) -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) clean: clean-am clean-am: clean-binPROGRAMS clean-generic mostlyclean-am distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-depend \ - distclean-generic distclean-tags +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags dvi: dvi-am @@ -340,6 +446,8 @@ install-man: installcheck-am: maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -347,28 +455,54 @@ mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic mostlyclean-kr +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + uninstall-am: uninstall-binPROGRAMS uninstall-info-am -.PHONY: GTAGS all all-am check check-am clean clean-binPROGRAMS \ - clean-generic distclean distclean-compile distclean-depend \ +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ + clean-generic ctags distclean distclean-compile \ distclean-generic distclean-tags distdir dvi dvi-am info \ info-am install install-am install-binPROGRAMS install-data \ install-data-am install-exec install-exec-am install-info \ install-info-am install-man install-strip installcheck \ installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-kr tags uninstall uninstall-am \ - uninstall-binPROGRAMS uninstall-info-am + mostlyclean-generic mostlyclean-kr pdf pdf-am ps ps-am tags \ + uninstall uninstall-am uninstall-binPROGRAMS uninstall-info-am +maybe-layout: + @case "${PATH_PERL}" in \ + /*) ${MAKE} check-layout ;; \ + esac + +ntpdc-layout.o: nl.c + +layout.here: ntpdc-layout + ./ntpdc-layout > $@ + +check-layout: ntpdc-layout layout.std layout.here + cmp $(srcdir)/layout.std layout.here && echo stamp > $@ + $(PROGRAMS): $(LDADD) ../libntp/libntp.a: cd ../libntp && $(MAKE) -version.o: $(ntpdc_OBJECTS) ../libntp/libntp.a @LIBRSAREF@ Makefile +version.o: $(ntpdc_OBJECTS) ../libntp/libntp.a Makefile $(top_srcdir)/version env CSET=`cat $(top_srcdir)/version` $(top_builddir)/scripts/mkver ntpdc $(COMPILE) -c version.c + +# I ran nl_in.c (attached, to be installed into ntpdc) through +# $(CC) -E nl_in.c | nl.pl > nl.c +nl.c: nl_in.c nl.pl + $(CC) -E $(DEFAULT_INCLUDES) $(INCLUDES) $(CPPFLAGS) $(srcdir)/nl_in.c | ./nl.pl > nl.c # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/contrib/ntp/ntpdc/layout.std b/contrib/ntp/ntpdc/layout.std new file mode 100644 index 0000000..0a67b73 --- /dev/null +++ b/contrib/ntp/ntpdc/layout.std @@ -0,0 +1,417 @@ +sizeof(struct req_pkt) = 212 +offsetof(rm_vn_mode) = 0 +offsetof(auth_seq) = 1 +offsetof(implementation) = 2 +offsetof(request) = 3 +offsetof(err_nitems) = 4 +offsetof(mbz_itemsize) = 6 +offsetof(data) = 8 +offsetof(tstamp) = 184 +offsetof(keyid) = 192 +offsetof(mac) = 196 + +sizeof(struct req_pkt_tail) = 28 +offsetof(tstamp) = 0 +offsetof(keyid) = 8 +offsetof(mac) = 12 + +sizeof(struct resp_pkt) = 508 +offsetof(rm_vn_mode) = 0 +offsetof(auth_seq) = 1 +offsetof(implementation) = 2 +offsetof(request) = 3 +offsetof(err_nitems) = 4 +offsetof(mbz_itemsize) = 6 +offsetof(data) = 8 + +sizeof(struct info_peer_list) = 32 +offsetof(addr) = 0 +offsetof(port) = 4 +offsetof(hmode) = 6 +offsetof(flags) = 7 +offsetof(v6_flag) = 8 +offsetof(unused1) = 12 +offsetof(addr6) = 16 + +sizeof(struct info_peer_summary) = 72 +offsetof(dstadr) = 0 +offsetof(srcadr) = 4 +offsetof(srcport) = 8 +offsetof(stratum) = 10 +offsetof(hpoll) = 11 +offsetof(ppoll) = 12 +offsetof(reach) = 13 +offsetof(flags) = 14 +offsetof(hmode) = 15 +offsetof(delay) = 16 +offsetof(offset) = 20 +offsetof(dispersion) = 28 +offsetof(v6_flag) = 32 +offsetof(unused1) = 36 +offsetof(dstadr6) = 40 +offsetof(srcadr6) = 56 + +sizeof(struct info_peer) = 280 +offsetof(dstadr) = 0 +offsetof(srcadr) = 4 +offsetof(srcport) = 8 +offsetof(flags) = 10 +offsetof(leap) = 11 +offsetof(hmode) = 12 +offsetof(pmode) = 13 +offsetof(stratum) = 14 +offsetof(ppoll) = 15 +offsetof(hpoll) = 16 +offsetof(precision) = 17 +offsetof(version) = 18 +offsetof(unused8) = 19 +offsetof(reach) = 20 +offsetof(unreach) = 21 +offsetof(flash) = 22 +offsetof(ttl) = 23 +offsetof(flash2) = 24 +offsetof(associd) = 26 +offsetof(keyid) = 28 +offsetof(pkeyid) = 32 +offsetof(refid) = 36 +offsetof(timer) = 40 +offsetof(rootdelay) = 44 +offsetof(rootdispersion) = 48 +offsetof(reftime) = 52 +offsetof(org) = 60 +offsetof(rec) = 68 +offsetof(xmt) = 76 +offsetof(filtdelay) = 84 +offsetof(filtoffset) = 116 +offsetof(order) = 180 +offsetof(delay) = 188 +offsetof(dispersion) = 192 +offsetof(offset) = 196 +offsetof(selectdisp) = 204 +offsetof(unused1) = 208 +offsetof(unused2) = 212 +offsetof(unused3) = 216 +offsetof(unused4) = 220 +offsetof(unused5) = 224 +offsetof(unused6) = 228 +offsetof(unused7) = 232 +offsetof(estbdelay) = 236 +offsetof(v6_flag) = 240 +offsetof(unused9) = 244 +offsetof(dstadr6) = 248 +offsetof(srcadr6) = 264 + +sizeof(struct info_peer_stats) = 120 +offsetof(dstadr) = 0 +offsetof(srcadr) = 4 +offsetof(srcport) = 8 +offsetof(flags) = 10 +offsetof(timereset) = 12 +offsetof(timereceived) = 16 +offsetof(timetosend) = 20 +offsetof(timereachable) = 24 +offsetof(sent) = 28 +offsetof(unused1) = 32 +offsetof(processed) = 36 +offsetof(unused2) = 40 +offsetof(badauth) = 44 +offsetof(bogusorg) = 48 +offsetof(oldpkt) = 52 +offsetof(unused3) = 56 +offsetof(unused4) = 60 +offsetof(seldisp) = 64 +offsetof(selbroken) = 68 +offsetof(unused5) = 72 +offsetof(candidate) = 76 +offsetof(unused6) = 77 +offsetof(unused7) = 78 +offsetof(unused8) = 79 +offsetof(v6_flag) = 80 +offsetof(unused9) = 84 +offsetof(dstadr6) = 88 +offsetof(srcadr6) = 104 + +sizeof(struct info_loop) = 24 +offsetof(last_offset) = 0 +offsetof(drift_comp) = 8 +offsetof(compliance) = 16 +offsetof(watchdog_timer) = 20 + +sizeof(struct info_sys) = 80 +offsetof(peer) = 0 +offsetof(peer_mode) = 4 +offsetof(leap) = 5 +offsetof(stratum) = 6 +offsetof(precision) = 7 +offsetof(rootdelay) = 8 +offsetof(rootdispersion) = 12 +offsetof(refid) = 16 +offsetof(reftime) = 20 +offsetof(poll) = 28 +offsetof(flags) = 32 +offsetof(unused1) = 33 +offsetof(unused2) = 34 +offsetof(unused3) = 35 +offsetof(bdelay) = 36 +offsetof(frequency) = 40 +offsetof(authdelay) = 44 +offsetof(stability) = 52 +offsetof(v6_flag) = 56 +offsetof(unused4) = 60 +offsetof(peer6) = 64 + +sizeof(struct info_sys_stats) = 44 +offsetof(timeup) = 0 +offsetof(timereset) = 4 +offsetof(denied) = 8 +offsetof(oldversionpkt) = 12 +offsetof(newversionpkt) = 16 +offsetof(unknownversion) = 20 +offsetof(badlength) = 24 +offsetof(processed) = 28 +offsetof(badauth) = 32 +offsetof(received) = 36 +offsetof(limitrejected) = 40 + +sizeof(struct old_info_sys_stats) = 40 +offsetof(timeup) = 0 +offsetof(timereset) = 4 +offsetof(denied) = 8 +offsetof(oldversionpkt) = 12 +offsetof(newversionpkt) = 16 +offsetof(unknownversion) = 20 +offsetof(badlength) = 24 +offsetof(processed) = 28 +offsetof(badauth) = 32 +offsetof(wanderhold) = 36 + +sizeof(struct info_mem_stats) = 148 +offsetof(timereset) = 0 +offsetof(totalpeermem) = 4 +offsetof(freepeermem) = 6 +offsetof(findpeer_calls) = 8 +offsetof(allocations) = 12 +offsetof(demobilizations) = 16 +offsetof(hashcount) = 20 + +sizeof(struct info_io_stats) = 40 +offsetof(timereset) = 0 +offsetof(totalrecvbufs) = 4 +offsetof(freerecvbufs) = 6 +offsetof(fullrecvbufs) = 8 +offsetof(lowwater) = 10 +offsetof(dropped) = 12 +offsetof(ignored) = 16 +offsetof(received) = 20 +offsetof(sent) = 24 +offsetof(notsent) = 28 +offsetof(interrupts) = 32 +offsetof(int_received) = 36 + +sizeof(struct info_timer_stats) = 16 +offsetof(timereset) = 0 +offsetof(alarms) = 4 +offsetof(overflows) = 8 +offsetof(xmtcalls) = 12 + +sizeof(struct old_conf_peer) = 16 +offsetof(peeraddr) = 0 +offsetof(hmode) = 4 +offsetof(version) = 5 +offsetof(minpoll) = 6 +offsetof(maxpoll) = 7 +offsetof(flags) = 8 +offsetof(ttl) = 9 +offsetof(unused) = 10 +offsetof(keyid) = 12 + +sizeof(struct conf_peer) = 168 +offsetof(peeraddr) = 0 +offsetof(hmode) = 4 +offsetof(version) = 5 +offsetof(minpoll) = 6 +offsetof(maxpoll) = 7 +offsetof(flags) = 8 +offsetof(ttl) = 9 +offsetof(unused1) = 10 +offsetof(keyid) = 12 +offsetof(keystr) = 16 +offsetof(v6_flag) = 144 +offsetof(unused2) = 148 +offsetof(peeraddr6) = 152 + +sizeof(struct conf_unpeer) = 24 +offsetof(peeraddr) = 0 +offsetof(v6_flag) = 4 +offsetof(peeraddr6) = 8 + +sizeof(struct conf_sys_flags) = 4 +offsetof(flags) = 0 + +sizeof(struct info_restrict) = 56 +offsetof(addr) = 0 +offsetof(mask) = 4 +offsetof(count) = 8 +offsetof(flags) = 12 +offsetof(mflags) = 14 +offsetof(v6_flag) = 16 +offsetof(unused1) = 20 +offsetof(addr6) = 24 +offsetof(mask6) = 40 + +sizeof(struct conf_restrict) = 48 +offsetof(addr) = 0 +offsetof(mask) = 4 +offsetof(flags) = 8 +offsetof(mflags) = 10 +offsetof(v6_flag) = 12 +offsetof(addr6) = 16 +offsetof(mask6) = 32 + +sizeof(struct info_monitor_1) = 72 +offsetof(lasttime) = 0 +offsetof(firsttime) = 4 +offsetof(lastdrop) = 8 +offsetof(count) = 12 +offsetof(addr) = 16 +offsetof(daddr) = 20 +offsetof(flags) = 24 +offsetof(port) = 28 +offsetof(mode) = 30 +offsetof(version) = 31 +offsetof(v6_flag) = 32 +offsetof(unused1) = 36 +offsetof(addr6) = 40 +offsetof(daddr6) = 56 + +sizeof(struct info_monitor) = 48 +offsetof(lasttime) = 0 +offsetof(firsttime) = 4 +offsetof(lastdrop) = 8 +offsetof(count) = 12 +offsetof(addr) = 16 +offsetof(port) = 20 +offsetof(mode) = 22 +offsetof(version) = 23 +offsetof(v6_flag) = 24 +offsetof(unused1) = 28 +offsetof(addr6) = 32 + +sizeof(struct old_info_monitor) = 40 +offsetof(lasttime) = 0 +offsetof(firsttime) = 4 +offsetof(count) = 8 +offsetof(addr) = 12 +offsetof(port) = 16 +offsetof(mode) = 18 +offsetof(version) = 19 +offsetof(v6_flag) = 20 +offsetof(addr6) = 24 + +sizeof(struct reset_flags) = 4 +offsetof(flags) = 0 + +sizeof(struct info_auth) = 36 +offsetof(timereset) = 0 +offsetof(numkeys) = 4 +offsetof(numfreekeys) = 8 +offsetof(keylookups) = 12 +offsetof(keynotfound) = 16 +offsetof(encryptions) = 20 +offsetof(decryptions) = 24 +offsetof(expired) = 28 +offsetof(keyuncached) = 32 + +sizeof(struct info_trap) = 64 +offsetof(local_address) = 0 +offsetof(trap_address) = 4 +offsetof(trap_port) = 8 +offsetof(sequence) = 10 +offsetof(settime) = 12 +offsetof(origtime) = 16 +offsetof(resets) = 20 +offsetof(flags) = 24 +offsetof(v6_flag) = 28 +offsetof(local_address6) = 32 +offsetof(trap_address6) = 48 + +sizeof(struct conf_trap) = 48 +offsetof(local_address) = 0 +offsetof(trap_address) = 4 +offsetof(trap_port) = 8 +offsetof(unused) = 10 +offsetof(v6_flag) = 12 +offsetof(local_address6) = 16 +offsetof(trap_address6) = 32 + +sizeof(struct info_control) = 60 +offsetof(ctltimereset) = 0 +offsetof(numctlreq) = 4 +offsetof(numctlbadpkts) = 8 +offsetof(numctlresponses) = 12 +offsetof(numctlfrags) = 16 +offsetof(numctlerrors) = 20 +offsetof(numctltooshort) = 24 +offsetof(numctlinputresp) = 28 +offsetof(numctlinputfrag) = 32 +offsetof(numctlinputerr) = 36 +offsetof(numctlbadoffset) = 40 +offsetof(numctlbadversion) = 44 +offsetof(numctldatatooshort) = 48 +offsetof(numctlbadop) = 52 +offsetof(numasyncmsgs) = 56 + +sizeof(struct info_clock) = 52 +offsetof(clockadr) = 0 +offsetof(type) = 4 +offsetof(flags) = 5 +offsetof(lastevent) = 6 +offsetof(currentstatus) = 7 +offsetof(polls) = 8 +offsetof(noresponse) = 12 +offsetof(badformat) = 16 +offsetof(baddata) = 20 +offsetof(timestarted) = 24 +offsetof(fudgetime1) = 28 +offsetof(fudgetime2) = 36 +offsetof(fudgeval1) = 44 +offsetof(fudgeval2) = 48 + +sizeof(struct conf_fudge) = 20 +offsetof(clockadr) = 0 +offsetof(which) = 4 +offsetof(fudgetime) = 8 +offsetof(fudgeval_flags) = 16 + +sizeof(struct info_clkbug) = 332 +offsetof(clockadr) = 0 +offsetof(nvalues) = 4 +offsetof(ntimes) = 5 +offsetof(svalues) = 6 +offsetof(stimes) = 8 +offsetof(values) = 12 +offsetof(times) = 76 + +sizeof(struct info_kernel) = 60 +offsetof(offset) = 0 +offsetof(freq) = 4 +offsetof(maxerror) = 8 +offsetof(esterror) = 12 +offsetof(status) = 16 +offsetof(shift) = 18 +offsetof(constant) = 20 +offsetof(precision) = 24 +offsetof(tolerance) = 28 +offsetof(ppsfreq) = 32 +offsetof(jitter) = 36 +offsetof(stabil) = 40 +offsetof(jitcnt) = 44 +offsetof(calcnt) = 48 +offsetof(errcnt) = 52 +offsetof(stbcnt) = 56 + +sizeof(struct info_dns_assoc) = 32 +offsetof(peeraddr) = 0 +offsetof(associd) = 4 +offsetof(hostname) = 6 + diff --git a/contrib/ntp/ntpdc/nl.pl b/contrib/ntp/ntpdc/nl.pl new file mode 100755 index 0000000..6974fe2 --- /dev/null +++ b/contrib/ntp/ntpdc/nl.pl @@ -0,0 +1,37 @@ +#! /usr/local/bin/perl -w + +$found = 0; +$last = 0; +$debug = 0; + +while (<>) { + next if /^#/; + next if /^\s*$/; + if (/^struct req_pkt/) { + $found = 1; + } + if (/^struct info_dns_assoc/) { + $last = 1; + } + if ($found) { + if (/^(struct\s*\w*)\s*{\s*$/) { + $type = $1; + print STDERR "type = '$type'\n" if $debug; + printf " printf(\"sizeof($type) = %%d\\n\", \n\t (int) sizeof($type));\n"; + next; + } + if (/\s*\w+\s*(\w*)(\[.*\])?\s*;\s*$/) { + $field = $1; + print STDERR "\tfield = '$field'\n" if $debug; + printf " printf(\"offsetof($field) = %%d\\n\", \n\t (int) offsetof($type, $field));\n"; + next; + } + if (/^};$/) { + printf " printf(\"\\n\");\n\n"; + $found = 0 if $last; + next; + } + print STDERR "Unmatched line: $_"; + exit 1; + } +} diff --git a/contrib/ntp/ntpdc/nl.pl.in b/contrib/ntp/ntpdc/nl.pl.in new file mode 100644 index 0000000..dfa79c2 --- /dev/null +++ b/contrib/ntp/ntpdc/nl.pl.in @@ -0,0 +1,37 @@ +#! @PATH_PERL@ -w + +$found = 0; +$last = 0; +$debug = 0; + +while (<>) { + next if /^#/; + next if /^\s*$/; + if (/^struct req_pkt/) { + $found = 1; + } + if (/^struct info_dns_assoc/) { + $last = 1; + } + if ($found) { + if (/^(struct\s*\w*)\s*{\s*$/) { + $type = $1; + print STDERR "type = '$type'\n" if $debug; + printf " printf(\"sizeof($type) = %%d\\n\", \n\t (int) sizeof($type));\n"; + next; + } + if (/\s*\w+\s*(\w*)(\[.*\])?\s*;\s*$/) { + $field = $1; + print STDERR "\tfield = '$field'\n" if $debug; + printf " printf(\"offsetof($field) = %%d\\n\", \n\t (int) offsetof($type, $field));\n"; + next; + } + if (/^};$/) { + printf " printf(\"\\n\");\n\n"; + $found = 0 if $last; + next; + } + print STDERR "Unmatched line: $_"; + exit 1; + } +} diff --git a/contrib/ntp/ntpdc/nl_in.c b/contrib/ntp/ntpdc/nl_in.c new file mode 100644 index 0000000..3df8c78 --- /dev/null +++ b/contrib/ntp/ntpdc/nl_in.c @@ -0,0 +1,3 @@ +#include <config.h> +#include "ntpdc.h" +#include "ntp_request.h" diff --git a/contrib/ntp/ntpdc/ntpdc-layout.c b/contrib/ntp/ntpdc/ntpdc-layout.c new file mode 100644 index 0000000..b05fbf3 --- /dev/null +++ b/contrib/ntp/ntpdc/ntpdc-layout.c @@ -0,0 +1,21 @@ +/* + * ntpdc-layout - print layout of NTP mode 7 request/response packets + */ + +#include <stdio.h> +#include <stddef.h> + +#include "ntpdc.h" +#include "ntp_stdlib.h" + +#if defined(IMPL_XNTPD_OLD) && IMPL_XNTPD != 3 +#error Unexpected IMPL_XNTPD +#endif + +int +main(void) +{ +#include "nl.c" + + return (EXIT_SUCCESS); +} diff --git a/contrib/ntp/ntpdc/ntpdc.c b/contrib/ntp/ntpdc/ntpdc.c index 6086dae..aa4f188 100644 --- a/contrib/ntp/ntpdc/ntpdc.c +++ b/contrib/ntp/ntpdc/ntpdc.c @@ -8,6 +8,10 @@ #include "ntp_select.h" #include "ntp_io.h" #include "ntp_stdlib.h" +/* Don't include ISC's version of IPv6 variables and structures */ +#define ISC_IPV6_H 1 +#include "isc/net.h" +#include "isc/result.h" #include <ctype.h> #include <signal.h> @@ -20,10 +24,10 @@ # define closesocket close #endif /* SYS_WINNT */ -#ifdef HAVE_LIBREADLINE +#if defined(HAVE_LIBREADLINE) || defined (HAVE_LIBEDIT) # include <readline/readline.h> # include <readline/history.h> -#endif /* HAVE_LIBREADLINE */ +#endif /* HAVE_LIBREADLINE || HAVE_LIBEDIT */ #ifdef SYS_VXWORKS /* vxWorks needs mode flag -casey*/ @@ -45,12 +49,11 @@ static const char * prompt = "ntpdc> "; /* prompt to ask him about */ static u_long info_auth_keyid; /* - * Type of key md5 or des + * Type of key md5 */ -#define KEY_TYPE_DES 3 #define KEY_TYPE_MD5 4 -static int info_auth_keytype = KEY_TYPE_MD5; /* MD5*/ +static int info_auth_keytype = KEY_TYPE_MD5; /* MD5 */ u_long current_time; /* needed by authkeys; not used */ int ntpdcmain P((int, char **)); @@ -60,7 +63,7 @@ int ntpdcmain P((int, char **)); static int openhost P((const char *)); static int sendpkt P((char *, int)); static void growpktdata P((void)); -static int getresponse P((int, int, int *, int *, char **)); +static int getresponse P((int, int, int *, int *, char **, int)); static int sendrequest P((int, int, int, int, int, char *)); static void getcmds P((void)); static RETSIGTYPE abortcmd P((int)); @@ -68,7 +71,7 @@ static void docmd P((const char *)); static void tokenize P((const char *, char **, int *)); static int findcmd P((char *, struct xcmd *, struct xcmd *, struct xcmd **)); static int getarg P((char *, int, arg_v *)); -static int getnetnum P((const char *, u_int32 *, char *)); +static int getnetnum P((const char *, struct sockaddr_storage *, char *, int)); static void help P((struct parse *, FILE *)); #ifdef QSORT_USES_VOID_P static int helpsort P((const void *, const void *)); @@ -108,8 +111,8 @@ static struct xcmd builtins[] = { { "delay", my_delay, { OPT|INT, NO, NO, NO }, { "msec", "", "", "" }, "set the delay added to encryption time stamps" }, - { "host", host, { OPT|NTP_STR, NO, NO, NO }, - { "hostname", "", "", "" }, + { "host", host, { OPT|NTP_STR, OPT|NTP_STR, NO, NO }, + { "-4|-6", "hostname", "", "" }, "specify the host whose NTP server we talk to" }, { "passwd", passwd, { OPT|NTP_STR, NO, NO, NO }, { "", "", "", "" }, @@ -151,7 +154,9 @@ static struct xcmd builtins[] = { #define MAXCMDS 100 /* maximum commands on cmd line */ #define MAXHOSTS 200 /* maximum hosts on cmd line */ #define MAXLINE 512 /* maximum line length */ -#define MAXTOKENS (1+MAXARGS+2) /* maximum number of usable tokens */ +#define MAXTOKENS (1+1+MAXARGS+2) /* maximum number of usable tokens */ + /* command + -4|-6 + MAXARGS + */ + /* redirection */ /* * Some variables used and manipulated locally @@ -160,20 +165,19 @@ static struct timeval tvout = { DEFTIMEOUT, 0 }; /* time out for reads */ static struct timeval tvsout = { DEFSTIMEOUT, 0 }; /* secondary time out */ static l_fp delay_time; /* delay time */ static char currenthost[LENHOSTNAME]; /* current host name */ -static struct sockaddr_in hostaddr = { 0 }; /* host address */ -static int showhostnames = 1; /* show host names by default */ +int showhostnames = 1; /* show host names by default */ -static int sockfd; /* fd socket is openned on */ +static int ai_fam_templ; /* address family */ +static int ai_fam_default; /* default address family */ +static SOCKET sockfd; /* fd socket is opened on */ static int havehost = 0; /* set to 1 when host open */ -struct servent *server_entry = NULL; /* server entry for ntp */ +int s_port = 0; #if defined (SYS_WINNT) || defined (SYS_VXWORKS) char password[9]; #endif /* SYS_WINNT || SYS_VXWORKS */ #ifdef SYS_WINNT -WORD wVersionRequested; -WSADATA wsaData; DWORD NumberOfBytesWritten; HANDLE TimerThreadHandle = NULL; /* 1998/06/03 - Used in ntplib/machines.c */ @@ -194,6 +198,7 @@ static int pktdatasize; /* * These are used to help the magic with old and new versions of ntpd. */ +int impl_ver = IMPL_XNTPD; static int req_pkt_size = REQ_LEN_NOMAC; /* @@ -268,7 +273,6 @@ void clear_globals(void) showhostnames = 0; /* show host names by default */ ntp_optind = 0; ntp_optarg = 0; - server_entry = NULL; /* server entry for ntp */ havehost = 0; /* set to 1 when host open */ numcmds = 0; numhosts = 0; @@ -297,9 +301,29 @@ ntpdcmain( taskPrioritySet(taskIdSelf(), 100 ); #endif +#ifdef SYS_WINNT + if (!Win32InitSockets()) + { + fprintf(stderr, "No useable winsock.dll:"); + exit(1); + } +#endif /* SYS_WINNT */ + + /* Check to see if we have IPv6. Otherwise force the -4 flag */ + if (isc_net_probeipv6() != ISC_R_SUCCESS) { + ai_fam_default = AF_INET; + } + progname = argv[0]; - while ((c = ntp_getopt(argc, argv, "c:dilnps")) != EOF) + ai_fam_templ = ai_fam_default; + while ((c = ntp_getopt(argc, argv, "46c:dilnps")) != EOF) switch (c) { + case '4': + ai_fam_templ = AF_INET; + break; + case '6': + ai_fam_templ = AF_INET6; + break; case 'c': ADDCMD(ntp_optarg); break; @@ -327,7 +351,7 @@ ntpdcmain( } if (errflg) { (void) fprintf(stderr, - "usage: %s [-dilnps] [-c cmd] host ...\n", + "usage: %s [-46dilnps] [-c cmd] host ...\n", progname); exit(2); } @@ -358,14 +382,6 @@ ntpdcmain( } pktdatasize = INITDATASIZE; -#ifdef SYS_WINNT - wVersionRequested = MAKEWORD(1,1); - if (WSAStartup(wVersionRequested, &wsaData)) { - fprintf(stderr, "No useable winsock.dll"); - exit(1); - } -#endif /* SYS_WINNT */ - if (numcmds == 0) { (void) openhost(chosts[0]); getcmds(); @@ -397,29 +413,68 @@ openhost( const char *hname ) { - u_int32 netnum; char temphost[LENHOSTNAME]; + int a_info, i; + struct addrinfo hints, *ai = NULL; + register const char *cp; + char name[LENHOSTNAME]; + char service[5]; - if (server_entry == NULL) { - server_entry = getservbyname("ntp", "udp"); - if (server_entry == NULL) { -#ifdef VMS /* UCX getservbyname() doesn't work [yet], but we do know better */ - server_entry = (struct servent *) - malloc(sizeof(struct servent)); - server_entry->s_port = htons(NTP_PORT); -#else - (void) fprintf(stderr, "%s: ntp/udp: unknown service\n", - progname); - exit(1); -#endif /* VMS & UCX */ - } - if (debug > 2) - printf("Got ntp/udp service entry\n"); + /* + * We need to get by the [] if they were entered + */ + + cp = hname; + + if (*cp == '[') { + cp++; + for(i = 0; *cp != ']'; cp++, i++) + name[i] = *cp; + name[i] = '\0'; + hname = name; + } + + /* + * First try to resolve it as an ip address and if that fails, + * do a fullblown (dns) lookup. That way we only use the dns + * when it is needed and work around some implementations that + * will return an "IPv4-mapped IPv6 address" address if you + * give it an IPv4 address to lookup. + */ + strcpy(service, "ntp"); + memset((char *)&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = ai_fam_templ; + hints.ai_protocol = IPPROTO_UDP; + hints.ai_socktype = SOCK_DGRAM; + hints.ai_flags = AI_NUMERICHOST; + + a_info = getaddrinfo(hname, service, &hints, &ai); + if (a_info == EAI_NONAME || a_info == EAI_NODATA) { + hints.ai_flags = AI_CANONNAME; +#ifdef AI_ADDRCONFIG + hints.ai_flags |= AI_ADDRCONFIG; +#endif + a_info = getaddrinfo(hname, service, &hints, &ai); + } + /* Some older implementations don't like AI_ADDRCONFIG. */ + if (a_info == EAI_BADFLAGS) { + hints.ai_flags = AI_CANONNAME; + a_info = getaddrinfo(hname, service, &hints, &ai); + } + if (a_info != 0) { + (void) fprintf(stderr, "%s\n", gai_strerror(a_info)); + return 0; + } + + if (ai->ai_canonname == NULL) { + strncpy(temphost, stoa((struct sockaddr_storage *)ai->ai_addr), + LENHOSTNAME); + temphost[LENHOSTNAME-1] = '\0'; + } else { + strncpy(temphost, ai->ai_canonname, LENHOSTNAME); + temphost[LENHOSTNAME-1] = '\0'; } - if (!getnetnum(hname, &netnum, temphost)) - return 0; - if (debug > 2) printf("Opening host %s\n", temphost); @@ -430,14 +485,18 @@ openhost( havehost = 0; } (void) strcpy(currenthost, temphost); - - hostaddr.sin_family = AF_INET; -#ifndef SYS_VXWORKS - hostaddr.sin_port = server_entry->s_port; -#else - hostaddr.sin_port = htons(SERVER_PORT_NUM); -#endif - hostaddr.sin_addr.s_addr = netnum; + + /* port maps to the same in both families */ + s_port = ((struct sockaddr_in6 *)ai->ai_addr)->sin6_port; +#ifdef SYS_VXWORKS + ((struct sockaddr_in6 *)&hostaddr)->sin6_port = htons(SERVER_PORT_NUM); + if (ai->ai_family == AF_INET) + *(struct sockaddr_in *)&hostaddr= + *((struct sockaddr_in *)ai->ai_addr); + else + *(struct sockaddr_in6 *)&hostaddr= + *((struct sockaddr_in6 *)ai->ai_addr); +#endif /* SYS_VXWORKS */ #ifdef SYS_WINNT { @@ -449,14 +508,14 @@ openhost( exit(1); } } - - sockfd = socket(AF_INET, SOCK_DGRAM, 0); + + sockfd = socket(ai->ai_family, SOCK_DGRAM, 0); if (sockfd == INVALID_SOCKET) { error("socket", "", ""); exit(-1); } #else - sockfd = socket(AF_INET, SOCK_DGRAM, 0); + sockfd = socket(ai->ai_family, SOCK_DGRAM, 0); if (sockfd == -1) error("socket", "", ""); #endif /* SYS_WINNT */ @@ -474,12 +533,19 @@ openhost( # endif #endif - if (connect(sockfd, (struct sockaddr *)&hostaddr, +#ifdef SYS_VXWORKS + if (connect(sockfd, (struct sockaddr *)&hostaddr, sizeof(hostaddr)) == -1) +#else + if (connect(sockfd, (struct sockaddr *)ai->ai_addr, + ai->ai_addrlen) == -1) +#endif /* SYS_VXWORKS */ error("connect", "", ""); - + if (a_info) + freeaddrinfo(ai); havehost = 1; req_pkt_size = REQ_LEN_NOMAC; + impl_ver = IMPL_XNTPD; return 1; } @@ -527,15 +593,18 @@ getresponse( int reqcode, int *ritems, int *rsize, - char **rdata + char **rdata, + int esize ) { struct resp_pkt rpkt; struct timeval tvo; int items; + int i; int size; int datasize; char *datap; + char *tmp_data; char haveseq[MAXSEQ+1]; int firstpkt; int lastseq; @@ -543,6 +612,7 @@ getresponse( int seq; fd_set fds; int n; + int pad; /* * This is pretty tricky. We may get between 1 and many packets @@ -666,13 +736,15 @@ getresponse( return (int)INFO_ERR(rpkt.err_nitems); } - /* * Collect items and size. Make sure they make sense. */ items = INFO_NITEMS(rpkt.err_nitems); size = INFO_ITEMSIZE(rpkt.mbz_itemsize); - + if (esize > size) + pad = esize - size; + else + pad = 0; if ((datasize = items*size) > (n-RESP_HEADER_SIZE)) { if (debug) printf( @@ -685,15 +757,14 @@ getresponse( * If this isn't our first packet, make sure the size matches * the other ones. */ - if (!firstpkt && size != *rsize) { + if (!firstpkt && esize != *rsize) { if (debug) printf("Received itemsize %d, previous %d\n", size, *rsize); goto again; } - /* - * If we've received this before, toss it + * If we've received this before, +toss it */ seq = INFO_SEQ(rpkt.auth_seq); if (haveseq[seq]) { @@ -717,17 +788,28 @@ getresponse( /* * So far, so good. Copy this data into the output array. */ - if ((datap + datasize) > (pktdata + pktdatasize)) { + if ((datap + datasize + (pad * items)) > (pktdata + pktdatasize)) { int offset = datap - pktdata; growpktdata(); *rdata = pktdata; /* might have been realloced ! */ datap = pktdata + offset; } - memmove(datap, (char *)rpkt.data, (unsigned)datasize); - datap += datasize; + /* + * We now move the pointer along according to size and number of + * items. This is so we can play nice with older implementations + */ + + tmp_data = (char *)rpkt.data; + for(i = 0; i <items; i++){ + memmove(datap, tmp_data, (unsigned)size); + tmp_data += size; + memset(datap + size, 0, pad); + datap += size + pad; + } + if (firstpkt) { firstpkt = 0; - *rsize = size; + *rsize = size + pad; } *ritems += items; @@ -796,8 +878,7 @@ sendrequest( info_auth_keyid = maclen; } if (!authistrusted(info_auth_keyid)) { - pass = getpass((info_auth_keytype == KEY_TYPE_DES) - ? "DES Password: " : "MD5 Password: "); + pass = getpass("MD5 Password: "); if (*pass == '\0') { (void) fprintf(stderr, "Invalid password\n"); @@ -837,7 +918,8 @@ doquery( int *ritems, int *rsize, char **rdata, - int quiet_mask + int quiet_mask, + int esize ) { int res; @@ -882,7 +964,7 @@ again: /* * Get the response. If we got a standard error, print a message */ - res = getresponse(implcode, reqcode, ritems, rsize, rdata); + res = getresponse(implcode, reqcode, ritems, rsize, rdata, esize); /* * Try to be compatible with older implementations of ntpd. @@ -894,9 +976,17 @@ again: switch(req_pkt_size) { case REQ_LEN_NOMAC: + req_pkt_size = 160; + break; + case 160: req_pkt_size = 48; break; } + if (impl_ver == IMPL_XNTPD) { + fprintf(stderr, + "***Warning changing to older implementation\n"); + return INFO_ERR_IMPL; + } fprintf(stderr, "***Warning changing the request packet size from %d to %d\n", @@ -908,6 +998,9 @@ again: if ((res > 0) && (((1 << res) & quiet_mask) == 0)) { switch(res) { case INFO_ERR_IMPL: + /* Give us a chance to try the older implementation. */ + if (implcode == IMPL_XNTPD) + break; (void) fprintf(stderr, "***Server implementation incompatable with our own\n"); break; @@ -949,7 +1042,7 @@ again: static void getcmds(void) { -#ifdef HAVE_LIBREADLINE +#if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT) char *line; for (;;) { @@ -958,7 +1051,7 @@ getcmds(void) docmd(line); free(line); } -#else /* not HAVE_LIBREADLINE */ +#else /* not (HAVE_LIBREADLINE || HAVE_LIBEDIT) */ char line[MAXLINE]; for (;;) { @@ -975,10 +1068,11 @@ getcmds(void) docmd(line); } -#endif /* not HAVE_LIBREADLINE */ +#endif /* not HAVE_LIBREADLINE || HAVE_LIBEDIT */ } +#ifndef SYS_WINNT /* Under NT cannot handle SIGINT, WIN32 spawns a handler */ /* * abortcmd - catch interrupts and abort the current command */ @@ -994,7 +1088,7 @@ abortcmd( (void) fflush(stderr); if (jump) longjmp(interrupt_buf, 1); } - +#endif /* SYS_WINNT */ /* * docmd - decode the command line and execute a command @@ -1007,9 +1101,11 @@ docmd( char *tokens[1+MAXARGS+2]; struct parse pcmd; int ntok; - static int i; + int i, ti; + int rval; struct xcmd *xcmd; + ai_fam_templ = ai_fam_default; /* * Tokenize the command line. If nothing on it, return. */ @@ -1037,22 +1133,29 @@ docmd( */ pcmd.keyword = tokens[0]; pcmd.nargs = 0; - for (i = 0; i < MAXARGS && xcmd->arg[i] != NO; i++) { - if ((i+1) >= ntok) { + ti = 1; + for (i = 0; i < MAXARGS && xcmd->arg[i] != NO;) { + if ((i+ti) >= ntok) { if (!(xcmd->arg[i] & OPT)) { printusage(xcmd, stderr); return; } break; } - if ((xcmd->arg[i] & OPT) && (*tokens[i+1] == '>')) - break; - if (!getarg(tokens[i+1], (int)xcmd->arg[i], &pcmd.argval[i])) - return; + if ((xcmd->arg[i] & OPT) && (*tokens[i+ti] == '>')) + break; + rval = getarg(tokens[i+ti], (int)xcmd->arg[i], &pcmd.argval[i]); + if (rval == -1) { + ti++; + continue; + } + if (rval == 0) + return; pcmd.nargs++; + i++; } - i++; + i += ti; if (i < ntok && *tokens[i] == '>') { char *fname; @@ -1071,10 +1174,8 @@ docmd( perror(""); return; } - i = 1; /* flag we need a close */ } else { current_output = stdout; - i = 0; /* flag no close */ } if (interactive && setjmp(interrupt_buf)) { @@ -1083,7 +1184,9 @@ docmd( jump = 1; (xcmd->handler)(&pcmd, current_output); jump = 0; - if (i) (void) fclose(current_output); + if (current_output != stdout) + (void) fclose(current_output); + current_output = NULL; } } @@ -1187,8 +1290,12 @@ findcmd( } - /* +/* * getarg - interpret an argument token + * + * return: 0 - failure + * 1 - success + * -1 - skip to next token */ static int getarg( @@ -1206,7 +1313,14 @@ getarg( argp->string = str; break; case ADD: - if (!getnetnum(str, &(argp->netnum), (char *)0)) { + if (!strcmp("-6", str)) { + ai_fam_templ = AF_INET6; + return -1; + } else if (!strcmp("-4", str)) { + ai_fam_templ = AF_INET; + return -1; + } + if (!getnetnum(str, &(argp->netnum), (char *)0, 0)) { return 0; } break; @@ -1240,6 +1354,17 @@ getarg( argp->ival = -argp->ival; } break; + case IP_VERSION: + if (!strcmp("-6", str)) + argp->ival = 6 ; + else if (!strcmp("-4", str)) + argp->ival = 4 ; + else { + (void) fprintf(stderr, + "***Version must be either 4 or 6\n"); + return 0; + } + break; } return 1; @@ -1253,24 +1378,36 @@ getarg( static int getnetnum( const char *hname, - u_int32 *num, - char *fullhost + struct sockaddr_storage *num, + char *fullhost, + int af ) { - struct hostent *hp; - + int err; + int sockaddr_len; + struct addrinfo hints, *ai = NULL; + + sockaddr_len = (af == AF_INET) + ? sizeof(struct sockaddr_in) + : sizeof(struct sockaddr_in6); + memset((char *)&hints, 0, sizeof(struct addrinfo)); + hints.ai_flags = AI_CANONNAME; +#ifdef AI_ADDRCONFIG + hints.ai_flags |= AI_ADDRCONFIG; +#endif + + /* decodenetnum only works with addresses */ if (decodenetnum(hname, num)) { if (fullhost != 0) { - (void) sprintf(fullhost, - "%u.%u.%u.%u", (u_int)((htonl(*num)>>24)&0xff), - (u_int)((htonl(*num)>>16)&0xff), (u_int)((htonl(*num)>>8)&0xff), - (u_int)(htonl(*num)&0xff)); + getnameinfo((struct sockaddr *)num, sockaddr_len, + fullhost, sizeof(fullhost), NULL, 0, + NI_NUMERICHOST); } return 1; - } else if ((hp = gethostbyname(hname)) != 0) { - memmove((char *)num, hp->h_addr, sizeof(u_int32)); + } else if ((err = getaddrinfo(hname, "ntp", &hints, &ai)) == 0) { + memmove((char *)num, ai->ai_addr, ai->ai_addrlen); if (fullhost != 0) - (void) strcpy(fullhost, hp->h_name); + (void) strcpy(fullhost, ai->ai_canonname); return 1; } else { (void) fprintf(stderr, "***Can't find host %s\n", hname); @@ -1285,14 +1422,15 @@ getnetnum( */ char * nntohost( - u_int32 netnum + struct sockaddr_storage *netnum ) { if (!showhostnames) - return numtoa(netnum); - if ((ntohl(netnum) & REFCLOCK_MASK) == REFCLOCK_ADDR) - return refnumtoa(netnum); - return numtohost(netnum); + return stoa(netnum); + + if ((netnum->ss_family == AF_INET) && ISREFCLOCKADR(netnum)) + return refnumtoa(netnum); + return socktohost(netnum); } @@ -1380,8 +1518,8 @@ helpsort( const void *t2 ) { - const char **name1 = (const char **)t1; - const char **name2 = (const char **)t2; + char const * const * name1 = (char const * const *)t1; + char const * const * name2 = (char const * const *)t2; return strcmp(*name1, *name2); } @@ -1406,10 +1544,15 @@ printusage( FILE *fp ) { - register int i; + int i, opt46; + opt46 = 0; (void) fprintf(fp, "usage: %s", xcp->keyword); for (i = 0; i < MAXARGS && xcp->arg[i] != NO; i++) { + if (opt46 == 0 && (xcp->arg[i] & ~OPT) == ADD) { + (void) fprintf(fp, " [ -4|-6 ]"); + opt46 = 1; + } if (xcp->arg[i] & OPT) (void) fprintf(fp, " [ %s ]", xcp->desc[i]); else @@ -1484,12 +1627,33 @@ host( FILE *fp ) { + int i; + if (pcmd->nargs == 0) { if (havehost) (void) fprintf(fp, "current host is %s\n", currenthost); else (void) fprintf(fp, "no current host\n"); - } else if (openhost(pcmd->argval[0].string)) { + return; + } + + i = 0; + if (pcmd->nargs == 2) { + if (!strcmp("-4", pcmd->argval[i].string)) + ai_fam_templ = AF_INET; + else if (!strcmp("-6", pcmd->argval[i].string)) + ai_fam_templ = AF_INET6; + else { + if (havehost) + (void) fprintf(fp, + "current host remains %s\n", currenthost); + else + (void) fprintf(fp, "still no current host\n"); + return; + } + i = 1; + } + if (openhost(pcmd->argval[i].string)) { (void) fprintf(fp, "current host set to %s\n", currenthost); } else { if (havehost) @@ -1532,7 +1696,7 @@ keytype( { if (pcmd->nargs == 0) fprintf(fp, "keytype is %s\n", - (info_auth_keytype == KEY_TYPE_MD5) ? "MD5" : "DES"); + (info_auth_keytype == KEY_TYPE_MD5) ? "MD5" : "???"); else switch (*(pcmd->argval[0].string)) { case 'm': @@ -1540,13 +1704,8 @@ keytype( info_auth_keytype = KEY_TYPE_MD5; break; - case 'd': - case 'D': - info_auth_keytype = KEY_TYPE_DES; - break; - default: - fprintf(fp, "keytype must be 'md5' or 'des'\n"); + fprintf(fp, "keytype must be 'md5'\n"); } } @@ -1576,10 +1735,7 @@ passwd( (u_char *)pcmd->argval[0].string); authtrust(info_auth_keyid, 1); } else { - pass = getpass((info_auth_keytype == KEY_TYPE_DES) - ? "DES Password: " - : "MD5 Password: " - ); + pass = getpass("MD5 Password: "); if (*pass == '\0') (void) fprintf(fp, "Password unchanged\n"); else { @@ -1729,7 +1885,7 @@ getkeyid( fprintf(stderr, "%s", keyprompt); fflush(stderr); for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) { if (p < &pbuf[18]) - *p++ = c; + *p++ = (char) c; } *p = '\0'; if (fi != stdin) diff --git a/contrib/ntp/ntpdc/ntpdc.h b/contrib/ntp/ntpdc/ntpdc.h index 8b35d4f..589529f 100644 --- a/contrib/ntp/ntpdc/ntpdc.h +++ b/contrib/ntp/ntpdc/ntpdc.h @@ -22,6 +22,7 @@ #define UINT 0x2 /* unsigned integer */ #define INT 0x3 /* signed integer */ #define ADD 0x4 /* IP network address */ +#define IP_VERSION 0x5 /* IP version */ /* * Arguments are returned in a union @@ -30,7 +31,7 @@ typedef union { char *string; long ival; u_long uval; - u_int32 netnum; + struct sockaddr_storage netnum; } arg_v; /* @@ -55,5 +56,9 @@ struct xcmd { const char *comment; }; -extern int doquery P((int, int, int, int, int, char *, int *, int *, char **, int)); -extern char * nntohost P((u_int32)); +extern int impl_ver; +extern int showhostnames; +extern int s_port; + +extern int doquery P((int, int, int, int, int, char *, int *, int *, char **, int, int)); +extern char * nntohost P((struct sockaddr_storage *)); diff --git a/contrib/ntp/ntpdc/ntpdc_ops.c b/contrib/ntp/ntpdc/ntpdc_ops.c index b163401..9fa3bd7 100644 --- a/contrib/ntp/ntpdc/ntpdc_ops.c +++ b/contrib/ntp/ntpdc/ntpdc_ops.c @@ -1,5 +1,5 @@ /* - * ntpdc_ops.c - subroutines which are called to perform operations by ntpdc + * ntpdc_ops.c - subroutines which are called to perform operations by xntpdc */ #ifdef HAVE_CONFIG_H @@ -7,6 +7,7 @@ #endif #include <stdio.h> +#include <stddef.h> #include "ntpdc.h" #include "ntp_control.h" @@ -83,16 +84,16 @@ static void kerninfo P((struct parse *, FILE *)); * Commands we understand. Ntpdc imports this. */ struct xcmd opcmds[] = { - { "listpeers", peerlist, { NO, NO, NO, NO }, - { "", "", "", "" }, - "display list of peers the server knows about" }, - { "peers", peers, { NO, NO, NO, NO }, - { "", "", "", "" }, - "display peer summary information" }, - { "dmpeers", dmpeers, { NO, NO, NO, NO }, - { "", "", "", "" }, - "display peer summary info the way Dave Mills likes it" }, - { "showpeer", showpeer, { ADD, OPT|ADD, OPT|ADD, OPT|ADD }, + { "listpeers", peerlist, { OPT|IP_VERSION, NO, NO, NO }, + { "-4|-6", "", "", "" }, + "display list of peers the server knows about [IP Version]" }, + { "peers", peers, { OPT|IP_VERSION, NO, NO, NO }, + { "-4|-6", "", "", "" }, + "display peer summary information [IP Version]" }, + { "dmpeers", dmpeers, { OPT|IP_VERSION, NO, NO, NO }, + { "-4|-6", "", "", "" }, + "display peer summary info the way Dave Mills likes it (IP Version)" }, + { "showpeer", showpeer, { ADD, OPT|ADD, OPT|ADD, OPT|ADD}, { "peer_address", "peer2_addr", "peer3_addr", "peer4_addr" }, "display detailed information for one or more peers" }, { "pstats", peerstats, { ADD, OPT|ADD, OPT|ADD, OPT|ADD }, @@ -137,8 +138,8 @@ struct xcmd opcmds[] = { { "disable", sys_clear, { NTP_STR, OPT|NTP_STR, OPT|NTP_STR, OPT|NTP_STR }, { "auth|bclient|monitor|pll|kernel|stats", "...", "...", "..." }, "clear a system flag (auth, bclient, monitor, pll, kernel, stats)" }, - { "reslist", reslist, { NO, NO, NO, NO }, - { "", "", "", "" }, + { "reslist", reslist, {OPT|IP_VERSION, NO, NO, NO }, + { "-4|-6", "", "", "" }, "display the server's restrict list" }, { "restrict", new_restrict, { ADD, ADD, NTP_STR, OPT|NTP_STR }, { "address", "mask", @@ -209,13 +210,6 @@ struct xcmd opcmds[] = { { "", "", "", "" }, "" } }; - -/* - * Imported from ntpdc.c - */ -extern int showhostnames; -extern struct servent *server_entry; - /* * For quick string comparisons */ @@ -292,25 +286,49 @@ peerlist( ) { struct info_peer_list *plist; + struct sockaddr_storage paddr; int items; int itemsize; int res; - res = doquery(IMPL_XNTPD, REQ_PEER_LIST, 0, 0, 0, (char *)NULL, &items, - &itemsize, (char **)&plist, 0); +again: + res = doquery(impl_ver, REQ_PEER_LIST, 0, 0, 0, (char *)NULL, &items, + &itemsize, (void *)&plist, 0, + sizeof(struct info_peer_list)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; if (!checkitems(items, fp)) return; - if (!checkitemsize(itemsize, sizeof(struct info_peer_list))) + if (!checkitemsize(itemsize, sizeof(struct info_peer_list)) && + !checkitemsize(itemsize, v4sizeof(struct info_peer_list))) return; while (items > 0) { - (void) fprintf(fp, "%-9s %s\n", modetoa(plist->hmode), - nntohost(plist->address)); + memset((char *)&paddr, 0, sizeof(paddr)); + if (plist->v6_flag != 0) { + GET_INADDR6(paddr) = plist->addr6; + paddr.ss_family = AF_INET6; + } else { + GET_INADDR(paddr) = plist->addr; + paddr.ss_family = AF_INET; + } +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR + paddr.ss_len = SOCKLEN(&paddr); +#endif + if ((pcmd->nargs == 0) || + ((pcmd->argval->ival == 6) && (plist->v6_flag != 0)) || + ((pcmd->argval->ival == 4) && (plist->v6_flag == 0))) + (void) fprintf(fp, "%-9s %s\n", + modetoa(plist->hmode), + nntohost(&paddr)); plist++; items--; } @@ -354,6 +372,8 @@ dopeers( ) { struct info_peer_summary *plist; + struct sockaddr_storage dstadr; + struct sockaddr_storage srcadr; int items; int itemsize; int ntp_poll; @@ -361,17 +381,25 @@ dopeers( int c; l_fp tempts; - res = doquery(IMPL_XNTPD, REQ_PEER_LIST_SUM, 0, 0, 0, (char *)NULL, - &items, &itemsize, (char **)&plist, 0); +again: + res = doquery(impl_ver, REQ_PEER_LIST_SUM, 0, 0, 0, (char *)NULL, + &items, &itemsize, (void *)&plist, 0, + sizeof(struct info_peer_summary)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; if (!checkitems(items, fp)) return; - if (!checkitemsize(itemsize, sizeof(struct info_peer_summary))) - return; + if (!checkitemsize(itemsize, sizeof(struct info_peer_summary)) && + !checkitemsize(itemsize, v4sizeof(struct info_peer_summary))) + return; (void) fprintf(fp, " remote local st poll reach delay offset disp\n"); @@ -406,15 +434,33 @@ dopeers( NTOHL_FP(&(plist->offset), &tempts); ntp_poll = 1<<max(min3(plist->ppoll, plist->hpoll, NTP_MAXPOLL), NTP_MINPOLL); - (void) fprintf(fp, - "%c%-15.15s %-15.15s %2d %4d %3o %7.7s %9.9s %7.7s\n", - c, nntohost(plist->srcadr), - numtoa(plist->dstadr), - plist->stratum, ntp_poll, plist->reach, - fptoa(NTOHS_FP(plist->delay), 5), - lfptoa(&tempts, 6), - ufptoa(NTOHS_FP(plist->dispersion), 5)); - + memset((char *)&dstadr, 0, sizeof(dstadr)); + memset((char *)&srcadr, 0, sizeof(srcadr)); + if (plist->v6_flag != 0) { + GET_INADDR6(dstadr) = plist->dstadr6; + GET_INADDR6(srcadr) = plist->srcadr6; + srcadr.ss_family = AF_INET6; + dstadr.ss_family = AF_INET6; + } else { + GET_INADDR(dstadr) = plist->dstadr; + GET_INADDR(srcadr) = plist->srcadr; + srcadr.ss_family = AF_INET; + dstadr.ss_family = AF_INET; + } +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR + srcadr.ss_len = SOCKLEN(&srcadr); + dstadr.ss_len = SOCKLEN(&dstadr); +#endif + if ((pcmd->nargs == 0) || + ((pcmd->argval->ival == 6) && (plist->v6_flag != 0)) || + ((pcmd->argval->ival == 4) && (plist->v6_flag == 0))) + (void) fprintf(fp, + "%c%-15.15s %-15.15s %2d %4d %3o %7.7s %9.9s %7.7s\n", + c, nntohost(&srcadr), stoa(&dstadr), + plist->stratum, ntp_poll, plist->reach, + fptoa(NTOHS_FP(plist->delay), 5), + lfptoa(&tempts, 6), + ufptoa(NTOHS_FP(plist->dispersion), 5)); plist++; items--; } @@ -449,10 +495,27 @@ printpeer( register int i; const char *str; l_fp tempts; - + struct sockaddr_storage srcadr, dstadr; + + memset((char *)&srcadr, 0, sizeof(srcadr)); + memset((char *)&dstadr, 0, sizeof(dstadr)); + if (pp->v6_flag != 0) { + srcadr.ss_family = AF_INET6; + dstadr.ss_family = AF_INET6; + GET_INADDR6(srcadr) = pp->srcadr6; + GET_INADDR6(dstadr) = pp->dstadr6; + } else { + srcadr.ss_family = AF_INET; + dstadr.ss_family = AF_INET; + GET_INADDR(srcadr) = pp->srcadr; + GET_INADDR(dstadr) = pp->dstadr; + } +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR + srcadr.ss_len = SOCKLEN(&srcadr); + dstadr.ss_len = SOCKLEN(&dstadr); +#endif (void) fprintf(fp, "remote %s, local %s\n", - numtoa(pp->srcadr), numtoa(pp->dstadr)); - + stoa(&srcadr), stoa(&dstadr)); (void) fprintf(fp, "hmode %s, pmode %s, stratum %d, precision %d\n", modetoa(pp->hmode), modetoa(pp->pmode), pp->stratum, pp->precision); @@ -570,29 +633,55 @@ showpeer( { struct info_peer *pp; /* 4 is the maximum number of peers which will fit in a packet */ - struct info_peer_list plist[min(MAXARGS, 4)]; + struct info_peer_list *pl, plist[min(MAXARGS, 4)]; int qitems; int items; int itemsize; int res; - - for (qitems = 0; qitems < min(pcmd->nargs, 4); qitems++) { - plist[qitems].address = pcmd->argval[qitems].netnum; - plist[qitems].port = server_entry->s_port; - plist[qitems].hmode = plist[qitems].flags = 0; + int sendsize; + +again: + if (impl_ver == IMPL_XNTPD) + sendsize = sizeof(struct info_peer_list); + else + sendsize = v4sizeof(struct info_peer_list); + + for (qitems = 0, pl = plist; qitems < min(pcmd->nargs, 4); qitems++) { + if (pcmd->argval[qitems].netnum.ss_family == AF_INET) { + pl->addr = GET_INADDR(pcmd->argval[qitems].netnum); + if (impl_ver == IMPL_XNTPD) + pl->v6_flag = 0; + } else { + if (impl_ver == IMPL_XNTPD_OLD) { + fprintf(stderr, + "***Server doesn't understand IPv6 addresses\n"); + return; + } + pl->addr6 = GET_INADDR6(pcmd->argval[qitems].netnum); + pl->v6_flag = 1; + } + pl->port = (u_short)s_port; + pl->hmode = pl->flags = 0; + pl = (struct info_peer_list *)((char *)pl + sendsize); } - res = doquery(IMPL_XNTPD, REQ_PEER_INFO, 0, qitems, - sizeof(struct info_peer_list), (char *)plist, &items, - &itemsize, (char **)&pp, 0); + res = doquery(impl_ver, REQ_PEER_INFO, 0, qitems, + sendsize, (char *)plist, &items, + &itemsize, (void *)&pp, 0, sizeof(struct info_peer)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; if (!checkitems(items, fp)) return; - if (!checkitemsize(itemsize, sizeof(struct info_peer))) + if (!checkitemsize(itemsize, sizeof(struct info_peer)) && + !checkitemsize(itemsize, v4sizeof(struct info_peer))) return; while (items-- > 0) { @@ -615,36 +704,82 @@ peerstats( { struct info_peer_stats *pp; /* 4 is the maximum number of peers which will fit in a packet */ - struct info_peer_list plist[min(MAXARGS, 4)]; + struct info_peer_list *pl, plist[min(MAXARGS, 4)]; + struct sockaddr_storage src, dst; int qitems; int items; int itemsize; int res; - - for (qitems = 0; qitems < min(pcmd->nargs, 4); qitems++) { - plist[qitems].address = pcmd->argval[qitems].netnum; - plist[qitems].port = server_entry->s_port; - plist[qitems].hmode = plist[qitems].flags = 0; + int sendsize; + +again: + if (impl_ver == IMPL_XNTPD) + sendsize = sizeof(struct info_peer_list); + else + sendsize = v4sizeof(struct info_peer_list); + + memset((char *)plist, 0, sizeof(struct info_peer_list) * min(MAXARGS, 4)); + for (qitems = 0, pl = plist; qitems < min(pcmd->nargs, 4); qitems++) { + if (pcmd->argval[qitems].netnum.ss_family == AF_INET) { + pl->addr = GET_INADDR(pcmd->argval[qitems].netnum); + if (impl_ver == IMPL_XNTPD) + pl->v6_flag = 0; + } else { + if (impl_ver == IMPL_XNTPD_OLD) { + fprintf(stderr, + "***Server doesn't understand IPv6 addresses\n"); + return; + } + pl->addr6 = GET_INADDR6(pcmd->argval[qitems].netnum); + pl->v6_flag = 1; + } + pl->port = (u_short)s_port; + pl->hmode = plist[qitems].flags = 0; + pl = (struct info_peer_list *)((char *)pl + sendsize); } - res = doquery(IMPL_XNTPD, REQ_PEER_STATS, 0, qitems, - sizeof(struct info_peer_list), (char *)plist, &items, - &itemsize, (char **)&pp, 0); + res = doquery(impl_ver, REQ_PEER_STATS, 0, qitems, + sendsize, (char *)plist, &items, + &itemsize, (void *)&pp, 0, + sizeof(struct info_peer_stats)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; if (!checkitems(items, fp)) return; - if (!checkitemsize(itemsize, sizeof(struct info_peer_stats))) + if (!checkitemsize(itemsize, sizeof(struct info_peer_stats)) && + !checkitemsize(itemsize, v4sizeof(struct info_peer_stats))) return; while (items-- > 0) { + memset((char *)&src, 0, sizeof(src)); + memset((char *)&dst, 0, sizeof(dst)); + if (pp->v6_flag != 0) { + GET_INADDR6(src) = pp->srcadr6; + GET_INADDR6(dst) = pp->dstadr6; + src.ss_family = AF_INET6; + dst.ss_family = AF_INET6; + } else { + GET_INADDR(src) = pp->srcadr; + GET_INADDR(dst) = pp->dstadr; + src.ss_family = AF_INET; + dst.ss_family = AF_INET; + } +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR + src.ss_len = SOCKLEN(&src); + dst.ss_len = SOCKLEN(&dst); +#endif (void) fprintf(fp, "remote host: %s\n", - nntohost(pp->srcadr)); + nntohost(&src)); (void) fprintf(fp, "local interface: %s\n", - numtoa(pp->dstadr)); + stoa(&dst)); (void) fprintf(fp, "time last received: %lds\n", (long)ntohl(pp->timereceived)); (void) fprintf(fp, "time until next send: %lds\n", @@ -701,9 +836,16 @@ loopinfo( } } - res = doquery(IMPL_XNTPD, REQ_LOOP_INFO, 0, 0, 0, (char *)NULL, - &items, &itemsize, (char **)&il, 0); +again: + res = doquery(impl_ver, REQ_LOOP_INFO, 0, 0, 0, (char *)NULL, + &items, &itemsize, (void *)&il, 0, + sizeof(struct info_loop)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; @@ -751,24 +893,44 @@ sysinfo( ) { struct info_sys *is; + struct sockaddr_storage peeraddr; int items; int itemsize; int res; l_fp tempts; - res = doquery(IMPL_XNTPD, REQ_SYS_INFO, 0, 0, 0, (char *)NULL, - &items, &itemsize, (char **)&is, 0); +again: + res = doquery(impl_ver, REQ_SYS_INFO, 0, 0, 0, (char *)NULL, + &items, &itemsize, (void *)&is, 0, + sizeof(struct info_sys)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; if (!check1item(items, fp)) return; - if (!checkitemsize(itemsize, sizeof(struct info_sys))) + if (!checkitemsize(itemsize, sizeof(struct info_sys)) && + !checkitemsize(itemsize, v4sizeof(struct info_sys))) return; - (void) fprintf(fp, "system peer: %s\n", nntohost(is->peer)); + memset((char *)&peeraddr, 0, sizeof(peeraddr)); + if (is->v6_flag != 0) { + GET_INADDR6(peeraddr) = is->peer6; + peeraddr.ss_family = AF_INET6; + } else { + GET_INADDR(peeraddr) = is->peer; + peeraddr.ss_family = AF_INET; + } +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR + peeraddr.ss_len = SOCKLEN(&peeraddr); +#endif + (void) fprintf(fp, "system peer: %s\n", nntohost(&peeraddr)); (void) fprintf(fp, "system peer mode: %s\n", modetoa(is->peer_mode)); (void) fprintf(fp, "leap indicator: %c%c\n", is->leap & 0x2 ? '1' : '0', @@ -834,9 +996,16 @@ sysstats( int itemsize; int res; - res = doquery(IMPL_XNTPD, REQ_SYS_STATS, 0, 0, 0, (char *)NULL, - &items, &itemsize, (char **)&ss, 0); +again: + res = doquery(impl_ver, REQ_SYS_STATS, 0, 0, 0, (char *)NULL, + &items, &itemsize, (void *)&ss, 0, + sizeof(struct info_sys_stats)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; @@ -849,30 +1018,31 @@ sysstats( checkitemsize(itemsize, sizeof(struct info_sys_stats)); return; } - - (void) fprintf(fp, "system uptime: %ld\n", - (u_long)ntohl(ss->timeup)); - (void) fprintf(fp, "time since reset: %ld\n", - (u_long)ntohl(ss->timereset)); - (void) fprintf(fp, "bad stratum in packet: %ld\n", - (u_long)ntohl(ss->badstratum)); - (void) fprintf(fp, "old version packets: %ld\n", - (u_long)ntohl(ss->oldversionpkt)); - (void) fprintf(fp, "new version packets: %ld\n", - (u_long)ntohl(ss->newversionpkt)); - (void) fprintf(fp, "unknown version number: %ld\n", - (u_long)ntohl(ss->unknownversion)); - (void) fprintf(fp, "bad packet format: %ld\n", - (u_long)ntohl(ss->badlength)); - (void) fprintf(fp, "packets processed: %ld\n", - (u_long)ntohl(ss->processed)); - (void) fprintf(fp, "bad authentication: %ld\n", - (u_long)ntohl(ss->badauth)); + fprintf(fp, "time since restart: %ld\n", + (u_long)ntohl(ss->timeup)); + fprintf(fp, "time since reset: %ld\n", + (u_long)ntohl(ss->timereset)); + fprintf(fp, "packets received: %ld\n", + (u_long)ntohl(ss->received)); + fprintf(fp, "packets processed: %ld\n", + (u_long)ntohl(ss->processed)); + fprintf(fp, "current version: %ld\n", + (u_long)ntohl(ss->newversionpkt)); + fprintf(fp, "previous version: %ld\n", + (u_long)ntohl(ss->oldversionpkt)); + fprintf(fp, "bad version: %ld\n", + (u_long)ntohl(ss->unknownversion)); + fprintf(fp, "access denied: %ld\n", + (u_long)ntohl(ss->denied)); + fprintf(fp, "bad length or format: %ld\n", + (u_long)ntohl(ss->badlength)); + fprintf(fp, "bad authentication: %ld\n", + (u_long)ntohl(ss->badauth)); if (itemsize != sizeof(struct info_sys_stats)) return; - (void) fprintf(fp, "packets rejected: %ld\n", - (u_long)ntohl(ss->limitrejected)); + fprintf(fp, "rate exceeded: %ld\n", + (u_long)ntohl(ss->limitrejected)); } @@ -892,9 +1062,16 @@ iostats( int itemsize; int res; - res = doquery(IMPL_XNTPD, REQ_IO_STATS, 0, 0, 0, (char *)NULL, - &items, &itemsize, (char **)&io, 0); +again: + res = doquery(impl_ver, REQ_IO_STATS, 0, 0, 0, (char *)NULL, + &items, &itemsize, (void *)&io, 0, + sizeof(struct info_io_stats)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; @@ -947,9 +1124,16 @@ memstats( int itemsize; int res; - res = doquery(IMPL_XNTPD, REQ_MEM_STATS, 0, 0, 0, (char *)NULL, - &items, &itemsize, (char **)&mem, 0); +again: + res = doquery(impl_ver, REQ_MEM_STATS, 0, 0, 0, (char *)NULL, + &items, &itemsize, (void *)&mem, 0, + sizeof(struct info_mem_stats)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; @@ -999,9 +1183,16 @@ timerstats( int itemsize; int res; - res = doquery(IMPL_XNTPD, REQ_TIMER_STATS, 0, 0, 0, (char *)NULL, - &items, &itemsize, (char **)&tim, 0); +again: + res = doquery(impl_ver, REQ_TIMER_STATS, 0, 0, 0, (char *)NULL, + &items, &itemsize, (void *)&tim, 0, + sizeof(struct info_timer_stats)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; @@ -1093,7 +1284,9 @@ doconfig( u_int flags; u_char cmode; int res; + int sendsize; +again: keyid = 0; version = NTP_OLDVERSION + 1; flags = 0; @@ -1101,6 +1294,11 @@ doconfig( cmode = 0; minpoll = NTP_MINDPOLL; + if (impl_ver == IMPL_XNTPD) + sendsize = sizeof(struct conf_peer); + else + sendsize = v4sizeof(struct conf_peer); + items = pcmd->nargs; if (refc) { @@ -1159,9 +1357,21 @@ doconfig( if (res) return; - memset((void *)&cpeer, 0, sizeof cpeer); + memset((void *)&cpeer, 0, sizeof(cpeer)); - cpeer.peeraddr = pcmd->argval[0].netnum; + if (pcmd->argval[0].netnum.ss_family == AF_INET) { + cpeer.peeraddr = GET_INADDR(pcmd->argval[0].netnum); + if (impl_ver == IMPL_XNTPD) + cpeer.v6_flag = 0; + } else { + if (impl_ver == IMPL_XNTPD_OLD) { + fprintf(stderr, + "***Server doesn't understand IPv6 addresses\n"); + return; + } + cpeer.peeraddr6 = GET_INADDR6(pcmd->argval[0].netnum); + cpeer.v6_flag = 1; + } cpeer.hmode = (u_char) mode; cpeer.keyid = keyid; cpeer.version = (u_char) version; @@ -1170,16 +1380,22 @@ doconfig( cpeer.flags = (u_char)flags; cpeer.ttl = cmode; - res = doquery(IMPL_XNTPD, REQ_CONFIG, 1, 1, - sizeof(struct conf_peer), (char *)&cpeer, &items, - &itemsize, &dummy, 0); + res = doquery(impl_ver, REQ_CONFIG, 1, 1, + sendsize, (char *)&cpeer, &items, + &itemsize, &dummy, 0, sizeof(struct conf_peer)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res == INFO_ERR_FMT) { (void) fprintf(fp, "***Retrying command with old conf_peer size\n"); - res = doquery(IMPL_XNTPD, REQ_CONFIG, 1, 1, + res = doquery(impl_ver, REQ_CONFIG, 1, 1, sizeof(struct old_conf_peer), (char *)&cpeer, - &items, &itemsize, &dummy, 0); + &items, &itemsize, &dummy, 0, + sizeof(struct conf_peer)); } if (res == 0) (void) fprintf(fp, "done!\n"); @@ -1197,21 +1413,47 @@ unconfig( ) { /* 8 is the maximum number of peers which will fit in a packet */ - struct conf_unpeer plist[min(MAXARGS, 8)]; + struct conf_unpeer *pl, plist[min(MAXARGS, 8)]; int qitems; int items; int itemsize; char *dummy; int res; - - for (qitems = 0; qitems < min(pcmd->nargs, 8); qitems++) { - plist[qitems].peeraddr = pcmd->argval[qitems].netnum; + int sendsize; + +again: + if (impl_ver == IMPL_XNTPD) + sendsize = sizeof(struct conf_unpeer); + else + sendsize = v4sizeof(struct conf_unpeer); + + for (qitems = 0, pl = plist; qitems < min(pcmd->nargs, 8); qitems++) { + if (pcmd->argval[0].netnum.ss_family == AF_INET) { + pl->peeraddr = GET_INADDR(pcmd->argval[qitems].netnum); + if (impl_ver == IMPL_XNTPD) + pl->v6_flag = 0; + } else { + if (impl_ver == IMPL_XNTPD_OLD) { + fprintf(stderr, + "***Server doesn't understand IPv6 addresses\n"); + return; + } + pl->peeraddr6 = + GET_INADDR6(pcmd->argval[qitems].netnum); + pl->v6_flag = 1; + } + pl = (struct conf_unpeer *)((char *)pl + sendsize); } - res = doquery(IMPL_XNTPD, REQ_UNCONFIG, 1, qitems, - sizeof(struct conf_unpeer), (char *)plist, &items, - &itemsize, &dummy, 0); + res = doquery(impl_ver, REQ_UNCONFIG, 1, qitems, + sendsize, (char *)plist, &items, + &itemsize, &dummy, 0, sizeof(struct conf_unpeer)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res == 0) (void) fprintf(fp, "done!\n"); } @@ -1289,10 +1531,16 @@ doset( if (res || sys.flags == 0) return; - res = doquery(IMPL_XNTPD, req, 1, 1, +again: + res = doquery(impl_ver, req, 1, 1, sizeof(struct conf_sys_flags), (char *)&sys, &items, - &itemsize, &dummy, 0); + &itemsize, &dummy, 0, sizeof(struct conf_sys_flags)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res == 0) (void) fprintf(fp, "done!\n"); } @@ -1318,6 +1566,7 @@ static struct resflags resflags[] = { { "limited", RES_LIMITED }, { "version", RES_VERSION }, { "kod", RES_DEMOBILIZE }, + { "timeout", RES_TIMEOUT }, { "", 0 } }; @@ -1340,9 +1589,12 @@ reslist( ) { struct info_restrict *rl; + struct sockaddr_storage resaddr; + struct sockaddr_storage maskaddr; int items; int itemsize; int res; + int skip; char *addr; char *mask; struct resflags *rf; @@ -1352,28 +1604,62 @@ reslist( char flagstr[300]; static const char *comma = ", "; - res = doquery(IMPL_XNTPD, REQ_GET_RESTRICT, 0, 0, 0, (char *)NULL, - &items, &itemsize, (char **)&rl, 0); +again: + res = doquery(impl_ver, REQ_GET_RESTRICT, 0, 0, 0, (char *)NULL, + &items, &itemsize, (void *)&rl, 0, + sizeof(struct info_restrict)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; if (!checkitems(items, fp)) return; - if (!checkitemsize(itemsize, sizeof(struct info_restrict))) + if (!checkitemsize(itemsize, sizeof(struct info_restrict)) && + !checkitemsize(itemsize, v4sizeof(struct info_restrict))) return; (void) fprintf(fp, - " address mask count flags\n"); + " address mask count flags\n"); (void) fprintf(fp, "=====================================================================\n"); + while (items > 0) { - if ((rl->mask == (u_int32)0xffffffff)) - addr = nntohost(rl->addr); - else - addr = numtoa( rl->addr ); - mask = numtoa(rl->mask); + memset((char *)&resaddr, 0, sizeof(resaddr)); + memset((char *)&maskaddr, 0, sizeof(maskaddr)); + if (rl->v6_flag != 0) { + GET_INADDR6(resaddr) = rl->addr6; + GET_INADDR6(maskaddr) = rl->mask6; + resaddr.ss_family = AF_INET6; + maskaddr.ss_family = AF_INET6; +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR + resaddr.ss_len = SOCKLEN(&resaddr); +#endif + addr = nntohost(&resaddr); + } else { + GET_INADDR(resaddr) = rl->addr; + GET_INADDR(maskaddr) = rl->mask; + resaddr.ss_family = AF_INET; + maskaddr.ss_family = AF_INET; +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR + resaddr.ss_len = SOCKLEN(&resaddr); +#endif + if ((rl->mask == (u_int32)0xffffffff)) + addr = nntohost(&resaddr); + else + addr = stoa(&resaddr); + } + mask = stoa(&maskaddr); + skip = 1; + if ((pcmd->nargs == 0) || + ((pcmd->argval->ival == 6) && (rl->v6_flag != 0)) || + ((pcmd->argval->ival == 4) && (rl->v6_flag == 0))) + skip = 0; count = ntohl(rl->count); flags = ntohs(rl->flags); mflags = ntohs(rl->mflags); @@ -1405,8 +1691,9 @@ reslist( if (flagstr[0] == '\0') (void) strcpy(flagstr, "none"); - (void) fprintf(fp, "%-15.15s %-15.15s %9ld %s\n", - addr, mask, (u_long)count, flagstr); + if (!skip) + (void) fprintf(fp, "%-15.15s %-15.15s %9ld %s\n", + addr, mask, (u_long)count, flagstr); rl++; items--; } @@ -1472,9 +1759,35 @@ do_restrict( int i; int res; int err; + int sendsize; - cres.addr = pcmd->argval[0].netnum; - cres.mask = pcmd->argval[1].netnum; + /* Initialize cres */ + cres.addr = 0; + cres.mask = 0; + cres.flags = 0; + cres.mflags = 0; + cres.v6_flag = 0; + +again: + if (impl_ver == IMPL_XNTPD) + sendsize = sizeof(struct conf_restrict); + else + sendsize = v4sizeof(struct conf_restrict); + + if (pcmd->argval[0].netnum.ss_family == AF_INET) { + cres.addr = GET_INADDR(pcmd->argval[0].netnum); + cres.mask = GET_INADDR(pcmd->argval[1].netnum); + if (impl_ver == IMPL_XNTPD) + cres.v6_flag = 0; + } else { + if (impl_ver == IMPL_XNTPD_OLD) { + fprintf(stderr, + "***Server doesn't understand IPv6 addresses\n"); + return; + } + cres.addr6 = GET_INADDR6(pcmd->argval[0].netnum); + cres.v6_flag = 1; + } cres.flags = 0; cres.mflags = 0; err = 0; @@ -1507,30 +1820,39 @@ do_restrict( * Make sure mask for default address is zero. Otherwise, * make sure mask bits are contiguous. */ - if (cres.addr == 0) { - cres.mask = 0; - } else { - num = ntohl(cres.mask); - for (bit = 0x80000000; bit != 0; bit >>= 1) - if ((num & bit) == 0) - break; - for ( ; bit != 0; bit >>= 1) - if ((num & bit) != 0) - break; - if (bit != 0) { - (void) fprintf(fp, "Invalid mask %s\n", - numtoa(cres.mask)); - err++; + if (pcmd->argval[0].netnum.ss_family == AF_INET) { + if (cres.addr == 0) { + cres.mask = 0; + } else { + num = ntohl(cres.mask); + for (bit = 0x80000000; bit != 0; bit >>= 1) + if ((num & bit) == 0) + break; + for ( ; bit != 0; bit >>= 1) + if ((num & bit) != 0) + break; + if (bit != 0) { + (void) fprintf(fp, "Invalid mask %s\n", + numtoa(cres.mask)); + err++; + } } + } else { + /* XXX IPv6 sanity checking stuff */ } if (err) return; - res = doquery(IMPL_XNTPD, req_code, 1, 1, - sizeof(struct conf_restrict), (char *)&cres, &items, - &itemsize, &dummy, 0); + res = doquery(impl_ver, req_code, 1, 1, + sendsize, (char *)&cres, &items, + &itemsize, &dummy, 0, sizeof(struct conf_restrict)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res == 0) (void) fprintf(fp, "done!\n"); return; @@ -1548,7 +1870,8 @@ monlist( ) { char *struct_star; - struct in_addr addr; + struct sockaddr_storage addr; + struct sockaddr_storage dstadr; int items; int itemsize; int res; @@ -1558,15 +1881,23 @@ monlist( version = pcmd->argval[0].ival; } - res = doquery(IMPL_XNTPD, +again: + res = doquery(impl_ver, (version == 1 || version == -1) ? REQ_MON_GETLIST_1 : REQ_MON_GETLIST, 0, 0, 0, (char *)NULL, &items, &itemsize, &struct_star, - (version < 0) ? (1 << INFO_ERR_REQ) : 0); + (version < 0) ? (1 << INFO_ERR_REQ) : 0, + sizeof(struct info_monitor_1)); + + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } if (res == INFO_ERR_REQ && version < 0) - res = doquery(IMPL_XNTPD, REQ_MON_GETLIST, 0, 0, 0, (char *)NULL, - &items, &itemsize, &struct_star, 0); + res = doquery(impl_ver, REQ_MON_GETLIST, 0, 0, 0, (char *)NULL, + &items, &itemsize, &struct_star, 0, + sizeof(struct info_monitor)); if (res != 0 && items == 0) return; @@ -1574,48 +1905,82 @@ monlist( if (!checkitems(items, fp)) return; - if (itemsize == sizeof(struct info_monitor_1)) { + if (itemsize == sizeof(struct info_monitor_1) || + itemsize == v4sizeof(struct info_monitor_1)) { struct info_monitor_1 *ml = (struct info_monitor_1 *) struct_star; (void) fprintf(fp, - "remote address port local address count m ver drop last first\n"); + "remote address port local address count m ver code avgint lstint\n"); (void) fprintf(fp, "===============================================================================\n"); while (items > 0) { - addr.s_addr = ml->daddr; - (void) fprintf(fp, - "%-22.22s %5d %-15s %8ld %1d %1d %6lu %6lu %7lu\n", - nntohost(ml->addr), - ntohs(ml->port), - inet_ntoa(addr), - (u_long)ntohl(ml->count), - ml->mode, - ml->version, - (u_long)ntohl(ml->lastdrop), - (u_long)ntohl(ml->lasttime), - (u_long)ntohl(ml->firsttime)); + memset((char *)&addr, 0, sizeof(addr)); + memset((char *)&dstadr, 0, sizeof(dstadr)); + if (ml->v6_flag != 0) { + GET_INADDR6(addr) = ml->addr6; + addr.ss_family = AF_INET6; + GET_INADDR6(dstadr) = ml->daddr6; + dstadr.ss_family = AF_INET6; + } else { + GET_INADDR(addr) = ml->addr; + addr.ss_family = AF_INET; + GET_INADDR(dstadr) = ml->daddr; + dstadr.ss_family = AF_INET; + } +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR + addr.ss_len = SOCKLEN(&addr); + dstadr.ss_len = SOCKLEN(&dstadr); +#endif + if ((pcmd->nargs == 0) || + ((pcmd->argval->ival == 6) && (ml->v6_flag != 0)) || + ((pcmd->argval->ival == 4) && (ml->v6_flag == 0))) + (void) fprintf(fp, + "%-22.22s %5d %-15s %8ld %1d %1d %6lx %6lu %7lu\n", + nntohost(&addr), + ntohs(ml->port), + stoa(&dstadr), + (u_long)ntohl(ml->count), + ml->mode, + ml->version, + (u_long)ntohl(ml->lastdrop), + (u_long)ntohl(ml->lasttime), + (u_long)ntohl(ml->firsttime)); ml++; items--; } - } else if (itemsize == sizeof(struct info_monitor)) { + } else if (itemsize == sizeof(struct info_monitor) || + itemsize == v4sizeof(struct info_monitor)) { struct info_monitor *ml = (struct info_monitor *) struct_star; (void) fprintf(fp, - " address port count mode ver lastdrop lasttime firsttime\n"); + " address port count mode ver code avgint lstint\n"); (void) fprintf(fp, "===============================================================================\n"); while (items > 0) { - addr.s_addr = ml->lastdrop; - (void) fprintf(fp, - "%-25.25s %5d %9ld %4d %2d %9lu %9lu %9lu\n", - nntohost(ml->addr), - ntohs(ml->port), - (u_long)ntohl(ml->count), - ml->mode, - ml->version, - (u_long)ntohl(ml->lastdrop), - (u_long)ntohl(ml->lasttime), - (u_long)ntohl(ml->firsttime)); + memset((char *)&dstadr, 0, sizeof(dstadr)); + if (ml->v6_flag != 0) { + GET_INADDR6(dstadr) = ml->addr6; + dstadr.ss_family = AF_INET6; + } else { + GET_INADDR(dstadr) = ml->addr; + dstadr.ss_family = AF_INET; + } +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR + dstadr.ss_len = SOCKLEN(&dstadr); +#endif + if ((pcmd->nargs == 0) || + ((pcmd->argval->ival == 6) && (ml->v6_flag != 0)) || + ((pcmd->argval->ival == 4) && (ml->v6_flag == 0))) + (void) fprintf(fp, + "%-25.25s %5d %9ld %4d %2d %9lx %9lu %9lu\n", + nntohost(&dstadr), + ntohs(ml->port), + (u_long)ntohl(ml->count), + ml->mode, + ml->version, + (u_long)ntohl(ml->lastdrop), + (u_long)ntohl(ml->lasttime), + (u_long)ntohl(ml->firsttime)); ml++; items--; } @@ -1626,8 +1991,19 @@ monlist( (void) fprintf(fp, "======================================================================\n"); while (items > 0) { + memset((char *)&dstadr, 0, sizeof(dstadr)); + if (oml->v6_flag != 0) { + GET_INADDR6(dstadr) = oml->addr6; + dstadr.ss_family = AF_INET6; + } else { + GET_INADDR(dstadr) = oml->addr; + dstadr.ss_family = AF_INET; + } +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR + dstadr.ss_len = SOCKLEN(&dstadr); +#endif (void) fprintf(fp, "%-20.20s %5d %9ld %4d %3d %9lu %9lu\n", - nntohost(oml->addr), + nntohost(&dstadr), ntohs(oml->port), (u_long)ntohl(oml->count), oml->mode, @@ -1698,10 +2074,16 @@ reset( return; } - res = doquery(IMPL_XNTPD, REQ_RESET_STATS, 1, 1, +again: + res = doquery(impl_ver, REQ_RESET_STATS, 1, 1, sizeof(struct reset_flags), (char *)&rflags, &items, - &itemsize, &dummy, 0); + &itemsize, &dummy, 0, sizeof(struct reset_flags)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res == 0) (void) fprintf(fp, "done!\n"); return; @@ -1719,21 +2101,47 @@ preset( ) { /* 8 is the maximum number of peers which will fit in a packet */ - struct conf_unpeer plist[min(MAXARGS, 8)]; + struct conf_unpeer *pl, plist[min(MAXARGS, 8)]; int qitems; int items; int itemsize; char *dummy; int res; - - for (qitems = 0; qitems < min(pcmd->nargs, 8); qitems++) { - plist[qitems].peeraddr = pcmd->argval[qitems].netnum; + int sendsize; + +again: + if (impl_ver == IMPL_XNTPD) + sendsize = sizeof(struct conf_unpeer); + else + sendsize = v4sizeof(struct conf_unpeer); + + for (qitems = 0, pl = plist; qitems < min(pcmd->nargs, 8); qitems++) { + if (pcmd->argval[qitems].netnum.ss_family == AF_INET) { + pl->peeraddr = GET_INADDR(pcmd->argval[qitems].netnum); + if (impl_ver == IMPL_XNTPD) + pl->v6_flag = 0; + } else { + if (impl_ver == IMPL_XNTPD_OLD) { + fprintf(stderr, + "***Server doesn't understand IPv6 addresses\n"); + return; + } + pl->peeraddr6 = + GET_INADDR6(pcmd->argval[qitems].netnum); + pl->v6_flag = 1; + } + pl = (struct conf_unpeer *)((char *)pl + sendsize); } - res = doquery(IMPL_XNTPD, REQ_RESET_PEER, 1, qitems, - sizeof(struct conf_unpeer), (char *)plist, &items, - &itemsize, &dummy, 0); + res = doquery(impl_ver, REQ_RESET_PEER, 1, qitems, + sendsize, (char *)plist, &items, + &itemsize, &dummy, 0, sizeof(struct conf_unpeer)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res == 0) (void) fprintf(fp, "done!\n"); } @@ -1754,9 +2162,15 @@ readkeys( char *dummy; int res; - res = doquery(IMPL_XNTPD, REQ_REREAD_KEYS, 1, 0, 0, (char *)0, - &items, &itemsize, &dummy, 0); +again: + res = doquery(impl_ver, REQ_REREAD_KEYS, 1, 0, 0, (char *)0, + &items, &itemsize, &dummy, 0, sizeof(dummy)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res == 0) (void) fprintf(fp, "done!\n"); return; @@ -1812,9 +2226,16 @@ do_trustkey( keyids[ritems++] = pcmd->argval[i].uval; } - res = doquery(IMPL_XNTPD, req, 1, ritems, sizeof(u_long), - (char *)keyids, &items, &itemsize, &dummy, 0); +again: + res = doquery(impl_ver, req, 1, ritems, sizeof(u_long), + (char *)keyids, &items, &itemsize, &dummy, 0, + sizeof(dummy)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res == 0) (void) fprintf(fp, "done!\n"); return; @@ -1837,9 +2258,16 @@ authinfo( int itemsize; int res; - res = doquery(IMPL_XNTPD, REQ_AUTHINFO, 0, 0, 0, (char *)NULL, - &items, &itemsize, (char **)&ia, 0); +again: + res = doquery(impl_ver, REQ_AUTHINFO, 0, 0, 0, (char *)NULL, + &items, &itemsize, (void *)&ia, 0, + sizeof(struct info_auth)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; @@ -1883,32 +2311,58 @@ traps( { int i; struct info_trap *it; + struct sockaddr_storage trap_addr, local_addr; int items; int itemsize; int res; - res = doquery(IMPL_XNTPD, REQ_TRAPS, 0, 0, 0, (char *)NULL, - &items, &itemsize, (char **)&it, 0); +again: + res = doquery(impl_ver, REQ_TRAPS, 0, 0, 0, (char *)NULL, + &items, &itemsize, (void *)&it, 0, + sizeof(struct info_trap)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; if (!checkitems(items, fp)) return; - if (!checkitemsize(itemsize, sizeof(struct info_trap))) + if (!checkitemsize(itemsize, sizeof(struct info_trap)) && + !checkitemsize(itemsize, v4sizeof(struct info_trap))) return; for (i = 0; i < items; i++ ) { if (i != 0) (void) fprintf(fp, "\n"); + memset((char *)&trap_addr, 0, sizeof(trap_addr)); + memset((char *)&local_addr, 0, sizeof(local_addr)); + if (it->v6_flag != 0) { + GET_INADDR6(trap_addr) = it->trap_address6; + GET_INADDR6(local_addr) = it->local_address6; + trap_addr.ss_family = AF_INET6; + local_addr.ss_family = AF_INET6; + } else { + GET_INADDR(trap_addr) = it->trap_address; + GET_INADDR(local_addr) = it->local_address; + trap_addr.ss_family = AF_INET; + local_addr.ss_family = AF_INET; + } +#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR + trap_addr.ss_len = SOCKLEN(&trap_addr); + local_addr.ss_len = SOCKLEN(&local_addr); +#endif (void) fprintf(fp, "address %s, port %d\n", - numtoa(it->trap_address), ntohs(it->trap_port)); + stoa(&trap_addr), + ntohs(it->trap_port)); (void) fprintf(fp, "interface: %s, ", - (it->local_address == 0) - ? "wildcard" - : numtoa(it->local_address)); - + (it->local_address == 0) + ? "wildcard" + : stoa(&local_addr)); if (ntohl(it->flags) & TRAP_CONFIGURED) (void) fprintf(fp, "configured\n"); else if (ntohl(it->flags) & TRAP_NONPRIO) @@ -1967,8 +2421,27 @@ do_addclr_trap( int itemsize; char *dummy; int res; - - ctrap.trap_address = pcmd->argval[0].netnum; + int sendsize; + +again: + if (impl_ver == IMPL_XNTPD) + sendsize = sizeof(struct conf_trap); + else + sendsize = v4sizeof(struct conf_trap); + + if (pcmd->argval[0].netnum.ss_family == AF_INET) { + ctrap.trap_address = GET_INADDR(pcmd->argval[0].netnum); + if (impl_ver == IMPL_XNTPD) + ctrap.v6_flag = 0; + } else { + if (impl_ver == IMPL_XNTPD_OLD) { + fprintf(stderr, + "***Server doesn't understand IPv6 addresses\n"); + return; + } + ctrap.trap_address6 = GET_INADDR6(pcmd->argval[0].netnum); + ctrap.v6_flag = 1; + } ctrap.local_address = 0; ctrap.trap_port = htons(TRAPPORT); ctrap.unused = 0; @@ -1976,13 +2449,29 @@ do_addclr_trap( if (pcmd->nargs > 1) { ctrap.trap_port = htons((u_short)(pcmd->argval[1].uval & 0xffff)); - if (pcmd->nargs > 2) - ctrap.local_address = pcmd->argval[2].netnum; + if (pcmd->nargs > 2) { + if (pcmd->argval[2].netnum.ss_family != + pcmd->argval[0].netnum.ss_family) { + fprintf(stderr, + "***Cannot mix IPv4 and IPv6 addresses\n"); + return; + } + if (pcmd->argval[2].netnum.ss_family == AF_INET) + ctrap.local_address = GET_INADDR(pcmd->argval[2].netnum); + else + ctrap.local_address6 = GET_INADDR6(pcmd->argval[2].netnum); + } } - res = doquery(IMPL_XNTPD, req, 1, 1, sizeof(struct conf_trap), - (char *)&ctrap, &items, &itemsize, &dummy, 0); + res = doquery(impl_ver, req, 1, 1, sendsize, + (char *)&ctrap, &items, &itemsize, &dummy, 0, + sizeof(struct conf_trap)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res == 0) (void) fprintf(fp, "done!\n"); return; @@ -2036,9 +2525,16 @@ do_changekey( key = htonl((u_int32)pcmd->argval[0].uval); - res = doquery(IMPL_XNTPD, req, 1, 1, sizeof(u_int32), - (char *)&key, &items, &itemsize, &dummy, 0); +again: + res = doquery(impl_ver, req, 1, 1, sizeof(u_int32), + (char *)&key, &items, &itemsize, &dummy, 0, + sizeof(dummy)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res == 0) (void) fprintf(fp, "done!\n"); return; @@ -2061,9 +2557,16 @@ ctlstats( int itemsize; int res; - res = doquery(IMPL_XNTPD, REQ_GET_CTLSTATS, 0, 0, 0, (char *)NULL, - &items, &itemsize, (char **)&ic, 0); +again: + res = doquery(impl_ver, REQ_GET_CTLSTATS, 0, 0, 0, (char *)NULL, + &items, &itemsize, (void *)&ic, 0, + sizeof(struct info_control)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; @@ -2127,12 +2630,18 @@ clockstat( u_long ltemp; for (qitems = 0; qitems < min(pcmd->nargs, 8); qitems++) - clist[qitems] = pcmd->argval[qitems].netnum; + clist[qitems] = GET_INADDR(pcmd->argval[qitems].netnum); - res = doquery(IMPL_XNTPD, REQ_GET_CLOCKINFO, 0, qitems, +again: + res = doquery(impl_ver, REQ_GET_CLOCKINFO, 0, qitems, sizeof(u_int32), (char *)clist, &items, - &itemsize, (char **)&cl, 0); + &itemsize, (void *)&cl, 0, sizeof(struct info_clock)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; @@ -2211,7 +2720,7 @@ fudge( err = 0; memset((char *)&fudgedata, 0, sizeof fudgedata); - fudgedata.clockadr = pcmd->argval[0].netnum; + fudgedata.clockadr = GET_INADDR(pcmd->argval[0].netnum); if (STREQ(pcmd->argval[1].string, "time1")) { fudgedata.which = htonl(FUDGE_TIME1); @@ -2255,10 +2764,15 @@ fudge( return; } - - res = doquery(IMPL_XNTPD, REQ_SET_CLKFUDGE, 1, 1, +again: + res = doquery(impl_ver, REQ_SET_CLKFUDGE, 1, 1, sizeof(struct conf_fudge), (char *)&fudgedata, &items, - &itemsize, &dummy, 0); + &itemsize, &dummy, 0, sizeof(dummy)); + + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } if (res == 0) (void) fprintf(fp, "done!\n"); @@ -2289,12 +2803,18 @@ clkbug( l_fp ts; for (qitems = 0; qitems < min(pcmd->nargs, 8); qitems++) - clist[qitems] = pcmd->argval[qitems].netnum; + clist[qitems] = GET_INADDR(pcmd->argval[qitems].netnum); - res = doquery(IMPL_XNTPD, REQ_GET_CLKBUGINFO, 0, qitems, +again: + res = doquery(impl_ver, REQ_GET_CLKBUGINFO, 0, qitems, sizeof(u_int32), (char *)clist, &items, - &itemsize, (char **)&cl, 0); + &itemsize, (void *)&cl, 0, sizeof(struct info_clkbug)); + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; @@ -2373,8 +2893,16 @@ kerninfo( unsigned status; double tscale = 1e-6; - res = doquery(IMPL_XNTPD, REQ_GET_KERNEL, 0, 0, 0, (char *)NULL, - &items, &itemsize, (char **)&ik, 0); +again: + res = doquery(impl_ver, REQ_GET_KERNEL, 0, 0, 0, (char *)NULL, + &items, &itemsize, (void *)&ik, 0, + sizeof(struct info_kernel)); + + if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { + impl_ver = IMPL_XNTPD_OLD; + goto again; + } + if (res != 0 && items == 0) return; if (!check1item(items, fp)) |