diff options
Diffstat (limited to 'ntpdc')
-rw-r--r-- | ntpdc/Makefile.am | 41 | ||||
-rw-r--r-- | ntpdc/Makefile.in | 291 | ||||
-rw-r--r-- | ntpdc/layout.std | 8 | ||||
-rwxr-xr-x | ntpdc/nl.pl | 2 | ||||
-rw-r--r-- | ntpdc/ntpdc-opts.c | 435 | ||||
-rw-r--r-- | ntpdc/ntpdc-opts.def | 4 | ||||
-rw-r--r-- | ntpdc/ntpdc-opts.h | 150 | ||||
-rw-r--r-- | ntpdc/ntpdc-opts.texi | 199 | ||||
-rw-r--r-- | ntpdc/ntpdc.1 | 19 | ||||
-rw-r--r-- | ntpdc/ntpdc.c | 555 | ||||
-rw-r--r-- | ntpdc/ntpdc.h | 8 | ||||
-rw-r--r-- | ntpdc/ntpdc_ops.c | 1077 |
12 files changed, 1447 insertions, 1342 deletions
diff --git a/ntpdc/Makefile.am b/ntpdc/Makefile.am index 858c523..00aeffb 100644 --- a/ntpdc/Makefile.am +++ b/ntpdc/Makefile.am @@ -1,13 +1,21 @@ -AUTOMAKE_OPTIONS= ../util/ansi2knr +NULL= +AUTOMAKE_OPTIONS= -bindir= ${exec_prefix}/${BINSUBDIR} +if NTP_BINSUBDIR_IS_BIN bin_PROGRAMS= ntpdc +else +sbin_PROGRAMS= ntpdc +endif + EXTRA_PROGRAMS= ntpdc-layout EXTRA_DATA= check-layout -BUILT_SOURCES= @MAKE_CHECK_LAYOUT@ -AM_CPPFLAGS= -I$(top_srcdir)/include $(LIBOPTS_CFLAGS) +BUILT_SOURCES= @MAKE_CHECK_LAYOUT@ ntpdc-opts.c ntpdc-opts.h +AM_CPPFLAGS= -I$(top_srcdir)/include -I$(top_srcdir)/lib/isc/include \ + -I$(top_srcdir)/lib/isc/nothreads/include \ + -I$(top_srcdir)/lib/isc/unix/include $(LIBOPTS_CFLAGS) # LDADD might need RESLIB and ADJLIB -ntpdc_LDADD= version.o @READLINE_LIBS@ $(LIBOPTS_LDADD) ../libntp/libntp.a +ntpdc_LDADD= version.o $(LIBOPTS_LDADD) ../libntp/libntp.a \ + @EDITLINE_LIBS@ @LCRYPTO@ # ntpdc-layout doesn't need any additional libraries at all ntpdc_layout_LDADD= DISTCLEANFILES= .version version.c @@ -16,10 +24,10 @@ noinst_HEADERS= ntpdc.h ETAGS_ARGS= Makefile.am EXTRA_DIST= nl_in.c nl.pl layout.std \ ntpdc-opts.def ntpdc.1 ntpdc-opts.texi ntpdc-opts.menu -BUILT_SOURCES+= ntpdc-opts.c ntpdc-opts.h ntpdc.1 ntpdc-opts.texi \ - ntpdc-opts.menu -man_MANS= ntpdc.1 -run_ag= cd $(srcdir) && autogen -L ../include --writable +man_MANS= $(srcdir)/ntpdc.1 +noinst_DATA= $(srcdir)/ntpdc-opts.texi $(srcdir)/ntpdc-opts.menu +run_ag= cd $(srcdir) && env PATH="$(abs_builddir):$(PATH)" \ + autogen -L ../include --writable std_def_list= $(top_srcdir)/include/debug-opt.def \ $(top_srcdir)/include/autogen-version.def \ $(top_srcdir)/include/copyright.def \ @@ -27,14 +35,20 @@ std_def_list= $(top_srcdir)/include/debug-opt.def \ $(top_srcdir)/include/version.def $(srcdir)/ntpdc-opts.h: $(srcdir)/ntpdc-opts.c + @: do-nothing action to avoid default SCCS get, .h built with .c + $(srcdir)/ntpdc-opts.c: $(srcdir)/ntpdc-opts.def $(std_def_list) $(run_ag) ntpdc-opts.def $(srcdir)/ntpdc.1: $(srcdir)/ntpdc-opts.def $(std_def_list) $(run_ag) -Tagman1.tpl -bntpdc ntpdc-opts.def -$(srcdir)/ntpdc-opts.texi $(srcdir)/ntpdc-opts.menu: $(srcdir)/ntpdc-opts.def $(std_def_list) +$(srcdir)/ntpdc-opts.menu: $(srcdir)/ntpdc-opts.texi + @: do-nothing action to avoid default SCCS get, .menu built with .texi + +$(srcdir)/ntpdc-opts.texi: $(srcdir)/ntpdc-opts.def $(std_def_list) $(run_ag) -Taginfo.tpl -DLEVEL=section ntpdc-opts.def + $(top_srcdir)/scripts/check--help $@ ntpdc_SOURCES = ntpdc.c ntpdc_ops.c ntpdc-opts.c ntpdc-opts.h @@ -43,7 +57,7 @@ ntpdc-layout.o: nl.c layout.here: ntpdc-layout ./ntpdc-layout > $@ -check-layout: ntpdc-layout layout.std layout.here +check-layout: ntpdc-layout $(srcdir)/layout.std layout.here cmp $(srcdir)/layout.std layout.here && echo stamp > $@ $(PROGRAMS): $(LDADD) @@ -60,7 +74,8 @@ version.o: $(ntpdc_OBJECTS) ../libntp/libntp.a Makefile $(top_srcdir)/version # 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 Makefile.am +nl.c: nl_in.c nl.pl Makefile.am ../config.h ../include/ntp_request.h ntpdc.h $(CC) -E $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(srcdir)/nl_in.c | ./nl.pl > nl.c -include ../bincheck.mf +include $(top_srcdir)/bincheck.mf +include $(top_srcdir)/depsver.mf diff --git a/ntpdc/Makefile.in b/ntpdc/Makefile.in index 0e4ce77..39ddb0f 100644 --- a/ntpdc/Makefile.in +++ b/ntpdc/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.11 from Makefile.am. +# Makefile.in generated by automake 1.11.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -20,6 +20,7 @@ # subdir to warn folks if there is another version there. + VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ @@ -39,16 +40,23 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -ANSI2KNR = ../util/ansi2knr -bin_PROGRAMS = ntpdc$(EXEEXT) +@NTP_BINSUBDIR_IS_BIN_TRUE@bin_PROGRAMS = ntpdc$(EXEEXT) +@NTP_BINSUBDIR_IS_BIN_FALSE@sbin_PROGRAMS = ntpdc$(EXEEXT) EXTRA_PROGRAMS = ntpdc-layout$(EXEEXT) -DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/../bincheck.mf \ - $(srcdir)/Makefile.am $(srcdir)/Makefile.in $(srcdir)/nl.pl.in +DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in $(srcdir)/nl.pl.in \ + $(top_srcdir)/bincheck.mf $(top_srcdir)/depsver.mf subdir = ntpdc ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/libopts/m4/libopts.m4 \ - $(top_srcdir)/m4/define_dir.m4 \ - $(top_srcdir)/m4/hs_ulong_const.m4 \ +am__aclocal_m4_deps = $(top_srcdir)/sntp/libopts/m4/libopts.m4 \ + $(top_srcdir)/m4/define_dir.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/m4/ntp_cacheversion.m4 \ + $(top_srcdir)/m4/ntp_dir_sep.m4 \ + $(top_srcdir)/m4/ntp_lineeditlibs.m4 \ + $(top_srcdir)/m4/ntp_openssl.m4 \ + $(top_srcdir)/m4/ntp_vpathhack.m4 \ $(top_srcdir)/m4/os_cflags.m4 $(top_srcdir)/version.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ @@ -57,16 +65,17 @@ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = nl.pl CONFIG_CLEAN_VPATH_FILES = -am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" -PROGRAMS = $(bin_PROGRAMS) -am_ntpdc_OBJECTS = ntpdc$U.$(OBJEXT) ntpdc_ops$U.$(OBJEXT) \ - ntpdc-opts$U.$(OBJEXT) +am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(sbindir)" \ + "$(DESTDIR)$(man1dir)" +PROGRAMS = $(bin_PROGRAMS) $(sbin_PROGRAMS) +am_ntpdc_OBJECTS = ntpdc.$(OBJEXT) ntpdc_ops.$(OBJEXT) \ + ntpdc-opts.$(OBJEXT) ntpdc_OBJECTS = $(am_ntpdc_OBJECTS) am__DEPENDENCIES_1 = ntpdc_DEPENDENCIES = version.o $(am__DEPENDENCIES_1) \ ../libntp/libntp.a ntpdc_layout_SOURCES = ntpdc-layout.c -ntpdc_layout_OBJECTS = ntpdc-layout$U.$(OBJEXT) +ntpdc_layout_OBJECTS = ntpdc-layout.$(OBJEXT) ntpdc_layout_DEPENDENCIES = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -107,6 +116,7 @@ am__base_list = \ man1dir = $(mandir)/man1 NROFF = nroff MANS = $(man_MANS) +DATA = $(noinst_DATA) HEADERS = $(noinst_HEADERS) ETAGS = etags CTAGS = ctags @@ -114,7 +124,6 @@ DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AR = @AR@ -ARLIB_DIR = @ARLIB_DIR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ @@ -131,14 +140,18 @@ CYGPATH_W = @CYGPATH_W@ DCFD = @DCFD@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ -ECHO = @ECHO@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ +EDITLINE_LIBS = @EDITLINE_LIBS@ EF_LIBS = @EF_LIBS@ EF_PROGS = @EF_PROGS@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ +FGREP = @FGREP@ GREP = @GREP@ HAVE_INLINE = @HAVE_INLINE@ INSTALL = @INSTALL@ @@ -147,6 +160,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LCRYPTO = @LCRYPTO@ +LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBOPTS_CFLAGS = @LIBOPTS_CFLAGS@ @@ -155,6 +169,7 @@ LIBOPTS_LDADD = @LIBOPTS_LDADD@ LIBPARSE = @LIBPARSE@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ LN_S = @LN_S@ LSCF = @LSCF@ LTLIBOBJS = @LTLIBOBJS@ @@ -166,15 +181,22 @@ MAKE_LIBNTPSIM = @MAKE_LIBNTPSIM@ MAKE_LIBPARSE = @MAKE_LIBPARSE@ MAKE_LIBPARSE_KERNEL = @MAKE_LIBPARSE_KERNEL@ MAKE_NTPDSIM = @MAKE_NTPDSIM@ +MAKE_NTPSNMPD = @MAKE_NTPSNMPD@ MAKE_NTPTIME = @MAKE_NTPTIME@ MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@ MAKE_TICKADJ = @MAKE_TICKADJ@ MAKE_TIMETRIM = @MAKE_TIMETRIM@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OPENSSL = @OPENSSL@ OPENSSL_INC = @OPENSSL_INC@ OPENSSL_LIB = @OPENSSL_LIB@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ @@ -182,29 +204,38 @@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_NET_SNMP_CONFIG = @PATH_NET_SNMP_CONFIG@ PATH_PERL = @PATH_PERL@ PATH_SEPARATOR = @PATH_SEPARATOR@ PATH_SH = @PATH_SH@ +PATH_TEST = @PATH_TEST@ +POSIX_SHELL = @POSIX_SHELL@ PROPDELAY = @PROPDELAY@ RANLIB = @RANLIB@ -READLINE_LIBS = @READLINE_LIBS@ +SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SNMP_CFLAGS = @SNMP_CFLAGS@ +SNMP_CPPFLAGS = @SNMP_CPPFLAGS@ +SNMP_LIBS = @SNMP_LIBS@ STRIP = @STRIP@ TESTDCF = @TESTDCF@ -U = @U@ VERSION = @VERSION@ +YACC = @YACC@ +YFLAGS = @YFLAGS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ -bindir = ${exec_prefix}/${BINSUBDIR} +bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ @@ -245,24 +276,33 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -AUTOMAKE_OPTIONS = ../util/ansi2knr +NULL = +AUTOMAKE_OPTIONS = EXTRA_DATA = check-layout -BUILT_SOURCES = @MAKE_CHECK_LAYOUT@ ntpdc-opts.c ntpdc-opts.h ntpdc.1 \ - ntpdc-opts.texi ntpdc-opts.menu -AM_CPPFLAGS = -I$(top_srcdir)/include $(LIBOPTS_CFLAGS) +BUILT_SOURCES = @MAKE_CHECK_LAYOUT@ ntpdc-opts.c ntpdc-opts.h \ + .deps-ver +AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/lib/isc/include \ + -I$(top_srcdir)/lib/isc/nothreads/include \ + -I$(top_srcdir)/lib/isc/unix/include $(LIBOPTS_CFLAGS) + # LDADD might need RESLIB and ADJLIB -ntpdc_LDADD = version.o @READLINE_LIBS@ $(LIBOPTS_LDADD) ../libntp/libntp.a +ntpdc_LDADD = version.o $(LIBOPTS_LDADD) ../libntp/libntp.a \ + @EDITLINE_LIBS@ @LCRYPTO@ + # 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 +CLEANFILES = check-layout layout.here nl.c ntpdc-layout .deps-ver noinst_HEADERS = ntpdc.h ETAGS_ARGS = Makefile.am EXTRA_DIST = nl_in.c nl.pl layout.std \ ntpdc-opts.def ntpdc.1 ntpdc-opts.texi ntpdc-opts.menu -man_MANS = ntpdc.1 -run_ag = cd $(srcdir) && autogen -L ../include --writable +man_MANS = $(srcdir)/ntpdc.1 +noinst_DATA = $(srcdir)/ntpdc-opts.texi $(srcdir)/ntpdc-opts.menu +run_ag = cd $(srcdir) && env PATH="$(abs_builddir):$(PATH)" \ + autogen -L ../include --writable + std_def_list = $(top_srcdir)/include/debug-opt.def \ $(top_srcdir)/include/autogen-version.def \ $(top_srcdir)/include/copyright.def \ @@ -275,7 +315,7 @@ all: $(BUILT_SOURCES) .SUFFIXES: .SUFFIXES: .c .lo .o .obj -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(srcdir)/../bincheck.mf $(am__configure_deps) +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/bincheck.mf $(top_srcdir)/depsver.mf $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -350,6 +390,49 @@ clean-binPROGRAMS: list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list +install-sbinPROGRAMS: $(sbin_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(sbindir)" || $(MKDIR_P) "$(DESTDIR)$(sbindir)" + @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p || test -f $$p1; \ + then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(sbindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(sbindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-sbinPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(sbindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(sbindir)" && rm -f $$files + +clean-sbinPROGRAMS: + @list='$(sbin_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list ntpdc$(EXEEXT): $(ntpdc_OBJECTS) $(ntpdc_DEPENDENCIES) @rm -f ntpdc$(EXEEXT) $(LINK) $(ntpdc_OBJECTS) $(ntpdc_LDADD) $(LIBS) @@ -362,16 +445,11 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -../util/ansi2knr: - $(am__cd) ../util && $(MAKE) $(AM_MAKEFLAGS) ./ansi2knr - -mostlyclean-kr: - -test "$U" = "" || rm -f *_.c -@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-opts$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpdc_ops$U.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpdc-layout.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpdc-opts.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpdc.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpdc_ops.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -393,17 +471,6 @@ mostlyclean-kr: @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< -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) > $@ || 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-opts_.c: ntpdc-opts.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntpdc-opts.c; then echo $(srcdir)/ntpdc-opts.c; else echo ntpdc-opts.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) > $@ || rm -f $@ -ntpdc_.$(OBJEXT) ntpdc_.lo ntpdc-layout_.$(OBJEXT) ntpdc-layout_.lo \ -ntpdc-opts_.$(OBJEXT) ntpdc-opts_.lo ntpdc_ops_.$(OBJEXT) \ -ntpdc_ops_.lo : $(ANSI2KNR) mostlyclean-libtool: -rm -f *.lo @@ -547,9 +614,9 @@ distdir: $(DISTFILES) check-am: all-am check: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) check-am -all-am: Makefile $(PROGRAMS) $(MANS) $(HEADERS) +all-am: Makefile $(PROGRAMS) $(MANS) $(DATA) $(HEADERS) installdirs: - for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"; do \ + for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man1dir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: $(BUILT_SOURCES) @@ -583,7 +650,8 @@ maintainer-clean-generic: -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) clean: clean-am -clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am +clean-am: clean-binPROGRAMS clean-generic clean-libtool \ + clean-sbinPROGRAMS mostlyclean-am distclean: distclean-am -rm -rf ./$(DEPDIR) @@ -609,7 +677,7 @@ install-dvi: install-dvi-am install-dvi-am: -install-exec-am: install-binPROGRAMS +install-exec-am: install-binPROGRAMS install-sbinPROGRAMS @$(NORMAL_INSTALL) $(MAKE) $(AM_MAKEFLAGS) install-exec-hook install-html: install-html-am @@ -639,7 +707,7 @@ maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am -mostlyclean-am: mostlyclean-compile mostlyclean-generic mostlyclean-kr \ +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf: pdf-am @@ -650,45 +718,52 @@ ps: ps-am ps-am: -uninstall-am: uninstall-binPROGRAMS uninstall-man +uninstall-am: uninstall-binPROGRAMS uninstall-man \ + uninstall-sbinPROGRAMS uninstall-man: uninstall-man1 -.MAKE: ../util/ansi2knr all check install install-am install-exec-am \ - install-strip +.MAKE: all check install install-am install-exec-am install-strip .PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ - clean-generic clean-libtool ctags distclean distclean-compile \ - distclean-generic distclean-libtool distclean-tags distdir dvi \ - dvi-am html html-am info info-am install install-am \ - install-binPROGRAMS install-data install-data-am install-dvi \ - install-dvi-am install-exec install-exec-am install-exec-hook \ - install-html install-html-am install-info install-info-am \ - install-man install-man1 install-pdf install-pdf-am install-ps \ - install-ps-am install-strip installcheck installcheck-am \ - installdirs maintainer-clean maintainer-clean-generic \ - mostlyclean mostlyclean-compile mostlyclean-generic \ - mostlyclean-kr mostlyclean-libtool pdf pdf-am ps ps-am tags \ - uninstall uninstall-am uninstall-binPROGRAMS uninstall-man \ - uninstall-man1 + clean-generic clean-libtool clean-sbinPROGRAMS ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-binPROGRAMS install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-exec-hook install-html install-html-am \ + install-info install-info-am install-man install-man1 \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-sbinPROGRAMS install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-binPROGRAMS \ + uninstall-man uninstall-man1 uninstall-sbinPROGRAMS $(srcdir)/ntpdc-opts.h: $(srcdir)/ntpdc-opts.c + @: do-nothing action to avoid default SCCS get, .h built with .c + $(srcdir)/ntpdc-opts.c: $(srcdir)/ntpdc-opts.def $(std_def_list) $(run_ag) ntpdc-opts.def $(srcdir)/ntpdc.1: $(srcdir)/ntpdc-opts.def $(std_def_list) $(run_ag) -Tagman1.tpl -bntpdc ntpdc-opts.def -$(srcdir)/ntpdc-opts.texi $(srcdir)/ntpdc-opts.menu: $(srcdir)/ntpdc-opts.def $(std_def_list) +$(srcdir)/ntpdc-opts.menu: $(srcdir)/ntpdc-opts.texi + @: do-nothing action to avoid default SCCS get, .menu built with .texi + +$(srcdir)/ntpdc-opts.texi: $(srcdir)/ntpdc-opts.def $(std_def_list) $(run_ag) -Taginfo.tpl -DLEVEL=section ntpdc-opts.def + $(top_srcdir)/scripts/check--help $@ ntpdc-layout.o: nl.c layout.here: ntpdc-layout ./ntpdc-layout > $@ -check-layout: ntpdc-layout layout.std layout.here +check-layout: ntpdc-layout $(srcdir)/layout.std layout.here cmp $(srcdir)/layout.std layout.here && echo stamp > $@ $(PROGRAMS): $(LDADD) @@ -705,20 +780,84 @@ version.o: $(ntpdc_OBJECTS) ../libntp/libntp.a Makefile $(top_srcdir)/version # 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 Makefile.am +nl.c: nl_in.c nl.pl Makefile.am ../config.h ../include/ntp_request.h ntpdc.h $(CC) -E $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(srcdir)/nl_in.c | ./nl.pl > nl.c install-exec-hook: - @case ${BINSUBDIR} in \ - bin) ODIR=${exec_prefix}/sbin ;; \ - sbin) ODIR=${exec_prefix}/bin ;; \ - esac; \ - test -z "${bin_PROGRAMS}${bin_SCRIPTS}" \ + @case ${BINSUBDIR} in \ + bin) ODIR=${sbindir} ;; \ + sbin) ODIR=${bindir} ;; \ + esac; \ + test -z "${bin_PROGRAMS}${bin_SCRIPTS}" \ || for i in ${bin_PROGRAMS} ${bin_SCRIPTS} " "; do \ test ! -f $$ODIR/$$i || echo "*** $$i is also in $$ODIR!"; \ done # +$(DEPDIR)/deps-ver: $(top_srcdir)/deps-ver + @[ -f $@ ] || \ + cp $(top_srcdir)/deps-ver $@ + @[ -w $@ ] || \ + chmod ug+w $@ + @cmp $(top_srcdir)/deps-ver $@ > /dev/null || ( \ + $(MAKE) clean && \ + echo -n "Prior $(subdir)/$(DEPDIR) version " && \ + cat $@ && \ + rm -rf $(DEPDIR) && \ + mkdir $(DEPDIR) && \ + case "$(top_builddir)" in \ + .) \ + ./config.status Makefile depfiles \ + ;; \ + ..) \ + cd .. && \ + ./config.status $(subdir)/Makefile depfiles && \ + cd $(subdir) \ + ;; \ + *) \ + echo 'Fatal: depsver.mf Automake fragment limited' \ + 'to immediate subdirectories.' && \ + echo "top_builddir: $(top_builddir)" && \ + echo "subdir: $(subdir)" && \ + exit 1 \ + ;; \ + esac && \ + echo -n "Cleaned $(subdir)/$(DEPDIR) version " && \ + cat $(top_srcdir)/deps-ver \ + ) + cp $(top_srcdir)/deps-ver $@ + +.deps-ver: $(top_srcdir)/deps-ver + @[ ! -d $(DEPDIR) ] || $(MAKE) $(DEPDIR)/deps-ver + @touch $@ + +# +# depsver.mf included in Makefile.am for directories with .deps +# +# When building in the same directory with sources that change over +# time, such as when tracking using bk, the .deps files can become +# stale with respect to moved, deleted, or superceded headers. Most +# commonly, this would exhibit as make reporting a failure to make a +# header file which is no longer in the location given. To address +# this issue, we use a deps-ver file which is updated with each change +# that breaks old .deps files. A copy of deps-ver is made into +# $(DEPDIR) if not already present. If $(DEPDIR)/deps-ver is present +# with different contents than deps-ver, we make clean to ensure all +# .o files built before the incompatible change are rebuilt along with +# their updated .deps files, then remove $(DEPDIR) and recreate it as +# empty stubs. +# +# It is normal when configured with --disable-dependency-tracking for +# the DEPDIR to not have been created. For this reason, we use the +# intermediate target .deps-ver, which invokes make recursively if +# DEPDIR exists. +# +# If you modify depsver.mf, please make the changes to the master +# copy, the one in sntp is copied by the bootstrap script from it. +# +# This comment block follows rather than leads the related code so that +# it stays with it in the generated Makefile.in and Makefile. +# # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/ntpdc/layout.std b/ntpdc/layout.std index daff636..8d538d1 100644 --- a/ntpdc/layout.std +++ b/ntpdc/layout.std @@ -1,4 +1,4 @@ -sizeof(struct req_pkt) = 212 +sizeof(struct req_pkt) = 216 offsetof(rm_vn_mode) = 0 offsetof(auth_seq) = 1 offsetof(implementation) = 2 @@ -10,7 +10,7 @@ offsetof(tstamp) = 184 offsetof(keyid) = 192 offsetof(mac) = 196 -sizeof(struct req_pkt_tail) = 28 +sizeof(struct req_pkt_tail) = 32 offsetof(tstamp) = 0 offsetof(keyid) = 8 offsetof(mac) = 12 @@ -271,7 +271,7 @@ offsetof(mask6) = 32 sizeof(struct info_monitor_1) = 72 offsetof(lasttime) = 0 offsetof(firsttime) = 4 -offsetof(lastdrop) = 8 +offsetof(restr) = 8 offsetof(count) = 12 offsetof(addr) = 16 offsetof(daddr) = 20 @@ -287,7 +287,7 @@ offsetof(daddr6) = 56 sizeof(struct info_monitor) = 48 offsetof(lasttime) = 0 offsetof(firsttime) = 4 -offsetof(lastdrop) = 8 +offsetof(restr) = 8 offsetof(count) = 12 offsetof(addr) = 16 offsetof(port) = 20 diff --git a/ntpdc/nl.pl b/ntpdc/nl.pl index afea8b7..57d6d53 100755 --- a/ntpdc/nl.pl +++ b/ntpdc/nl.pl @@ -1,4 +1,4 @@ -#! /usr/local/bin/perl -w +#! /usr/local/perl-5.8.8/bin/perl -w $found = 0; $last = 0; diff --git a/ntpdc/ntpdc-opts.c b/ntpdc/ntpdc-opts.c index 41be37e..d84268d 100644 --- a/ntpdc/ntpdc-opts.c +++ b/ntpdc/ntpdc-opts.c @@ -1,31 +1,31 @@ /* * EDIT THIS FILE WITH CAUTION (ntpdc-opts.c) * - * It has been AutoGen-ed Tuesday December 8, 2009 at 08:14:00 AM EST + * It has been AutoGen-ed December 24, 2011 at 06:34:16 PM by AutoGen 5.12 * From the definitions ntpdc-opts.def * and the template file options * - * Generated from AutoOpts 29:0:4 templates. - */ - -/* - * This file was produced by an AutoOpts template. AutoOpts is a - * copyrighted work. This source file is not encumbered by AutoOpts - * licensing, but is provided under the licensing terms chosen by the - * ntpdc author or copyright holder. AutoOpts is licensed under - * the terms of the LGPL. The redistributable library (``libopts'') is - * licensed under the terms of either the LGPL or, at the users discretion, - * the BSD license. See the AutoOpts and/or libopts sources for details. + * Generated from AutoOpts 35:0:10 templates. * - * This source file is copyrighted and licensed under the following terms: + * AutoOpts is a copyrighted work. This source file is not encumbered + * by AutoOpts licensing, but is provided under the licensing terms chosen + * by the ntpdc author or copyright holder. AutoOpts is + * licensed under the terms of the LGPL. The redistributable library + * (``libopts'') is licensed under the terms of either the LGPL or, at the + * users discretion, the BSD license. See the AutoOpts and/or libopts sources + * for details. * - * ntpdc copyright 1970-2009 David L. Mills and/or others - all rights reserved + * This source file is copyrighted and licensed under the following terms: * - * see html/copyright.html + * see html/copyright.html + * */ +#include <sys/types.h> #include <limits.h> +#include <stdio.h> +#include <stdlib.h> #define OPTION_CODE_COMPILE 1 #include "ntpdc-opts.h" @@ -33,12 +33,16 @@ #ifdef __cplusplus extern "C" { #endif -tSCC zCopyright[] = - "ntpdc copyright (c) 1970-2009 David L. Mills and/or others, all rights reserved"; -tSCC zCopyrightNotice[] = - -/* extracted from ../include/copyright.def near line 8 */ -"see html/copyright.html"; +extern FILE * option_usage_fp; + +/* TRANSLATORS: choose the translation for option names wisely because you + cannot ever change your mind. */ +static char const zCopyright[39] = +"ntpdc 4.2.6p5\n\ +see html/copyright.html\n"; +static char const zLicenseDescrip[25] = +"see html/copyright.html\n"; + extern tUsageProc optionUsage; /* @@ -53,37 +57,40 @@ extern tUsageProc optionUsage; #ifndef NULL # define NULL 0 #endif -#ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -#endif -#ifndef EXIT_FAILURE -# define EXIT_FAILURE 1 -#endif + /* - * Ipv4 option description: + * Ipv4 option description with + * "Must also have options" and "Incompatible options": */ -tSCC zIpv4Text[] = +static char const zIpv4Text[] = "Force IPv4 DNS name resolution"; -tSCC zIpv4_NAME[] = "IPV4"; -tSCC zIpv4_Name[] = "ipv4"; +static char const zIpv4_NAME[] = "IPV4"; +static char const zIpv4_Name[] = "ipv4"; +static const int + aIpv4CantList[] = { + INDEX_OPT_IPV6, NO_EQUIVALENT }; #define IPV4_FLAGS (OPTST_DISABLED) /* - * Ipv6 option description: + * Ipv6 option description with + * "Must also have options" and "Incompatible options": */ -tSCC zIpv6Text[] = +static char const zIpv6Text[] = "Force IPv6 DNS name resolution"; -tSCC zIpv6_NAME[] = "IPV6"; -tSCC zIpv6_Name[] = "ipv6"; +static char const zIpv6_NAME[] = "IPV6"; +static char const zIpv6_Name[] = "ipv6"; +static const int + aIpv6CantList[] = { + INDEX_OPT_IPV4, NO_EQUIVALENT }; #define IPV6_FLAGS (OPTST_DISABLED) /* * Command option description: */ -tSCC zCommandText[] = +static char const zCommandText[] = "run a command and exit"; -tSCC zCommand_NAME[] = "COMMAND"; -tSCC zCommand_Name[] = "command"; +static char const zCommand_NAME[] = "COMMAND"; +static char const zCommand_Name[] = "command"; #define COMMAND_FLAGS (OPTST_DISABLED | OPTST_STACKED \ | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) @@ -91,10 +98,10 @@ tSCC zCommand_Name[] = "command"; * Listpeers option description with * "Must also have options" and "Incompatible options": */ -tSCC zListpeersText[] = +static char const zListpeersText[] = "Print a list of the peers"; -tSCC zListpeers_NAME[] = "LISTPEERS"; -tSCC zListpeers_Name[] = "listpeers"; +static char const zListpeers_NAME[] = "LISTPEERS"; +static char const zListpeers_Name[] = "listpeers"; static const int aListpeersCantList[] = { INDEX_OPT_COMMAND, NO_EQUIVALENT }; @@ -104,10 +111,10 @@ static const int * Peers option description with * "Must also have options" and "Incompatible options": */ -tSCC zPeersText[] = +static char const zPeersText[] = "Print a list of the peers"; -tSCC zPeers_NAME[] = "PEERS"; -tSCC zPeers_Name[] = "peers"; +static char const zPeers_NAME[] = "PEERS"; +static char const zPeers_Name[] = "peers"; static const int aPeersCantList[] = { INDEX_OPT_COMMAND, NO_EQUIVALENT }; @@ -117,10 +124,10 @@ static const int * Showpeers option description with * "Must also have options" and "Incompatible options": */ -tSCC zShowpeersText[] = +static char const zShowpeersText[] = "Show a list of the peers"; -tSCC zShowpeers_NAME[] = "SHOWPEERS"; -tSCC zShowpeers_Name[] = "showpeers"; +static char const zShowpeers_NAME[] = "SHOWPEERS"; +static char const zShowpeers_Name[] = "showpeers"; static const int aShowpeersCantList[] = { INDEX_OPT_COMMAND, NO_EQUIVALENT }; @@ -130,10 +137,10 @@ static const int * Interactive option description with * "Must also have options" and "Incompatible options": */ -tSCC zInteractiveText[] = +static char const zInteractiveText[] = "Force ntpq to operate in interactive mode"; -tSCC zInteractive_NAME[] = "INTERACTIVE"; -tSCC zInteractive_Name[] = "interactive"; +static char const zInteractive_NAME[] = "INTERACTIVE"; +static char const zInteractive_Name[] = "interactive"; static const int aInteractiveCantList[] = { INDEX_OPT_COMMAND, @@ -145,88 +152,69 @@ static const int /* * Debug_Level option description: */ -#ifdef DEBUG -tSCC zDebug_LevelText[] = +static char const zDebug_LevelText[] = "Increase output debug message level"; -tSCC zDebug_Level_NAME[] = "DEBUG_LEVEL"; -tSCC zDebug_Level_Name[] = "debug-level"; +static char const zDebug_Level_NAME[] = "DEBUG_LEVEL"; +static char const zDebug_Level_Name[] = "debug-level"; #define DEBUG_LEVEL_FLAGS (OPTST_DISABLED) -#else /* disable Debug_Level */ -#define VALUE_OPT_DEBUG_LEVEL NO_EQUIVALENT -#define DEBUG_LEVEL_FLAGS (OPTST_OMITTED | OPTST_NO_INIT) -#define zDebug_LevelText NULL -#define zDebug_Level_NAME NULL -#define zDebug_Level_Name NULL -#endif /* DEBUG */ - /* * Set_Debug_Level option description: */ -#ifdef DEBUG -tSCC zSet_Debug_LevelText[] = +static char const zSet_Debug_LevelText[] = "Set the output debug message level"; -tSCC zSet_Debug_Level_NAME[] = "SET_DEBUG_LEVEL"; -tSCC zSet_Debug_Level_Name[] = "set-debug-level"; +static char const zSet_Debug_Level_NAME[] = "SET_DEBUG_LEVEL"; +static char const zSet_Debug_Level_Name[] = "set-debug-level"; #define SET_DEBUG_LEVEL_FLAGS (OPTST_DISABLED \ | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) -#else /* disable Set_Debug_Level */ -#define VALUE_OPT_SET_DEBUG_LEVEL NO_EQUIVALENT -#define SET_DEBUG_LEVEL_FLAGS (OPTST_OMITTED | OPTST_NO_INIT) -#define zSet_Debug_LevelText NULL -#define zSet_Debug_Level_NAME NULL -#define zSet_Debug_Level_Name NULL -#endif /* DEBUG */ - /* * Numeric option description: */ -tSCC zNumericText[] = +static char const zNumericText[] = "numeric host addresses"; -tSCC zNumeric_NAME[] = "NUMERIC"; -tSCC zNumeric_Name[] = "numeric"; +static char const zNumeric_NAME[] = "NUMERIC"; +static char const zNumeric_Name[] = "numeric"; #define NUMERIC_FLAGS (OPTST_DISABLED) /* * Help/More_Help/Version option descriptions: */ -tSCC zHelpText[] = "Display usage information and exit"; -tSCC zHelp_Name[] = "help"; - -tSCC zMore_HelpText[] = "Extended usage information passed thru pager"; -tSCC zMore_Help_Name[] = "more-help"; - -tSCC zVersionText[] = "Output version information and exit"; -tSCC zVersion_Name[] = "version"; - -/* - * Save/Load_Opts option description: - */ -tSCC zSave_OptsText[] = "Save the option state to a config file"; -tSCC zSave_Opts_Name[] = "save-opts"; - -tSCC zLoad_OptsText[] = "Load options from a config file"; -tSCC zLoad_Opts_NAME[] = "LOAD_OPTS"; +static char const zHelpText[] = "Display extended usage information and exit"; +static char const zHelp_Name[] = "help"; +#ifdef HAVE_WORKING_FORK +#define OPTST_MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT) +static char const zMore_Help_Name[] = "more-help"; +static char const zMore_HelpText[] = "Extended usage information passed thru pager"; +#else +#define OPTST_MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT) +#define zMore_Help_Name NULL +#define zMore_HelpText NULL +#endif +#ifdef NO_OPTIONAL_OPT_ARGS +# define OPTST_VERSION_FLAGS OPTST_IMM | OPTST_NO_INIT +#else +# define OPTST_VERSION_FLAGS OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \ + OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT +#endif -tSCC zNotLoad_Opts_Name[] = "no-load-opts"; -tSCC zNotLoad_Opts_Pfx[] = "no"; +static char const zVersionText[] = "Output version information and exit"; +static char const zVersion_Name[] = "version"; +static char const zSave_OptsText[] = "Save the option state to a config file"; +static char const zSave_Opts_Name[] = "save-opts"; +static char const zLoad_OptsText[] = "Load options from a config file"; +static char const zLoad_Opts_NAME[] = "LOAD_OPTS"; +static char const zNotLoad_Opts_Name[] = "no-load-opts"; +static char const zNotLoad_Opts_Pfx[] = "no"; #define zLoad_Opts_Name (zNotLoad_Opts_Name + 3) /* * Declare option callback procedures */ -#ifdef DEBUG - static tOptProc doOptSet_Debug_Level; -#else /* not DEBUG */ -# define doOptSet_Debug_Level NULL -#endif /* def/not DEBUG */ #if defined(TEST_NTPDC_OPTS) /* * Under test, omit argument processing, or call optionStackArg, * if multiple copies are allowed. */ -extern tOptProc - optionPagedUsage, optionStackArg, optionVersionStderr; static tOptProc doUsageOpt; @@ -241,9 +229,12 @@ static tOptProc * When not under test, there are different procs to use */ extern tOptProc - optionPagedUsage, optionPrintVersion, optionStackArg; + optionBooleanVal, optionNestedVal, optionNumericVal, + optionPagedUsage, optionPrintVersion, optionResetOpt, + optionStackArg, optionTimeDate, optionTimeVal, + optionUnstackArg, optionVersionStderr; static tOptProc - doUsageOpt; + doOptSet_Debug_Level, doUsageOpt; /* * #define map the "normal" callout procs @@ -262,27 +253,27 @@ static tOptProc * * Define the Ntpdc Option Descriptions. */ -static tOptDesc optDesc[ OPTION_CT ] = { +static tOptDesc optDesc[OPTION_CT] = { { /* entry idx, value */ 0, VALUE_OPT_IPV4, - /* equiv idx, value */ NO_EQUIVALENT, 0, + /* equiv idx, value */ 0, VALUE_OPT_IPV4, /* equivalenced to */ NO_EQUIVALENT, /* min, max, act ct */ 0, 1, 0, /* opt state flags */ IPV4_FLAGS, 0, /* last opt argumnt */ { NULL }, /* arg list/cookie */ NULL, - /* must/cannot opts */ NULL, NULL, + /* must/cannot opts */ NULL, aIpv4CantList, /* option proc */ NULL, /* desc, NAME, name */ zIpv4Text, zIpv4_NAME, zIpv4_Name, /* disablement strs */ NULL, NULL }, { /* entry idx, value */ 1, VALUE_OPT_IPV6, - /* equiv idx, value */ NOLIMIT, NOLIMIT, - /* equivalenced to */ INDEX_OPT_IPV4, + /* equiv idx, value */ 1, VALUE_OPT_IPV6, + /* equivalenced to */ NO_EQUIVALENT, /* min, max, act ct */ 0, 1, 0, /* opt state flags */ IPV6_FLAGS, 0, /* last opt argumnt */ { NULL }, /* arg list/cookie */ NULL, - /* must/cannot opts */ NULL, NULL, + /* must/cannot opts */ NULL, aIpv6CantList, /* option proc */ NULL, /* desc, NAME, name */ zIpv6Text, zIpv6_NAME, zIpv6_Name, /* disablement strs */ NULL, NULL }, @@ -383,18 +374,11 @@ static tOptDesc optDesc[ OPTION_CT ] = { /* desc, NAME, name */ zNumericText, zNumeric_NAME, zNumeric_Name, /* disablement strs */ NULL, NULL }, -#ifdef NO_OPTIONAL_OPT_ARGS -# define VERSION_OPT_FLAGS OPTST_IMM | OPTST_NO_INIT -#else -# define VERSION_OPT_FLAGS OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \ - OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT -#endif - { /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION, /* equiv idx value */ NO_EQUIVALENT, 0, /* equivalenced to */ NO_EQUIVALENT, /* min, max, act ct */ 0, 1, 0, - /* opt state flags */ VERSION_OPT_FLAGS, 0, + /* opt state flags */ OPTST_VERSION_FLAGS, 0, /* last opt argumnt */ { NULL }, /* arg list/cookie */ NULL, /* must/cannot opts */ NULL, NULL, @@ -402,7 +386,6 @@ static tOptDesc optDesc[ OPTION_CT ] = { /* desc, NAME, name */ zVersionText, NULL, zVersion_Name, /* disablement strs */ NULL, NULL }, -#undef VERSION_OPT_FLAGS { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP, @@ -421,7 +404,7 @@ static tOptDesc optDesc[ OPTION_CT ] = { /* equiv idx value */ NO_EQUIVALENT, 0, /* equivalenced to */ NO_EQUIVALENT, /* min, max, act ct */ 0, 1, 0, - /* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0, + /* opt state flags */ OPTST_MORE_HELP_FLAGS, 0, /* last opt argumnt */ { NULL }, /* arg list/cookie */ NULL, /* must/cannot opts */ NULL, NULL, @@ -446,7 +429,7 @@ static tOptDesc optDesc[ OPTION_CT ] = { /* equiv idx value */ NO_EQUIVALENT, 0, /* equivalenced to */ NO_EQUIVALENT, /* min, max, act ct */ 0, NOLIMIT, 0, - /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) \ + /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | OPTST_DISABLE_IMM, 0, /* last opt argumnt */ { NULL }, /* arg list/cookie */ NULL, @@ -460,37 +443,30 @@ static tOptDesc optDesc[ OPTION_CT ] = { * * Define the Ntpdc Option Environment */ -tSCC zPROGNAME[] = "NTPDC"; -tSCC zUsageTitle[] = -"ntpdc - vendor-specific NTP query program - Ver. 4.2.4p8\n\ +static char const zPROGNAME[6] = "NTPDC"; +static char const zUsageTitle[127] = +"ntpdc - vendor-specific NTP query program - Ver. 4.2.6p5\n\ USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]... [ host ...]\n"; -tSCC zRcName[] = ".ntprc"; -tSCC* apzHomeList[] = { - "$HOME", - ".", - NULL }; +static char const zRcName[7] = ".ntprc"; +static char const * const apzHomeList[3] = { + "$HOME", + ".", + NULL }; -tSCC zBugsAddr[] = "http://bugs.ntp.org, bugs@ntp.org"; +static char const zBugsAddr[34] = "http://bugs.ntp.org, bugs@ntp.org"; #define zExplain NULL -tSCC zDetail[] = "\n\ -The\n\ -[= prog-name =]\n\ -utility program is used to query an NTP daemon about its\n\ -current state and to request changes in that state.\n\ -It uses NTP mode 7 control message formats described in the source code.\n\ -The program may\n\ +static char const zDetail[601] = "\n\ +The [= prog-name =] utility program is used to query an NTP daemon about\n\ +its current state and to request changes in that state. It uses NTP mode\n\ +7 control message formats described in the source code. The program may\n\ be run either in interactive mode or controlled using command line\n\ -arguments.\n\ -Extensive state and statistics information is available\n\ -through the\n\ -[= prog-name =]\n\ -interface.\n\ -In addition, nearly all the\n\ -configuration options which can be specified at startup using\n\ -ntpd's configuration file may also be specified at run time using\n\ -[= prog-name =] .\n"; -tSCC zFullVersion[] = NTPDC_FULL_VERSION; -/* extracted from /usr/local/gnu/autogen-5.9.1/share/autogen/optcode.tpl near line 408 */ +arguments. Extensive state and statistics information is available\n\ +through the [= prog-name =] interface. In addition, nearly all the\n\ +configuration options which can be specified at startup using ntpd's\n\ +configuration file may also be specified at run time using [= prog-name =]\n\ +.\n"; +static char const zFullVersion[] = NTPDC_FULL_VERSION; +/* extracted from optcode.tlib near line 515 */ #if defined(ENABLE_NLS) # define OPTPROC_BASE OPTPROC_TRANSLATE @@ -500,6 +476,29 @@ tSCC zFullVersion[] = NTPDC_FULL_VERSION; # define translate_option_strings NULL #endif /* ENABLE_NLS */ + +#define ntpdc_full_usage NULL +#define ntpdc_short_usage NULL +#ifndef PKGDATADIR +# define PKGDATADIR "" +#endif + +#ifndef WITH_PACKAGER +# define ntpdc_packager_info NULL +#else +static char const ntpdc_packager_info[] = + "Packaged by " WITH_PACKAGER + +# ifdef WITH_PACKAGER_VERSION + " ("WITH_PACKAGER_VERSION")" +# endif + +# ifdef WITH_PACKAGER_BUG_REPORTS + "\nReport ntpdc bugs to " WITH_PACKAGER_BUG_REPORTS +# endif + "\n"; +#endif + tOptions ntpdcOptions = { OPTIONS_STRUCT_VERSION, 0, NULL, /* original argc + argv */ @@ -509,74 +508,72 @@ tOptions ntpdcOptions = { + OPTPROC_LONGOPT + OPTPROC_NO_REQ_OPT + OPTPROC_ENVIRON - + OPTPROC_HAS_IMMED ), + + OPTPROC_MISUSE ), 0, NULL, /* current option index, current option */ NULL, NULL, zPROGNAME, - zRcName, zCopyright, zCopyrightNotice, + zRcName, zCopyright, zLicenseDescrip, zFullVersion, apzHomeList, zUsageTitle, zExplain, zDetail, optDesc, zBugsAddr, /* address to send bugs to */ NULL, NULL, /* extensions/saved state */ - optionUsage, /* usage procedure */ + optionUsage, /* usage procedure */ translate_option_strings, /* translation procedure */ /* * Indexes to special options */ - { INDEX_OPT_MORE_HELP, - INDEX_OPT_SAVE_OPTS, - NO_EQUIVALENT /* index of '-#' option */, + { INDEX_OPT_MORE_HELP, /* more-help option index */ + INDEX_OPT_SAVE_OPTS, /* save option index */ + NO_EQUIVALENT, /* '-#' option index */ NO_EQUIVALENT /* index of default opt */ }, - 15 /* full option count */, 10 /* user option count */ + 15 /* full option count */, 10 /* user option count */, + ntpdc_full_usage, ntpdc_short_usage, + NULL, NULL, + PKGDATADIR, ntpdc_packager_info }; /* * Create the static procedure(s) declared above. */ static void -doUsageOpt( - tOptions* pOptions, - tOptDesc* pOptDesc ) +doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc) { - USAGE( EXIT_SUCCESS ); + (void)pOptions; + USAGE(NTPDC_EXIT_SUCCESS); } #if ! defined(TEST_NTPDC_OPTS) -/* * * * * * * +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * For the set-debug-level option, when DEBUG is #define-d. + * For the set-debug-level option. */ -#ifdef DEBUG static void -doOptSet_Debug_Level( - tOptions* pOptions, - tOptDesc* pOptDesc ) +doOptSet_Debug_Level(tOptions* pOptions, tOptDesc* pOptDesc) { - /* extracted from ../include/debug-opt.def, line 29 */ + /* extracted from debug-opt.def, line 27 */ DESC(DEBUG_LEVEL).optOccCt = atoi( pOptDesc->pzLastArg ); } -#endif /* defined DEBUG */ - #endif /* defined(TEST_NTPDC_OPTS) */ - -/* extracted from /usr/local/gnu/autogen-5.9.1/share/autogen/optmain.tpl near line 92 */ +/* extracted from optmain.tlib near line 128 */ #if defined(TEST_NTPDC_OPTS) /* TEST MAIN PROCEDURE: */ +extern void optionPutShell(tOptions*); + int -main( int argc, char** argv ) +main(int argc, char ** argv) { - int res = EXIT_SUCCESS; - (void)optionProcess( &ntpdcOptions, argc, argv ); - { - void optionPutShell( tOptions* ); - optionPutShell( &ntpdcOptions ); - } + int res = NTPDC_EXIT_SUCCESS; + (void)optionProcess(&ntpdcOptions, argc, argv); + optionPutShell(&ntpdcOptions); + res = ferror(stdout); + if (res != 0) + fputs("output error writing to stdout\n", stderr); return res; } #endif /* defined TEST_NTPDC_OPTS */ -/* extracted from /usr/local/gnu/autogen-5.9.1/share/autogen/optcode.tpl near line 514 */ +/* extracted from optcode.tlib near line 666 */ #if ENABLE_NLS #include <stdio.h> @@ -585,11 +582,11 @@ main( int argc, char** argv ) #include <unistd.h> #include <autoopts/usage-txt.h> -static char* AO_gettext( char const* pz ); +static char* AO_gettext(char const* pz); static void coerce_it(void** s); static char* -AO_gettext( char const* pz ) +AO_gettext(char const* pz) { char* pzRes; if (pz == NULL) @@ -597,66 +594,68 @@ AO_gettext( char const* pz ) pzRes = _(pz); if (pzRes == pz) return pzRes; - pzRes = strdup( pzRes ); + pzRes = strdup(pzRes); if (pzRes == NULL) { - fputs( _("No memory for duping translated strings\n"), stderr ); - exit( EXIT_FAILURE ); + fputs(_("No memory for duping translated strings\n"), stderr); + exit(NTPDC_EXIT_FAILURE); } return pzRes; } -static void coerce_it(void** s) { *s = AO_gettext(*s); } -#define COERSION(_f) \ - coerce_it((void*)&(ntpdcOptions._f)) +static void coerce_it(void** s) { *s = AO_gettext(*s); +} /* * This invokes the translation code (e.g. gettext(3)). */ static void -translate_option_strings( void ) +translate_option_strings(void) { + tOptions * const pOpt = &ntpdcOptions; + /* * Guard against re-translation. It won't work. The strings will have * been changed by the first pass through this code. One shot only. */ - if (option_usage_text.field_ct == 0) - return; - /* - * Do the translations. The first pointer follows the field count field. - * The field count field is the size of a pointer. - */ - { - char** ppz = (char**)(void*)&(option_usage_text); - int ix = option_usage_text.field_ct; + if (option_usage_text.field_ct != 0) { + /* + * Do the translations. The first pointer follows the field count + * field. The field count field is the size of a pointer. + */ + tOptDesc * pOD = pOpt->pOptDesc; + char ** ppz = (char**)(void*)&(option_usage_text); + int ix = option_usage_text.field_ct; do { ppz++; *ppz = AO_gettext(*ppz); } while (--ix > 0); + + coerce_it((void*)&(pOpt->pzCopyright)); + coerce_it((void*)&(pOpt->pzCopyNotice)); + coerce_it((void*)&(pOpt->pzFullVersion)); + coerce_it((void*)&(pOpt->pzUsageTitle)); + coerce_it((void*)&(pOpt->pzExplain)); + coerce_it((void*)&(pOpt->pzDetail)); + coerce_it((void*)&(pOpt->pzPackager)); + option_usage_text.field_ct = 0; + + for (ix = pOpt->optCt; ix > 0; ix--, pOD++) + coerce_it((void*)&(pOD->pzText)); } - option_usage_text.field_ct = 0; - - { - tOptDesc* pOD = ntpdcOptions.pOptDesc; - int ix = ntpdcOptions.optCt; - - for (;;) { - pOD->pzText = AO_gettext(pOD->pzText); - pOD->pz_NAME = AO_gettext(pOD->pz_NAME); - pOD->pz_Name = AO_gettext(pOD->pz_Name); - pOD->pz_DisableName = AO_gettext(pOD->pz_DisableName); - pOD->pz_DisablePfx = AO_gettext(pOD->pz_DisablePfx); - if (--ix <= 0) - break; - pOD++; + + if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) { + tOptDesc * pOD = pOpt->pOptDesc; + int ix; + + for (ix = pOpt->optCt; ix > 0; ix--, pOD++) { + coerce_it((void*)&(pOD->pz_Name)); + coerce_it((void*)&(pOD->pz_DisableName)); + coerce_it((void*)&(pOD->pz_DisablePfx)); } + /* prevent re-translation */ + ntpdcOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT; } - COERSION(pzCopyright); - COERSION(pzCopyNotice); - COERSION(pzFullVersion); - COERSION(pzUsageTitle); - COERSION(pzExplain); - COERSION(pzDetail); } #endif /* ENABLE_NLS */ diff --git a/ntpdc/ntpdc-opts.def b/ntpdc/ntpdc-opts.def index 0b5aefe..a42eb67 100644 --- a/ntpdc/ntpdc-opts.def +++ b/ntpdc/ntpdc-opts.def @@ -15,7 +15,7 @@ test-main; flag = { name = ipv4; value = 4; - equivalence = ipv4; + flags-cant = ipv6; descrip = "Force IPv4 DNS name resolution"; doc = <<- _EndOfDoc_ Force DNS resolution of following host names on the command line @@ -26,7 +26,7 @@ flag = { flag = { name = ipv6; value = 6; - equivalence = ipv4; + flags-cant = ipv4; descrip = "Force IPv6 DNS name resolution"; doc = <<- _EndOfDoc_ Force DNS resolution of following host names on the command line diff --git a/ntpdc/ntpdc-opts.h b/ntpdc/ntpdc-opts.h index f6eef65..2f20607 100644 --- a/ntpdc/ntpdc-opts.h +++ b/ntpdc/ntpdc-opts.h @@ -1,27 +1,24 @@ /* * EDIT THIS FILE WITH CAUTION (ntpdc-opts.h) * - * It has been AutoGen-ed Tuesday December 8, 2009 at 08:14:00 AM EST + * It has been AutoGen-ed December 24, 2011 at 06:34:16 PM by AutoGen 5.12 * From the definitions ntpdc-opts.def * and the template file options * - * Generated from AutoOpts 29:0:4 templates. - */ - -/* - * This file was produced by an AutoOpts template. AutoOpts is a - * copyrighted work. This header file is not encumbered by AutoOpts - * licensing, but is provided under the licensing terms chosen by the - * ntpdc author or copyright holder. AutoOpts is licensed under - * the terms of the LGPL. The redistributable library (``libopts'') is - * licensed under the terms of either the LGPL or, at the users discretion, - * the BSD license. See the AutoOpts and/or libopts sources for details. + * Generated from AutoOpts 35:0:10 templates. * - * This source file is copyrighted and licensed under the following terms: + * AutoOpts is a copyrighted work. This header file is not encumbered + * by AutoOpts licensing, but is provided under the licensing terms chosen + * by the ntpdc author or copyright holder. AutoOpts is + * licensed under the terms of the LGPL. The redistributable library + * (``libopts'') is licensed under the terms of either the LGPL or, at the + * users discretion, the BSD license. See the AutoOpts and/or libopts sources + * for details. * - * ntpdc copyright 1970-2009 David L. Mills and/or others - all rights reserved + * This source file is copyrighted and licensed under the following terms: * - * see html/copyright.html + * see html/copyright.html + * */ /* * This file contains the programmatic interface to the Automated @@ -30,7 +27,7 @@ * "AutoOpts" chapter. Please refer to that doc for usage help. */ #ifndef AUTOOPTS_NTPDC_OPTS_H_GUARD -#define AUTOOPTS_NTPDC_OPTS_H_GUARD +#define AUTOOPTS_NTPDC_OPTS_H_GUARD 1 #include "config.h" #include <autoopts/options.h> @@ -41,7 +38,7 @@ * tolerable version is at least as old as what was current when the header * template was released. */ -#define AO_TEMPLATE_VERSION 118784 +#define AO_TEMPLATE_VERSION 143360 #if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \ || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION) # error option template version mismatches autoopts/options.h header @@ -52,31 +49,31 @@ * Enumeration of each option: */ typedef enum { - INDEX_OPT_IPV4 = 0, - INDEX_OPT_IPV6 = 1, - INDEX_OPT_COMMAND = 2, - INDEX_OPT_LISTPEERS = 3, - INDEX_OPT_PEERS = 4, - INDEX_OPT_SHOWPEERS = 5, - INDEX_OPT_INTERACTIVE = 6, - INDEX_OPT_DEBUG_LEVEL = 7, - INDEX_OPT_SET_DEBUG_LEVEL = 8, - INDEX_OPT_NUMERIC = 9, - INDEX_OPT_VERSION = 10, - INDEX_OPT_HELP = 11, - INDEX_OPT_MORE_HELP = 12, - INDEX_OPT_SAVE_OPTS = 13, - INDEX_OPT_LOAD_OPTS = 14 + INDEX_OPT_IPV4 = 0, + INDEX_OPT_IPV6 = 1, + INDEX_OPT_COMMAND = 2, + INDEX_OPT_LISTPEERS = 3, + INDEX_OPT_PEERS = 4, + INDEX_OPT_SHOWPEERS = 5, + INDEX_OPT_INTERACTIVE = 6, + INDEX_OPT_DEBUG_LEVEL = 7, + INDEX_OPT_SET_DEBUG_LEVEL = 8, + INDEX_OPT_NUMERIC = 9, + INDEX_OPT_VERSION = 10, + INDEX_OPT_HELP = 11, + INDEX_OPT_MORE_HELP = 12, + INDEX_OPT_SAVE_OPTS = 13, + INDEX_OPT_LOAD_OPTS = 14 } teOptIndex; #define OPTION_CT 15 -#define NTPDC_VERSION "4.2.4p8" -#define NTPDC_FULL_VERSION "ntpdc - vendor-specific NTP query program - Ver. 4.2.4p8" +#define NTPDC_VERSION "4.2.6p5" +#define NTPDC_FULL_VERSION "ntpdc 4.2.6p5" /* * Interface defines for all options. Replace "n" with the UPPER_CASED * option name (as in the teOptIndex enumeration above). - * e.g. HAVE_OPT( IPV4 ) + * e.g. HAVE_OPT(IPV4) */ #define DESC(n) (ntpdcOptions.pOptDesc[INDEX_OPT_## n]) #define HAVE_OPT(n) (! UNUSED_OPT(& DESC(n))) @@ -90,10 +87,18 @@ typedef enum { #define STACKLST_OPT(n) (((tArgList*)(DESC(n).optCookie))->apzArgs) #define CLEAR_OPT(n) STMTS( \ DESC(n).fOptState &= OPTST_PERSISTENT_MASK; \ - if ( (DESC(n).fOptState & OPTST_INITENABLED) == 0) \ + if ((DESC(n).fOptState & OPTST_INITENABLED) == 0) \ DESC(n).fOptState |= OPTST_DISABLED; \ DESC(n).optCookie = NULL ) +/* * * * * * + * + * Enumeration of ntpdc exit codes + */ +typedef enum { + NTPDC_EXIT_SUCCESS = 0, + NTPDC_EXIT_FAILURE = 1 +} ntpdc_exit_code_t; /* * Make sure there are no #define name conflicts with the option names */ @@ -151,29 +156,23 @@ typedef enum { # undef NUMERIC #endif /* NO_OPTION_NAME_WARNINGS */ -/* +/* * * * * * + * * Interface defines for specific options. */ #define VALUE_OPT_IPV4 '4' -#define WHICH_OPT_IPV4 (DESC(IPV4).optActualValue) -#define WHICH_IDX_IPV4 (DESC(IPV4).optActualIndex) #define VALUE_OPT_IPV6 '6' #define VALUE_OPT_COMMAND 'c' #define VALUE_OPT_LISTPEERS 'l' #define VALUE_OPT_PEERS 'p' #define VALUE_OPT_SHOWPEERS 's' #define VALUE_OPT_INTERACTIVE 'i' -#ifdef DEBUG #define VALUE_OPT_DEBUG_LEVEL 'd' -#endif /* DEBUG */ -#ifdef DEBUG #define VALUE_OPT_SET_DEBUG_LEVEL 'D' -#endif /* DEBUG */ #define VALUE_OPT_NUMERIC 'n' - -#define VALUE_OPT_VERSION 'v' #define VALUE_OPT_HELP '?' #define VALUE_OPT_MORE_HELP '!' +#define VALUE_OPT_VERSION INDEX_OPT_VERSION #define VALUE_OPT_SAVE_OPTS '>' #define VALUE_OPT_LOAD_OPTS '<' #define SET_OPT_SAVE_OPTS(a) STMTS( \ @@ -183,37 +182,56 @@ typedef enum { /* * Interface defines not associated with particular options */ -#define ERRSKIP_OPTERR STMTS( ntpdcOptions.fOptSet &= ~OPTPROC_ERRSTOP ) -#define ERRSTOP_OPTERR STMTS( ntpdcOptions.fOptSet |= OPTPROC_ERRSTOP ) +#define ERRSKIP_OPTERR STMTS(ntpdcOptions.fOptSet &= ~OPTPROC_ERRSTOP) +#define ERRSTOP_OPTERR STMTS(ntpdcOptions.fOptSet |= OPTPROC_ERRSTOP) #define RESTART_OPT(n) STMTS( \ ntpdcOptions.curOptIdx = (n); \ - ntpdcOptions.pzCurOpt = NULL ) + ntpdcOptions.pzCurOpt = NULL) #define START_OPT RESTART_OPT(1) -#define USAGE(c) (*ntpdcOptions.pUsageProc)( &ntpdcOptions, c ) -/* extracted from /usr/local/gnu/autogen-5.9.1/share/autogen/opthead.tpl near line 360 */ +#define USAGE(c) (*ntpdcOptions.pUsageProc)(&ntpdcOptions, c) +/* extracted from opthead.tlib near line 451 */ + +#ifdef __cplusplus +extern "C" { +#endif /* * * * * * * * Declare the ntpdc option descriptor. */ -#ifdef __cplusplus -extern "C" { -#endif +extern tOptions ntpdcOptions; -extern tOptions ntpdcOptions; +#if defined(ENABLE_NLS) +# ifndef _ +# include <stdio.h> +static inline char* aoGetsText(char const* pz) { + if (pz == NULL) return NULL; + return (char*)gettext(pz); +} +# define _(s) aoGetsText(s) +# endif /* _() */ -#ifndef _ -# if ENABLE_NLS -# include <stdio.h> - static inline char* aoGetsText( char const* pz ) { - if (pz == NULL) return NULL; - return (char*)gettext( pz ); - } -# define _(s) aoGetsText(s) -# else /* ENABLE_NLS */ -# define _(s) s -# endif /* ENABLE_NLS */ -#endif +# define OPT_NO_XLAT_CFG_NAMES STMTS(ntpdcOptions.fOptSet |= \ + OPTPROC_NXLAT_OPT_CFG;) +# define OPT_NO_XLAT_OPT_NAMES STMTS(ntpdcOptions.fOptSet |= \ + OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG;) + +# define OPT_XLAT_CFG_NAMES STMTS(ntpdcOptions.fOptSet &= \ + ~(OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG);) +# define OPT_XLAT_OPT_NAMES STMTS(ntpdcOptions.fOptSet &= \ + ~OPTPROC_NXLAT_OPT;) + +#else /* ENABLE_NLS */ +# define OPT_NO_XLAT_CFG_NAMES +# define OPT_NO_XLAT_OPT_NAMES + +# define OPT_XLAT_CFG_NAMES +# define OPT_XLAT_OPT_NAMES + +# ifndef _ +# define _(_s) _s +# endif +#endif /* ENABLE_NLS */ #ifdef __cplusplus } diff --git a/ntpdc/ntpdc-opts.texi b/ntpdc/ntpdc-opts.texi index 121c270..b868c5e 100644 --- a/ntpdc/ntpdc-opts.texi +++ b/ntpdc/ntpdc-opts.texi @@ -6,7 +6,7 @@ # # EDIT THIS FILE WITH CAUTION (ntpdc-opts.texi) # -# It has been AutoGen-ed Tuesday December 8, 2009 at 08:14:02 AM EST +# It has been AutoGen-ed December 24, 2011 at 06:34:25 PM by AutoGen 5.12 # From the definitions ntpdc-opts.def # and the template file aginfo.tpl @end ignore @@ -32,22 +32,22 @@ ntpd's configuration file may also be specified at run time using This section was generated by @strong{AutoGen}, -the aginfo template and the option descriptions for the @command{ntpdc} program. It documents the ntpdc usage text and option meanings. +the aginfo template and the option descriptions for the @command{ntpdc} program. It documents the @command{ntpdc} usage text and option meanings. This software is released under a specialized copyright license. @menu * ntpdc usage:: ntpdc usage help (-?) -* ntpdc command:: command option (-c) -* ntpdc debug-level:: debug-level option (-d) -* ntpdc interactive:: interactive option (-i) -* ntpdc ipv4:: ipv4 option (-4) -* ntpdc ipv6:: ipv6 option (-6) -* ntpdc listpeers:: listpeers option (-l) -* ntpdc numeric:: numeric option (-n) -* ntpdc peers:: peers option (-p) -* ntpdc set-debug-level:: set-debug-level option (-D) -* ntpdc showpeers:: showpeers option (-s) +* ntpdc command:: command option (-c) +* ntpdc debug-level:: debug-level option (-d) +* ntpdc interactive:: interactive option (-i) +* ntpdc ipv4:: ipv4 option (-4) +* ntpdc ipv6:: ipv6 option (-6) +* ntpdc listpeers:: listpeers option (-l) +* ntpdc numeric:: numeric option (-n) +* ntpdc peers:: peers option (-p) +* ntpdc set-debug-level:: set-debug-level option (-D) +* ntpdc showpeers:: showpeers option (-s) @end menu @node ntpdc usage @@ -58,7 +58,7 @@ This is the automatically generated usage text for ntpdc: @exampleindent 0 @example -ntpdc - vendor-specific NTP query program - Ver. 4.2.5p247-RC +ntpdc - vendor-specific NTP query program - Ver. 4.2.6p5 USAGE: ntpdc [ -<flag> [<val>] | --<name>[@{=| @}<val>] ]... [ host ...] Flg Arg Option-Name Description -4 no ipv4 Force IPv4 DNS name resolution @@ -97,118 +97,111 @@ USAGE: ntpdc [ -<flag> [<val>] | --<name>[@{=| @}<val>] ]... [ host ...] - disabled as --no-load-opts - may appear multiple times -Options are specified by doubled hyphens and their name -or by a single hyphen and the flag character. +Options are specified by doubled hyphens and their name or by a single +hyphen and the flag character. The following option preset mechanisms are supported: - - reading file /users/stenn/.ntprc - - reading file /deacon/backroom/snaps/ntp-stable/ntpdc/.ntprc + - reading file $HOME/.ntprc + - reading file ./.ntprc - examining environment variables named NTPDC_* -The -[= prog-name =] -utility program is used to query an NTP daemon about its -current state and to request changes in that state. -It uses NTP mode 7 control message formats described in the source code. -The program may +The [= prog-name =] utility program is used to query an NTP daemon about +its current state and to request changes in that state. It uses NTP mode +7 control message formats described in the source code. The program may be run either in interactive mode or controlled using command line -arguments. -Extensive state and statistics information is available -through the -[= prog-name =] -interface. -In addition, nearly all the -configuration options which can be specified at startup using -ntpd's configuration file may also be specified at run time using -[= prog-name =] . +arguments. Extensive state and statistics information is available +through the [= prog-name =] interface. In addition, nearly all the +configuration options which can be specified at startup using ntpd's +configuration file may also be specified at run time using [= prog-name =] +. please send bug reports to: http://bugs.ntp.org, bugs@@ntp.org @end example @exampleindent 4 -@node ntpdc ipv4 -@subsection ipv4 option (-4) -@cindex ntpdc-ipv4 +@node ntpdc command +@subsection command option (-c) +@cindex ntpdc-command -This is the ``force ipv4 dns name resolution'' option. +This is the ``run a command and exit'' option. This option has some usage constraints. It: @itemize @bullet @item -is a member of the ipv4 class of options. +may appear an unlimited number of times. @end itemize -Force DNS resolution of following host names on the command line -to the IPv4 namespace. +The following argument is interpreted as an interactive format command +and is added to the list of commands to be executed on the specified +host(s). -@node ntpdc ipv6 -@subsection ipv6 option (-6) -@cindex ntpdc-ipv6 +@node ntpdc debug-level +@subsection debug-level option (-d) +@cindex ntpdc-debug-level -This is the ``force ipv6 dns name resolution'' option. +This is the ``increase output debug message level'' option. This option has some usage constraints. It: @itemize @bullet @item -is a member of the ipv4 class of options. +may appear an unlimited number of times. @end itemize -Force DNS resolution of following host names on the command line -to the IPv6 namespace. +Increase the debugging message output level. -@node ntpdc command -@subsection command option (-c) -@cindex ntpdc-command +@node ntpdc interactive +@subsection interactive option (-i) +@cindex ntpdc-interactive -This is the ``run a command and exit'' option. +This is the ``force ntpq to operate in interactive mode'' option. This option has some usage constraints. It: @itemize @bullet @item -may appear an unlimited number of times. +must not appear in combination with any of the following options: +command, listpeers, peers, showpeers. @end itemize -The following argument is interpreted as an interactive format command -and is added to the list of commands to be executed on the specified -host(s). +Force ntpq to operate in interactive mode. Prompts will be written +to the standard output and commands read from the standard input. -@node ntpdc listpeers -@subsection listpeers option (-l) -@cindex ntpdc-listpeers +@node ntpdc ipv4 +@subsection ipv4 option (-4) +@cindex ntpdc-ipv4 -This is the ``print a list of the peers'' option. +This is the ``force ipv4 dns name resolution'' option. This option has some usage constraints. It: @itemize @bullet @item must not appear in combination with any of the following options: -command. +ipv6. @end itemize -Print a list of the peers known to the server as well as a summary of -their state. This is equivalent to the 'listpeers' interactive command. +Force DNS resolution of following host names on the command line +to the IPv4 namespace. -@node ntpdc peers -@subsection peers option (-p) -@cindex ntpdc-peers +@node ntpdc ipv6 +@subsection ipv6 option (-6) +@cindex ntpdc-ipv6 -This is the ``print a list of the peers'' option. +This is the ``force ipv6 dns name resolution'' option. This option has some usage constraints. It: @itemize @bullet @item must not appear in combination with any of the following options: -command. +ipv4. @end itemize -Print a list of the peers known to the server as well as a summary -of their state. This is equivalent to the 'peers' interactive command. +Force DNS resolution of following host names on the command line +to the IPv6 namespace. -@node ntpdc showpeers -@subsection showpeers option (-s) -@cindex ntpdc-showpeers +@node ntpdc listpeers +@subsection listpeers option (-l) +@cindex ntpdc-listpeers -This is the ``show a list of the peers'' option. +This is the ``print a list of the peers'' option. This option has some usage constraints. It: @itemize @bullet @@ -217,40 +210,32 @@ must not appear in combination with any of the following options: command. @end itemize -Print a list of the peers known to the server as well as a summary -of their state. This is equivalent to the 'dmpeers' interactive command. - -@node ntpdc interactive -@subsection interactive option (-i) -@cindex ntpdc-interactive - -This is the ``force ntpq to operate in interactive mode'' option. +Print a list of the peers known to the server as well as a summary of +their state. This is equivalent to the 'listpeers' interactive command. -This option has some usage constraints. It: -@itemize @bullet -@item -must not appear in combination with any of the following options: -command, listpeers, peers, showpeers. -@end itemize +@node ntpdc numeric +@subsection numeric option (-n) +@cindex ntpdc-numeric -Force ntpq to operate in interactive mode. Prompts will be written -to the standard output and commands read from the standard input. +This is the ``numeric host addresses'' option. +Output all host addresses in dotted-quad numeric format rather than +converting to the canonical host names. -@node ntpdc debug-level -@subsection debug-level option (-d) -@cindex ntpdc-debug-level +@node ntpdc peers +@subsection peers option (-p) +@cindex ntpdc-peers -This is the ``increase output debug message level'' option. +This is the ``print a list of the peers'' option. This option has some usage constraints. It: @itemize @bullet @item -may appear an unlimited number of times. -@item -must be compiled in by defining @code{DEBUG} during the compilation. +must not appear in combination with any of the following options: +command. @end itemize -Increase the debugging message output level. +Print a list of the peers known to the server as well as a summary +of their state. This is equivalent to the 'peers' interactive command. @node ntpdc set-debug-level @subsection set-debug-level option (-D) @@ -262,17 +247,23 @@ This option has some usage constraints. It: @itemize @bullet @item may appear an unlimited number of times. -@item -must be compiled in by defining @code{DEBUG} during the compilation. @end itemize Set the output debugging level. Can be supplied multiple times, but each overrides the previous value(s). -@node ntpdc numeric -@subsection numeric option (-n) -@cindex ntpdc-numeric +@node ntpdc showpeers +@subsection showpeers option (-s) +@cindex ntpdc-showpeers -This is the ``numeric host addresses'' option. -Output all host addresses in dotted-quad numeric format rather than -converting to the canonical host names. +This is the ``show a list of the peers'' option. + +This option has some usage constraints. It: +@itemize @bullet +@item +must not appear in combination with any of the following options: +command. +@end itemize + +Print a list of the peers known to the server as well as a summary +of their state. This is equivalent to the 'dmpeers' interactive command. diff --git a/ntpdc/ntpdc.1 b/ntpdc/ntpdc.1 index 4227065..3ff7497 100644 --- a/ntpdc/ntpdc.1 +++ b/ntpdc/ntpdc.1 @@ -1,7 +1,7 @@ -.TH NTPDC 1 2009-12-08 "( 4.2.4p8)" "Programmer's Manual" +.TH NTPDC 1 2011-12-24 "( 4.2.6p5)" "Programmer's Manual" .\" EDIT THIS FILE WITH CAUTION (ntpdc.1) .\" -.\" It has been AutoGen-ed Tuesday December 8, 2009 at 08:14:01 AM EST +.\" It has been AutoGen-ed December 24, 2011 at 06:34:25 PM by AutoGen 5.12 .\" From the definitions ntpdc-opts.def .\" and the template file agman1.tpl .\" @@ -15,7 +15,7 @@ ntpdc \- vendor-specific NTP query program .in +8 [ host ...] .SH "DESCRIPTION" -This manual page documents, briefly, the \fBntpdc\fP command. +This manual page briefly documents the \fBntpdc\fP command. The [= prog-name =] utility program is used to query an NTP daemon about its @@ -38,14 +38,16 @@ ntpd's configuration file may also be specified at run time using .TP .BR \-4 ", " \--ipv4 Force IPv4 DNS name resolution. -This option is a member of the ipv4 class of options. +This option must not appear in combination with any of the following options: +ipv6. .sp Force DNS resolution of following host names on the command line to the IPv4 namespace. .TP .BR \-6 ", " \--ipv6 Force IPv6 DNS name resolution. -This option is a member of the ipv4 class of options. +This option must not appear in combination with any of the following options: +ipv4. .sp Force DNS resolution of following host names on the command line to the IPv6 namespace. @@ -110,7 +112,7 @@ Output all host addresses in dotted-quad numeric format rather than converting to the canonical host names. .TP .BR \-? , " \--help" -Display usage information and exit. +Display extended usage information and exit. .TP .BR \-! , " \--more-help" Extended usage information passed thru pager. @@ -125,7 +127,7 @@ The \fIno-load-opts\fP form will disable the loading of earlier RC/INI files. \fI--no-load-opts\fP is handled early, out of order. .TP -.BR \-v " [{\fIv|c|n\fP}]," " \--version" "[=\fI{v|c|n}\fP]" +.BR \- " [{\fIv|c|n\fP}]," " \--version" "[=\fI{v|c|n}\fP]" Output version of program and exit. The default mode is `v', a simple version. The `c' mode will print copyright information and `n' will print the full copyright notice. @@ -136,7 +138,7 @@ environment variables named: .nf \fBNTPDC_<option-name>\fP or \fBNTPDC\fP .fi -.aj +.ad The environmental presets take precedence (are processed later than) the configuration files. The \fIhomerc\fP files are "\fI$HOME\fP", and "\fI.\fP". @@ -151,6 +153,7 @@ Please send bug reports to: http://bugs.ntp.org, bugs@ntp.org .nf .na see html/copyright.html + .fi .ad .PP diff --git a/ntpdc/ntpdc.c b/ntpdc/ntpdc.c index 9126533..bffaf09 100644 --- a/ntpdc/ntpdc.c +++ b/ntpdc/ntpdc.c @@ -3,7 +3,7 @@ */ #include <stdio.h> - +#include <stddef.h> #include <ctype.h> #include <signal.h> #include <setjmp.h> @@ -12,25 +12,20 @@ #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 "ntp_assert.h" +#include "ntp_lineedit.h" #include "isc/net.h" #include "isc/result.h" +#include <ssl_applink.c> +#include "ntp_libopts.h" #include "ntpdc-opts.h" #ifdef SYS_WINNT # include <Mswsock.h> # include <io.h> -#else -# define closesocket close #endif /* SYS_WINNT */ -#if defined(HAVE_LIBREADLINE) || defined (HAVE_LIBEDIT) -# include <readline/readline.h> -# include <readline/history.h> -#endif /* HAVE_LIBREADLINE || HAVE_LIBEDIT */ - #ifdef SYS_VXWORKS /* vxWorks needs mode flag -casey*/ # define open(name, flags) open(name, flags, 0777) @@ -56,12 +51,8 @@ static const char * prompt = "ntpdc> "; /* prompt to ask him about */ static u_long info_auth_keyid; static int keyid_entered = 0; -/* - * Type of key md5 - */ -#define KEY_TYPE_MD5 4 - -static int info_auth_keytype = KEY_TYPE_MD5; /* MD5 */ +static int info_auth_keytype = NID_md5; /* MD5 */ +static size_t info_auth_hashlen = 16; /* MD5 */ u_long current_time; /* needed by authkeys; not used */ /* @@ -69,42 +60,38 @@ u_long current_time; /* needed by authkeys; not used */ */ s_char sys_precision; /* local clock precision (log2 s) */ -int ntpdcmain P((int, char **)); +int ntpdcmain (int, char **); /* * Built in command handler declarations */ -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 **, int)); -static int sendrequest P((int, int, int, int, int, char *)); -static void getcmds P((void)); -static RETSIGTYPE abortcmd P((int)); -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 *, 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 *)); -#else -static int helpsort P((char **, char **)); -#endif -static void printusage P((struct xcmd *, FILE *)); -static void timeout P((struct parse *, FILE *)); -static void my_delay P((struct parse *, FILE *)); -static void host P((struct parse *, FILE *)); -static void keyid P((struct parse *, FILE *)); -static void keytype P((struct parse *, FILE *)); -static void passwd P((struct parse *, FILE *)); -static void hostnames P((struct parse *, FILE *)); -static void setdebug P((struct parse *, FILE *)); -static void quit P((struct parse *, FILE *)); -static void version P((struct parse *, FILE *)); -static void warning P((const char *, const char *, const char *)); -static void error P((const char *, const char *, const char *)); -static u_long getkeyid P((const char *)); +static int openhost (const char *); +static int sendpkt (void *, size_t); +static void growpktdata (void); +static int getresponse (int, int, int *, int *, char **, int); +static int sendrequest (int, int, int, u_int, size_t, char *); +static void getcmds (void); +static RETSIGTYPE abortcmd (int); +static void docmd (const char *); +static void tokenize (const char *, char **, int *); +static int findcmd (char *, struct xcmd *, struct xcmd *, struct xcmd **); +static int getarg (char *, int, arg_v *); +static int getnetnum (const char *, sockaddr_u *, char *, int); +static void help (struct parse *, FILE *); +static int helpsort (const void *, const void *); +static void printusage (struct xcmd *, FILE *); +static void timeout (struct parse *, FILE *); +static void my_delay (struct parse *, FILE *); +static void host (struct parse *, FILE *); +static void keyid (struct parse *, FILE *); +static void keytype (struct parse *, FILE *); +static void passwd (struct parse *, FILE *); +static void hostnames (struct parse *, FILE *); +static void setdebug (struct parse *, FILE *); +static void quit (struct parse *, FILE *); +static void version (struct parse *, FILE *); +static void warning (const char *, const char *, const char *); +static void error (const char *, const char *, const char *); +static u_long getkeyid (const char *); @@ -159,10 +146,10 @@ static struct xcmd builtins[] = { /* * Default values we use. */ +#define DEFHOST "localhost" /* default host name */ #define DEFTIMEOUT (5) /* 5 second time out */ #define DEFSTIMEOUT (2) /* 2 second time out after first */ #define DEFDELAY 0x51EB852 /* 20 milliseconds, l_fp fraction */ -#define DEFHOST "localhost" /* default host name */ #define LENHOSTNAME 256 /* host name is 256 characters long */ #define MAXCMDS 100 /* maximum commands on cmd line */ #define MAXHOSTS 200 /* maximum hosts on cmd line */ @@ -173,8 +160,8 @@ static struct xcmd builtins[] = { /* * Some variables used and manipulated locally */ -static struct timeval tvout = { DEFTIMEOUT, 0 }; /* time out for reads */ -static struct timeval tvsout = { DEFSTIMEOUT, 0 }; /* secondary time out */ +static struct sock_timeval tvout = { DEFTIMEOUT, 0 }; /* time out for reads */ +static struct sock_timeval tvsout = { DEFSTIMEOUT, 0 };/* secondary time out */ static l_fp delay_time; /* delay time */ static char currenthost[LENHOSTNAME]; /* current host name */ int showhostnames = 1; /* show host names by default */ @@ -185,18 +172,6 @@ static SOCKET sockfd; /* fd socket is opened on */ static int havehost = 0; /* set to 1 when host open */ int s_port = 0; -#if defined (SYS_WINNT) || defined (SYS_VXWORKS) -char password[9]; -#endif /* SYS_WINNT || SYS_VXWORKS */ - -#ifdef SYS_WINNT -DWORD NumberOfBytesWritten; - -HANDLE TimerThreadHandle = NULL; /* 1998/06/03 - Used in ntplib/machines.c */ -void timer(void) { ; }; /* 1998/06/03 - Used in ntplib/machines.c */ - -#endif /* SYS_WINNT */ - /* * Holds data returned from queries. We allocate INITDATASIZE * octets to begin with, increasing this as we need to. @@ -306,38 +281,27 @@ ntpdcmain( taskPrioritySet(taskIdSelf(), 100 ); #endif -#ifdef SYS_WINNT - if (!Win32InitSockets()) - { - fprintf(stderr, "No useable winsock.dll:"); - exit(1); - } -#endif /* SYS_WINNT */ + init_lib(); /* sets up ipv4_works, ipv6_works */ + ssl_applink(); - /* Check to see if we have IPv6. Otherwise force the -4 flag */ - if (isc_net_probeipv6() != ISC_R_SUCCESS) { + /* Check to see if we have IPv6. Otherwise default to IPv4 */ + if (!ipv6_works) ai_fam_default = AF_INET; - } progname = argv[0]; { - int optct = optionProcess(&ntpdcOptions, argc, argv); + int optct = ntpOptionProcess(&ntpdcOptions, argc, argv); argc -= optct; argv += optct; } - switch (WHICH_IDX_IPV4) { - case INDEX_OPT_IPV4: + if (HAVE_OPT(IPV4)) ai_fam_templ = AF_INET; - break; - case INDEX_OPT_IPV6: + else if (HAVE_OPT(IPV6)) ai_fam_templ = AF_INET6; - break; - default: + else ai_fam_templ = ai_fam_default; - break; - } if (HAVE_OPT(COMMAND)) { int cmdct = STACKCT_OPT( COMMAND ); @@ -446,12 +410,8 @@ ntpdcmain( /* * Initialize the packet data buffer */ - pktdata = (char *)malloc(INITDATASIZE); - if (pktdata == NULL) { - (void) fprintf(stderr, "%s: malloc() failed!\n", progname); - exit(1); - } pktdatasize = INITDATASIZE; + pktdata = emalloc(INITDATASIZE); if (numcmds == 0) { (void) openhost(chosts[0]); @@ -499,10 +459,14 @@ openhost( if (*cp == '[') { cp++; - for(i = 0; *cp != ']'; cp++, i++) - name[i] = *cp; - name[i] = '\0'; - hname = name; + for (i = 0; *cp && *cp != ']'; cp++, i++) + name[i] = *cp; + if (*cp == ']') { + name[i] = '\0'; + hname = name; + } else { + return 0; + } } /* @@ -517,7 +481,7 @@ openhost( hints.ai_family = ai_fam_templ; hints.ai_protocol = IPPROTO_UDP; hints.ai_socktype = SOCK_DGRAM; - hints.ai_flags = AI_NUMERICHOST; + hints.ai_flags = Z_AI_NUMERICHOST; a_info = getaddrinfo(hname, service, &hints, &ai); if (a_info == EAI_NONAME @@ -543,8 +507,14 @@ openhost( return 0; } + /* + * getaddrinfo() has returned without error so ai should not + * be NULL. + */ + NTP_INSIST(ai != NULL); + if (ai->ai_canonname == NULL) { - strncpy(temphost, stoa((struct sockaddr_storage *)ai->ai_addr), + strncpy(temphost, stoa((sockaddr_u *)ai->ai_addr), LENHOSTNAME); temphost[LENHOSTNAME-1] = '\0'; } else { @@ -619,8 +589,8 @@ openhost( ai->ai_addrlen) == -1) #endif /* SYS_VXWORKS */ error("connect", "", ""); - if (ai != NULL) - freeaddrinfo(ai); + + freeaddrinfo(ai); havehost = 1; req_pkt_size = REQ_LEN_NOMAC; impl_ver = IMPL_XNTPD; @@ -634,11 +604,11 @@ openhost( */ static int sendpkt( - char *xdata, - int xdatalen + void * xdata, + size_t xdatalen ) { - if (send(sockfd, xdata, (size_t)xdatalen, 0) == -1) { + if (send(sockfd, xdata, xdatalen, 0) == -1) { warning("write to %s failed", currenthost, ""); return -1; } @@ -654,11 +624,7 @@ static void growpktdata(void) { pktdatasize += INCDATASIZE; - pktdata = (char *)realloc(pktdata, (unsigned)pktdatasize); - if (pktdata == 0) { - (void) fprintf(stderr, "%s: realloc() failed!\n", progname); - exit(1); - } + pktdata = erealloc(pktdata, (size_t)pktdatasize); } @@ -676,7 +642,7 @@ getresponse( ) { struct resp_pkt rpkt; - struct timeval tvo; + struct sock_timeval tvo; int items; int i; int size; @@ -710,9 +676,9 @@ getresponse( again: if (firstpkt) - tvo = tvout; + tvo = tvout; else - tvo = tvsout; + tvo = tvsout; FD_SET(sockfd, &fds); n = select(sockfd+1, &fds, (fd_set *)0, (fd_set *)0, &tvo); @@ -823,11 +789,12 @@ getresponse( pad = esize - size; else pad = 0; - if ((datasize = items*size) > (n-RESP_HEADER_SIZE)) { + datasize = items * size; + if ((size_t)datasize > (n-RESP_HEADER_SIZE)) { if (debug) printf( - "Received items %d, size %d (total %d), data in packet is %d\n", - items, size, datasize, n-RESP_HEADER_SIZE); + "Received items %d, size %d (total %d), data in packet is %lu\n", + items, size, datasize, (u_long)(n-RESP_HEADER_SIZE)); goto again; } @@ -869,7 +836,7 @@ getresponse( if ((datap + datasize + (pad * items)) > (pktdata + pktdatasize)) { int offset = datap - pktdata; growpktdata(); - *rdata = pktdata; /* might have been realloced ! */ + *rdata = pktdata; /* might have been realloced ! */ datap = pktdata + offset; } /* @@ -877,9 +844,9 @@ getresponse( * 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 = rpkt.data; + for (i = 0; i < items; i++) { + memcpy(datap, tmp_data, (unsigned)size); tmp_data += size; memset(datap + size, 0, pad); datap += size + pad; @@ -897,36 +864,62 @@ getresponse( */ ++numrecv; if (numrecv <= lastseq) - goto again; + goto again; return INFO_OKAY; } /* * sendrequest - format and send a request packet + * + * Historically, ntpdc has used a fixed-size request packet regardless + * of the actual payload size. When authenticating, the timestamp, key + * ID, and digest have been placed just before the end of the packet. + * With the introduction in late 2009 of support for authenticated + * ntpdc requests using larger 20-octet digests (vs. 16 for MD5), we + * come up four bytes short. + * + * To maintain interop while allowing for larger digests, the behavior + * is unchanged when using 16-octet digests. For larger digests, the + * timestamp, key ID, and digest are placed immediately following the + * request payload, with the overall packet size variable. ntpd can + * distinguish 16-octet digests by the overall request size being + * REQ_LEN_NOMAC + 4 + 16 with the auth bit enabled. When using a + * longer digest, that request size should be avoided. + * + * With the form used with 20-octet and larger digests, the timestamp, + * key ID, and digest are located by ntpd relative to the start of the + * packet, and the size of the digest is then implied by the packet + * size. */ static int sendrequest( int implcode, int reqcode, int auth, - int qitems, - int qsize, + u_int qitems, + size_t qsize, char *qdata ) { struct req_pkt qpkt; - int datasize; + size_t datasize; + size_t reqsize; + u_long key_id; + l_fp ts; + l_fp * ptstamp; + int maclen; + char * pass; - memset((char *)&qpkt, 0, sizeof qpkt); + memset(&qpkt, 0, sizeof(qpkt)); qpkt.rm_vn_mode = RM_VN_MODE(0, 0, 0); qpkt.implementation = (u_char)implcode; qpkt.request = (u_char)reqcode; datasize = qitems * qsize; - if (datasize != 0 && qdata != NULL) { - memmove((char *)qpkt.data, qdata, (unsigned)datasize); + if (datasize && qdata != NULL) { + memcpy(qpkt.data, qdata, datasize); qpkt.err_nitems = ERR_NITEMS(0, qitems); qpkt.mbz_itemsize = MBZ_ITEMSIZE(qsize); } else { @@ -936,53 +929,61 @@ sendrequest( if (!auth || (keyid_entered && info_auth_keyid == 0)) { qpkt.auth_seq = AUTH_SEQ(0, 0); - return sendpkt((char *)&qpkt, req_pkt_size); - } else { - l_fp ts; - int maclen = 0; - const char *pass = "\0"; - struct req_pkt_tail *qpktail; - - qpktail = (struct req_pkt_tail *)((char *)&qpkt + req_pkt_size - + MAX_MAC_LEN - sizeof(struct req_pkt_tail)); + return sendpkt(&qpkt, req_pkt_size); + } - if (info_auth_keyid == 0) { - if (((struct conf_peer *)qpkt.data)->keyid > 0) - info_auth_keyid = ((struct conf_peer *)qpkt.data)->keyid; - else { - maclen = getkeyid("Keyid: "); - if (maclen == 0) { - (void) fprintf(stderr, - "Invalid key identifier\n"); - return 1; - } - info_auth_keyid = maclen; - } + if (info_auth_keyid == 0) { + key_id = getkeyid("Keyid: "); + if (!key_id) { + fprintf(stderr, "Invalid key identifier\n"); + return 1; } - if (!authistrusted(info_auth_keyid)) { - pass = getpass("MD5 Password: "); - if (*pass == '\0') { - (void) fprintf(stderr, - "Invalid password\n"); - return (1); - } + info_auth_keyid = key_id; + } + if (!authistrusted(info_auth_keyid)) { + pass = getpass_keytype(info_auth_keytype); + if ('\0' == pass[0]) { + fprintf(stderr, "Invalid password\n"); + return 1; } - authusekey(info_auth_keyid, info_auth_keytype, (const u_char *)pass); + authusekey(info_auth_keyid, info_auth_keytype, + (u_char *)pass); authtrust(info_auth_keyid, 1); - qpkt.auth_seq = AUTH_SEQ(1, 0); - qpktail->keyid = htonl(info_auth_keyid); - get_systime(&ts); - L_ADD(&ts, &delay_time); - HTONL_FP(&ts, &qpktail->tstamp); - maclen = authencrypt(info_auth_keyid, (u_int32 *)&qpkt, - req_pkt_size); - if (maclen == 0) { - (void) fprintf(stderr, "Key not found\n"); - return (1); - } - return sendpkt((char *)&qpkt, (int)(req_pkt_size + maclen)); } - /*NOTREACHED*/ + qpkt.auth_seq = AUTH_SEQ(1, 0); + if (info_auth_hashlen > 16) { + /* + * Only ntpd which expects REQ_LEN_NOMAC plus maclen + * octets in an authenticated request using a 16 octet + * digest (that is, a newer ntpd) will handle digests + * larger than 16 octets, so for longer digests, do + * not attempt to shorten the requests for downlevel + * ntpd compatibility. + */ + if (REQ_LEN_NOMAC != req_pkt_size) + return 1; + reqsize = REQ_LEN_HDR + datasize + sizeof(*ptstamp); + /* align to 32 bits */ + reqsize = (reqsize + 3) & ~3; + } else + reqsize = req_pkt_size; + ptstamp = (void *)((char *)&qpkt + reqsize); + ptstamp--; + get_systime(&ts); + L_ADD(&ts, &delay_time); + HTONL_FP(&ts, ptstamp); + maclen = authencrypt(info_auth_keyid, (void *)&qpkt, reqsize); + if (!maclen) { + fprintf(stderr, "Key not found\n"); + return 1; + } else if (maclen != (info_auth_hashlen + sizeof(keyid_t))) { + fprintf(stderr, + "%d octet MAC, %lu expected with %lu octet digest\n", + maclen, (u_long)(info_auth_hashlen + sizeof(keyid_t)), + (u_long)info_auth_hashlen); + return 1; + } + return sendpkt(&qpkt, reqsize + maclen); } @@ -1007,7 +1008,7 @@ doquery( int res; char junk[512]; fd_set fds; - struct timeval tvzero; + struct sock_timeval tvzero; /* * Check to make sure host is open @@ -1041,7 +1042,7 @@ again: */ res = sendrequest(implcode, reqcode, auth, qitems, qsize, qdata); if (res != 0) - return res; + return res; /* * Get the response. If we got a standard error, print a message @@ -1079,36 +1080,36 @@ again: /* log error message if not told to be quiet */ if ((res > 0) && (((1 << res) & quiet_mask) == 0)) { switch(res) { - case INFO_ERR_IMPL: + 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; - case INFO_ERR_REQ: + case INFO_ERR_REQ: (void) fprintf(stderr, "***Server doesn't implement this request\n"); break; - case INFO_ERR_FMT: + case INFO_ERR_FMT: (void) fprintf(stderr, "***Server reports a format error in the received packet (shouldn't happen)\n"); break; - case INFO_ERR_NODATA: + case INFO_ERR_NODATA: (void) fprintf(stderr, "***Server reports data not found\n"); break; - case INFO_ERR_AUTH: + case INFO_ERR_AUTH: (void) fprintf(stderr, "***Permission denied\n"); break; - case ERR_TIMEOUT: + case ERR_TIMEOUT: (void) fprintf(stderr, "***Request timed out\n"); break; - case ERR_INCOMPLETE: + case ERR_INCOMPLETE: (void) fprintf(stderr, "***Response from server was incomplete\n"); break; - default: + default: (void) fprintf(stderr, "***Server returns unknown error code %d\n", res); break; @@ -1124,33 +1125,20 @@ again: static void getcmds(void) { -#if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT) - char *line; + char * line; + int count; + + ntp_readline_init(interactive ? prompt : NULL); for (;;) { - if ((line = readline(interactive?prompt:"")) == NULL) return; - if (*line) add_history(line); + line = ntp_readline(&count); + if (NULL == line) + break; docmd(line); free(line); } -#else /* not (HAVE_LIBREADLINE || HAVE_LIBEDIT) */ - char line[MAXLINE]; - for (;;) { - if (interactive) { -#ifdef VMS /* work around a problem with mixing stdout & stderr */ - fputs("",stdout); -#endif - (void) fputs(prompt, stderr); - (void) fflush(stderr); - } - - if (fgets(line, sizeof line, stdin) == NULL) - return; - - docmd(line); - } -#endif /* not HAVE_LIBREADLINE || HAVE_LIBEDIT */ + ntp_readline_uninit(); } @@ -1482,41 +1470,47 @@ getarg( static int getnetnum( const char *hname, - struct sockaddr_storage *num, + sockaddr_u *num, char *fullhost, int af ) { - 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)); + ZERO(hints); hints.ai_flags = AI_CANONNAME; #ifdef AI_ADDRCONFIG hints.ai_flags |= AI_ADDRCONFIG; #endif - /* decodenetnum only works with addresses */ + /* + * decodenetnum only works with addresses, but handles syntax + * that getaddrinfo doesn't: [2001::1]:1234 + */ if (decodenetnum(hname, num)) { - if (fullhost != 0) { - getnameinfo((struct sockaddr *)num, sockaddr_len, - fullhost, sizeof(fullhost), NULL, 0, - NI_NUMERICHOST); - } + if (fullhost != NULL) + getnameinfo(&num->sa, SOCKLEN(num), fullhost, + LENHOSTNAME, NULL, 0, 0); return 1; } else if (getaddrinfo(hname, "ntp", &hints, &ai) == 0) { - memmove((char *)num, ai->ai_addr, ai->ai_addrlen); - if (fullhost != 0) - (void) strcpy(fullhost, ai->ai_canonname); + NTP_INSIST(sizeof(*num) >= ai->ai_addrlen); + memcpy(num, ai->ai_addr, ai->ai_addrlen); + if (fullhost != NULL) { + if (ai->ai_canonname != NULL) { + strncpy(fullhost, ai->ai_canonname, + LENHOSTNAME); + fullhost[LENHOSTNAME - 1] = '\0'; + } else { + getnameinfo(&num->sa, SOCKLEN(num), + fullhost, LENHOSTNAME, NULL, + 0, 0); + } + } return 1; - } else { - (void) fprintf(stderr, "***Can't find host %s\n", hname); - return 0; } - /*NOTREACHED*/ + fprintf(stderr, "***Can't find host %s\n", hname); + + return 0; } /* @@ -1525,13 +1519,13 @@ getnetnum( */ char * nntohost( - struct sockaddr_storage *netnum + sockaddr_u *netnum ) { if (!showhostnames) - return stoa(netnum); + return stoa(netnum); - if ((netnum->ss_family == AF_INET) && ISREFCLOCKADR(netnum)) + if (ISREFCLOCKADR(netnum)) return refnumtoa(netnum); return socktohost(netnum); } @@ -1553,58 +1547,51 @@ help( struct xcmd *xcp; char *cmd; const char *list[100]; - int word, words; - int row, rows; - int col, cols; + size_t word, words; + size_t row, rows; + size_t col, cols; + size_t length; if (pcmd->nargs == 0) { words = 0; for (xcp = builtins; xcp->keyword != 0; xcp++) { if (*(xcp->keyword) != '?') - list[words++] = xcp->keyword; + list[words++] = xcp->keyword; } - for (xcp = opcmds; xcp->keyword != 0; xcp++) - list[words++] = xcp->keyword; + for (xcp = opcmds; xcp->keyword != 0; xcp++) + list[words++] = xcp->keyword; - qsort( -#ifdef QSORT_USES_VOID_P - (void *) -#else - (char *) -#endif - (list), (size_t)(words), sizeof(char *), helpsort); + qsort((void *)list, (size_t)words, sizeof(list[0]), + helpsort); col = 0; for (word = 0; word < words; word++) { - int length = strlen(list[word]); - if (col < length) { - col = length; - } + length = strlen(list[word]); + col = max(col, length); } cols = SCREENWIDTH / ++col; - rows = (words + cols - 1) / cols; + rows = (words + cols - 1) / cols; - (void) fprintf(fp, "ntpdc commands:\n"); + fprintf(fp, "ntpdc commands:\n"); for (row = 0; row < rows; row++) { - for (word = row; word < words; word += rows) { - (void) fprintf(fp, "%-*.*s", col, col-1, list[word]); - } - (void) fprintf(fp, "\n"); + for (word = row; word < words; word += rows) + fprintf(fp, "%-*.*s", col, col-1, list[word]); + fprintf(fp, "\n"); } } else { cmd = pcmd->argval[0].string; words = findcmd(cmd, builtins, opcmds, &xcp); if (words == 0) { - (void) fprintf(stderr, - "Command `%s' is unknown\n", cmd); + fprintf(stderr, + "Command `%s' is unknown\n", cmd); return; } else if (words >= 2) { - (void) fprintf(stderr, - "Command `%s' is ambiguous\n", cmd); + fprintf(stderr, + "Command `%s' is ambiguous\n", cmd); return; } - (void) fprintf(fp, "function: %s\n", xcp->comment); + fprintf(fp, "function: %s\n", xcp->comment); printusage(xcp, fp); } } @@ -1613,28 +1600,17 @@ help( /* * helpsort - do hostname qsort comparisons */ -#ifdef QSORT_USES_VOID_P static int helpsort( const void *t1, const void *t2 ) { - char const * const * name1 = (char const * const *)t1; - char const * const * name2 = (char const * const *)t2; + const char * const * name1 = t1; + const char * const * name2 = t2; return strcmp(*name1, *name2); } -#else -static int -helpsort( - char **name1, - char **name2 - ) -{ - return strcmp(*name1, *name2); -} -#endif /* @@ -1799,21 +1775,34 @@ keytype( FILE *fp ) { - if (pcmd->nargs == 0) - fprintf(fp, "keytype is %s\n", - (info_auth_keytype == KEY_TYPE_MD5) ? "MD5" : "???"); - else - switch (*(pcmd->argval[0].string)) { - case 'm': - case 'M': - info_auth_keytype = KEY_TYPE_MD5; - break; + const char * digest_name; + size_t digest_len; + int key_type; + + if (!pcmd->nargs) { + fprintf(fp, "keytype is %s with %lu octet digests\n", + keytype_name(info_auth_keytype), + (u_long)info_auth_hashlen); + return; + } - default: - fprintf(fp, "keytype must be 'md5'\n"); - } -} + digest_name = pcmd->argval[0].string; + digest_len = 0; + key_type = keytype_from_text(digest_name, &digest_len); + if (!key_type) { + fprintf(fp, "keytype must be 'md5'%s\n", +#ifdef OPENSSL + " or a digest type provided by OpenSSL"); +#else + ""); +#endif + return; + } + + info_auth_keytype = key_type; + info_auth_hashlen = digest_len; +} /* @@ -1840,7 +1829,7 @@ passwd( (u_char *)pcmd->argval[0].string); authtrust(info_auth_keyid, 1); } else { - pass = getpass("MD5 Password: "); + pass = getpass_keytype(info_auth_keytype); if (*pass == '\0') (void) fprintf(fp, "Password unchanged\n"); else { @@ -1974,26 +1963,28 @@ getkeyid( const char *keyprompt ) { - register char *p; - register int c; + int c; FILE *fi; char pbuf[20]; + size_t i; + size_t ilim; #ifndef SYS_WINNT if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL) #else - if ((fi = _fdopen((int)GetStdHandle(STD_INPUT_HANDLE), "r")) == NULL) + if ((fi = _fdopen(open("CONIN$", _O_TEXT), "r")) == NULL) #endif /* SYS_WINNT */ fi = stdin; - else + else setbuf(fi, (char *)NULL); fprintf(stderr, "%s", keyprompt); fflush(stderr); - for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) { - if (p < &pbuf[18]) - *p++ = (char) c; - } - *p = '\0'; + for (i = 0, ilim = COUNTOF(pbuf) - 1; + i < ilim && (c = getc(fi)) != '\n' && c != EOF; + ) + pbuf[i++] = (char)c; + pbuf[i] = '\0'; if (fi != stdin) - fclose(fi); - return (u_int32)atoi(pbuf); + fclose(fi); + + return (u_long) atoi(pbuf); } diff --git a/ntpdc/ntpdc.h b/ntpdc/ntpdc.h index 785c312..9d41a70 100644 --- a/ntpdc/ntpdc.h +++ b/ntpdc/ntpdc.h @@ -34,7 +34,7 @@ typedef struct { char *string; long ival; u_long uval; - struct sockaddr_storage netnum; + sockaddr_u netnum; } arg_v; /* @@ -53,7 +53,7 @@ struct parse { */ struct xcmd { const char *keyword; /* command key word */ - void (*handler) P((struct parse *, FILE *)); /* command handler */ + void (*handler) (struct parse *, FILE *); /* command handler */ u_char arg[MAXARGS]; /* descriptors for arguments */ const char *desc[MAXARGS]; /* descriptions for arguments */ const char *comment; @@ -63,5 +63,5 @@ 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 *)); +extern int doquery (int, int, int, int, int, char *, int *, int *, char **, int, int); +extern char * nntohost (sockaddr_u *); diff --git a/ntpdc/ntpdc_ops.c b/ntpdc/ntpdc_ops.c index e40016b..9350c8c 100644 --- a/ntpdc/ntpdc_ops.c +++ b/ntpdc/ntpdc_ops.c @@ -1,5 +1,6 @@ /* - * ntpdc_ops.c - subroutines which are called to perform operations by xntpdc + * ntpdc_ops.c - subroutines which are called to perform operations by + * ntpdc */ #ifdef HAVE_CONFIG_H @@ -10,6 +11,7 @@ #include <stddef.h> #include "ntpdc.h" +#include "ntp_net.h" #include "ntp_control.h" #include "ntp_refclock.h" #include "ntp_stdlib.h" @@ -19,67 +21,73 @@ # include <sys/timex.h> #endif #if !defined(__bsdi__) && !defined(apollo) +#ifdef HAVE_NETINET_IN_H #include <netinet/in.h> #endif +#endif #include <arpa/inet.h> /* + * utility functions + */ +static int checkitems (int, FILE *); +static int checkitemsize (int, int); +static int check1item (int, FILE *); + +/* * Declarations for command handlers in here */ -static int checkitems P((int, FILE *)); -static int checkitemsize P((int, int)); -static int check1item P((int, FILE *)); -static void peerlist P((struct parse *, FILE *)); -static void peers P((struct parse *, FILE *)); -static void doconfig P((struct parse *pcmd, FILE *fp, int mode, int refc)); -static void dmpeers P((struct parse *, FILE *)); -static void dopeers P((struct parse *, FILE *, int)); -static void printpeer P((struct info_peer *, FILE *)); -static void showpeer P((struct parse *, FILE *)); -static void peerstats P((struct parse *, FILE *)); -static void loopinfo P((struct parse *, FILE *)); -static void sysinfo P((struct parse *, FILE *)); -static void sysstats P((struct parse *, FILE *)); -static void iostats P((struct parse *, FILE *)); -static void memstats P((struct parse *, FILE *)); -static void timerstats P((struct parse *, FILE *)); -static void addpeer P((struct parse *, FILE *)); -static void addserver P((struct parse *, FILE *)); -static void addrefclock P((struct parse *, FILE *)); -static void broadcast P((struct parse *, FILE *)); -static void doconfig P((struct parse *, FILE *, int, int)); -static void unconfig P((struct parse *, FILE *)); -static void set P((struct parse *, FILE *)); -static void sys_clear P((struct parse *, FILE *)); -static void doset P((struct parse *, FILE *, int)); -static void reslist P((struct parse *, FILE *)); -static void new_restrict P((struct parse *, FILE *)); -static void unrestrict P((struct parse *, FILE *)); -static void delrestrict P((struct parse *, FILE *)); -static void do_restrict P((struct parse *, FILE *, int)); -static void monlist P((struct parse *, FILE *)); -static void reset P((struct parse *, FILE *)); -static void preset P((struct parse *, FILE *)); -static void readkeys P((struct parse *, FILE *)); -static void trustkey P((struct parse *, FILE *)); -static void untrustkey P((struct parse *, FILE *)); -static void do_trustkey P((struct parse *, FILE *, int)); -static void authinfo P((struct parse *, FILE *)); -static void traps P((struct parse *, FILE *)); -static void addtrap P((struct parse *, FILE *)); -static void clrtrap P((struct parse *, FILE *)); -static void do_addclr_trap P((struct parse *, FILE *, int)); -static void requestkey P((struct parse *, FILE *)); -static void controlkey P((struct parse *, FILE *)); -static void do_changekey P((struct parse *, FILE *, int)); -static void ctlstats P((struct parse *, FILE *)); -static void clockstat P((struct parse *, FILE *)); -static void fudge P((struct parse *, FILE *)); -static void clkbug P((struct parse *, FILE *)); -static void kerninfo P((struct parse *, FILE *)); -static void get_if_stats P((struct parse *, FILE *)); -static void do_if_reload P((struct parse *, FILE *)); +static void peerlist (struct parse *, FILE *); +static void peers (struct parse *, FILE *); +static void doconfig (struct parse *pcmd, FILE *fp, int mode, int refc); +static void dmpeers (struct parse *, FILE *); +static void dopeers (struct parse *, FILE *, int); +static void printpeer (struct info_peer *, FILE *); +static void showpeer (struct parse *, FILE *); +static void peerstats (struct parse *, FILE *); +static void loopinfo (struct parse *, FILE *); +static void sysinfo (struct parse *, FILE *); +static void sysstats (struct parse *, FILE *); +static void iostats (struct parse *, FILE *); +static void memstats (struct parse *, FILE *); +static void timerstats (struct parse *, FILE *); +static void addpeer (struct parse *, FILE *); +static void addserver (struct parse *, FILE *); +static void addrefclock (struct parse *, FILE *); +static void broadcast (struct parse *, FILE *); +static void doconfig (struct parse *, FILE *, int, int); +static void unconfig (struct parse *, FILE *); +static void set (struct parse *, FILE *); +static void sys_clear (struct parse *, FILE *); +static void doset (struct parse *, FILE *, int); +static void reslist (struct parse *, FILE *); +static void new_restrict (struct parse *, FILE *); +static void unrestrict (struct parse *, FILE *); +static void delrestrict (struct parse *, FILE *); +static void do_restrict (struct parse *, FILE *, int); +static void monlist (struct parse *, FILE *); +static void reset (struct parse *, FILE *); +static void preset (struct parse *, FILE *); +static void readkeys (struct parse *, FILE *); +static void trustkey (struct parse *, FILE *); +static void untrustkey (struct parse *, FILE *); +static void do_trustkey (struct parse *, FILE *, int); +static void authinfo (struct parse *, FILE *); +static void traps (struct parse *, FILE *); +static void addtrap (struct parse *, FILE *); +static void clrtrap (struct parse *, FILE *); +static void do_addclr_trap (struct parse *, FILE *, int); +static void requestkey (struct parse *, FILE *); +static void controlkey (struct parse *, FILE *); +static void do_changekey (struct parse *, FILE *, int); +static void ctlstats (struct parse *, FILE *); +static void clockstat (struct parse *, FILE *); +static void fudge (struct parse *, FILE *); +static void clkbug (struct parse *, FILE *); +static void kerninfo (struct parse *, FILE *); +static void get_if_stats (struct parse *, FILE *); +static void do_if_reload (struct parse *, FILE *); /* * Commands we understand. Ntpdc imports this. @@ -221,6 +229,84 @@ struct xcmd opcmds[] = { */ #define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0) +/* + * SET_SS_LEN_IF_PRESENT - used by SET_ADDR, SET_ADDRS macros + */ + +#ifdef ISC_PLATFORM_HAVESALEN +#define SET_SS_LEN_IF_PRESENT(psau) \ + do { \ + (psau)->sa.sa_len = SOCKLEN(psau); \ + } while (0) +#else +#define SET_SS_LEN_IF_PRESENT(psau) do { } while (0) +#endif + +/* + * SET_ADDR - setup address for v4/v6 as needed + */ +#define SET_ADDR(address, v6flag, v4addr, v6addr) \ +do { \ + memset(&(address), 0, sizeof(address)); \ + if (v6flag) { \ + AF(&(address)) = AF_INET6; \ + SOCK_ADDR6(&(address)) = (v6addr); \ + } else { \ + AF(&(address)) = AF_INET; \ + NSRCADR(&(address)) = (v4addr); \ + } \ + SET_SS_LEN_IF_PRESENT(&(address)); \ +} while (0) + + +/* + * SET_ADDRS - setup source and destination addresses for + * v4/v6 as needed + */ +#define SET_ADDRS(a1, a2, info, a1prefix, a2prefix) \ +do { \ + memset(&(a1), 0, sizeof(a1)); \ + memset(&(a2), 0, sizeof(a2)); \ + if ((info)->v6_flag) { \ + AF(&(a1)) = AF_INET6; \ + AF(&(a2)) = AF_INET6; \ + SOCK_ADDR6(&(a1)) = (info)->a1prefix##6; \ + SOCK_ADDR6(&(a2)) = (info)->a2prefix##6; \ + } else { \ + AF(&(a1)) = AF_INET; \ + AF(&(a2)) = AF_INET; \ + NSRCADR(&(a1)) = (info)->a1prefix; \ + NSRCADR(&(a2)) = (info)->a2prefix; \ + } \ + SET_SS_LEN_IF_PRESENT(&(a1)); \ + SET_SS_LEN_IF_PRESENT(&(a2)); \ +} while (0) + + +/* + * SET_ADDRS - setup source and destination addresses for + * v4/v6 as needed + */ +#if 0 +#define SET_ADDR_MASK(address, addrmask, info) \ +do { \ + memset(&(address), 0, sizeof(address)); \ + memset(&(mask), 0, sizeof(mask)); \ + if ((info)->v6_flag) { \ + AF(&(address)) = AF_INET6; \ + AF(&(addrmask)) = AF_INET6; \ + SOCK_ADDR6(&(address)) = (info)->addr6; \ + SOCK_ADDR6(&(addrmask)) = (info)->mask6; \ + } else { \ + AF(&(address)) = AF_INET; \ + AF(&(addrmask)) = AF_INET; \ + NSRCADR(&(address)) = (info)->addr; \ + NSRCADR(&(addrmask)) = (info)->mask; \ + } \ + SET_SS_LEN_IF_PRESENT(&(address)); \ + SET_SS_LEN_IF_PRESENT(&(addrmask)); \ +} while (0) +#endif /* * checkitems - utility to print a message if no items were returned @@ -280,7 +366,6 @@ check1item( } - /* * peerlist - get a short list of peers */ @@ -292,7 +377,7 @@ peerlist( ) { struct info_peer_list *plist; - struct sockaddr_storage paddr; + sockaddr_u paddr; int items; int itemsize; int res; @@ -318,17 +403,7 @@ again: return; while (items > 0) { - 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 + SET_ADDR(paddr, plist->v6_flag, plist->addr, plist->addr6); if ((pcmd->nargs == 0) || ((pcmd->argval->ival == 6) && (plist->v6_flag != 0)) || ((pcmd->argval->ival == 4) && (plist->v6_flag == 0))) @@ -378,8 +453,8 @@ dopeers( ) { struct info_peer_summary *plist; - struct sockaddr_storage dstadr; - struct sockaddr_storage srcadr; + sockaddr_u dstadr; + sockaddr_u srcadr; int items; int itemsize; int ntp_poll; @@ -440,28 +515,12 @@ again: NTOHL_FP(&(plist->offset), &tempts); ntp_poll = 1<<max(min3(plist->ppoll, plist->hpoll, NTP_MAXPOLL), NTP_MINPOLL); - 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 + SET_ADDRS(dstadr, srcadr, plist, dstadr, srcadr); 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%-15.15s %-15.15s %2u %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), @@ -546,25 +605,10 @@ printpeer( { register int i; l_fp tempts; - struct sockaddr_storage srcadr, dstadr; + sockaddr_u srcadr, dstadr; + + SET_ADDRS(dstadr, srcadr, pp, dstadr, srcadr); - 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", stoa(&srcadr), stoa(&dstadr)); (void) fprintf(fp, "hmode %s, pmode %s, stratum %d, precision %d\n", @@ -653,6 +697,7 @@ showpeer( struct info_peer *pp; /* 4 is the maximum number of peers which will fit in a packet */ struct info_peer_list *pl, plist[min(MAXARGS, 4)]; + int qitemlim; int qitems; int items; int itemsize; @@ -665,9 +710,10 @@ again: 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); + qitemlim = min(pcmd->nargs, COUNTOF(plist)); + for (qitems = 0, pl = plist; qitems < qitemlim; qitems++) { + if (IS_IPV4(&pcmd->argval[qitems].netnum)) { + pl->addr = NSRCADR(&pcmd->argval[qitems].netnum); if (impl_ver == IMPL_XNTPD) pl->v6_flag = 0; } else { @@ -676,7 +722,7 @@ again: "***Server doesn't understand IPv6 addresses\n"); return; } - pl->addr6 = GET_INADDR6(pcmd->argval[qitems].netnum); + pl->addr6 = SOCK_ADDR6(&pcmd->argval[qitems].netnum); pl->v6_flag = 1; } pl->port = (u_short)s_port; @@ -724,7 +770,8 @@ peerstats( struct info_peer_stats *pp; /* 4 is the maximum number of peers which will fit in a packet */ struct info_peer_list *pl, plist[min(MAXARGS, 4)]; - struct sockaddr_storage src, dst; + sockaddr_u src, dst; + int qitemlim; int qitems; int items; int itemsize; @@ -737,10 +784,12 @@ again: 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); + memset(plist, 0, sizeof(plist)); + + qitemlim = min(pcmd->nargs, COUNTOF(plist)); + for (qitems = 0, pl = plist; qitems < qitemlim; qitems++) { + if (IS_IPV4(&pcmd->argval[qitems].netnum)) { + pl->addr = NSRCADR(&pcmd->argval[qitems].netnum); if (impl_ver == IMPL_XNTPD) pl->v6_flag = 0; } else { @@ -749,7 +798,7 @@ again: "***Server doesn't understand IPv6 addresses\n"); return; } - pl->addr6 = GET_INADDR6(pcmd->argval[qitems].netnum); + pl->addr6 = SOCK_ADDR6(&pcmd->argval[qitems].netnum); pl->v6_flag = 1; } pl->port = (u_short)s_port; @@ -778,54 +827,54 @@ again: return; while (items-- > 0) { - memset((char *)&src, 0, sizeof(src)); - memset((char *)&dst, 0, sizeof(dst)); + ZERO_SOCK(&dst); + ZERO_SOCK(&src); 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; + AF(&dst) = AF_INET6; + AF(&src) = AF_INET6; + SOCK_ADDR6(&dst) = pp->dstadr6; + SOCK_ADDR6(&src) = pp->srcadr6; } else { - GET_INADDR(src) = pp->srcadr; - GET_INADDR(dst) = pp->dstadr; - src.ss_family = AF_INET; - dst.ss_family = AF_INET; + AF(&dst) = AF_INET; + AF(&src) = AF_INET; + NSRCADR(&dst) = pp->dstadr; + NSRCADR(&src) = pp->srcadr; } -#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR - src.ss_len = SOCKLEN(&src); - dst.ss_len = SOCKLEN(&dst); +#ifdef ISC_PLATFORM_HAVESALEN + src.sa.sa_len = SOCKLEN(&src); + dst.sa.sa_len = SOCKLEN(&dst); #endif - (void) fprintf(fp, "remote host: %s\n", - nntohost(&src)); - (void) fprintf(fp, "local interface: %s\n", - stoa(&dst)); - (void) fprintf(fp, "time last received: %lds\n", - (long)ntohl(pp->timereceived)); - (void) fprintf(fp, "time until next send: %lds\n", - (long)ntohl(pp->timetosend)); - (void) fprintf(fp, "reachability change: %lds\n", - (long)ntohl(pp->timereachable)); - (void) fprintf(fp, "packets sent: %ld\n", - (long)ntohl(pp->sent)); - (void) fprintf(fp, "packets received: %ld\n", - (long)ntohl(pp->processed)); - (void) fprintf(fp, "bad authentication: %ld\n", - (long)ntohl(pp->badauth)); - (void) fprintf(fp, "bogus origin: %ld\n", - (long)ntohl(pp->bogusorg)); - (void) fprintf(fp, "duplicate: %ld\n", - (long)ntohl(pp->oldpkt)); - (void) fprintf(fp, "bad dispersion: %ld\n", - (long)ntohl(pp->seldisp)); - (void) fprintf(fp, "bad reference time: %ld\n", - (long)ntohl(pp->selbroken)); - (void) fprintf(fp, "candidate order: %d\n", - (int)pp->candidate); + fprintf(fp, "remote host: %s\n", + nntohost(&src)); + fprintf(fp, "local interface: %s\n", + stoa(&dst)); + fprintf(fp, "time last received: %lus\n", + (u_long)ntohl(pp->timereceived)); + fprintf(fp, "time until next send: %lus\n", + (u_long)ntohl(pp->timetosend)); + fprintf(fp, "reachability change: %lus\n", + (u_long)ntohl(pp->timereachable)); + fprintf(fp, "packets sent: %lu\n", + (u_long)ntohl(pp->sent)); + fprintf(fp, "packets received: %lu\n", + (u_long)ntohl(pp->processed)); + fprintf(fp, "bad authentication: %lu\n", + (u_long)ntohl(pp->badauth)); + fprintf(fp, "bogus origin: %lu\n", + (u_long)ntohl(pp->bogusorg)); + fprintf(fp, "duplicate: %lu\n", + (u_long)ntohl(pp->oldpkt)); + fprintf(fp, "bad dispersion: %lu\n", + (u_long)ntohl(pp->seldisp)); + fprintf(fp, "bad reference time: %lu\n", + (u_long)ntohl(pp->selbroken)); + fprintf(fp, "candidate order: %u\n", + pp->candidate); if (items > 0) - (void) fprintf(fp, "\n"); - (void) fprintf(fp, "flags: "); + fprintf(fp, "\n"); + fprintf(fp, "flags: "); print_pflag(fp, ntohs(pp->flags)); - pp++; + pp++; } } @@ -886,7 +935,7 @@ again: "offset %s, frequency %s, time_const %ld, watchdog %ld\n", lfptoa(&tempts, 6), lfptoa(&temp2ts, 3), - (long)(int32_t)ntohl((u_long)il->compliance), + (long)(int32)ntohl((u_long)il->compliance), (u_long)ntohl((u_long)il->watchdog_timer)); } else { NTOHL_FP(&il->last_offset, &tempts); @@ -896,7 +945,7 @@ again: (void) fprintf(fp, "frequency: %s ppm\n", lfptoa(&tempts, 3)); (void) fprintf(fp, "poll adjust: %ld\n", - (long)(int32_t)ntohl(il->compliance)); + (long)(int32)ntohl(il->compliance)); (void) fprintf(fp, "watchdog timer: %ld s\n", (u_long)ntohl(il->watchdog_timer)); } @@ -914,7 +963,7 @@ sysinfo( ) { struct info_sys *is; - struct sockaddr_storage peeraddr; + sockaddr_u peeraddr; int items; int itemsize; int res; @@ -940,17 +989,8 @@ again: !checkitemsize(itemsize, v4sizeof(struct info_sys))) return; - 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 + SET_ADDR(peeraddr, is->v6_flag, is->peer, is->peer6); + (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", @@ -1039,30 +1079,30 @@ again: checkitemsize(itemsize, sizeof(struct info_sys_stats)); return; } - fprintf(fp, "time since restart: %ld\n", - (u_long)ntohl(ss->timeup)); - fprintf(fp, "time since reset: %ld\n", + fprintf(fp, "time since restart: %lu\n", + (u_long)ntohl(ss->timeup)); + fprintf(fp, "time since reset: %lu\n", (u_long)ntohl(ss->timereset)); - fprintf(fp, "packets received: %ld\n", + fprintf(fp, "packets received: %lu\n", (u_long)ntohl(ss->received)); - fprintf(fp, "packets processed: %ld\n", + fprintf(fp, "packets processed: %lu\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", + fprintf(fp, "current version: %lu\n", + (u_long)ntohl(ss->newversionpkt)); + fprintf(fp, "previous version: %lu\n", + (u_long)ntohl(ss->oldversionpkt)); + fprintf(fp, "declined: %lu\n", + (u_long)ntohl(ss->unknownversion)); + fprintf(fp, "access denied: %lu\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)); + fprintf(fp, "bad length or format: %lu\n", + (u_long)ntohl(ss->badlength)); + fprintf(fp, "bad authentication: %lu\n", + (u_long)ntohl(ss->badauth)); if (itemsize != sizeof(struct info_sys_stats)) return; - fprintf(fp, "rate exceeded: %ld\n", + fprintf(fp, "rate exceeded: %lu\n", (u_long)ntohl(ss->limitrejected)); } @@ -1084,9 +1124,8 @@ iostats( int res; again: - res = doquery(impl_ver, REQ_IO_STATS, 0, 0, 0, (char *)NULL, - &items, &itemsize, (void *)&io, 0, - sizeof(struct info_io_stats)); + res = doquery(impl_ver, REQ_IO_STATS, 0, 0, 0, NULL, &items, + &itemsize, (void *)&io, 0, sizeof(*io)); if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { impl_ver = IMPL_XNTPD_OLD; @@ -1094,38 +1133,38 @@ again: } if (res != 0) - return; + return; if (!check1item(items, fp)) - return; + return; - if (!checkitemsize(itemsize, sizeof(struct info_io_stats))) - return; + if (!checkitemsize(itemsize, sizeof(*io))) + return; - (void) fprintf(fp, "time since reset: %ld\n", - (u_long)ntohl(io->timereset)); - (void) fprintf(fp, "receive buffers: %d\n", - ntohs(io->totalrecvbufs)); - (void) fprintf(fp, "free receive buffers: %d\n", - ntohs(io->freerecvbufs)); - (void) fprintf(fp, "used receive buffers: %d\n", - ntohs(io->fullrecvbufs)); - (void) fprintf(fp, "low water refills: %d\n", - ntohs(io->lowwater)); - (void) fprintf(fp, "dropped packets: %ld\n", - (u_long)ntohl(io->dropped)); - (void) fprintf(fp, "ignored packets: %ld\n", - (u_long)ntohl(io->ignored)); - (void) fprintf(fp, "received packets: %ld\n", - (u_long)ntohl(io->received)); - (void) fprintf(fp, "packets sent: %ld\n", - (u_long)ntohl(io->sent)); - (void) fprintf(fp, "packets not sent: %ld\n", - (u_long)ntohl(io->notsent)); - (void) fprintf(fp, "interrupts handled: %ld\n", - (u_long)ntohl(io->interrupts)); - (void) fprintf(fp, "received by int: %ld\n", - (u_long)ntohl(io->int_received)); + fprintf(fp, "time since reset: %lu\n", + (u_long)ntohl(io->timereset)); + fprintf(fp, "receive buffers: %u\n", + (u_int)ntohs(io->totalrecvbufs)); + fprintf(fp, "free receive buffers: %u\n", + (u_int)ntohs(io->freerecvbufs)); + fprintf(fp, "used receive buffers: %u\n", + (u_int)ntohs(io->fullrecvbufs)); + fprintf(fp, "low water refills: %u\n", + (u_int)ntohs(io->lowwater)); + fprintf(fp, "dropped packets: %lu\n", + (u_long)ntohl(io->dropped)); + fprintf(fp, "ignored packets: %lu\n", + (u_long)ntohl(io->ignored)); + fprintf(fp, "received packets: %lu\n", + (u_long)ntohl(io->received)); + fprintf(fp, "packets sent: %lu\n", + (u_long)ntohl(io->sent)); + fprintf(fp, "packets not sent: %lu\n", + (u_long)ntohl(io->notsent)); + fprintf(fp, "interrupts handled: %lu\n", + (u_long)ntohl(io->interrupts)); + fprintf(fp, "received by int: %lu\n", + (u_long)ntohl(io->int_received)); } @@ -1146,9 +1185,8 @@ memstats( int res; again: - res = doquery(impl_ver, REQ_MEM_STATS, 0, 0, 0, (char *)NULL, - &items, &itemsize, (void *)&mem, 0, - sizeof(struct info_mem_stats)); + res = doquery(impl_ver, REQ_MEM_STATS, 0, 0, 0, NULL, &items, + &itemsize, (void *)&mem, 0, sizeof(*mem)); if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { impl_ver = IMPL_XNTPD_OLD; @@ -1156,35 +1194,34 @@ again: } if (res != 0) - return; + return; if (!check1item(items, fp)) - return; + return; - if (!checkitemsize(itemsize, sizeof(struct info_mem_stats))) - return; + if (!checkitemsize(itemsize, sizeof(*mem))) + return; - (void) fprintf(fp, "time since reset: %ld\n", - (u_long)ntohl(mem->timereset)); - (void) fprintf(fp, "total peer memory: %d\n", - ntohs(mem->totalpeermem)); - (void) fprintf(fp, "free peer memory: %d\n", - ntohs(mem->freepeermem)); - (void) fprintf(fp, "calls to findpeer: %ld\n", - (u_long)ntohl(mem->findpeer_calls)); - (void) fprintf(fp, "new peer allocations: %ld\n", - (u_long)ntohl(mem->allocations)); - (void) fprintf(fp, "peer demobilizations: %ld\n", - (u_long)ntohl(mem->demobilizations)); - - (void) fprintf(fp, "hash table counts: "); + fprintf(fp, "time since reset: %lu\n", + (u_long)ntohl(mem->timereset)); + fprintf(fp, "total peer memory: %u\n", + (u_int)ntohs(mem->totalpeermem)); + fprintf(fp, "free peer memory: %u\n", + (u_int)ntohs(mem->freepeermem)); + fprintf(fp, "calls to findpeer: %lu\n", + (u_long)ntohl(mem->findpeer_calls)); + fprintf(fp, "new peer allocations: %lu\n", + (u_long)ntohl(mem->allocations)); + fprintf(fp, "peer demobilizations: %lu\n", + (u_long)ntohl(mem->demobilizations)); + + fprintf(fp, "hash table counts: "); for (i = 0; i < NTP_HASH_SIZE; i++) { - (void) fprintf(fp, "%4d", (int)mem->hashcount[i]); - if ((i % 8) == 7 && i != (NTP_HASH_SIZE-1)) { - (void) fprintf(fp, "\n "); - } + fprintf(fp, "%4d", (int)mem->hashcount[i]); + if ((i % 8) == 7 && i != (NTP_HASH_SIZE-1)) + fprintf(fp, "\n "); } - (void) fprintf(fp, "\n"); + fprintf(fp, "\n"); } @@ -1205,9 +1242,8 @@ timerstats( int res; again: - res = doquery(impl_ver, REQ_TIMER_STATS, 0, 0, 0, (char *)NULL, - &items, &itemsize, (void *)&tim, 0, - sizeof(struct info_timer_stats)); + res = doquery(impl_ver, REQ_TIMER_STATS, 0, 0, 0, NULL, &items, + &itemsize, (void *)&tim, 0, sizeof(*tim)); if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { impl_ver = IMPL_XNTPD_OLD; @@ -1215,22 +1251,22 @@ again: } if (res != 0) - return; + return; if (!check1item(items, fp)) - return; + return; - if (!checkitemsize(itemsize, sizeof(struct info_timer_stats))) - return; + if (!checkitemsize(itemsize, sizeof(*tim))) + return; - (void) fprintf(fp, "time since reset: %ld\n", - (u_long)ntohl(tim->timereset)); - (void) fprintf(fp, "alarms handled: %ld\n", - (u_long)ntohl(tim->alarms)); - (void) fprintf(fp, "alarm overruns: %ld\n", - (u_long)ntohl(tim->overflows)); - (void) fprintf(fp, "calls to transmit: %ld\n", - (u_long)ntohl(tim->xmtcalls)); + fprintf(fp, "time since reset: %lu\n", + (u_long)ntohl(tim->timereset)); + fprintf(fp, "alarms handled: %lu\n", + (u_long)ntohl(tim->alarms)); + fprintf(fp, "alarm overruns: %lu\n", + (u_long)ntohl(tim->overflows)); + fprintf(fp, "calls to transmit: %lu\n", + (u_long)ntohl(tim->xmtcalls)); } @@ -1292,7 +1328,7 @@ doconfig( struct parse *pcmd, FILE *fp, int mode, - int refc + int refc ) { struct conf_peer cpeer; @@ -1308,18 +1344,19 @@ doconfig( int res; int sendsize; int numtyp; + long val; again: keyid = 0; version = 3; flags = 0; - res = 0; + res = FALSE; cmode = 0; minpoll = NTP_MINDPOLL; maxpoll = NTP_MAXDPOLL; numtyp = 1; if (refc) - numtyp = 5; + numtyp = 5; if (impl_ver == IMPL_XNTPD) sendsize = sizeof(struct conf_peer); @@ -1329,89 +1366,85 @@ again: items = 1; while (pcmd->nargs > items) { if (STREQ(pcmd->argval[items].string, "prefer")) - flags |= CONF_FLAG_PREFER; + flags |= CONF_FLAG_PREFER; else if (STREQ(pcmd->argval[items].string, "burst")) - flags |= CONF_FLAG_BURST; - else if (STREQ(pcmd->argval[items].string, "dynamic")) - (void) fprintf(fp, "Warning: the \"dynamic\" keyword has been obsoleted and will be removed in the next release\n"); + flags |= CONF_FLAG_BURST; else if (STREQ(pcmd->argval[items].string, "iburst")) - flags |= CONF_FLAG_IBURST; + flags |= CONF_FLAG_IBURST; else if (!refc && STREQ(pcmd->argval[items].string, "keyid")) - numtyp = 1; + numtyp = 1; else if (!refc && STREQ(pcmd->argval[items].string, "version")) - numtyp = 2; + numtyp = 2; else if (STREQ(pcmd->argval[items].string, "minpoll")) - numtyp = 3; + numtyp = 3; else if (STREQ(pcmd->argval[items].string, "maxpoll")) - numtyp = 4; + numtyp = 4; else { - long val; if (!atoint(pcmd->argval[items].string, &val)) - numtyp = 0; + numtyp = 0; switch (numtyp) { case 1: - keyid = val; - numtyp = 2; - break; - + keyid = val; + numtyp = 2; + break; + case 2: - version = (u_int) val; - numtyp = 0; - break; + version = (u_int)val; + numtyp = 0; + break; case 3: - minpoll = (u_char)val; - numtyp = 0; - break; + minpoll = (u_char)val; + numtyp = 0; + break; case 4: - maxpoll = (u_char)val; - numtyp = 0; - break; + maxpoll = (u_char)val; + numtyp = 0; + break; case 5: - cmode = (u_char)val; - numtyp = 0; - break; + cmode = (u_char)val; + numtyp = 0; + break; default: - (void) fprintf(fp, "*** '%s' not understood\n", - pcmd->argval[items].string); - res++; - numtyp = 0; + fprintf(fp, "*** '%s' not understood\n", + pcmd->argval[items].string); + res = TRUE; + numtyp = 0; } if (val < 0) { - (void) fprintf(stderr, - "***Value '%s' should be unsigned\n", - pcmd->argval[items].string); - res++; + fprintf(stderr, + "*** Value '%s' should be unsigned\n", + pcmd->argval[items].string); + res = TRUE; } - } - items++; + } + items++; } if (keyid > 0) - flags |= CONF_FLAG_AUTHENABLE; - if (version > NTP_VERSION || - version < NTP_OLDVERSION) { - (void)fprintf(fp, "***invalid version number: %u\n", - version); - res++; + flags |= CONF_FLAG_AUTHENABLE; + if (version > NTP_VERSION || version < NTP_OLDVERSION) { + fprintf(fp, "***invalid version number: %u\n", + version); + res = TRUE; } if (minpoll < NTP_MINPOLL || minpoll > NTP_MAXPOLL || maxpoll < NTP_MINPOLL || maxpoll > NTP_MAXPOLL || minpoll > maxpoll) { - (void) fprintf(fp, "***min/max-poll must be within %d..%d\n", - NTP_MINPOLL, NTP_MAXPOLL); - res++; + fprintf(fp, "***min/max-poll must be within %d..%d\n", + NTP_MINPOLL, NTP_MAXPOLL); + res = TRUE; } if (res) - return; + return; - memset((void *)&cpeer, 0, sizeof(cpeer)); + memset(&cpeer, 0, sizeof(cpeer)); - if (pcmd->argval[0].netnum.ss_family == AF_INET) { - cpeer.peeraddr = GET_INADDR(pcmd->argval[0].netnum); + if (IS_IPV4(&pcmd->argval[0].netnum)) { + cpeer.peeraddr = NSRCADR(&pcmd->argval[0].netnum); if (impl_ver == IMPL_XNTPD) cpeer.v6_flag = 0; } else { @@ -1420,7 +1453,7 @@ again: "***Server doesn't understand IPv6 addresses\n"); return; } - cpeer.peeraddr6 = GET_INADDR6(pcmd->argval[0].netnum); + cpeer.peeraddr6 = SOCK_ADDR6(&pcmd->argval[0].netnum); cpeer.v6_flag = 1; } cpeer.hmode = (u_char) mode; @@ -1465,6 +1498,7 @@ unconfig( { /* 8 is the maximum number of peers which will fit in a packet */ struct conf_unpeer *pl, plist[min(MAXARGS, 8)]; + int qitemlim; int qitems; int items; int itemsize; @@ -1478,9 +1512,10 @@ again: 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); + qitemlim = min(pcmd->nargs, COUNTOF(plist)); + for (qitems = 0, pl = plist; qitems < qitemlim; qitems++) { + if (IS_IPV4(&pcmd->argval[0].netnum)) { + pl->peeraddr = NSRCADR(&pcmd->argval[qitems].netnum); if (impl_ver == IMPL_XNTPD) pl->v6_flag = 0; } else { @@ -1490,7 +1525,7 @@ again: return; } pl->peeraddr6 = - GET_INADDR6(pcmd->argval[qitems].netnum); + SOCK_ADDR6(&pcmd->argval[qitems].netnum); pl->v6_flag = 1; } pl = (struct conf_unpeer *)((char *)pl + sendsize); @@ -1546,7 +1581,6 @@ doset( int req ) { - /* 8 is the maximum number of peers which will fit in a packet */ struct conf_sys_flags sys; int items; int itemsize; @@ -1632,7 +1666,7 @@ static struct resflags resflagsV3[] = { { "lptrap", RES_LPTRAP }, { "limited", RES_LIMITED }, { "version", RES_VERSION }, - { "kod", RES_DEMOBILIZE }, + { "kod", RES_KOD }, { "timeout", RES_TIMEOUT }, { "", 0 } @@ -1656,8 +1690,8 @@ reslist( ) { struct info_restrict *rl; - struct sockaddr_storage resaddr; - struct sockaddr_storage maskaddr; + sockaddr_u resaddr; + sockaddr_u maskaddr; int items; int itemsize; int res; @@ -1697,27 +1731,12 @@ again: "=====================================================================\n"); while (items > 0) { - memset((char *)&resaddr, 0, sizeof(resaddr)); - memset((char *)&maskaddr, 0, sizeof(maskaddr)); + SET_ADDRS(resaddr, maskaddr, rl, addr, mask); 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); + addr = nntohost(&resaddr); else addr = stoa(&resaddr); } @@ -1759,11 +1778,11 @@ again: } if (flagstr[0] == '\0') - (void) strcpy(flagstr, "none"); + strcpy(flagstr, "none"); if (!skip) - (void) fprintf(fp, "%-15.15s %-15.15s %9ld %s\n", - addr, mask, (u_long)count, flagstr); + fprintf(fp, "%-15.15s %-15.15s %9lu %s\n", + addr, mask, (u_long)count, flagstr); rl++; items--; } @@ -1844,23 +1863,23 @@ again: 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 (IS_IPV4(&pcmd->argval[0].netnum)) { + cres.addr = NSRCADR(&pcmd->argval[0].netnum); + cres.mask = NSRCADR(&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"); + "***Server doesn't understand IPv6 addresses\n"); return; } - cres.addr6 = GET_INADDR6(pcmd->argval[0].netnum); + cres.addr6 = SOCK_ADDR6(&pcmd->argval[0].netnum); cres.v6_flag = 1; } cres.flags = 0; cres.mflags = 0; - err = 0; + err = FALSE; for (res = 2; res < pcmd->nargs; res++) { if (STREQ(pcmd->argval[res].string, "ntpport")) { cres.mflags |= RESM_NTPONLY; @@ -1868,20 +1887,20 @@ again: for (i = 0; resflagsV3[i].bit != 0; i++) { if (STREQ(pcmd->argval[res].string, resflagsV3[i].str)) - break; + break; } if (resflagsV3[i].bit != 0) { cres.flags |= resflagsV3[i].bit; if (req_code == REQ_UNRESTRICT) { - (void) fprintf(fp, - "Flag %s inappropriate\n", - resflagsV3[i].str); - err++; + fprintf(fp, + "Flag %s inappropriate\n", + resflagsV3[i].str); + err = TRUE; } } else { - (void) fprintf(fp, "Unknown flag %s\n", - pcmd->argval[res].string); - err++; + fprintf(fp, "Unknown flag %s\n", + pcmd->argval[res].string); + err = TRUE; } } } @@ -1892,21 +1911,21 @@ again: * Make sure mask for default address is zero. Otherwise, * make sure mask bits are contiguous. */ - if (pcmd->argval[0].netnum.ss_family == AF_INET) { + if (IS_IPV4(&pcmd->argval[0].netnum)) { if (cres.addr == 0) { cres.mask = 0; } else { num = ntohl(cres.mask); for (bit = 0x80000000; bit != 0; bit >>= 1) - if ((num & bit) == 0) - break; + if ((num & bit) == 0) + break; for ( ; bit != 0; bit >>= 1) - if ((num & bit) != 0) - break; + if ((num & bit) != 0) + break; if (bit != 0) { - (void) fprintf(fp, "Invalid mask %s\n", - numtoa(cres.mask)); - err++; + fprintf(fp, "Invalid mask %s\n", + numtoa(cres.mask)); + err = TRUE; } } } else { @@ -1914,11 +1933,10 @@ again: } if (err) - return; + return; - res = doquery(impl_ver, req_code, 1, 1, - sendsize, (char *)&cres, &items, - &itemsize, &dummy, 0, sizeof(struct conf_restrict)); + res = doquery(impl_ver, req_code, 1, 1, sendsize, (char *)&cres, + &items, &itemsize, &dummy, 0, sizeof(cres)); if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { impl_ver = IMPL_XNTPD_OLD; @@ -1942,8 +1960,8 @@ monlist( ) { char *struct_star; - struct sockaddr_storage addr; - struct sockaddr_storage dstadr; + sockaddr_u addr; + sockaddr_u dstadr; int items; int itemsize; int res; @@ -1982,39 +2000,23 @@ again: struct info_monitor_1 *ml = (struct info_monitor_1 *) struct_star; (void) fprintf(fp, - "remote address port local address count m ver code avgint lstint\n"); + "remote address port local address count m ver rstr avgint lstint\n"); (void) fprintf(fp, "===============================================================================\n"); while (items > 0) { - 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 + SET_ADDRS(dstadr, addr, ml, daddr, addr); 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", + fprintf(fp, + "%-22.22s %5d %-15s %8lu %1u %1u %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->restr), (u_long)ntohl(ml->lasttime), (u_long)ntohl(ml->firsttime)); ml++; @@ -2025,32 +2027,22 @@ again: struct info_monitor *ml = (struct info_monitor *) struct_star; (void) fprintf(fp, - " address port count mode ver code avgint lstint\n"); + " address port count mode ver rstr avgint lstint\n"); (void) fprintf(fp, "===============================================================================\n"); while (items > 0) { - 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 + SET_ADDR(dstadr, ml->v6_flag, ml->addr, ml->addr6); 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", + "%-25.25s %5u %9lu %4u %2u %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->restr), (u_long)ntohl(ml->lasttime), (u_long)ntohl(ml->firsttime)); ml++; @@ -2063,18 +2055,8 @@ again: (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", + SET_ADDR(dstadr, oml->v6_flag, oml->addr, oml->addr6); + (void) fprintf(fp, "%-20.20s %5u %9lu %4u %3u %9lu %9lu\n", nntohost(&dstadr), ntohs(oml->port), (u_long)ntohl(oml->count), @@ -2175,6 +2157,7 @@ preset( { /* 8 is the maximum number of peers which will fit in a packet */ struct conf_unpeer *pl, plist[min(MAXARGS, 8)]; + int qitemlim; int qitems; int items; int itemsize; @@ -2188,9 +2171,10 @@ again: 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); + qitemlim = min(pcmd->nargs, COUNTOF(plist)); + for (qitems = 0, pl = plist; qitems < qitemlim; qitems++) { + if (IS_IPV4(&pcmd->argval[qitems].netnum)) { + pl->peeraddr = NSRCADR(&pcmd->argval[qitems].netnum); if (impl_ver == IMPL_XNTPD) pl->v6_flag = 0; } else { @@ -2200,7 +2184,7 @@ again: return; } pl->peeraddr6 = - GET_INADDR6(pcmd->argval[qitems].netnum); + SOCK_ADDR6(&pcmd->argval[qitems].netnum); pl->v6_flag = 1; } pl = (struct conf_unpeer *)((char *)pl + sendsize); @@ -2332,9 +2316,8 @@ authinfo( int res; again: - res = doquery(impl_ver, REQ_AUTHINFO, 0, 0, 0, (char *)NULL, - &items, &itemsize, (void *)&ia, 0, - sizeof(struct info_auth)); + res = doquery(impl_ver, REQ_AUTHINFO, 0, 0, 0, NULL, &items, + &itemsize, (void *)&ia, 0, sizeof(*ia)); if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { impl_ver = IMPL_XNTPD_OLD; @@ -2342,32 +2325,32 @@ again: } if (res != 0) - return; + return; if (!check1item(items, fp)) - return; + return; - if (!checkitemsize(itemsize, sizeof(struct info_auth))) - return; + if (!checkitemsize(itemsize, sizeof(*ia))) + return; - (void) fprintf(fp, "time since reset: %ld\n", - (u_long)ntohl(ia->timereset)); - (void) fprintf(fp, "stored keys: %ld\n", - (u_long)ntohl(ia->numkeys)); - (void) fprintf(fp, "free keys: %ld\n", - (u_long)ntohl(ia->numfreekeys)); - (void) fprintf(fp, "key lookups: %ld\n", - (u_long)ntohl(ia->keylookups)); - (void) fprintf(fp, "keys not found: %ld\n", - (u_long)ntohl(ia->keynotfound)); - (void) fprintf(fp, "uncached keys: %ld\n", - (u_long)ntohl(ia->keyuncached)); - (void) fprintf(fp, "encryptions: %ld\n", - (u_long)ntohl(ia->encryptions)); - (void) fprintf(fp, "decryptions: %ld\n", - (u_long)ntohl(ia->decryptions)); - (void) fprintf(fp, "expired keys: %ld\n", - (u_long)ntohl(ia->expired)); + fprintf(fp, "time since reset: %lu\n", + (u_long)ntohl(ia->timereset)); + fprintf(fp, "stored keys: %lu\n", + (u_long)ntohl(ia->numkeys)); + fprintf(fp, "free keys: %lu\n", + (u_long)ntohl(ia->numfreekeys)); + fprintf(fp, "key lookups: %lu\n", + (u_long)ntohl(ia->keylookups)); + fprintf(fp, "keys not found: %lu\n", + (u_long)ntohl(ia->keynotfound)); + fprintf(fp, "uncached keys: %lu\n", + (u_long)ntohl(ia->keyuncached)); + fprintf(fp, "encryptions: %lu\n", + (u_long)ntohl(ia->encryptions)); + fprintf(fp, "decryptions: %lu\n", + (u_long)ntohl(ia->decryptions)); + fprintf(fp, "expired keys: %lu\n", + (u_long)ntohl(ia->expired)); } @@ -2384,7 +2367,7 @@ traps( { int i; struct info_trap *it; - struct sockaddr_storage trap_addr, local_addr; + sockaddr_u trap_addr, local_addr; int items; int itemsize; int res; @@ -2412,23 +2395,7 @@ again: 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 + SET_ADDRS(trap_addr, local_addr, it, trap_address, local_address); (void) fprintf(fp, "address %s, port %d\n", stoa(&trap_addr), ntohs(it->trap_port)); @@ -2502,8 +2469,8 @@ again: 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 (IS_IPV4(&pcmd->argval[0].netnum)) { + ctrap.trap_address = NSRCADR(&pcmd->argval[0].netnum); if (impl_ver == IMPL_XNTPD) ctrap.v6_flag = 0; } else { @@ -2512,7 +2479,7 @@ again: "***Server doesn't understand IPv6 addresses\n"); return; } - ctrap.trap_address6 = GET_INADDR6(pcmd->argval[0].netnum); + ctrap.trap_address6 = SOCK_ADDR6(&pcmd->argval[0].netnum); ctrap.v6_flag = 1; } ctrap.local_address = 0; @@ -2520,19 +2487,18 @@ again: ctrap.unused = 0; if (pcmd->nargs > 1) { - ctrap.trap_port - = htons((u_short)(pcmd->argval[1].uval & 0xffff)); + ctrap.trap_port = htons((u_short)pcmd->argval[1].uval); if (pcmd->nargs > 2) { - if (pcmd->argval[2].netnum.ss_family != - pcmd->argval[0].netnum.ss_family) { + if (AF(&pcmd->argval[2].netnum) != + AF(&pcmd->argval[0].netnum)) { 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); + if (IS_IPV4(&pcmd->argval[2].netnum)) + ctrap.local_address = NSRCADR(&pcmd->argval[2].netnum); else - ctrap.local_address6 = GET_INADDR6(pcmd->argval[2].netnum); + ctrap.local_address6 = SOCK_ADDR6(&pcmd->argval[2].netnum); } } @@ -2631,9 +2597,8 @@ ctlstats( int res; again: - res = doquery(impl_ver, REQ_GET_CTLSTATS, 0, 0, 0, (char *)NULL, - &items, &itemsize, (void *)&ic, 0, - sizeof(struct info_control)); + res = doquery(impl_ver, REQ_GET_CTLSTATS, 0, 0, 0, NULL, &items, + &itemsize, (void *)&ic, 0, sizeof(*ic)); if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) { impl_ver = IMPL_XNTPD_OLD; @@ -2641,44 +2606,44 @@ again: } if (res != 0) - return; + return; if (!check1item(items, fp)) - return; + return; - if (!checkitemsize(itemsize, sizeof(struct info_control))) - return; + if (!checkitemsize(itemsize, sizeof(*ic))) + return; - (void) fprintf(fp, "time since reset: %ld\n", - (u_long)ntohl(ic->ctltimereset)); - (void) fprintf(fp, "requests received: %ld\n", - (u_long)ntohl(ic->numctlreq)); - (void) fprintf(fp, "responses sent: %ld\n", - (u_long)ntohl(ic->numctlresponses)); - (void) fprintf(fp, "fragments sent: %ld\n", - (u_long)ntohl(ic->numctlfrags)); - (void) fprintf(fp, "async messages sent: %ld\n", - (u_long)ntohl(ic->numasyncmsgs)); - (void) fprintf(fp, "error msgs sent: %ld\n", - (u_long)ntohl(ic->numctlerrors)); - (void) fprintf(fp, "total bad pkts: %ld\n", - (u_long)ntohl(ic->numctlbadpkts)); - (void) fprintf(fp, "packet too short: %ld\n", - (u_long)ntohl(ic->numctltooshort)); - (void) fprintf(fp, "response on input: %ld\n", - (u_long)ntohl(ic->numctlinputresp)); - (void) fprintf(fp, "fragment on input: %ld\n", - (u_long)ntohl(ic->numctlinputfrag)); - (void) fprintf(fp, "error set on input: %ld\n", - (u_long)ntohl(ic->numctlinputerr)); - (void) fprintf(fp, "bad offset on input: %ld\n", - (u_long)ntohl(ic->numctlbadoffset)); - (void) fprintf(fp, "bad version packets: %ld\n", - (u_long)ntohl(ic->numctlbadversion)); - (void) fprintf(fp, "data in pkt too short: %ld\n", - (u_long)ntohl(ic->numctldatatooshort)); - (void) fprintf(fp, "unknown op codes: %ld\n", - (u_long)ntohl(ic->numctlbadop)); + fprintf(fp, "time since reset: %lu\n", + (u_long)ntohl(ic->ctltimereset)); + fprintf(fp, "requests received: %lu\n", + (u_long)ntohl(ic->numctlreq)); + fprintf(fp, "responses sent: %lu\n", + (u_long)ntohl(ic->numctlresponses)); + fprintf(fp, "fragments sent: %lu\n", + (u_long)ntohl(ic->numctlfrags)); + fprintf(fp, "async messages sent: %lu\n", + (u_long)ntohl(ic->numasyncmsgs)); + fprintf(fp, "error msgs sent: %lu\n", + (u_long)ntohl(ic->numctlerrors)); + fprintf(fp, "total bad pkts: %lu\n", + (u_long)ntohl(ic->numctlbadpkts)); + fprintf(fp, "packet too short: %lu\n", + (u_long)ntohl(ic->numctltooshort)); + fprintf(fp, "response on input: %lu\n", + (u_long)ntohl(ic->numctlinputresp)); + fprintf(fp, "fragment on input: %lu\n", + (u_long)ntohl(ic->numctlinputfrag)); + fprintf(fp, "error set on input: %lu\n", + (u_long)ntohl(ic->numctlinputerr)); + fprintf(fp, "bad offset on input: %lu\n", + (u_long)ntohl(ic->numctlbadoffset)); + fprintf(fp, "bad version packets: %lu\n", + (u_long)ntohl(ic->numctlbadversion)); + fprintf(fp, "data in pkt too short: %lu\n", + (u_long)ntohl(ic->numctldatatooshort)); + fprintf(fp, "unknown op codes: %lu\n", + (u_long)ntohl(ic->numctlbadop)); } @@ -2694,6 +2659,7 @@ clockstat( struct info_clock *cl; /* 8 is the maximum number of clocks which will fit in a packet */ u_long clist[min(MAXARGS, 8)]; + int qitemlim; int qitems; int items; int itemsize; @@ -2701,8 +2667,9 @@ clockstat( l_fp ts; struct clktype *clk; - for (qitems = 0; qitems < min(pcmd->nargs, 8); qitems++) - clist[qitems] = GET_INADDR(pcmd->argval[qitems].netnum); + qitemlim = min(pcmd->nargs, COUNTOF(clist)); + for (qitems = 0; qitems < qitemlim; qitems++) + clist[qitems] = NSRCADR(&pcmd->argval[qitems].netnum); again: res = doquery(impl_ver, REQ_GET_CLOCKINFO, 0, qitems, @@ -2715,13 +2682,13 @@ again: } if (res != 0) - return; + return; if (!checkitems(items, fp)) - return; + return; if (!checkitemsize(itemsize, sizeof(struct info_clock))) - return; + return; while (items-- > 0) { (void) fprintf(fp, "clock address: %s\n", @@ -2791,7 +2758,7 @@ fudge( err = 0; memset((char *)&fudgedata, 0, sizeof fudgedata); - fudgedata.clockadr = GET_INADDR(pcmd->argval[0].netnum); + fudgedata.clockadr = NSRCADR(&pcmd->argval[0].netnum); if (STREQ(pcmd->argval[1].string, "time1")) { fudgedata.which = htonl(FUDGE_TIME1); @@ -2866,6 +2833,7 @@ clkbug( /* 8 is the maximum number of clocks which will fit in a packet */ u_long clist[min(MAXARGS, 8)]; u_int32 ltemp; + int qitemlim; int qitems; int items; int itemsize; @@ -2873,8 +2841,9 @@ clkbug( int needsp; l_fp ts; - for (qitems = 0; qitems < min(pcmd->nargs, 8); qitems++) - clist[qitems] = GET_INADDR(pcmd->argval[qitems].netnum); + qitemlim = min(pcmd->nargs, COUNTOF(clist)); + for (qitems = 0; qitems < qitemlim; qitems++) + clist[qitems] = NSRCADR(&pcmd->argval[qitems].netnum); again: res = doquery(impl_ver, REQ_GET_CLKBUGINFO, 0, qitems, @@ -2887,13 +2856,13 @@ again: } if (res != 0) - return; + return; if (!checkitems(items, fp)) - return; + return; if (!checkitemsize(itemsize, sizeof(struct info_clkbug))) - return; + return; while (items-- > 0) { (void) fprintf(fp, "clock address: %s\n", @@ -2990,7 +2959,7 @@ again: tscale = 1e-9; #endif (void)fprintf(fp, "pll offset: %g s\n", - (int32_t)ntohl(ik->offset) * tscale); + (int32)ntohl(ik->offset) * tscale); (void)fprintf(fp, "pll frequency: %s ppm\n", fptoa((s_fp)ntohl(ik->freq), 3)); (void)fprintf(fp, "maximum error: %g s\n", @@ -3082,11 +3051,11 @@ again: (u_long)ntohl(ik->errcnt)); } -#define IF_LIST_FMT "%2d %c %48s %c %c %12.12s %03x %3d %2d %5d %5d %5d %2d %2d %3d %7d\n" -#define IF_LIST_FMT_STR "%2s %c %48s %c %c %12.12s %3s %3s %2s %5s %5s %5s %2s %2s %3s %7s\n" +#define IF_LIST_FMT "%2d %c %48s %c %c %12.12s %03lx %3lu %2lu %5lu %5lu %5lu %2lu %3lu %7lu\n" +#define IF_LIST_FMT_STR "%2s %c %48s %c %c %12.12s %3s %3s %2s %5s %5s %5s %2s %3s %7s\n" #define IF_LIST_AFMT_STR " %48s %c\n" -#define IF_LIST_LABELS "#", 'A', "Address/Mask/Broadcast", 'T', 'E', "IF name", "Flg", "TL", "#M", "recv", "sent", "drop", "S", "IX", "PC", "uptime" -#define IF_LIST_LINE "=====================================================================================================================\n" +#define IF_LIST_LABELS "#", 'A', "Address/Mask/Broadcast", 'T', 'E', "IF name", "Flg", "TL", "#M", "recv", "sent", "drop", "S", "PC", "uptime" +#define IF_LIST_LINE "==================================================================================================================\n" static void iflist( @@ -3098,7 +3067,7 @@ iflist( ) { static char *actions = "?.+-"; - struct sockaddr_storage saddr; + sockaddr_u saddr; if (res != 0) return; @@ -3113,51 +3082,31 @@ iflist( fprintf(fp, IF_LIST_LINE); while (items > 0) { - if (ntohl(ifs->v6_flag)) { - memcpy((char *)&GET_INADDR6(saddr), (char *)&ifs->unaddr.addr6, sizeof(ifs->unaddr.addr6)); - saddr.ss_family = AF_INET6; - } else { - memcpy((char *)&GET_INADDR(saddr), (char *)&ifs->unaddr.addr, sizeof(ifs->unaddr.addr)); - saddr.ss_family = AF_INET; - } -#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR - saddr.ss_len = SOCKLEN(&saddr); -#endif + SET_ADDR(saddr, ntohl(ifs->v6_flag), + ifs->unaddr.addr.s_addr, ifs->unaddr.addr6); fprintf(fp, IF_LIST_FMT, ntohl(ifs->ifnum), actions[(ifs->action >= 1 && ifs->action < 4) ? ifs->action : 0], stoa((&saddr)), 'A', ifs->ignore_packets ? 'D' : 'E', ifs->name, - ntohl(ifs->flags), - ntohl(ifs->last_ttl), - ntohl(ifs->num_mcast), - ntohl(ifs->received), - ntohl(ifs->sent), - ntohl(ifs->notsent), - ntohl(ifs->scopeid), - ntohl(ifs->ifindex), - ntohl(ifs->peercnt), - ntohl(ifs->uptime)); - - if (ntohl(ifs->v6_flag)) { - memcpy((char *)&GET_INADDR6(saddr), (char *)&ifs->unmask.addr6, sizeof(ifs->unmask.addr6)); - saddr.ss_family = AF_INET6; - } else { - memcpy((char *)&GET_INADDR(saddr), (char *)&ifs->unmask.addr, sizeof(ifs->unmask.addr)); - saddr.ss_family = AF_INET; - } -#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR - saddr.ss_len = SOCKLEN(&saddr); -#endif + (u_long)ntohl(ifs->flags), + (u_long)ntohl(ifs->last_ttl), + (u_long)ntohl(ifs->num_mcast), + (u_long)ntohl(ifs->received), + (u_long)ntohl(ifs->sent), + (u_long)ntohl(ifs->notsent), + (u_long)ntohl(ifs->scopeid), + (u_long)ntohl(ifs->peercnt), + (u_long)ntohl(ifs->uptime)); + + SET_ADDR(saddr, ntohl(ifs->v6_flag), + ifs->unmask.addr.s_addr, ifs->unmask.addr6); fprintf(fp, IF_LIST_AFMT_STR, stoa(&saddr), 'M'); if (!ntohl(ifs->v6_flag) && ntohl(ifs->flags) & (INT_BCASTOPEN)) { - memcpy((char *)&GET_INADDR(saddr), (char *)&ifs->unbcast.addr, sizeof(ifs->unbcast.addr)); - saddr.ss_family = AF_INET; -#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR - saddr.ss_len = SOCKLEN(&saddr); -#endif + SET_ADDR(saddr, ntohl(ifs->v6_flag), + ifs->unbcast.addr.s_addr, ifs->unbcast.addr6); fprintf(fp, IF_LIST_AFMT_STR, stoa(&saddr), 'B'); } |