diff options
Diffstat (limited to 'ntpq')
-rw-r--r-- | ntpq/Makefile.am | 41 | ||||
-rw-r--r-- | ntpq/Makefile.in | 381 | ||||
-rw-r--r-- | ntpq/ntpq-opts.c | 607 | ||||
-rw-r--r-- | ntpq/ntpq-opts.def | 345 | ||||
-rw-r--r-- | ntpq/ntpq-opts.h | 208 | ||||
-rw-r--r-- | ntpq/ntpq-opts.menu | 1 | ||||
-rw-r--r-- | ntpq/ntpq-opts.texi | 215 | ||||
-rw-r--r-- | ntpq/ntpq-subs.c (renamed from ntpq/ntpq_ops.c) | 110 | ||||
-rw-r--r-- | ntpq/ntpq.1 | 385 | ||||
-rw-r--r-- | ntpq/ntpq.c | 249 | ||||
-rw-r--r-- | ntpq/ntpq.h | 19 |
11 files changed, 2291 insertions, 270 deletions
diff --git a/ntpq/Makefile.am b/ntpq/Makefile.am index 0bd05fc9cf0a1..7cd3f0aa04d1b 100644 --- a/ntpq/Makefile.am +++ b/ntpq/Makefile.am @@ -1,21 +1,42 @@ -#AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies -AUTOMAKE_OPTIONS = ../util/ansi2knr -bin_PROGRAMS = ntpq -INCLUDES = -I$(top_srcdir)/include +AUTOMAKE_OPTIONS= ../util/ansi2knr + +bin_PROGRAMS= ntpq +AM_CPPFLAGS= -I$(top_srcdir)/include $(LIBOPTS_CFLAGS) + # LDADD might need RESLIB and ADJLIB -ntpq_LDADD = version.o ../libntp/libntp.a @READLINE_LIBS@ -DISTCLEANFILES = .version version.c -noinst_HEADERS = ntpq.h -#EXTRA_DIST = ntpq.mak -ETAGS_ARGS = Makefile.am +ntpq_LDADD= version.o @READLINE_LIBS@ $(LIBOPTS_LDADD) ../libntp/libntp.a +DISTCLEANFILES= .version version.c +noinst_HEADERS= ntpq.h +ETAGS_ARGS= Makefile.am +EXTRA_DIST= ntpq-opts.def ntpq.1 ntpq-opts.texi ntpq-opts.menu +BUILT_SOURCES= ntpq-opts.c ntpq-opts.h ntpq.1 ntpq-opts.texi ntpq-opts.menu +man_MANS= ntpq.1 +run_ag= cd $(srcdir) && autogen -L ../include --writable +std_def_list= $(top_srcdir)/include/debug-opt.def \ + $(top_srcdir)/include/autogen-version.def \ + $(top_srcdir)/include/copyright.def \ + $(top_srcdir)/include/homerc.def \ + $(top_srcdir)/include/version.def +ntpq_SOURCES= ntpq.c ntpq-subs.c ntpq-opts.c ntpq-opts.h + +$(srcdir)/ntpq-opts.h: $(srcdir)/ntpq-opts.c +$(srcdir)/ntpq-opts.c: $(srcdir)/ntpq-opts.def $(std_def_list) + $(run_ag) ntpq-opts.def -ntpq_SOURCES = ntpq.c ntpq_ops.c +$(srcdir)/ntpq.1: $(srcdir)/ntpq-opts.def $(std_def_list) + $(run_ag) -Tagman1.tpl -bntpq ntpq-opts.def + +$(srcdir)/ntpq-opts.texi $(srcdir)/ntpq-opts.menu: $(srcdir)/ntpq-opts.def $(std_def_list) + $(run_ag) -Taginfo.tpl -DLEVEL=section ntpq-opts.def $(PROGRAMS): $(LDADD) ../libntp/libntp.a: cd ../libntp && $(MAKE) +$(top_srcdir)/version : + cd $(top_srcdir) && $(MAKE) version + version.o: $(ntpq_OBJECTS) ../libntp/libntp.a Makefile $(top_srcdir)/version env CSET=`cat $(top_srcdir)/version` $(top_builddir)/scripts/mkver ntpq $(COMPILE) -c version.c diff --git a/ntpq/Makefile.in b/ntpq/Makefile.in index 7ddf4d3709bb0..32616a95f37e8 100644 --- a/ntpq/Makefile.in +++ b/ntpq/Makefile.in @@ -1,8 +1,8 @@ -# Makefile.in generated by automake 1.7.7 from Makefile.am. +# Makefile.in generated by automake 1.9.6 from Makefile.am. # @configure_input@ -# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 -# Free Software Foundation, Inc. +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -14,6 +14,7 @@ @SET_MAKE@ + srcdir = @srcdir@ top_srcdir = @top_srcdir@ VPATH = @srcdir@ @@ -21,7 +22,6 @@ pkgdatadir = $(datadir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ top_builddir = .. - am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd INSTALL = @INSTALL@ install_sh_DATA = $(install_sh) -c -m 644 @@ -37,16 +37,61 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -target_triplet = @target@ +ANSI2KNR = ../util/ansi2knr +bin_PROGRAMS = ntpq$(EXEEXT) +subdir = ntpq +DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/libopts/m4/libopts.m4 \ + $(top_srcdir)/m4/define_dir.m4 \ + $(top_srcdir)/m4/hs_ulong_const.m4 \ + $(top_srcdir)/m4/os_cflags.m4 $(top_srcdir)/version.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" +binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) +PROGRAMS = $(bin_PROGRAMS) +am_ntpq_OBJECTS = ntpq$U.$(OBJEXT) ntpq-subs$U.$(OBJEXT) \ + ntpq-opts$U.$(OBJEXT) +ntpq_OBJECTS = $(am_ntpq_OBJECTS) +am__DEPENDENCIES_1 = +ntpq_DEPENDENCIES = version.o $(am__DEPENDENCIES_1) ../libntp/libntp.a +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(ntpq_SOURCES) +DIST_SOURCES = $(ntpq_SOURCES) +man1dir = $(mandir)/man1 +NROFF = nroff +MANS = $(man_MANS) +HEADERS = $(noinst_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMDEP_FALSE = @AMDEP_FALSE@ AMDEP_TRUE = @AMDEP_TRUE@ AMTAR = @AMTAR@ +AR = @AR@ ARLIB_DIR = @ARLIB_DIR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BINSUBDIR = @BINSUBDIR@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -54,10 +99,15 @@ CHUTEST = @CHUTEST@ CLKTEST = @CLKTEST@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DCFD = @DCFD@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +ECHO = @ECHO@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ @@ -65,30 +115,39 @@ EF_LIBS = @EF_LIBS@ EF_PROGS = @EF_PROGS@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ INSTALL_DATA = @INSTALL_DATA@ +INSTALL_LIBOPTS_FALSE = @INSTALL_LIBOPTS_FALSE@ +INSTALL_LIBOPTS_TRUE = @INSTALL_LIBOPTS_TRUE@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LCRYPTO = @LCRYPTO@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ +LIBOPTS_CFLAGS = @LIBOPTS_CFLAGS@ +LIBOPTS_DIR = @LIBOPTS_DIR@ +LIBOPTS_LDADD = @LIBOPTS_LDADD@ LIBPARSE = @LIBPARSE@ LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ MAKE_ADJTIMED = @MAKE_ADJTIMED@ +MAKE_CHECK_LAYOUT = @MAKE_CHECK_LAYOUT@ MAKE_CHECK_Y2K = @MAKE_CHECK_Y2K@ MAKE_LIBNTPSIM = @MAKE_LIBNTPSIM@ MAKE_LIBPARSE = @MAKE_LIBPARSE@ MAKE_LIBPARSE_KERNEL = @MAKE_LIBPARSE_KERNEL@ MAKE_NTPDSIM = @MAKE_NTPDSIM@ MAKE_NTPTIME = @MAKE_NTPTIME@ -MAKE_NTP_KEYGEN = @MAKE_NTP_KEYGEN@ MAKE_PARSEKMODULE = @MAKE_PARSEKMODULE@ -MAKE_SNTP = @MAKE_SNTP@ MAKE_TICKADJ = @MAKE_TICKADJ@ MAKE_TIMETRIM = @MAKE_TIMETRIM@ +NEED_LIBOPTS_FALSE = @NEED_LIBOPTS_FALSE@ +NEED_LIBOPTS_TRUE = @NEED_LIBOPTS_TRUE@ OBJEXT = @OBJEXT@ OPENSSL = @OPENSSL@ OPENSSL_INC = @OPENSSL_INC@ @@ -111,14 +170,21 @@ STRIP = @STRIP@ TESTDCF = @TESTDCF@ U = @U@ VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ ac_ct_RANLIB = @ac_ct_RANLIB@ ac_ct_STRIP = @ac_ct_STRIP@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ @@ -139,6 +205,7 @@ libdir = @libdir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ mandir = @mandir@ +mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ prefix = @prefix@ program_transform_name = @program_transform_name@ @@ -146,72 +213,71 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ subdirs = @subdirs@ sysconfdir = @sysconfdir@ -target = @target@ target_alias = @target_alias@ -target_cpu = @target_cpu@ -target_os = @target_os@ -target_vendor = @target_vendor@ - -#AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies AUTOMAKE_OPTIONS = ../util/ansi2knr -bin_PROGRAMS = ntpq -INCLUDES = -I$(top_srcdir)/include +AM_CPPFLAGS = -I$(top_srcdir)/include $(LIBOPTS_CFLAGS) + # LDADD might need RESLIB and ADJLIB -ntpq_LDADD = version.o ../libntp/libntp.a @READLINE_LIBS@ +ntpq_LDADD = version.o @READLINE_LIBS@ $(LIBOPTS_LDADD) ../libntp/libntp.a DISTCLEANFILES = .version version.c noinst_HEADERS = ntpq.h -#EXTRA_DIST = ntpq.mak ETAGS_ARGS = Makefile.am - -ntpq_SOURCES = ntpq.c ntpq_ops.c -subdir = ntpq -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = -bin_PROGRAMS = ntpq$(EXEEXT) -PROGRAMS = $(bin_PROGRAMS) - -am_ntpq_OBJECTS = ntpq$U.$(OBJEXT) ntpq_ops$U.$(OBJEXT) -ntpq_OBJECTS = $(am_ntpq_OBJECTS) -ntpq_DEPENDENCIES = version.o ../libntp/libntp.a -ntpq_LDFLAGS = - -DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/depcomp -am__depfiles_maybe = depfiles -@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/ntpq$U.Po ./$(DEPDIR)/ntpq_ops$U.Po -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -DIST_SOURCES = $(ntpq_SOURCES) -HEADERS = $(noinst_HEADERS) - -DIST_COMMON = README $(noinst_HEADERS) $(srcdir)/Makefile.in \ - Makefile.am -SOURCES = $(ntpq_SOURCES) - -all: all-am +EXTRA_DIST = ntpq-opts.def ntpq.1 ntpq-opts.texi ntpq-opts.menu +BUILT_SOURCES = ntpq-opts.c ntpq-opts.h ntpq.1 ntpq-opts.texi ntpq-opts.menu +man_MANS = ntpq.1 +run_ag = cd $(srcdir) && autogen -L ../include --writable +std_def_list = $(top_srcdir)/include/debug-opt.def \ + $(top_srcdir)/include/autogen-version.def \ + $(top_srcdir)/include/copyright.def \ + $(top_srcdir)/include/homerc.def \ + $(top_srcdir)/include/version.def + +ntpq_SOURCES = ntpq.c ntpq-subs.c ntpq-opts.c ntpq-opts.h +all: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: -.SUFFIXES: .c .o .obj -$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign ntpq/Makefile'; \ cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu ntpq/Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) -binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) + $(AUTOMAKE) --foreign ntpq/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) - $(mkinstalldirs) $(DESTDIR)$(bindir) + test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)" @list='$(bin_PROGRAMS)'; for p in $$list; do \ p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ if test -f $$p \ + || test -f $$p1 \ ; then \ f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ - echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f"; \ - $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f || exit 1; \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \ else :; fi; \ done @@ -219,23 +285,25 @@ uninstall-binPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(bin_PROGRAMS)'; for p in $$list; do \ f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ - echo " rm -f $(DESTDIR)$(bindir)/$$f"; \ - rm -f $(DESTDIR)$(bindir)/$$f; \ + echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \ + rm -f "$(DESTDIR)$(bindir)/$$f"; \ done clean-binPROGRAMS: - -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done ntpq$(EXEEXT): $(ntpq_OBJECTS) $(ntpq_DEPENDENCIES) @rm -f ntpq$(EXEEXT) $(LINK) $(ntpq_LDFLAGS) $(ntpq_OBJECTS) $(ntpq_LDADD) $(LIBS) mostlyclean-compile: - -rm -f *.$(OBJEXT) core *.core + -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c - -ANSI2KNR = ../util/ansi2knr ../util/ansi2knr: cd ../util && $(MAKE) $(AM_MAKEFLAGS) ansi2knr @@ -243,43 +311,92 @@ mostlyclean-kr: -test "$U" = "" || rm -f *_.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpq$U.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpq_ops$U.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpq-opts$U.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntpq-subs$U.Po@am__quote@ .c.o: -@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \ -@am__fastdepCC_TRUE@ -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \ -@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \ -@am__fastdepCC_TRUE@ fi +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$< +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< .c.obj: -@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \ -@am__fastdepCC_TRUE@ -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \ -@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \ -@am__fastdepCC_TRUE@ fi +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi` +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< ntpq_.c: ntpq.c $(ANSI2KNR) $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntpq.c; then echo $(srcdir)/ntpq.c; else echo ntpq.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -ntpq_ops_.c: ntpq_ops.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntpq_ops.c; then echo $(srcdir)/ntpq_ops.c; else echo ntpq_ops.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ -ntpq_.$(OBJEXT) ntpq_ops_.$(OBJEXT) : $(ANSI2KNR) -uninstall-info-am: +ntpq-opts_.c: ntpq-opts.c $(ANSI2KNR) + $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntpq-opts.c; then echo $(srcdir)/ntpq-opts.c; else echo ntpq-opts.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ +ntpq-subs_.c: ntpq-subs.c $(ANSI2KNR) + $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntpq-subs.c; then echo $(srcdir)/ntpq-subs.c; else echo ntpq-subs.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > $@ || rm -f $@ +ntpq_.$(OBJEXT) ntpq_.lo ntpq-opts_.$(OBJEXT) ntpq-opts_.lo \ +ntpq-subs_.$(OBJEXT) ntpq-subs_.lo : $(ANSI2KNR) -ETAGS = etags -ETAGSFLAGS = +mostlyclean-libtool: + -rm -f *.lo -CTAGS = ctags -CTAGSFLAGS = +clean-libtool: + -rm -rf .libs _libs -tags: TAGS +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-man1: $(man1_MANS) $(man_MANS) + @$(NORMAL_INSTALL) + test -z "$(man1dir)" || $(mkdir_p) "$(DESTDIR)$(man1dir)" + @list='$(man1_MANS) $(dist_man1_MANS) $(nodist_man1_MANS)'; \ + l2='$(man_MANS) $(dist_man_MANS) $(nodist_man_MANS)'; \ + for i in $$l2; do \ + case "$$i" in \ + *.1*) list="$$list $$i" ;; \ + esac; \ + done; \ + for i in $$list; do \ + if test -f $(srcdir)/$$i; then file=$(srcdir)/$$i; \ + else file=$$i; fi; \ + ext=`echo $$i | sed -e 's/^.*\\.//'`; \ + case "$$ext" in \ + 1*) ;; \ + *) ext='1' ;; \ + esac; \ + inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ + inst=`echo $$inst | sed -e 's/^.*\///'`; \ + inst=`echo $$inst | sed '$(transform)'`.$$ext; \ + echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man1dir)/$$inst'"; \ + $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man1dir)/$$inst"; \ + done +uninstall-man1: + @$(NORMAL_UNINSTALL) + @list='$(man1_MANS) $(dist_man1_MANS) $(nodist_man1_MANS)'; \ + l2='$(man_MANS) $(dist_man_MANS) $(nodist_man_MANS)'; \ + for i in $$l2; do \ + case "$$i" in \ + *.1*) list="$$list $$i" ;; \ + esac; \ + done; \ + for i in $$list; do \ + ext=`echo $$i | sed -e 's/^.*\\.//'`; \ + case "$$ext" in \ + 1*) ;; \ + *) ext='1' ;; \ + esac; \ + inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ + inst=`echo $$inst | sed -e 's/^.*\///'`; \ + inst=`echo $$inst | sed '$(transform)'`.$$ext; \ + echo " rm -f '$(DESTDIR)$(man1dir)/$$inst'"; \ + rm -f "$(DESTDIR)$(man1dir)/$$inst"; \ + done ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ @@ -289,6 +406,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) $(AWK) ' { files[$$0] = 1; } \ END { for (i in files) print i; }'`; \ mkid -fID $$unique +tags: TAGS TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) @@ -300,10 +418,11 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ done | \ $(AWK) ' { files[$$0] = 1; } \ END { for (i in files) print i; }'`; \ - test -z "$(ETAGS_ARGS)$$tags$$unique" \ - || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique - + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) @@ -326,10 +445,6 @@ GTAGS: distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) - -top_distdir = .. -distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ @@ -343,7 +458,7 @@ distdir: $(DISTFILES) dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ if test "$$dir" != "$$file" && test "$$dir" != "."; then \ dir="/$$dir"; \ - $(mkinstalldirs) "$(distdir)$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ else \ dir=''; \ fi; \ @@ -359,12 +474,15 @@ distdir: $(DISTFILES) fi; \ done check-am: all-am -check: check-am -all-am: Makefile $(PROGRAMS) $(HEADERS) - +check: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) check-am +all-am: Makefile $(PROGRAMS) $(MANS) $(HEADERS) installdirs: - $(mkinstalldirs) $(DESTDIR)$(bindir) -install: install-am + for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am @@ -375,7 +493,7 @@ install-am: all-am installcheck: installcheck-am install-strip: $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - INSTALL_STRIP_FLAG=-s \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ `test -z '$(STRIP)' || \ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install mostlyclean-generic: @@ -383,50 +501,52 @@ mostlyclean-generic: clean-generic: distclean-generic: - -rm -f $(CONFIG_CLEAN_FILES) + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) clean: clean-am -clean-am: clean-binPROGRAMS clean-generic mostlyclean-am +clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am distclean: distclean-am -rm -rf ./$(DEPDIR) -rm -f Makefile - distclean-am: clean-am distclean-compile distclean-generic \ - distclean-tags + distclean-libtool distclean-tags dvi: dvi-am dvi-am: +html: html-am + info: info-am info-am: -install-data-am: +install-data-am: install-man install-exec-am: install-binPROGRAMS install-info: install-info-am -install-man: +install-man: install-man1 installcheck-am: maintainer-clean: maintainer-clean-am -rm -rf ./$(DEPDIR) -rm -f Makefile - maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am -mostlyclean-am: mostlyclean-compile mostlyclean-generic mostlyclean-kr +mostlyclean-am: mostlyclean-compile mostlyclean-generic mostlyclean-kr \ + mostlyclean-libtool pdf: pdf-am @@ -436,25 +556,42 @@ ps: ps-am ps-am: -uninstall-am: uninstall-binPROGRAMS uninstall-info-am +uninstall-am: uninstall-binPROGRAMS uninstall-info-am uninstall-man + +uninstall-man: uninstall-man1 .PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ - clean-generic ctags distclean distclean-compile \ - distclean-generic distclean-tags distdir dvi dvi-am info \ - info-am install install-am install-binPROGRAMS install-data \ - install-data-am install-exec install-exec-am install-info \ - install-info-am install-man install-strip installcheck \ - installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-kr pdf pdf-am ps ps-am tags \ - uninstall uninstall-am uninstall-binPROGRAMS uninstall-info-am + clean-generic clean-libtool ctags distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-binPROGRAMS install-data install-data-am install-exec \ + install-exec-am install-info install-info-am install-man \ + install-man1 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-info-am \ + uninstall-man uninstall-man1 +$(srcdir)/ntpq-opts.h: $(srcdir)/ntpq-opts.c +$(srcdir)/ntpq-opts.c: $(srcdir)/ntpq-opts.def $(std_def_list) + $(run_ag) ntpq-opts.def + +$(srcdir)/ntpq.1: $(srcdir)/ntpq-opts.def $(std_def_list) + $(run_ag) -Tagman1.tpl -bntpq ntpq-opts.def + +$(srcdir)/ntpq-opts.texi $(srcdir)/ntpq-opts.menu: $(srcdir)/ntpq-opts.def $(std_def_list) + $(run_ag) -Taginfo.tpl -DLEVEL=section ntpq-opts.def + $(PROGRAMS): $(LDADD) ../libntp/libntp.a: cd ../libntp && $(MAKE) +$(top_srcdir)/version : + cd $(top_srcdir) && $(MAKE) version + version.o: $(ntpq_OBJECTS) ../libntp/libntp.a Makefile $(top_srcdir)/version env CSET=`cat $(top_srcdir)/version` $(top_builddir)/scripts/mkver ntpq $(COMPILE) -c version.c diff --git a/ntpq/ntpq-opts.c b/ntpq/ntpq-opts.c new file mode 100644 index 0000000000000..0e73886b7232e --- /dev/null +++ b/ntpq/ntpq-opts.c @@ -0,0 +1,607 @@ +/* + * EDIT THIS FILE WITH CAUTION (ntpq-opts.c) + * + * It has been AutoGen-ed Sunday August 17, 2008 at 05:26:55 AM EDT + * From the definitions ntpq-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 + * ntpq 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. + * + * This source file is copyrighted and licensed under the following terms: + * + * ntpq copyright 1970-2008 David L. Mills and/or others - all rights reserved + * + * see html/copyright.html + */ + + +#include <limits.h> + +#define OPTION_CODE_COMPILE 1 +#include "ntpq-opts.h" + +#ifdef __cplusplus +extern "C" { +#endif +tSCC zCopyright[] = + "ntpq copyright (c) 1970-2008 David L. Mills and/or others, all rights reserved"; +tSCC zCopyrightNotice[] = + +/* extracted from ../include/copyright.def near line 8 */ +"see html/copyright.html"; +extern tUsageProc optionUsage; + +/* + * global included definitions + */ +#ifdef __windows + extern int atoi(const char*); +#else +# include <stdlib.h> +#endif + +#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: + */ +tSCC zIpv4Text[] = + "Force IPv4 DNS name resolution"; +tSCC zIpv4_NAME[] = "IPV4"; +tSCC zIpv4_Name[] = "ipv4"; +#define IPV4_FLAGS (OPTST_DISABLED) + +/* + * Ipv6 option description: + */ +tSCC zIpv6Text[] = + "Force IPv6 DNS name resolution"; +tSCC zIpv6_NAME[] = "IPV6"; +tSCC zIpv6_Name[] = "ipv6"; +#define IPV6_FLAGS (OPTST_DISABLED) + +/* + * Command option description: + */ +tSCC zCommandText[] = + "run a command and exit"; +tSCC zCommand_NAME[] = "COMMAND"; +tSCC zCommand_Name[] = "command"; +#define COMMAND_FLAGS (OPTST_DISABLED | OPTST_STACKED \ + | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING)) + +/* + * Debug_Level option description: + */ +#ifdef DEBUG +tSCC zDebug_LevelText[] = + "Increase output debug message level"; +tSCC zDebug_Level_NAME[] = "DEBUG_LEVEL"; +tSCC 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[] = + "Set the output debug message level"; +tSCC zSet_Debug_Level_NAME[] = "SET_DEBUG_LEVEL"; +tSCC 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 */ + +/* + * Peers option description with + * "Must also have options" and "Incompatible options": + */ +tSCC zPeersText[] = + "Print a list of the peers"; +tSCC zPeers_NAME[] = "PEERS"; +tSCC zPeers_Name[] = "peers"; +static const int + aPeersCantList[] = { + INDEX_OPT_INTERACTIVE, NO_EQUIVALENT }; +#define PEERS_FLAGS (OPTST_DISABLED) + +/* + * Interactive option description with + * "Must also have options" and "Incompatible options": + */ +tSCC zInteractiveText[] = + "Force ntpq to operate in interactive mode"; +tSCC zInteractive_NAME[] = "INTERACTIVE"; +tSCC zInteractive_Name[] = "interactive"; +static const int + aInteractiveCantList[] = { + INDEX_OPT_COMMAND, + INDEX_OPT_PEERS, NO_EQUIVALENT }; +#define INTERACTIVE_FLAGS (OPTST_DISABLED) + +/* + * Numeric option description: + */ +tSCC zNumericText[] = + "numeric host addresses"; +tSCC zNumeric_NAME[] = "NUMERIC"; +tSCC 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"; + +tSCC zNotLoad_Opts_Name[] = "no-load-opts"; +tSCC 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_NTPQ_OPTS) +/* + * Under test, omit argument processing, or call optionStackArg, + * if multiple copies are allowed. + */ +extern tOptProc + optionPagedUsage, optionStackArg, optionVersionStderr; +static tOptProc + doUsageOpt; + +/* + * #define map the "normal" callout procs to the test ones... + */ +#define SET_DEBUG_LEVEL_OPT_PROC optionStackArg + + +#else /* NOT defined TEST_NTPQ_OPTS */ +/* + * When not under test, there are different procs to use + */ +extern tOptProc + optionPagedUsage, optionPrintVersion, optionStackArg; +static tOptProc + doUsageOpt; + +/* + * #define map the "normal" callout procs + */ +#define SET_DEBUG_LEVEL_OPT_PROC doOptSet_Debug_Level + +#define SET_DEBUG_LEVEL_OPT_PROC doOptSet_Debug_Level +#endif /* defined(TEST_NTPQ_OPTS) */ +#ifdef TEST_NTPQ_OPTS +# define DOVERPROC optionVersionStderr +#else +# define DOVERPROC optionPrintVersion +#endif /* TEST_NTPQ_OPTS */ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * + * Define the Ntpq Option Descriptions. + */ +static tOptDesc optDesc[ OPTION_CT ] = { + { /* entry idx, value */ 0, VALUE_OPT_IPV4, + /* equiv idx, value */ NO_EQUIVALENT, 0, + /* 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, + /* 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, + /* 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, + /* option proc */ NULL, + /* desc, NAME, name */ zIpv6Text, zIpv6_NAME, zIpv6_Name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 2, VALUE_OPT_COMMAND, + /* equiv idx, value */ 2, VALUE_OPT_COMMAND, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, NOLIMIT, 0, + /* opt state flags */ COMMAND_FLAGS, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ optionStackArg, + /* desc, NAME, name */ zCommandText, zCommand_NAME, zCommand_Name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 3, VALUE_OPT_DEBUG_LEVEL, + /* equiv idx, value */ 3, VALUE_OPT_DEBUG_LEVEL, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, NOLIMIT, 0, + /* opt state flags */ DEBUG_LEVEL_FLAGS, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ zDebug_LevelText, zDebug_Level_NAME, zDebug_Level_Name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 4, VALUE_OPT_SET_DEBUG_LEVEL, + /* equiv idx, value */ 4, VALUE_OPT_SET_DEBUG_LEVEL, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, NOLIMIT, 0, + /* opt state flags */ SET_DEBUG_LEVEL_FLAGS, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ SET_DEBUG_LEVEL_OPT_PROC, + /* desc, NAME, name */ zSet_Debug_LevelText, zSet_Debug_Level_NAME, zSet_Debug_Level_Name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 5, VALUE_OPT_PEERS, + /* equiv idx, value */ 5, VALUE_OPT_PEERS, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ PEERS_FLAGS, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, aPeersCantList, + /* option proc */ NULL, + /* desc, NAME, name */ zPeersText, zPeers_NAME, zPeers_Name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 6, VALUE_OPT_INTERACTIVE, + /* equiv idx, value */ 6, VALUE_OPT_INTERACTIVE, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ INTERACTIVE_FLAGS, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, aInteractiveCantList, + /* option proc */ NULL, + /* desc, NAME, name */ zInteractiveText, zInteractive_NAME, zInteractive_Name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ 7, VALUE_OPT_NUMERIC, + /* equiv idx, value */ 7, VALUE_OPT_NUMERIC, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ NUMERIC_FLAGS, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* 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, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ DOVERPROC, + /* desc, NAME, name */ zVersionText, NULL, zVersion_Name, + /* disablement strs */ NULL, NULL }, + +#undef VERSION_OPT_FLAGS + + + { /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP, + /* 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, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ doUsageOpt, + /* desc, NAME, name */ zHelpText, NULL, zHelp_Name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP, + /* 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, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ optionPagedUsage, + /* desc, NAME, name */ zMore_HelpText, NULL, zMore_Help_Name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ INDEX_OPT_SAVE_OPTS, VALUE_OPT_SAVE_OPTS, + /* equiv idx value */ NO_EQUIVALENT, 0, + /* equivalenced to */ NO_EQUIVALENT, + /* min, max, act ct */ 0, 1, 0, + /* opt state flags */ OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) + | OPTST_ARG_OPTIONAL | OPTST_NO_INIT, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ NULL, + /* desc, NAME, name */ zSave_OptsText, NULL, zSave_Opts_Name, + /* disablement strs */ NULL, NULL }, + + { /* entry idx, value */ INDEX_OPT_LOAD_OPTS, VALUE_OPT_LOAD_OPTS, + /* 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) \ + | OPTST_DISABLE_IMM, 0, + /* last opt argumnt */ { NULL }, + /* arg list/cookie */ NULL, + /* must/cannot opts */ NULL, NULL, + /* option proc */ optionLoadOpt, + /* desc, NAME, name */ zLoad_OptsText, zLoad_Opts_NAME, zLoad_Opts_Name, + /* disablement strs */ zNotLoad_Opts_Name, zNotLoad_Opts_Pfx } +}; + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * + * Define the Ntpq Option Environment + */ +tSCC zPROGNAME[] = "NTPQ"; +tSCC zUsageTitle[] = +"ntpq - standard NTP query program - Ver. 4.2.4p5\n\ +USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]... [ host ...]\n"; +tSCC zRcName[] = ".ntprc"; +tSCC* apzHomeList[] = { + "$HOME", + ".", + NULL }; + +tSCC zBugsAddr[] = "http://bugs.ntp.isc.org, bugs@ntp.org"; +#define zExplain NULL +tSCC zDetail[] = "\n\ +The\n\ +[= prog-name =]\n\ +utility program is used to query NTP servers which\n\ +implement the standard NTP mode 6 control message formats defined\n\ +in Appendix B of the NTPv3 specification RFC1305, requesting\n\ +information about current state and/or changes in that state.\n\ +The same formats are used in NTPv4, although some of the\n\ +variables have changed and new ones added.\n"; +tSCC zFullVersion[] = NTPQ_FULL_VERSION; +/* extracted from /usr/local/gnu/share/autogen/optcode.tpl near line 408 */ + +#if defined(ENABLE_NLS) +# define OPTPROC_BASE OPTPROC_TRANSLATE + static tOptionXlateProc translate_option_strings; +#else +# define OPTPROC_BASE OPTPROC_NONE +# define translate_option_strings NULL +#endif /* ENABLE_NLS */ + +tOptions ntpqOptions = { + OPTIONS_STRUCT_VERSION, + 0, NULL, /* original argc + argv */ + ( OPTPROC_BASE + + OPTPROC_ERRSTOP + + OPTPROC_SHORTOPT + + OPTPROC_LONGOPT + + OPTPROC_NO_REQ_OPT + + OPTPROC_ENVIRON + + OPTPROC_HAS_IMMED ), + 0, NULL, /* current option index, current option */ + NULL, NULL, zPROGNAME, + zRcName, zCopyright, zCopyrightNotice, + zFullVersion, apzHomeList, zUsageTitle, + zExplain, zDetail, optDesc, + zBugsAddr, /* address to send bugs to */ + NULL, NULL, /* extensions/saved state */ + 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 */, + NO_EQUIVALENT /* index of default opt */ + }, + 13 /* full option count */, 8 /* user option count */ +}; + +/* + * Create the static procedure(s) declared above. + */ +static void +doUsageOpt( + tOptions* pOptions, + tOptDesc* pOptDesc ) +{ + USAGE( EXIT_SUCCESS ); +} + +#if ! defined(TEST_NTPQ_OPTS) + +/* * * * * * * + * + * For the set-debug-level option, when DEBUG is #define-d. + */ +#ifdef DEBUG +static void +doOptSet_Debug_Level( + tOptions* pOptions, + tOptDesc* pOptDesc ) +{ + /* extracted from ../include/debug-opt.def, line 29 */ +DESC(DEBUG_LEVEL).optOccCt = atoi( pOptDesc->pzLastArg ); +} +#endif /* defined DEBUG */ + +#endif /* defined(TEST_NTPQ_OPTS) */ + +/* extracted from /usr/local/gnu/share/autogen/optmain.tpl near line 92 */ + +#if defined(TEST_NTPQ_OPTS) /* TEST MAIN PROCEDURE: */ + +int +main( int argc, char** argv ) +{ + int res = EXIT_SUCCESS; + (void)optionProcess( &ntpqOptions, argc, argv ); + { + void optionPutShell( tOptions* ); + optionPutShell( &ntpqOptions ); + } + return res; +} +#endif /* defined TEST_NTPQ_OPTS */ +/* extracted from /usr/local/gnu/share/autogen/optcode.tpl near line 514 */ + +#if ENABLE_NLS +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <autoopts/usage-txt.h> + +static char* AO_gettext( char const* pz ); +static void coerce_it(void** s); + +static char* +AO_gettext( char const* pz ) +{ + char* pzRes; + if (pz == NULL) + return NULL; + pzRes = _(pz); + if (pzRes == pz) + return pzRes; + pzRes = strdup( pzRes ); + if (pzRes == NULL) { + fputs( _("No memory for duping translated strings\n"), stderr ); + exit( EXIT_FAILURE ); + } + return pzRes; +} + +static void coerce_it(void** s) { *s = AO_gettext(*s); } +#define COERSION(_f) \ + coerce_it((void*)&(ntpqOptions._f)) + +/* + * This invokes the translation code (e.g. gettext(3)). + */ +static void +translate_option_strings( void ) +{ + /* + * 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; + + do { + ppz++; + *ppz = AO_gettext(*ppz); + } while (--ix > 0); + } + option_usage_text.field_ct = 0; + + { + tOptDesc* pOD = ntpqOptions.pOptDesc; + int ix = ntpqOptions.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++; + } + } + COERSION(pzCopyright); + COERSION(pzCopyNotice); + COERSION(pzFullVersion); + COERSION(pzUsageTitle); + COERSION(pzExplain); + COERSION(pzDetail); +} + +#endif /* ENABLE_NLS */ + +#ifdef __cplusplus +} +#endif +/* ntpq-opts.c ends here */ diff --git a/ntpq/ntpq-opts.def b/ntpq/ntpq-opts.def new file mode 100644 index 0000000000000..928bd9df9b361 --- /dev/null +++ b/ntpq/ntpq-opts.def @@ -0,0 +1,345 @@ +/* -*- Mode: Text -*- */ + +autogen definitions options; + +#include copyright.def +#include homerc.def +#include autogen-version.def + +prog-name = "ntpq"; +prog-title = "standard NTP query program"; +argument = '[ host ...]'; + +test-main; + +flag = { + name = ipv4; + value = 4; + equivalence = ipv4; + descrip = "Force IPv4 DNS name resolution"; + doc = <<- _EndOfDoc_ + Force DNS resolution of following host names on the command line + to the IPv4 namespace. + _EndOfDoc_; +}; + +flag = { + name = ipv6; + value = 6; + equivalence = ipv4; + descrip = "Force IPv6 DNS name resolution"; + doc = <<- _EndOfDoc_ + Force DNS resolution of following host names on the command line + to the IPv6 namespace. + _EndOfDoc_; +}; + +flag = { + name = command; + value = c; + arg-type = string; + descrip = "run a command and exit"; + max = NOLIMIT; + arg-name = cmd; + stack-arg; + doc = <<- _EndOfDoc_ + 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). + _EndOfDoc_; +}; + +#include debug-opt.def + +flag = { + name = peers; + value = p; + descrip = "Print a list of the peers"; + flags-cant = interactive; + doc = <<- _EndOfDoc_ + 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. + _EndOfDoc_; +}; + +flag = { + name = interactive; + value = i; + flags-cant = command, peers; + descrip = "Force ntpq to operate in interactive mode"; + doc = <<- _EndOfDoc_ + Force ntpq to operate in interactive mode. Prompts will be written + to the standard output and commands read from the standard input. + _EndOfDoc_; +}; + +flag = { + name = numeric; + value = n; + descrip = "numeric host addresses"; + doc = <<- _EndOfDoc_ + Output all host addresses in dotted-quad numeric format rather than + converting to the canonical host names. + _EndOfDoc_; +}; + +detail = <<- _END_DETAIL + The + [= prog-name =] + utility program is used to query NTP servers which + implement the standard NTP mode 6 control message formats defined + in Appendix B of the NTPv3 specification RFC1305, requesting + information about current state and/or changes in that state. + The same formats are used in NTPv4, although some of the + variables have changed and new ones added. + _END_DETAIL; + +prog-man-descrip = <<- _END_PROG_MAN_DESCRIP + The + [= prog-name =] + utility program is used to query NTP servers which + implement the standard NTP mode 6 control message formats defined + in Appendix B of the NTPv3 specification RFC1305, requesting + information about current state and/or changes in that state. + The same formats are used in NTPv4, although some of the + variables have changed and new ones added. The description on this + page is for the NTPv4 variables. + The program may be run either in interactive mode or controlled using + command line arguments. + Requests to read and write arbitrary + variables can be assembled, with raw and pretty-printed output + options being available. + The + [= prog-name =] + utility can also obtain and print a + list of peers in a common format by sending multiple queries to the + server. + + If one or more request options is included on the command line + when + [= prog-name =] + is executed, each of the requests will be sent + to the NTP servers running on each of the hosts given as command + line arguments, or on localhost by default. + If no request options + are given, + [= prog-name =] + will attempt to read commands from the + standard input and execute these on the NTP server running on the + first host given on the command line, again defaulting to localhost + when no other host is specified. + The + [= prog-name =] + utility will prompt for + commands if the standard input is a terminal device. + + The + [= prog-name =] + utility uses NTP mode 6 packets to communicate with the + NTP server, and hence can be used to query any compatible server on + the network which permits it. + Note that since NTP is a UDP protocol + this communication will be somewhat unreliable, especially over + large distances in terms of network topology. + The + [= prog-name =] + utility makes + one attempt to retransmit requests, and will time requests out if + the remote host is not heard from within a suitable timeout + time. + + Specifying a + command line option other than + .Fl i + or + .Fl n + will + cause the specified query (queries) to be sent to the indicated + host(s) immediately. + Otherwise, + [= prog-name =] + will attempt to read + interactive format commands from the standard input. + .Ss "Internal Commands" + Interactive format commands consist of a keyword followed by zero + to four arguments. + Only enough characters of the full keyword to + uniquely identify the command need be typed. + + A + number of interactive format commands are executed entirely within + the + [= prog-name =] + utility itself and do not result in NTP mode 6 + requests being sent to a server. + These are described following. + @table @code + @item ? [command_keyword] + @itemx help [command_keyword] + A + .Ql \&? + by itself will print a list of all the command + keywords known to this incarnation of + [= prog-name =] . + A + .Ql \&? + followed by a command keyword will print function and usage + information about the command. + This command is probably a better + source of information about + [= prog-name =] + than this manual + page. + @item addvars + .Ar variable_name [=value] ... + .Xc + @item rmvars variable_name ... + @item clearvars + The data carried by NTP mode 6 messages consists of a list of + items of the form + .Ql variable_name=value , + where the + .Ql =value + is ignored, and can be omitted, + in requests to the server to read variables. + The + [= prog-name =] + utility maintains an internal list in which data to be included in control + messages can be assembled, and sent using the + .Ic readlist + and + .Ic writelist + commands described below. + The + .Ic addvars + command allows variables and their optional values to be added to + the list. + If more than one variable is to be added, the list should + be comma-separated and not contain white space. + The + .Ic rmvars + command can be used to remove individual variables from the list, + while the + .Ic clearlist + command removes all variables from the + list. + @item authenticate [ yes | no ] + Normally + [= prog-name =] + does not authenticate requests unless + they are write requests. + The command + .Ql authenticate yes + causes + [= prog-name =] + to send authentication with all requests it + makes. + Authenticated requests causes some servers to handle + requests slightly differently, and can occasionally melt the CPU in + fuzzballs if you turn authentication on before doing a + .Ic peer + display. + The command + .Ql authenticate + causes + [= prog-name =] + to display whether or not + [= prog-name =] + is currently autheinticating requests. + @item cooked + Causes output from query commands to be "cooked", so that + variables which are recognized by + [= prog-name =] + will have their + values reformatted for human consumption. + Variables which + [= prog-name =] + thinks should have a decodable value but didn't are + marked with a trailing + .Ql \&? . + .@item debug [ + .Cm more | + .Cm less | + .Cm off + ] + .Xc + With no argument, displays the current debug level. + Otherwise, the debug level is changed to the indicated level. + @item delay milliseconds + Specify a time interval to be added to timestamps included in + requests which require authentication. + This is used to enable + (unreliable) server reconfiguration over long delay network paths + or between machines whose clocks are unsynchronized. + Actually the + server does not now require timestamps in authenticated requests, + so this command may be obsolete. + @item host hostname + Set the host to which future queries will be sent. + Hostname may + be either a host name or a numeric address. + @item hostnames Cm yes | Cm no + If + .Cm yes + is specified, host names are printed in + information displays. + If + .Cm no + is specified, numeric + addresses are printed instead. + The default is + .Cm yes , + unless + modified using the command line + .Fl n + switch. + @item keyid keyid + This command allows the specification of a key number to be + used to authenticate configuration requests. + This must correspond + to a key number the server has been configured to use for this + purpose. + @item ntpversion [ + .Cm 1 | + .Cm 2 | + .Cm 3 | + .Cm 4 + ] + .Xc + Sets the NTP version number which + [= prog-name =] + claims in + packets. + Defaults to 3, Note that mode 6 control messages (and + modes, for that matter) didn't exist in NTP version 1. + There appear + to be no servers left which demand version 1. + With no argument, displays the current NTP version that will be used + when communicating with servers. + @item quit + Exit + [= prog-name =] . + @item passwd + This command prompts you to type in a password (which will not + be echoed) which will be used to authenticate configuration + requests. + The password must correspond to the key configured for + use by the NTP server for this purpose if such requests are to be + successful. + @item raw + Causes all output from query commands is printed as received + from the remote server. + The only formating/interpretation done on + the data is to transform nonascii data into a printable (but barely + understandable) form. + @item timeout Ar milliseconds + Specify a timeout period for responses to server queries. + The + default is about 5000 milliseconds. + Note that since + [= prog-name =] + retries each query once after a timeout, the total waiting time for + a timeout will be twice the timeout value set. + @end table + + _END_PROG_MAN_DESCRIP; diff --git a/ntpq/ntpq-opts.h b/ntpq/ntpq-opts.h new file mode 100644 index 0000000000000..bbd35ca343998 --- /dev/null +++ b/ntpq/ntpq-opts.h @@ -0,0 +1,208 @@ +/* + * EDIT THIS FILE WITH CAUTION (ntpq-opts.h) + * + * It has been AutoGen-ed Sunday August 17, 2008 at 05:26:55 AM EDT + * From the definitions ntpq-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 + * ntpq 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. + * + * This source file is copyrighted and licensed under the following terms: + * + * ntpq copyright 1970-2008 David L. Mills and/or others - all rights reserved + * + * see html/copyright.html + */ +/* + * This file contains the programmatic interface to the Automated + * Options generated for the ntpq program. + * These macros are documented in the AutoGen info file in the + * "AutoOpts" chapter. Please refer to that doc for usage help. + */ +#ifndef AUTOOPTS_NTPQ_OPTS_H_GUARD +#define AUTOOPTS_NTPQ_OPTS_H_GUARD +#include "config.h" +#include <autoopts/options.h> + +/* + * Ensure that the library used for compiling this generated header is at + * least as new as the version current when the header template was released + * (not counting patch version increments). Also ensure that the oldest + * tolerable version is at least as old as what was current when the header + * template was released. + */ +#define AO_TEMPLATE_VERSION 118784 +#if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \ + || (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION) +# error option template version mismatches autoopts/options.h header + Choke Me. +#endif + +/* + * Enumeration of each option: + */ +typedef enum { + INDEX_OPT_IPV4 = 0, + INDEX_OPT_IPV6 = 1, + INDEX_OPT_COMMAND = 2, + INDEX_OPT_DEBUG_LEVEL = 3, + INDEX_OPT_SET_DEBUG_LEVEL = 4, + INDEX_OPT_PEERS = 5, + INDEX_OPT_INTERACTIVE = 6, + INDEX_OPT_NUMERIC = 7, + INDEX_OPT_VERSION = 8, + INDEX_OPT_HELP = 9, + INDEX_OPT_MORE_HELP = 10, + INDEX_OPT_SAVE_OPTS = 11, + INDEX_OPT_LOAD_OPTS = 12 +} teOptIndex; + +#define OPTION_CT 13 +#define NTPQ_VERSION "4.2.4p5" +#define NTPQ_FULL_VERSION "ntpq - standard NTP query program - Ver. 4.2.4p5" + +/* + * Interface defines for all options. Replace "n" with the UPPER_CASED + * option name (as in the teOptIndex enumeration above). + * e.g. HAVE_OPT( IPV4 ) + */ +#define DESC(n) (ntpqOptions.pOptDesc[INDEX_OPT_## n]) +#define HAVE_OPT(n) (! UNUSED_OPT(& DESC(n))) +#define OPT_ARG(n) (DESC(n).optArg.argString) +#define STATE_OPT(n) (DESC(n).fOptState & OPTST_SET_MASK) +#define COUNT_OPT(n) (DESC(n).optOccCt) +#define ISSEL_OPT(n) (SELECTED_OPT(&DESC(n))) +#define ISUNUSED_OPT(n) (UNUSED_OPT(& DESC(n))) +#define ENABLED_OPT(n) (! DISABLED_OPT(& DESC(n))) +#define STACKCT_OPT(n) (((tArgList*)(DESC(n).optCookie))->useCt) +#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) \ + DESC(n).fOptState |= OPTST_DISABLED; \ + DESC(n).optCookie = NULL ) + +/* + * Make sure there are no #define name conflicts with the option names + */ +#ifndef NO_OPTION_NAME_WARNINGS +# ifdef IPV4 +# warning undefining IPV4 due to option name conflict +# undef IPV4 +# endif +# ifdef IPV6 +# warning undefining IPV6 due to option name conflict +# undef IPV6 +# endif +# ifdef COMMAND +# warning undefining COMMAND due to option name conflict +# undef COMMAND +# endif +# ifdef DEBUG_LEVEL +# warning undefining DEBUG_LEVEL due to option name conflict +# undef DEBUG_LEVEL +# endif +# ifdef SET_DEBUG_LEVEL +# warning undefining SET_DEBUG_LEVEL due to option name conflict +# undef SET_DEBUG_LEVEL +# endif +# ifdef PEERS +# warning undefining PEERS due to option name conflict +# undef PEERS +# endif +# ifdef INTERACTIVE +# warning undefining INTERACTIVE due to option name conflict +# undef INTERACTIVE +# endif +# ifdef NUMERIC +# warning undefining NUMERIC due to option name conflict +# undef NUMERIC +# endif +#else /* NO_OPTION_NAME_WARNINGS */ +# undef IPV4 +# undef IPV6 +# undef COMMAND +# undef DEBUG_LEVEL +# undef SET_DEBUG_LEVEL +# undef PEERS +# undef INTERACTIVE +# 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' +#ifdef DEBUG +#define VALUE_OPT_DEBUG_LEVEL 'd' +#endif /* DEBUG */ +#ifdef DEBUG +#define VALUE_OPT_SET_DEBUG_LEVEL 'D' +#endif /* DEBUG */ +#define VALUE_OPT_PEERS 'p' +#define VALUE_OPT_INTERACTIVE 'i' +#define VALUE_OPT_NUMERIC 'n' + +#define VALUE_OPT_VERSION 'v' +#define VALUE_OPT_HELP '?' +#define VALUE_OPT_MORE_HELP '!' +#define VALUE_OPT_SAVE_OPTS '>' +#define VALUE_OPT_LOAD_OPTS '<' +#define SET_OPT_SAVE_OPTS(a) STMTS( \ + DESC(SAVE_OPTS).fOptState &= OPTST_PERSISTENT_MASK; \ + DESC(SAVE_OPTS).fOptState |= OPTST_SET; \ + DESC(SAVE_OPTS).optArg.argString = (char const*)(a) ) +/* + * Interface defines not associated with particular options + */ +#define ERRSKIP_OPTERR STMTS( ntpqOptions.fOptSet &= ~OPTPROC_ERRSTOP ) +#define ERRSTOP_OPTERR STMTS( ntpqOptions.fOptSet |= OPTPROC_ERRSTOP ) +#define RESTART_OPT(n) STMTS( \ + ntpqOptions.curOptIdx = (n); \ + ntpqOptions.pzCurOpt = NULL ) +#define START_OPT RESTART_OPT(1) +#define USAGE(c) (*ntpqOptions.pUsageProc)( &ntpqOptions, c ) +/* extracted from /usr/local/gnu/share/autogen/opthead.tpl near line 360 */ + +/* * * * * * + * + * Declare the ntpq option descriptor. + */ +#ifdef __cplusplus +extern "C" { +#endif + +extern tOptions ntpqOptions; + +#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 + +#ifdef __cplusplus +} +#endif +#endif /* AUTOOPTS_NTPQ_OPTS_H_GUARD */ +/* ntpq-opts.h ends here */ diff --git a/ntpq/ntpq-opts.menu b/ntpq/ntpq-opts.menu new file mode 100644 index 0000000000000..c06f90d34aca4 --- /dev/null +++ b/ntpq/ntpq-opts.menu @@ -0,0 +1 @@ +* ntpq Invocation:: Invoking ntpq diff --git a/ntpq/ntpq-opts.texi b/ntpq/ntpq-opts.texi new file mode 100644 index 0000000000000..0c4ca7d9c669c --- /dev/null +++ b/ntpq/ntpq-opts.texi @@ -0,0 +1,215 @@ +@node ntpq Invocation +@section Invoking ntpq +@pindex ntpq +@cindex standard NTP query program +@ignore +# +# EDIT THIS FILE WITH CAUTION (ntpq-opts.texi) +# +# It has been AutoGen-ed Sunday August 17, 2008 at 05:26:58 AM EDT +# From the definitions ntpq-opts.def +# and the template file aginfo.tpl +@end ignore +This program has no explanation. + +The +[= prog-name =] +utility program is used to query NTP servers which +implement the standard NTP mode 6 control message formats defined +in Appendix B of the NTPv3 specification RFC1305, requesting +information about current state and/or changes in that state. +The same formats are used in NTPv4, although some of the +variables have changed and new ones added. + +This section was generated by @strong{AutoGen}, +the aginfo template and the option descriptions for the @command{ntpq} program. It documents the ntpq usage text and option meanings. + +This software is released under a specialized copyright license. + +@menu +* ntpq usage:: ntpq usage help (-?) +* ntpq command:: command option (-c) +* ntpq debug-level:: debug-level option (-d) +* ntpq interactive:: interactive option (-i) +* ntpq ipv4:: ipv4 option (-4) +* ntpq ipv6:: ipv6 option (-6) +* ntpq numeric:: numeric option (-n) +* ntpq peers:: peers option (-p) +* ntpq set-debug-level:: set-debug-level option (-D) +@end menu + +@node ntpq usage +@subsection ntpq usage help (-?) +@cindex ntpq usage + +This is the automatically generated usage text for ntpq: + +@exampleindent 0 +@example +ntpq - standard NTP query program - Ver. 4.2.5p113 +USAGE: ntpq [ -<flag> [<val>] | --<name>[@{=| @}<val>] ]... [ host ...] + Flg Arg Option-Name Description + -4 no ipv4 Force IPv4 DNS name resolution + -6 no ipv6 Force IPv6 DNS name resolution + - an alternate for ipv4 + -c Str command run a command and exit + - may appear multiple times + -d no debug-level Increase output debug message level + - may appear multiple times + -D Str set-debug-level Set the output debug message level + - may appear multiple times + -p no peers Print a list of the peers + - prohibits these options: + interactive + -i no interactive Force ntpq to operate in interactive mode + - prohibits these options: + command + peers + -n no numeric numeric host addresses + opt version Output version information and exit + -? no help Display usage information and exit + -! no more-help Extended usage information passed thru pager + -> opt save-opts Save the option state to a config file + -< Str load-opts Load options from a config file + - 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. + +The following option preset mechanisms are supported: + - reading file /users/stenn/.ntprc + - reading file /deacon/backroom/snaps/ntp-stable/ntpq/.ntprc + - examining environment variables named NTPQ_* + +The +[= prog-name =] +utility program is used to query NTP servers which +implement the standard NTP mode 6 control message formats defined +in Appendix B of the NTPv3 specification RFC1305, requesting +information about current state and/or changes in that state. +The same formats are used in NTPv4, although some of the +variables have changed and new ones added. + +please send bug reports to: http://bugs.ntp.org, bugs@@ntp.org +@end example +@exampleindent 4 + +@node ntpq ipv4 +@subsection ipv4 option (-4) +@cindex ntpq-ipv4 + +This is the ``force ipv4 dns name resolution'' option. + +This option has some usage constraints. It: +@itemize @bullet +@item +is a member of the ipv4 class of options. +@end itemize + +Force DNS resolution of following host names on the command line +to the IPv4 namespace. + +@node ntpq ipv6 +@subsection ipv6 option (-6) +@cindex ntpq-ipv6 + +This is the ``force ipv6 dns name resolution'' option. + +This option has some usage constraints. It: +@itemize @bullet +@item +is a member of the ipv4 class of options. +@end itemize + +Force DNS resolution of following host names on the command line +to the IPv6 namespace. + +@node ntpq command +@subsection command option (-c) +@cindex ntpq-command + +This is the ``run a command and exit'' option. + +This option has some usage constraints. It: +@itemize @bullet +@item +may appear an unlimited number of times. +@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). + +@node ntpq debug-level +@subsection debug-level option (-d) +@cindex ntpq-debug-level + +This is the ``increase output debug message level'' 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. +@end itemize + +Increase the debugging message output level. + +@node ntpq set-debug-level +@subsection set-debug-level option (-D) +@cindex ntpq-set-debug-level + +This is the ``set the output debug message level'' 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. +@end itemize + +Set the output debugging level. Can be supplied multiple times, +but each overrides the previous value(s). + +@node ntpq peers +@subsection peers option (-p) +@cindex ntpq-peers + +This is the ``print 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: +interactive. +@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. + +@node ntpq interactive +@subsection interactive option (-i) +@cindex ntpq-interactive + +This is the ``force ntpq to operate in interactive mode'' option. + +This option has some usage constraints. It: +@itemize @bullet +@item +must not appear in combination with any of the following options: +command, peers. +@end itemize + +Force ntpq to operate in interactive mode. Prompts will be written +to the standard output and commands read from the standard input. + +@node ntpq numeric +@subsection numeric option (-n) +@cindex ntpq-numeric + +This is the ``numeric host addresses'' option. +Output all host addresses in dotted-quad numeric format rather than +converting to the canonical host names. diff --git a/ntpq/ntpq_ops.c b/ntpq/ntpq-subs.c index c4936313eb587..07f25cecefda6 100644 --- a/ntpq/ntpq_ops.c +++ b/ntpq/ntpq-subs.c @@ -6,7 +6,6 @@ #include <ctype.h> #include <sys/types.h> #include <sys/time.h> -#include <netdb.h> #include "ntpq.h" #include "ntp_stdlib.h" @@ -82,10 +81,10 @@ struct xcmd opcmds[] = { { "lpassociations", lpassociations, { NO, NO, NO, NO }, { "", "", "", "" }, "print last obtained list of associations, including client information" }, - { "addvars", addvars, { STR, NO, NO, NO }, + { "addvars", addvars, { NTP_STR, NO, NO, NO }, { "name[=value][,...]", "", "", "" }, "add variables to the variable list or change their values" }, - { "rmvars", rmvars, { STR, NO, NO, NO }, + { "rmvars", rmvars, { NTP_STR, NO, NO, NO }, { "name[,...]", "", "", "" }, "remove variables from the variable list" }, { "clearvars", clearvars, { NO, NO, NO, NO }, @@ -94,49 +93,49 @@ struct xcmd opcmds[] = { { "showvars", showvars, { NO, NO, NO, NO }, { "", "", "", "" }, "print variables on the variable list" }, - { "readlist", readlist, { OPT|UINT, NO, NO, NO }, + { "readlist", readlist, { OPT|NTP_UINT, NO, NO, NO }, { "assocID", "", "", "" }, "read the system or peer variables included in the variable list" }, - { "rl", readlist, { OPT|UINT, NO, NO, NO }, + { "rl", readlist, { OPT|NTP_UINT, NO, NO, NO }, { "assocID", "", "", "" }, "read the system or peer variables included in the variable list" }, - { "writelist", writelist, { OPT|UINT, NO, NO, NO }, + { "writelist", writelist, { OPT|NTP_UINT, NO, NO, NO }, { "assocID", "", "", "" }, "write the system or peer variables included in the variable list" }, - { "readvar", readvar, { OPT|UINT, OPT|STR, NO, NO }, + { "readvar", readvar, { OPT|NTP_UINT, OPT|NTP_STR, NO, NO }, { "assocID", "name=value[,...]", "", "" }, "read system or peer variables" }, - { "rv", readvar, { OPT|UINT, OPT|STR, NO, NO }, + { "rv", readvar, { OPT|NTP_UINT, OPT|NTP_STR, NO, NO }, { "assocID", "name=value[,...]", "", "" }, "read system or peer variables" }, - { "writevar", writevar, { UINT, STR, NO, NO }, + { "writevar", writevar, { NTP_UINT, NTP_STR, NO, NO }, { "assocID", "name=value,[...]", "", "" }, "write system or peer variables" }, - { "mreadlist", mreadlist, { UINT, UINT, NO, NO }, + { "mreadlist", mreadlist, { NTP_UINT, NTP_UINT, NO, NO }, { "assocID", "assocID", "", "" }, "read the peer variables in the variable list for multiple peers" }, - { "mrl", mreadlist, { UINT, UINT, NO, NO }, + { "mrl", mreadlist, { NTP_UINT, NTP_UINT, NO, NO }, { "assocID", "assocID", "", "" }, "read the peer variables in the variable list for multiple peers" }, - { "mreadvar", mreadvar, { UINT, UINT, OPT|STR, NO }, + { "mreadvar", mreadvar, { NTP_UINT, NTP_UINT, OPT|NTP_STR, NO }, { "assocID", "assocID", "name=value[,...]", "" }, "read peer variables from multiple peers" }, - { "mrv", mreadvar, { UINT, UINT, OPT|STR, NO }, + { "mrv", mreadvar, { NTP_UINT, NTP_UINT, OPT|NTP_STR, NO }, { "assocID", "assocID", "name=value[,...]", "" }, "read peer variables from multiple peers" }, - { "clocklist", clocklist, { OPT|UINT, NO, NO, NO }, + { "clocklist", clocklist, { OPT|NTP_UINT, NO, NO, NO }, { "assocID", "", "", "" }, "read the clock variables included in the variable list" }, - { "cl", clocklist, { OPT|UINT, NO, NO, NO }, + { "cl", clocklist, { OPT|NTP_UINT, NO, NO, NO }, { "assocID", "", "", "" }, "read the clock variables included in the variable list" }, - { "clockvar", clockvar, { OPT|UINT, OPT|STR, NO, NO }, + { "clockvar", clockvar, { OPT|NTP_UINT, OPT|NTP_STR, NO, NO }, { "assocID", "name=value[,...]", "", "" }, "read clock variables" }, - { "cv", clockvar, { OPT|UINT, OPT|STR, NO, NO }, + { "cv", clockvar, { OPT|NTP_UINT, OPT|NTP_STR, NO, NO }, { "assocID", "name=value[,...]", "", "" }, "read clock variables" }, - { "pstatus", pstatus, { UINT, NO, NO, NO }, + { "pstatus", pstatus, { NTP_UINT, NO, NO, NO }, { "assocID", "", "", "" }, "print status information returned for a peer" }, { "peers", peers, { OPT|IP_VERSION, NO, NO, NO }, @@ -522,6 +521,8 @@ dolist( if (res != 0) return 0; + if (numhosts > 1) + (void) fprintf(fp, "server=%s ", currenthost); if (dsize == 0) { if (associd == 0) (void) fprintf(fp, "No system%s variables returned\n", @@ -533,6 +534,7 @@ dolist( return 1; } + (void) fprintf(fp,"assID=%d ",associd); printvars(dsize, datap, (int)rstatus, type, fp); return 1; } @@ -595,11 +597,15 @@ writelist( if (res != 0) return; + if (numhosts > 1) + (void) fprintf(fp, "server=%s ", currenthost); if (dsize == 0) (void) fprintf(fp, "done! (no data returned)\n"); - else + else { + (void) fprintf(fp,"assID=%d ",associd); printvars(dsize, datap, (int)rstatus, (associd != 0) ? TYPE_PEER : TYPE_SYS, fp); + } return; } @@ -666,11 +672,15 @@ writevar( if (res != 0) return; + if (numhosts > 1) + (void) fprintf(fp, "server=%s ", currenthost); if (dsize == 0) (void) fprintf(fp, "done! (no data returned)\n"); - else + else { + (void) fprintf(fp,"assID=%d ",associd); printvars(dsize, datap, (int)rstatus, (associd != 0) ? TYPE_PEER : TYPE_SYS, fp); + } return; } @@ -859,23 +869,27 @@ dogetassoc( FILE *fp ) { - u_short *datap; + char *datap; int res; int dsize; u_short rstatus; res = doquery(CTL_OP_READSTAT, 0, 0, 0, (char *)0, &rstatus, - &dsize, (void *)&datap); + &dsize, &datap); if (res != 0) return 0; if (dsize == 0) { + if (numhosts > 1) + (void) fprintf(fp, "server=%s ", currenthost); (void) fprintf(fp, "No association ID's returned\n"); return 0; } if (dsize & 0x3) { + if (numhosts > 1) + (void) fprintf(stderr, "server=%s ", currenthost); (void) fprintf(stderr, "***Server returned %d octets, should be multiple of 4\n", dsize); @@ -884,10 +898,10 @@ dogetassoc( numassoc = 0; while (dsize > 0) { - assoc_cache[numassoc].assid = ntohs(*datap); - datap++; - assoc_cache[numassoc].status = ntohs(*datap); - datap++; + assoc_cache[numassoc].assid = ntohs(*((u_short *)datap)); + datap += sizeof(u_short); + assoc_cache[numassoc].status = ntohs(*((u_short *)datap)); + datap += sizeof(u_short); if (++numassoc >= MAXASSOC) break; dsize -= sizeof(u_short) + sizeof(u_short); @@ -928,7 +942,7 @@ printassoc( * Output a header */ (void) fprintf(fp, - "ind assID status conf reach auth condition last_event cnt\n"); + "\nind assID status conf reach auth condition last_event cnt\n"); (void) fprintf(fp, "===========================================================\n"); for (i = 0; i < numassoc; i++) { @@ -1127,6 +1141,8 @@ radiostatus( if (res != 0) return; + if (numhosts > 1) + (void) fprintf(fp, "server=%s ", currenthost); if (dsize == 0) { (void) fprintf(fp, "No radio status string returned\n"); return; @@ -1161,6 +1177,8 @@ pstatus( if (res != 0) return; + if (numhosts > 1) + (void) fprintf(fp, "server=%s ", currenthost); if (dsize == 0) { (void) fprintf(fp, "No information returned for association %u\n", @@ -1168,6 +1186,7 @@ pstatus( return; } + (void) fprintf(fp,"assID=%d ",associd); printvars(dsize, datap, (int)rstatus, TYPE_PEER, fp); } @@ -1374,7 +1393,7 @@ doprintpeers( while (nextvar(&datalen, &data, &name, &value)) { struct sockaddr_storage dum_store; - i = findvar(name, peer_var); + i = findvar(name, peer_var, 1); if (i == 0) continue; /* don't know this one */ switch (i) { @@ -1397,6 +1416,13 @@ doprintpeers( havevar[HAVE_REFID] = 1; if (*value == '\0') { dstadr_refid = "0.0.0.0"; + } else if ((int)strlen(value) <= 4) { + refid_string[0] = '.'; + (void) strcpy(&refid_string[1], value); + i = strlen(refid_string); + refid_string[i] = '.'; + refid_string[i+1] = '\0'; + dstadr_refid = refid_string; } else if (decodenetnum(value, &dstadr)) { if (SOCKNUL(&dstadr)) dstadr_refid = "0.0.0.0"; @@ -1407,13 +1433,6 @@ doprintpeers( else dstadr_refid = stoa(&dstadr); - } else if ((int)strlen(value) <= 4) { - refid_string[0] = '.'; - (void) strcpy(&refid_string[1], value); - i = strlen(refid_string); - refid_string[i] = '.'; - refid_string[i+1] = '\0'; - dstadr_refid = refid_string; } else { havevar[HAVE_REFID] = 0; } @@ -1450,8 +1469,9 @@ doprintpeers( havevar[HAVE_OFFSET] = 1; break; case CP_JITTER: - if (decodetime(value, &estjitter)) - havevar[HAVE_JITTER] = 1; + if (pvl == peervarlist) + if (decodetime(value, &estjitter)) + havevar[HAVE_JITTER] = 1; break; case CP_DISPERSION: if (decodetime(value, &estdisp)) @@ -1558,6 +1578,8 @@ dogetpeers( return 0; if (dsize == 0) { + if (numhosts > 1) + (void) fprintf(stderr, "server=%s ", currenthost); (void) fprintf(stderr, "***No information returned for association %d\n", associd); @@ -1591,7 +1613,7 @@ dopeers( maxhostlen = strlen(fullname); } if (numhosts > 1) - (void) fprintf(fp, "%-*.*s ", maxhostlen, maxhostlen, "host"); + (void) fprintf(fp, "%-*.*s ", maxhostlen, maxhostlen, "server"); (void) fprintf(fp, " remote refid st t when poll reach delay offset jitter\n"); if (numhosts > 1) @@ -1668,12 +1690,24 @@ doopeers( ) { register int i; + char fullname[LENHOSTNAME]; + struct sockaddr_storage netnum; if (!dogetassoc(fp)) return; + for (i = 0; i < numhosts; ++i) { + if (getnetnum(chosts[i], &netnum, fullname, af)) + if ((int)strlen(fullname) > maxhostlen) + maxhostlen = strlen(fullname); + } + if (numhosts > 1) + (void) fprintf(fp, "%-*.*s ", maxhostlen, maxhostlen, "server"); (void) fprintf(fp, " remote local st t when poll reach delay offset disp\n"); + if (numhosts > 1) + for (i = 0; i <= maxhostlen; ++i) + (void) fprintf(fp, "="); (void) fprintf(fp, "==============================================================================\n"); diff --git a/ntpq/ntpq.1 b/ntpq/ntpq.1 new file mode 100644 index 0000000000000..d418636715b37 --- /dev/null +++ b/ntpq/ntpq.1 @@ -0,0 +1,385 @@ +.TH NTPQ 1 2008-08-17 "( 4.2.4p5)" "Programmer's Manual" +.\" EDIT THIS FILE WITH CAUTION (ntpq.1) +.\" +.\" It has been AutoGen-ed Sunday August 17, 2008 at 05:26:57 AM EDT +.\" From the definitions ntpq-opts.def +.\" and the template file agman1.tpl +.\" +.SH NAME +ntpq \- standard NTP query program +.SH SYNOPSIS +.B ntpq +.\" Mixture of short (flag) options and long options +.RB [ \-\fIflag\fP " [\fIvalue\fP]]... [" \--\fIopt-name\fP " [[=| ]\fIvalue\fP]]..." +.br +.in +8 +[ host ...] +.SH "DESCRIPTION" +This manual page documents, briefly, the \fBntpq\fP command. +The +[= prog-name =] +utility program is used to query NTP servers which +implement the standard NTP mode 6 control message formats defined +in Appendix B of the NTPv3 specification RFC1305, requesting +information about current state and/or changes in that state. +The same formats are used in NTPv4, although some of the +variables have changed and new ones added. The description on this +page is for the NTPv4 variables. +The program may be run either in interactive mode or controlled using +command line arguments. +Requests to read and write arbitrary +variables can be assembled, with raw and pretty-printed output +options being available. +The +[= prog-name =] +utility can also obtain and print a +list of peers in a common format by sending multiple queries to the +server. + +If one or more request options is included on the command line +when +[= prog-name =] +is executed, each of the requests will be sent +to the NTP servers running on each of the hosts given as command +line arguments, or on localhost by default. +If no request options +are given, +[= prog-name =] +will attempt to read commands from the +standard input and execute these on the NTP server running on the +first host given on the command line, again defaulting to localhost +when no other host is specified. +The +[= prog-name =] +utility will prompt for +commands if the standard input is a terminal device. + +The +[= prog-name =] +utility uses NTP mode 6 packets to communicate with the +NTP server, and hence can be used to query any compatible server on +the network which permits it. +Note that since NTP is a UDP protocol +this communication will be somewhat unreliable, especially over +large distances in terms of network topology. +The +[= prog-name =] +utility makes +one attempt to retransmit requests, and will time requests out if +the remote host is not heard from within a suitable timeout +time. + +Specifying a +command line option other than +.Fl i +or +.Fl n +will +cause the specified query (queries) to be sent to the indicated +host(s) immediately. +Otherwise, +[= prog-name =] +will attempt to read +interactive format commands from the standard input. +.Ss "Internal Commands" +Interactive format commands consist of a keyword followed by zero +to four arguments. +Only enough characters of the full keyword to +uniquely identify the command need be typed. + +A +number of interactive format commands are executed entirely within +the +[= prog-name =] +utility itself and do not result in NTP mode 6 +requests being sent to a server. +These are described following. +.sp +.IR "? [command_keyword]" +.sp 1x help [command_keyword] +A +.Ql \&? +by itself will print a list of all the command +keywords known to this incarnation of +[= prog-name =] . +A +.Ql \&? +followed by a command keyword will print function and usage +information about the command. +This command is probably a better +source of information about +[= prog-name =] +than this manual +page. +.sp +.IR "addvars" +.Ar variable_name [=value] ... +.Xc +.sp +.IR "rmvars variable_name ..." +.sp +.IR "clearvars" +The data carried by NTP mode 6 messages consists of a list of +items of the form +.Ql variable_name=value , +where the +.Ql =value +is ignored, and can be omitted, +in requests to the server to read variables. +The +[= prog-name =] +utility maintains an internal list in which data to be included in control +messages can be assembled, and sent using the +.Ic readlist +and +.Ic writelist +commands described below. +The +.Ic addvars +command allows variables and their optional values to be added to +the list. +If more than one variable is to be added, the list should +be comma-separated and not contain white space. +The +.Ic rmvars +command can be used to remove individual variables from the list, +while the +.Ic clearlist +command removes all variables from the +list. +.sp +.IR "authenticate [ yes | no ]" +Normally +[= prog-name =] +does not authenticate requests unless +they are write requests. +The command +.Ql authenticate yes +causes +[= prog-name =] +to send authentication with all requests it +makes. +Authenticated requests causes some servers to handle +requests slightly differently, and can occasionally melt the CPU in +fuzzballs if you turn authentication on before doing a +.Ic peer +display. +The command +.Ql authenticate +causes +[= prog-name =] +to display whether or not +[= prog-name =] +is currently autheinticating requests. +.sp +.IR "cooked" +Causes output from query commands to be "cooked", so that +variables which are recognized by +[= prog-name =] +will have their +values reformatted for human consumption. +Variables which +[= prog-name =] +thinks should have a decodable value but didn't are +marked with a trailing +.Ql \&? . +.@item debug [ +.Cm more | +.Cm less | +.Cm off +] +.Xc +With no argument, displays the current debug level. +Otherwise, the debug level is changed to the indicated level. +.sp +.IR "delay milliseconds" +Specify a time interval to be added to timestamps included in +requests which require authentication. +This is used to enable +(unreliable) server reconfiguration over long delay network paths +or between machines whose clocks are unsynchronized. +Actually the +server does not now require timestamps in authenticated requests, +so this command may be obsolete. +.sp +.IR "host hostname" +Set the host to which future queries will be sent. +Hostname may +be either a host name or a numeric address. +.sp +.IR "hostnames Cm yes | Cm no" +If +.Cm yes +is specified, host names are printed in +information displays. +If +.Cm no +is specified, numeric +addresses are printed instead. +The default is +.Cm yes , +unless +modified using the command line +.Fl n +switch. +.sp +.IR "keyid keyid" +This command allows the specification of a key number to be +used to authenticate configuration requests. +This must correspond +to a key number the server has been configured to use for this +purpose. +.sp +.IR "ntpversion [" +.Cm 1 | +.Cm 2 | +.Cm 3 | +.Cm 4 +] +.Xc +Sets the NTP version number which +[= prog-name =] +claims in +packets. +Defaults to 3, Note that mode 6 control messages (and +modes, for that matter) didn't exist in NTP version 1. +There appear +to be no servers left which demand version 1. +With no argument, displays the current NTP version that will be used +when communicating with servers. +.sp +.IR "quit" +Exit +[= prog-name =] . +.sp +.IR "passwd" +This command prompts you to type in a password (which will not +be echoed) which will be used to authenticate configuration +requests. +The password must correspond to the key configured for +use by the NTP server for this purpose if such requests are to be +successful. +.sp +.IR "raw" +Causes all output from query commands is printed as received +from the remote server. +The only formating/interpretation done on +the data is to transform nonascii data into a printable (but barely +understandable) form. +.sp +.IR "timeout Ar milliseconds" +Specify a timeout period for responses to server queries. +The +default is about 5000 milliseconds. +Note that since +[= prog-name =] +retries each query once after a timeout, the total waiting time for +a timeout will be twice the timeout value set. +.br + +.SH OPTIONS +.TP +.BR \-4 ", " \--ipv4 +Force IPv4 DNS name resolution. +This option is a member of the ipv4 class of options. +.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. +.sp +Force DNS resolution of following host names on the command line +to the IPv6 namespace. +.TP +.BR \-c " \fIcmd\fP, " \--command "=" \fIcmd\fP +run a command and exit. +This option may appear an unlimited number of times. +.sp +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). +.TP +.BR \-d ", " \--debug-level +Increase output debug message level. +This option may appear an unlimited number of times. +.sp +Increase the debugging message output level. +.TP +.BR \-D " \fIstring\fP, " \--set-debug-level "=" \fIstring\fP +Set the output debug message level. +This option may appear an unlimited number of times. +.sp +Set the output debugging level. Can be supplied multiple times, +but each overrides the previous value(s). +.TP +.BR \-p ", " \--peers +Print a list of the peers. +This option must not appear in combination with any of the following options: +interactive. +.sp +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. +.TP +.BR \-i ", " \--interactive +Force ntpq to operate in interactive mode. +This option must not appear in combination with any of the following options: +command, peers. +.sp +Force ntpq to operate in interactive mode. Prompts will be written +to the standard output and commands read from the standard input. +.TP +.BR \-n ", " \--numeric +numeric host addresses. +.sp +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. +.TP +.BR \-! , " \--more-help" +Extended usage information passed thru pager. +.TP +.BR \-> " [\fIrcfile\fP]," " \--save-opts" "[=\fIrcfile\fP]" +Save the option state to \fIrcfile\fP. The default is the \fIlast\fP +configuration file listed in the \fBOPTION PRESETS\fP section, below. +.TP +.BR \-< " \fIrcfile\fP," " \--load-opts" "=\fIrcfile\fP," " \--no-load-opts" +Load options from \fIrcfile\fP. +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]" +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. +.SH OPTION PRESETS +Any option that is not marked as \fInot presettable\fP may be preset +by loading values from configuration ("RC" or ".INI") file(s) and values from +environment variables named: +.nf + \fBNTPQ_<option-name>\fP or \fBNTPQ\fP +.fi +.aj +The environmental presets take precedence (are processed later than) +the configuration files. +The \fIhomerc\fP files are "\fI$HOME\fP", and "\fI.\fP". +If any of these are directories, then the file \fI.ntprc\fP +is searched for within those directories. +.SH AUTHOR +David L. Mills and/or others +.br +Please send bug reports to: http://bugs.ntp.isc.org, bugs@ntp.org + +.PP +.nf +.na +see html/copyright.html +.fi +.ad +.PP +This manual page was \fIAutoGen\fP-erated from the \fBntpq\fP +option definitions. diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index bc12725eec080..91379408ff7c9 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -4,6 +4,12 @@ #include <stdio.h> +#include <ctype.h> +#include <signal.h> +#include <setjmp.h> +#include <sys/types.h> +#include <sys/time.h> + #include "ntpq.h" #include "ntp_unixtime.h" #include "ntp_calendar.h" @@ -15,16 +21,13 @@ #include "isc/net.h" #include "isc/result.h" -#include <ctype.h> -#include <signal.h> -#include <setjmp.h> -#include <sys/types.h> -#include <sys/time.h> -#include <netdb.h> +#include "ntpq-opts.h" + #ifdef SYS_WINNT +# include <Mswsock.h> # include <io.h> #else -#define closesocket close +# define closesocket close #endif /* SYS_WINNT */ #if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT) @@ -33,9 +36,14 @@ #endif /* HAVE_LIBREADLINE || HAVE_LIBEDIT */ #ifdef SYS_VXWORKS -/* vxWorks needs mode flag -casey*/ -#define open(name, flags) open(name, flags, 0777) -#define SERVER_PORT_NUM 123 + /* vxWorks needs mode flag -casey*/ +# define open(name, flags) open(name, flags, 0777) +# define SERVER_PORT_NUM 123 +#endif + +/* we use COMMAND as an autogen keyword */ +#ifdef COMMAND +# undef COMMAND #endif /* @@ -47,6 +55,11 @@ const char *prompt = "ntpq> "; /* prompt to ask him about */ /* + * for get_systime() + */ +s_char sys_precision; /* local clock precision (log2 s) */ + +/* * Keyid used for authenticated requests. Obtained on the fly. */ u_long info_auth_keyid = 0; @@ -156,7 +169,7 @@ struct ctl_var peer_var[] = { { CP_REC, TS, "rec" }, /* 19 */ { CP_XMT, TS, "xmt" }, /* 20 */ { CP_REACH, OC, "reach" }, /* 21 */ - { CP_VALID, UI, "valid" }, /* 22 */ + { CP_UNREACH, UI, "unreach" }, /* 22 */ { CP_TIMER, UI, "timer" }, /* 23 */ { CP_DELAY, FS, "delay" }, /* 24 */ { CP_OFFSET, FL, "offset" }, /* 25 */ @@ -209,17 +222,19 @@ struct ctl_var clock_var[] = { * flasher bits */ static const char *tstflagnames[] = { - "dup_pkt", /* TEST1 */ - "bogus_pkt", /* TEST2 */ - "proto_unsync", /* TEST3 */ - "no_access", /* TEST4 */ - "bad_auth", /* TEST5 */ - "peer_unsync", /* TEST6 */ - "peer_stratum", /* TEST7 */ - "root_bounds", /* TEST8 */ - "peer_bounds", /* TEST9 */ - "bad_autokey", /* TEST10 */ - "not_proventic" /* TEST11*/ + "pkt_dup", /* TEST1 */ + "pkt_bogus", /* TEST2 */ + "pkt_proto", /* TEST3 */ + "pkt_denied", /* TEST4 */ + "pkt_auth", /* TEST5 */ + "pkt_synch", /* TEST6 */ + "pkt_dist", /* TEST7 */ + "pkt_autokey", /* TEST8 */ + "pkt_crypto", /* TEST9 */ + "peer_stratum", /* TEST10 */ + "peer_dist", /* TEST11 */ + "peer_loop", /* TEST12 */ + "peer_unfit" /* TEST13 */ }; @@ -284,31 +299,31 @@ static int assoccmp P((struct association *, struct association *)); * Built-in commands we understand */ struct xcmd builtins[] = { - { "?", help, { OPT|STR, NO, NO, NO }, + { "?", help, { OPT|NTP_STR, NO, NO, NO }, { "command", "", "", "" }, "tell the use and syntax of commands" }, - { "help", help, { OPT|STR, NO, NO, NO }, + { "help", help, { OPT|NTP_STR, NO, NO, NO }, { "command", "", "", "" }, "tell the use and syntax of commands" }, - { "timeout", timeout, { OPT|UINT, NO, NO, NO }, + { "timeout", timeout, { OPT|NTP_UINT, NO, NO, NO }, { "msec", "", "", "" }, "set the primary receive time out" }, - { "delay", auth_delay, { OPT|INT, NO, NO, NO }, + { "delay", auth_delay, { OPT|NTP_INT, NO, NO, NO }, { "msec", "", "", "" }, "set the delay added to encryption time stamps" }, - { "host", host, { OPT|STR, OPT|STR, NO, NO }, + { "host", host, { OPT|NTP_STR, OPT|NTP_STR, NO, NO }, { "-4|-6", "hostname", "", "" }, "specify the host whose NTP server we talk to" }, - { "poll", ntp_poll, { OPT|UINT, OPT|STR, NO, NO }, + { "poll", ntp_poll, { OPT|NTP_UINT, OPT|NTP_STR, NO, NO }, { "n", "verbose", "", "" }, "poll an NTP server in client mode `n' times" }, { "passwd", passwd, { NO, NO, NO, NO }, { "", "", "", "" }, "specify a password to use for authenticated requests"}, - { "hostnames", hostnames, { OPT|STR, NO, NO, NO }, + { "hostnames", hostnames, { OPT|NTP_STR, NO, NO, NO }, { "yes|no", "", "", "" }, "specify whether hostnames or net numbers are printed"}, - { "debug", setdebug, { OPT|STR, NO, NO, NO }, + { "debug", setdebug, { OPT|NTP_STR, NO, NO, NO }, { "no|more|less", "", "", "" }, "set/change debugging level" }, { "quit", quit, { NO, NO, NO, NO }, @@ -317,7 +332,7 @@ struct xcmd builtins[] = { { "exit", quit, { NO, NO, NO, NO }, { "", "", "", "" }, "exit ntpq" }, - { "keyid", keyid, { OPT|UINT, NO, NO, NO }, + { "keyid", keyid, { OPT|NTP_UINT, NO, NO, NO }, { "key#", "", "", "" }, "set keyid to use for authenticated requests" }, { "version", version, { NO, NO, NO, NO }, @@ -329,13 +344,13 @@ struct xcmd builtins[] = { { "cooked", cooked, { NO, NO, NO, NO }, { "", "", "", "" }, "do cooked mode variable output" }, - { "authenticate", authenticate, { OPT|STR, NO, NO, NO }, + { "authenticate", authenticate, { OPT|NTP_STR, NO, NO, NO }, { "yes|no", "", "", "" }, "always authenticate requests to this server" }, - { "ntpversion", ntpversion, { OPT|UINT, NO, NO, NO }, + { "ntpversion", ntpversion, { OPT|NTP_UINT, NO, NO, NO }, { "version number", "", "", "" }, "set the NTP version number to use for requests" }, - { "keytype", keytype, { OPT|STR, NO, NO, NO }, + { "keytype", keytype, { OPT|NTP_STR, NO, NO, NO }, { "key type (md5|des)", "", "", "" }, "set key type to use for authenticated requests (des|md5)" }, { 0, 0, { NO, NO, NO, NO }, @@ -358,6 +373,7 @@ struct xcmd builtins[] = { #define MAXVARLEN 256 /* maximum length of a variable name */ #define MAXVALLEN 400 /* maximum length of a variable value */ #define MAXOUTLINE 72 /* maximum length of an output line */ +#define SCREENWIDTH 76 /* nominal screen width in columns */ /* * Some variables used and manipulated locally @@ -457,10 +473,8 @@ CALL(ntpq,"ntpq",ntpqmain); void clear_globals(void) { extern int ntp_optind; - extern char *ntp_optarg; showhostnames = 0; /* don'tshow host names by default */ ntp_optind = 0; - ntp_optarg = 0; server_entry = NULL; /* server entry for ntp */ havehost = 0; /* set to 1 when host open */ numassoc = 0; /* number of cached associations */ @@ -489,15 +503,13 @@ ntpqmain( char *argv[] ) { - int c; - int errflg = 0; extern int ntp_optind; - extern char *ntp_optarg; -#ifdef NO_MAIN_ALLOWED - clear_globals(); - taskPrioritySet(taskIdSelf(), 100 ); +#ifdef SYS_VXWORKS + clear_globals(); + taskPrioritySet(taskIdSelf(), 100 ); #endif + delay_time.l_ui = 0; delay_time.l_uf = DEFDELAY; @@ -515,7 +527,49 @@ ntpqmain( } progname = argv[0]; - ai_fam_templ = ai_fam_default; + + { + int optct = optionProcess(&ntpqOptions, argc, argv); + argc -= optct; + argv += optct; + } + + switch (WHICH_IDX_IPV4) { + case INDEX_OPT_IPV4: + ai_fam_templ = AF_INET; + break; + case INDEX_OPT_IPV6: + ai_fam_templ = AF_INET6; + break; + default: + ai_fam_templ = ai_fam_default; + break; + } + + if (HAVE_OPT(COMMAND)) { + int cmdct = STACKCT_OPT( COMMAND ); + const char** cmds = STACKLST_OPT( COMMAND ); + + while (cmdct-- > 0) { + ADDCMD(*cmds++); + } + } + + debug = DESC(DEBUG_LEVEL).optOccCt; + + if (HAVE_OPT(INTERACTIVE)) { + interactive = 1; + } + + if (HAVE_OPT(NUMERIC)) { + showhostnames = 0; + } + + if (HAVE_OPT(PEERS)) { + ADDCMD("peers"); + } + +#if 0 while ((c = ntp_getopt(argc, argv, "46c:dinp")) != EOF) switch (c) { case '4': @@ -549,6 +603,7 @@ ntpqmain( progname); exit(2); } +#endif if (ntp_optind == argc) { ADDHOST(DEFHOST); } else { @@ -630,7 +685,11 @@ openhost( hints.ai_flags = AI_NUMERICHOST; a_info = getaddrinfo(hname, service, &hints, &ai); - if (a_info == EAI_NONAME || a_info == EAI_NODATA) { + if (a_info == EAI_NONAME +#ifdef EAI_NODATA + || a_info == EAI_NODATA +#endif + ) { hints.ai_flags = AI_CANONNAME; #ifdef AI_ADDRCONFIG hints.ai_flags |= AI_ADDRCONFIG; @@ -684,6 +743,7 @@ openhost( { int optionValue = SO_SYNCHRONOUS_NONALERT; int err; + err = setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&optionValue, sizeof(optionValue)); if (err != NO_ERROR) { (void) fprintf(stderr, "cannot open nonoverlapped sockets\n"); @@ -1268,6 +1328,8 @@ doquery( done = 1; goto again; } + if (numhosts > 1) + (void) fprintf(stderr, "server=%s ", currenthost); switch(res) { case CERR_BADFMT: (void) fprintf(stderr, @@ -1577,16 +1639,16 @@ getarg( static const char *digits = "0123456789"; switch (code & ~OPT) { - case STR: + case NTP_STR: argp->string = str; break; - case ADD: + case NTP_ADD: if (!getnetnum(str, &(argp->netnum), (char *)0, 0)) { return 0; } break; - case INT: - case UINT: + case NTP_INT: + case NTP_UINT: isneg = 0; np = str; if (*np == '&') { @@ -1629,7 +1691,7 @@ getarg( } while (*(++np) != '\0'); if (isneg) { - if ((code & ~OPT) == UINT) { + if ((code & ~OPT) == NTP_UINT) { (void) fprintf(stderr, "***Value %s should be unsigned\n", str); return 0; @@ -1666,7 +1728,6 @@ getnetnum( int af ) { - int err; int sockaddr_len; struct addrinfo hints, *ai = NULL; @@ -1685,10 +1746,9 @@ getnetnum( getnameinfo((struct sockaddr *)num, sockaddr_len, fullhost, sizeof(fullhost), NULL, 0, NI_NUMERICHOST); - } return 1; - } else if ((err = getaddrinfo(hname, "ntp", &hints, &ai)) == 0) { + } else if (getaddrinfo(hname, "ntp", &hints, &ai) == 0) { memmove((char *)num, ai->ai_addr, ai->ai_addrlen); if (ai->ai_canonname != 0) (void) strcpy(fullhost, ai->ai_canonname); @@ -1915,8 +1975,8 @@ decodeint( { if (*str == '0') { if (*(str+1) == 'x' || *(str+1) == 'X') - return hextoint(str+2, (void *)&val); - return octtoint(str, (void *)&val); + return hextoint(str+2, val); + return octtoint(str, val); } return atoint(str, val); } @@ -1991,57 +2051,56 @@ help( FILE *fp ) { - int i; - int n; struct xcmd *xcp; char *cmd; - const char *cmdsort[100]; - int length[100]; - int maxlength; - int numperline; - static const char *spaces = " "; /* 20 spaces */ + const char *list[100]; + int word, words; + int row, rows; + int col, cols; if (pcmd->nargs == 0) { - n = 0; + words = 0; for (xcp = builtins; xcp->keyword != 0; xcp++) { if (*(xcp->keyword) != '?') - cmdsort[n++] = xcp->keyword; + list[words++] = xcp->keyword; } for (xcp = opcmds; xcp->keyword != 0; xcp++) - cmdsort[n++] = xcp->keyword; + list[words++] = xcp->keyword; + qsort( #ifdef QSORT_USES_VOID_P - qsort(cmdsort, (size_t)n, sizeof(char *), helpsort); + (void *) #else - qsort((char *)cmdsort, (size_t)n, sizeof(char *), helpsort); + (char *) #endif - - maxlength = 0; - for (i = 0; i < n; i++) { - length[i] = strlen(cmdsort[i]); - if (length[i] > maxlength) - maxlength = length[i]; - } - maxlength++; - numperline = 76 / maxlength; - - (void) fprintf(fp, "Commands available:\n"); - for (i = 0; i < n; i++) { - if ((i % numperline) == (numperline-1) - || i == (n-1)) - (void) fprintf(fp, "%s\n", cmdsort[i]); - else - (void) fprintf(fp, "%s%s", cmdsort[i], - spaces+20-maxlength+length[i]); + (list), (size_t)(words), sizeof(char *), helpsort); + col = 0; + for (word = 0; word < words; word++) { + int length = strlen(list[word]); + if (col < length) { + col = length; + } } + + cols = SCREENWIDTH / ++col; + rows = (words + cols - 1) / cols; + + (void) fprintf(fp, "ntpq 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"); + } } else { cmd = pcmd->argval[0].string; - n = findcmd(cmd, builtins, opcmds, &xcp); - if (n == 0) { + words = findcmd(cmd, builtins, opcmds, &xcp); + if (words == 0) { (void) fprintf(stderr, "Command `%s' is unknown\n", cmd); return; - } else if (n >= 2) { + } else if (words >= 2) { (void) fprintf(stderr, "Command `%s' is ambiguous\n", cmd); return; @@ -2743,12 +2802,15 @@ nextvar( /* - * findvar - see if this variable is known to us + * findvar - see if this variable is known to us. + * If "code" is 1, return ctl_var->code. + * Otherwise return the ordinal position of the found variable. */ int findvar( char *varname, - struct ctl_var *varlist + struct ctl_var *varlist, + int code ) { register char *np; @@ -2758,7 +2820,10 @@ findvar( np = varname; while (vl->fmt != EOV) { if (vl->fmt != PADDING && STREQ(np, vl->text)) - return vl->code; + return (code) + ? vl->code + : (vl - varlist) + ; vl++; } return 0; @@ -2964,7 +3029,7 @@ tstflags( cb += strlen(cb); } else { *cb++ = ' '; - for (i = 0; i < 11; i++) { + for (i = 0; i < 13; i++) { if (val & 0x1) { sprintf(cb, "%s%s", sep, tstflagnames[i]); sep = ", "; @@ -3022,7 +3087,7 @@ cookedprint( startoutput(); while (nextvar(&length, &data, &name, &value)) { - varid = findvar(name, varlist); + varid = findvar(name, varlist, 0); if (varid == 0) { output_raw = '*'; } else { diff --git a/ntpq/ntpq.h b/ntpq/ntpq.h index 1bb102847f57a..0f29fd53c9d28 100644 --- a/ntpq/ntpq.h +++ b/ntpq/ntpq.h @@ -15,14 +15,17 @@ /* * Flags for forming descriptors. */ -#define OPT 0x80 /* this argument is optional, or'd with type */ +/* + * Flags for forming descriptors. + */ +#define OPT 0x80 /* this argument is optional, or'd with type */ -#define NO 0x0 -#define STR 0x1 /* string argument */ -#define UINT 0x2 /* unsigned integer */ -#define INT 0x3 /* signed integer */ -#define ADD 0x4 /* IP network address */ -#define IP_VERSION 0x5 /* IP address family */ +#define NO 0x0 +#define NTP_STR 0x1 /* string argument */ +#define NTP_UINT 0x2 /* unsigned integer */ +#define NTP_INT 0x3 /* signed integer */ +#define NTP_ADD 0x4 /* IP network address */ +#define IP_VERSION 0x5 /* IP version */ /* * Arguments are returned in a union @@ -87,4 +90,4 @@ extern int nextvar P((int *, char **, char **, char **)); extern int decodetime P((char *, l_fp *)); extern void printvars P((int, char *, int, int, FILE *)); extern int decodeint P((char *, long *)); -extern int findvar P((char *, struct ctl_var *)); +extern int findvar P((char *, struct ctl_var *, int code)); |