]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Many files:
authorHarlan Stenn <stenn@ntp.org>
Wed, 18 Aug 1999 05:34:12 +0000 (05:34 -0000)
committerHarlan Stenn <stenn@ntp.org>
Wed, 18 Aug 1999 05:34:12 +0000 (05:34 -0000)
  * configure.in:
  * dot.emacs:
  * ntpdate/Makefile.am:
  * ntpdate/ntpdate.h:
  * ntpdate/ntptime_config.c:
  * ntpdate/ntptimeset.c:
  From: Jeffrey Hutzelman <jhutz@cmu.edu>
ChangeLog, NEWS, ntp_stdlib.h:
  * include/ntp_stdlib.h: NeXT portability patch
  From: Jack Bryans <jbryans@csulb.edu>

bk: 37ba45d4N4mYrfBuHGP-b-6i-AeGGg

ChangeLog
NEWS
configure
configure.in
dot.emacs
include/ntp_stdlib.h
ntpdate/Makefile.am
ntpdate/Makefile.in
ntpdate/ntpdate.h
ntpdate/ntptime_config.c [new file with mode: 0644]
ntpdate/ntptimeset.c [new file with mode: 0644]

index 67f712bbf0be974dbab3fe893c878544c9e9612e..53ed62a69a973f2f80f345e7e986b3f8052e60f4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 1999-08-18  Harlan Stenn  <stenn@whimsy.udel.edu>
 
+       * include/ntp_stdlib.h: NeXT portability patch
+       From: Jack Bryans <jbryans@csulb.edu>
+
+       * configure.in:
+       * dot.emacs: (cleanup)
+       * ntpdate/Makefile.am:
+       * ntpdate/ntpdate.h:
+       * ntpdate/ntptime_config.c:
+       * ntpdate/ntptimeset.c:
+       ntptimeset patches.
+       From: Jeffrey Hutzelman <jhutz@cmu.edu>
+       
        * ntpd/refclock_parse.c (local_input): ts.l_ui -> ts.fp.l_ui
 
 1999-08-11  Harlan Stenn  <stenn@whimsy.udel.edu>
diff --git a/NEWS b/NEWS
index 67384f9f01e98b98489fa0a5f05e2141b1f7495a..99d7406e1c1dcd535cebd3073f5a1fae67f11603 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
+* NeXT portability
+* ntptimeset utility added
 * cygwin portability patches
 (4.0.96)
 * -lnsl, -lsocket, -lgen configuration patches
index 99ef7950f6fa06e12faa60c6635d10a981a5be89..311de8624693bdd5e6231d9e17898a378f785614 100755 (executable)
--- a/configure
+++ b/configure
@@ -6544,6 +6544,7 @@ EOF
 
     case "`basename $ac_cv_prog_CC`" in
      acc*) ;;
+     gcc*) ;;
      *) cat >> confdefs.h <<\EOF
 #define DECL_STDIO_0 1
 EOF
@@ -6649,7 +6650,7 @@ EOF
 esac
 
 echo $ac_n "checking if we should use a streams device for ifconfig""... $ac_c" 1>&6
-echo "configure:6653: checking if we should use a streams device for ifconfig" >&5
+echo "configure:6654: checking if we should use a streams device for ifconfig" >&5
 if eval "test \"\${ac_cv_var_use_streams_device_for_ifconfig+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -6659,7 +6660,7 @@ fi
 echo "$ac_t""$ac_cv_var_use_streams_device_for_ifconfig" 1>&6
 
 echo $ac_n "checking if we need extra room for SO_RCVBUF""... $ac_c" 1>&6
-echo "configure:6663: checking if we need extra room for SO_RCVBUF" >&5
+echo "configure:6664: checking if we need extra room for SO_RCVBUF" >&5
 if eval "test \"\${ac_cv_var_rcvbuf_slop+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -6681,7 +6682,7 @@ EOF
 esac
 
 echo $ac_n "checking if we will open the broadcast socket""... $ac_c" 1>&6
-echo "configure:6685: checking if we will open the broadcast socket" >&5
+echo "configure:6686: checking if we will open the broadcast socket" >&5
 if eval "test \"\${ac_cv_var_open_bcast_socket+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -6706,7 +6707,7 @@ EOF
 esac
 
 echo $ac_n "checking if we want the HPUX version of FindConfig()""... $ac_c" 1>&6
-echo "configure:6710: checking if we want the HPUX version of FindConfig()" >&5
+echo "configure:6711: checking if we want the HPUX version of FindConfig()" >&5
 if eval "test \"\${ac_cv_var_hpux_findconfig+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -6728,7 +6729,7 @@ EOF
 esac
 
 echo $ac_n "checking if process groups are set with -pid""... $ac_c" 1>&6
-echo "configure:6732: checking if process groups are set with -pid" >&5
+echo "configure:6733: checking if process groups are set with -pid" >&5
 if eval "test \"\${ac_cv_arg_setpgrp_negpid+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -6764,7 +6765,7 @@ EOF
 esac
 
 echo $ac_n "checking if we need a ctty for F_SETOWN""... $ac_c" 1>&6
-echo "configure:6768: checking if we need a ctty for F_SETOWN" >&5
+echo "configure:6769: checking if we need a ctty for F_SETOWN" >&5
 if eval "test \"\${ac_cv_func_ctty_for_f_setown+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -6794,7 +6795,7 @@ esac
 
 ntp_warning='GRONK'
 echo $ac_n "checking if we'll use clock_settime or settimeofday or stime""... $ac_c" 1>&6
-echo "configure:6798: checking if we'll use clock_settime or settimeofday or stime" >&5
+echo "configure:6799: checking if we'll use clock_settime or settimeofday or stime" >&5
 case "$ac_cv_func_clock_settime$ac_cv_func_settimeofday$ac_cv_func_stime" in
  yes*)
     ntp_warning=''
@@ -6823,7 +6824,7 @@ case "$ntp_warning" in
 esac
 
 echo $ac_n "checking if we have a losing syscall()""... $ac_c" 1>&6
-echo "configure:6827: checking if we have a losing syscall()" >&5
+echo "configure:6828: checking if we have a losing syscall()" >&5
 if eval "test \"\${ac_cv_var_syscall_bug+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -6846,7 +6847,7 @@ EOF
 esac
 
 echo $ac_n "checking for Streams/TLI""... $ac_c" 1>&6
-echo "configure:6850: checking for Streams/TLI" >&5
+echo "configure:6851: checking for Streams/TLI" >&5
 if eval "test \"\${ac_cv_var_streams_tli+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -6875,12 +6876,12 @@ EOF
 esac
 
 echo $ac_n "checking for SIGIO""... $ac_c" 1>&6
-echo "configure:6879: checking for SIGIO" >&5
+echo "configure:6880: checking for SIGIO" >&5
 if eval "test \"\${ac_cv_hdr_def_sigio+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 6884 "configure"
+#line 6885 "configure"
 #include "confdefs.h"
 #include <signal.h>
 #ifdef SIGIO
@@ -6903,7 +6904,7 @@ fi
 echo "$ac_t""$ac_cv_hdr_def_sigio" 1>&6
 
 echo $ac_n "checking if we want to use signalled IO""... $ac_c" 1>&6
-echo "configure:6907: checking if we want to use signalled IO" >&5
+echo "configure:6908: checking if we want to use signalled IO" >&5
 if eval "test \"\${ac_cv_var_signalled_io+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -6954,12 +6955,12 @@ EOF
 esac
 
 echo $ac_n "checking for SIGPOLL""... $ac_c" 1>&6
-echo "configure:6958: checking for SIGPOLL" >&5
+echo "configure:6959: checking for SIGPOLL" >&5
 if eval "test \"\${ac_cv_hdr_def_sigpoll+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 6963 "configure"
+#line 6964 "configure"
 #include "confdefs.h"
 #include <signal.h>
 #ifdef SIGPOLL
@@ -6982,12 +6983,12 @@ fi
 echo "$ac_t""$ac_cv_hdr_def_sigpoll" 1>&6
 
 echo $ac_n "checking for SIGSYS""... $ac_c" 1>&6
-echo "configure:6986: checking for SIGSYS" >&5
+echo "configure:6987: checking for SIGSYS" >&5
 if eval "test \"\${ac_cv_hdr_def_sigsys+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 6991 "configure"
+#line 6992 "configure"
 #include "confdefs.h"
 #include <signal.h>
 #ifdef SIGSYS
@@ -7010,7 +7011,7 @@ fi
 echo "$ac_t""$ac_cv_hdr_def_sigsys" 1>&6
 
 echo $ac_n "checking if we can use SIGPOLL for UDP I/O""... $ac_c" 1>&6
-echo "configure:7014: checking if we can use SIGPOLL for UDP I/O" >&5
+echo "configure:7015: checking if we can use SIGPOLL for UDP I/O" >&5
 if eval "test \"\${ac_cv_var_use_udp_sigpoll+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -7065,7 +7066,7 @@ EOF
 esac
 
 echo $ac_n "checking if we can use SIGPOLL for TTY I/O""... $ac_c" 1>&6
-echo "configure:7069: checking if we can use SIGPOLL for TTY I/O" >&5
+echo "configure:7070: checking if we can use SIGPOLL for TTY I/O" >&5
 if eval "test \"\${ac_cv_var_use_tty_sigpoll+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -7120,7 +7121,7 @@ EOF
 esac
 
 echo $ac_n "checking if nlist() values might require extra indirection""... $ac_c" 1>&6
-echo "configure:7124: checking if nlist() values might require extra indirection" >&5
+echo "configure:7125: checking if nlist() values might require extra indirection" >&5
 if eval "test \"\${ac_cv_var_nlist_extra_indirection+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -7142,7 +7143,7 @@ EOF
 esac
 
 echo $ac_n "checking for a minimum recommended value of tickadj""... $ac_c" 1>&6
-echo "configure:7146: checking for a minimum recommended value of tickadj" >&5
+echo "configure:7147: checking for a minimum recommended value of tickadj" >&5
 if eval "test \"\${ac_cv_var_min_rec_tickadj+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -7165,7 +7166,7 @@ EOF
 esac
 
 echo $ac_n "checking if the TTY code permits PARENB and IGNPAR""... $ac_c" 1>&6
-echo "configure:7169: checking if the TTY code permits PARENB and IGNPAR" >&5
+echo "configure:7170: checking if the TTY code permits PARENB and IGNPAR" >&5
 if eval "test \"\${ac_cv_var_no_parenb_ignpar+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -7190,7 +7191,7 @@ EOF
 esac
 
 echo $ac_n "checking if we're including debugging code""... $ac_c" 1>&6
-echo "configure:7194: checking if we're including debugging code" >&5
+echo "configure:7195: checking if we're including debugging code" >&5
 # Check whether --enable-debugging or --disable-debugging was given.
 if test "${enable_debugging+set}" = set; then
   enableval="$enable_debugging"
@@ -7208,7 +7209,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking for a the number of minutes in a DST adjustment""... $ac_c" 1>&6
-echo "configure:7212: checking for a the number of minutes in a DST adjustment" >&5
+echo "configure:7213: checking for a the number of minutes in a DST adjustment" >&5
 # Check whether --enable-dst_minutes or --disable-dst_minutes was given.
 if test "${enable_dst_minutes+set}" = set; then
   enableval="$enable_dst_minutes"
@@ -7224,7 +7225,7 @@ EOF
 echo "$ac_t""$ans" 1>&6
 
 echo $ac_n "checking if we have the tty_clk line discipline/streams module""... $ac_c" 1>&6
-echo "configure:7228: checking if we have the tty_clk line discipline/streams module" >&5
+echo "configure:7229: checking if we have the tty_clk line discipline/streams module" >&5
 if eval "test \"\${ac_cv_var_tty_clk+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -7240,7 +7241,7 @@ EOF
 esac
 
 echo $ac_n "checking for the ppsclock streams module""... $ac_c" 1>&6
-echo "configure:7244: checking for the ppsclock streams module" >&5
+echo "configure:7245: checking for the ppsclock streams module" >&5
 if eval "test \"\${ac_cv_var_ppsclock+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -7256,7 +7257,7 @@ EOF
 esac
 
 echo $ac_n "checking for kernel multicast support""... $ac_c" 1>&6
-echo "configure:7260: checking for kernel multicast support" >&5
+echo "configure:7261: checking for kernel multicast support" >&5
 if eval "test \"\${ac_cv_var_mcast+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -7264,7 +7265,7 @@ else
   case "$target" in
    i386-sequent-sysv4) ;;
    *) cat > conftest.$ac_ext <<EOF
-#line 7268 "configure"
+#line 7269 "configure"
 #include "confdefs.h"
 #include <netinet/in.h>
 #ifdef IP_ADD_MEMBERSHIP
@@ -7291,7 +7292,7 @@ EOF
 esac
 
 echo $ac_n "checking availability of ntp_{adj,get}time()""... $ac_c" 1>&6
-echo "configure:7295: checking availability of ntp_{adj,get}time()" >&5
+echo "configure:7296: checking availability of ntp_{adj,get}time()" >&5
 if eval "test \"\${ac_cv_var_ntp_syscalls+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -7305,7 +7306,7 @@ else
         ac_cv_var_ntp_syscalls=libc
         ;;
       *) cat > conftest.$ac_ext <<EOF
-#line 7309 "configure"
+#line 7310 "configure"
 #include "confdefs.h"
 #include <sys/syscall.h>
 #if defined(SYS_ntp_gettime) && defined(SYS_ntp_adjtime)
@@ -7345,12 +7346,12 @@ EOF
 esac
 
 echo $ac_n "checking if sys/timex.h has STA_FLL""... $ac_c" 1>&6
-echo "configure:7349: checking if sys/timex.h has STA_FLL" >&5
+echo "configure:7350: checking if sys/timex.h has STA_FLL" >&5
 if eval "test \"\${ac_cv_var_sta_fll+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 7354 "configure"
+#line 7355 "configure"
 #include "confdefs.h"
 #include <sys/timex.h>
 #ifdef STA_FLL
@@ -7373,7 +7374,7 @@ fi
 echo "$ac_t""$ac_cv_var_sta_fll" 1>&6
 
 echo $ac_n "checking if we have kernel PLL support""... $ac_c" 1>&6
-echo "configure:7377: checking if we have kernel PLL support" >&5
+echo "configure:7378: checking if we have kernel PLL support" >&5
 if eval "test \"\${ac_cv_var_kernel_pll+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -7397,7 +7398,7 @@ EOF
 esac
 
 echo $ac_n "checking if SIOCGIFCONF returns buffer size in the buffer""... $ac_c" 1>&6
-echo "configure:7401: checking if SIOCGIFCONF returns buffer size in the buffer" >&5
+echo "configure:7402: checking if SIOCGIFCONF returns buffer size in the buffer" >&5
 if eval "test \"\${ac_cv_var_size_returned_in_buffer+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -7426,7 +7427,7 @@ esac
 
 
 echo $ac_n "checking if we want to use MD5 authentication""... $ac_c" 1>&6
-echo "configure:7430: checking if we want to use MD5 authentication" >&5
+echo "configure:7431: checking if we want to use MD5 authentication" >&5
 if eval "test \"\${ac_cv_var_use_md5+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -7451,10 +7452,10 @@ esac
 
 # Check for ioctls TIOCGPPSEV
 echo $ac_n "checking ioctl TIOCGPPSEV""... $ac_c" 1>&6
-echo "configure:7455: checking ioctl TIOCGPPSEV" >&5
+echo "configure:7456: checking ioctl TIOCGPPSEV" >&5
 if test "$ac_cv_header_termios_h" = "yes"; then
     cat > conftest.$ac_ext <<EOF
-#line 7458 "configure"
+#line 7459 "configure"
 #include "confdefs.h"
 #include <termios.h>
 #ifdef TIOCGPPSEV
@@ -7487,10 +7488,10 @@ echo "$ac_t""$ntp_ok" 1>&6
 
 # Check for ioctls TIOCSPPS
 echo $ac_n "checking ioctl TIOCSPPS""... $ac_c" 1>&6
-echo "configure:7491: checking ioctl TIOCSPPS" >&5
+echo "configure:7492: checking ioctl TIOCSPPS" >&5
 if test "$ac_cv_header_termios_h" = "yes"; then
     cat > conftest.$ac_ext <<EOF
-#line 7494 "configure"
+#line 7495 "configure"
 #include "confdefs.h"
 #include <termios.h>
 #ifdef TIOCSPPS
@@ -7522,10 +7523,10 @@ echo "$ac_t""$ntp_ok" 1>&6
 
 # Check for ioctls CIOGETEV
 echo $ac_n "checking ioctl CIOGETEV""... $ac_c" 1>&6
-echo "configure:7526: checking ioctl CIOGETEV" >&5
+echo "configure:7527: checking ioctl CIOGETEV" >&5
 if test "$ac_cv_header_sys_ppsclock_h" = "yes"; then
     cat > conftest.$ac_ext <<EOF
-#line 7529 "configure"
+#line 7530 "configure"
 #include "confdefs.h"
 #include <sys/ppsclock.h>
 #ifdef CIOGETEV
@@ -7582,17 +7583,17 @@ esac
 # Check for ioctls TIOCGSERIAL, TIOCSSERIAL, ASYNC_PPS_CD_POS, ASYNC_PPS_CD_NEG
 ac_safe=`echo "linux/serial.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for linux/serial.h""... $ac_c" 1>&6
-echo "configure:7586: checking for linux/serial.h" >&5
+echo "configure:7587: checking for linux/serial.h" >&5
 if eval "test \"\${ac_cv_header_$ac_safe+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 7591 "configure"
+#line 7592 "configure"
 #include "confdefs.h"
 #include <linux/serial.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:7596: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:7597: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -7614,11 +7615,11 @@ else
 fi
 
 echo $ac_n "checking ioctl TIOCGSERIAL""... $ac_c" 1>&6
-echo "configure:7618: checking ioctl TIOCGSERIAL" >&5
+echo "configure:7619: checking ioctl TIOCGSERIAL" >&5
 case "$ac_cv_header_sys_ppsclock_h$ac_cv_header_linux_serial_h" in
   yesyes)
     cat > conftest.$ac_ext <<EOF
-#line 7622 "configure"
+#line 7623 "configure"
 #include "confdefs.h"
 #include <sys/time.h>
 typedef int u_int;
@@ -7665,7 +7666,7 @@ ntp_refclock=no
 
 # HPUX only, and by explicit request
 echo $ac_n "checking Datum/Bancomm bc635/VME interface""... $ac_c" 1>&6
-echo "configure:7669: checking Datum/Bancomm bc635/VME interface" >&5
+echo "configure:7670: checking Datum/Bancomm bc635/VME interface" >&5
 # Check whether --enable-BANCOMM or --disable-BANCOMM was given.
 if test "${enable_BANCOMM+set}" = set; then
   enableval="$enable_BANCOMM"
@@ -7689,7 +7690,7 @@ esac
 
 #HPUX only, and only by explicit request
 echo $ac_n "checking TrueTime GPS receiver/VME interface""... $ac_c" 1>&6
-echo "configure:7693: checking TrueTime GPS receiver/VME interface" >&5
+echo "configure:7694: checking TrueTime GPS receiver/VME interface" >&5
 # Check whether --enable-GPSVME or --disable-GPSVME was given.
 if test "${enable_GPSVME+set}" = set; then
   enableval="$enable_GPSVME"
@@ -7712,7 +7713,7 @@ case "$ntp_ok$target" in
 esac
 
 echo $ac_n "checking for PCL720 clock support""... $ac_c" 1>&6
-echo "configure:7716: checking for PCL720 clock support" >&5
+echo "configure:7717: checking for PCL720 clock support" >&5
 case "$ac_cv_header_machine_inline_h$ac_cv_header_sys_pcl720_h$ac_cv_header_sys_i8253_h" in
  yesyesyes)
     cat >> confdefs.h <<\EOF
@@ -7728,7 +7729,7 @@ esac
 echo "$ac_t""$ans" 1>&6
 
 echo $ac_n "checking for SHM clock attached thru shared memory""... $ac_c" 1>&6
-echo "configure:7732: checking for SHM clock attached thru shared memory" >&5
+echo "configure:7733: checking for SHM clock attached thru shared memory" >&5
 # Check whether --enable-SHM or --disable-SHM was given.
 if test "${enable_SHM+set}" = set; then
   enableval="$enable_SHM"
@@ -7747,7 +7748,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking for ONCORE Motorola VP/UT Oncore GPS""... $ac_c" 1>&6
-echo "configure:7751: checking for ONCORE Motorola VP/UT Oncore GPS" >&5
+echo "configure:7752: checking for ONCORE Motorola VP/UT Oncore GPS" >&5
 # Check whether --enable-ONCORE or --disable-ONCORE was given.
 if test "${enable_ONCORE+set}" = set; then
   enableval="$enable_ONCORE"
@@ -7769,7 +7770,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking for default inclusion of all suitable non-PARSE clocks""... $ac_c" 1>&6
-echo "configure:7773: checking for default inclusion of all suitable non-PARSE clocks" >&5
+echo "configure:7774: checking for default inclusion of all suitable non-PARSE clocks" >&5
 # Check whether --enable-all-clocks or --disable-all-clocks was given.
 if test "${enable_all_clocks+set}" = set; then
   enableval="$enable_all_clocks"
@@ -7781,7 +7782,7 @@ fi
 echo "$ac_t""$ntp_eac" 1>&6
 
 echo $ac_n "checking if we have support for PARSE clocks""... $ac_c" 1>&6
-echo "configure:7785: checking if we have support for PARSE clocks" >&5
+echo "configure:7786: checking if we have support for PARSE clocks" >&5
 case "$ac_cv_header_termio_h$ac_cv_header_termios_h" in
  *yes*)
     ntp_canparse=yes
@@ -7793,14 +7794,14 @@ echo "$ac_t""$ntp_canparse" 1>&6
 
 # Requires modem control
 echo $ac_n "checking ACTS modem service""... $ac_c" 1>&6
-echo "configure:7797: checking ACTS modem service" >&5
+echo "configure:7798: checking ACTS modem service" >&5
 # Check whether --enable-ACTS or --disable-ACTS was given.
 if test "${enable_ACTS+set}" = set; then
   enableval="$enable_ACTS"
   ntp_ok=$enableval
 else
   cat > conftest.$ac_ext <<EOF
-#line 7804 "configure"
+#line 7805 "configure"
 #include "confdefs.h"
 #include <termios.h>
 #ifdef HAVE_SYS_IOCTL_H
@@ -7833,7 +7834,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking Arbiter 1088A/B GPS receiver""... $ac_c" 1>&6
-echo "configure:7837: checking Arbiter 1088A/B GPS receiver" >&5
+echo "configure:7838: checking Arbiter 1088A/B GPS receiver" >&5
 # Check whether --enable-ARBITER or --disable-ARBITER was given.
 if test "${enable_ARBITER+set}" = set; then
   enableval="$enable_ARBITER"
@@ -7852,7 +7853,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking Arcron MSF receiver""... $ac_c" 1>&6
-echo "configure:7856: checking Arcron MSF receiver" >&5
+echo "configure:7857: checking Arcron MSF receiver" >&5
 # Check whether --enable-ARCRON_MSF or --disable-ARCRON_MSF was given.
 if test "${enable_ARCRON_MSF+set}" = set; then
   enableval="$enable_ARCRON_MSF"
@@ -7871,7 +7872,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking Austron 2200A/2201A GPS receiver""... $ac_c" 1>&6
-echo "configure:7875: checking Austron 2200A/2201A GPS receiver" >&5
+echo "configure:7876: checking Austron 2200A/2201A GPS receiver" >&5
 # Check whether --enable-AS2201 or --disable-AS2201 was given.
 if test "${enable_AS2201+set}" = set; then
   enableval="$enable_AS2201"
@@ -7890,7 +7891,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking PPS interface""... $ac_c" 1>&6
-echo "configure:7894: checking PPS interface" >&5
+echo "configure:7895: checking PPS interface" >&5
 # Check whether --enable-ATOM or --disable-ATOM was given.
 if test "${enable_ATOM+set}" = set; then
   enableval="$enable_ATOM"
@@ -7909,7 +7910,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking CHU modem/decoder""... $ac_c" 1>&6
-echo "configure:7913: checking CHU modem/decoder" >&5
+echo "configure:7914: checking CHU modem/decoder" >&5
 # Check whether --enable-CHU or --disable-CHU was given.
 if test "${enable_CHU+set}" = set; then
   enableval="$enable_CHU"
@@ -7929,7 +7930,7 @@ echo "$ac_t""$ntp_ok" 1>&6
 ac_refclock_chu=$ntp_ok
 
 echo $ac_n "checking CHU audio/decoder""... $ac_c" 1>&6
-echo "configure:7933: checking CHU audio/decoder" >&5
+echo "configure:7934: checking CHU audio/decoder" >&5
 # Check whether --enable-AUDIO-CHU or --disable-AUDIO-CHU was given.
 if test "${enable_AUDIO_CHU+set}" = set; then
   enableval="$enable_AUDIO_CHU"
@@ -7953,7 +7954,7 @@ esac
 
 # Not under HP-UX
 echo $ac_n "checking Datum Programmable Time System""... $ac_c" 1>&6
-echo "configure:7957: checking Datum Programmable Time System" >&5
+echo "configure:7958: checking Datum Programmable Time System" >&5
 # Check whether --enable-DATUM or --disable-DATUM was given.
 if test "${enable_DATUM+set}" = set; then
   enableval="$enable_DATUM"
@@ -7979,14 +7980,14 @@ echo "$ac_t""$ntp_ok" 1>&6
 
 # Requires modem control
 echo $ac_n "checking Heath GC-1000 WWV/WWVH receiver""... $ac_c" 1>&6
-echo "configure:7983: checking Heath GC-1000 WWV/WWVH receiver" >&5
+echo "configure:7984: checking Heath GC-1000 WWV/WWVH receiver" >&5
 # Check whether --enable-HEATH or --disable-HEATH was given.
 if test "${enable_HEATH+set}" = set; then
   enableval="$enable_HEATH"
   ntp_ok=$enableval
 else
   cat > conftest.$ac_ext <<EOF
-#line 7990 "configure"
+#line 7991 "configure"
 #include "confdefs.h"
 #include <termios.h>
 #ifdef HAVE_SYS_IOCTL_H
@@ -8019,7 +8020,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking HP 58503A GPS receiver""... $ac_c" 1>&6
-echo "configure:8023: checking HP 58503A GPS receiver" >&5
+echo "configure:8024: checking HP 58503A GPS receiver" >&5
 # Check whether --enable-HPGPS or --disable-HPGPS was given.
 if test "${enable_HPGPS+set}" = set; then
   enableval="$enable_HPGPS"
@@ -8038,7 +8039,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking Sun IRIG audio decoder""... $ac_c" 1>&6
-echo "configure:8042: checking Sun IRIG audio decoder" >&5
+echo "configure:8043: checking Sun IRIG audio decoder" >&5
 # Check whether --enable-IRIG or --disable-IRIG was given.
 if test "${enable_IRIG+set}" = set; then
   enableval="$enable_IRIG"
@@ -8066,7 +8067,7 @@ case "$ntp_ok$ac_cv_header_sun_audioio_h$ac_cv_header_sys_audioio_h" in
 esac
 
 echo $ac_n "checking Leitch CSD 5300 Master Clock System Driver""... $ac_c" 1>&6
-echo "configure:8070: checking Leitch CSD 5300 Master Clock System Driver" >&5
+echo "configure:8071: checking Leitch CSD 5300 Master Clock System Driver" >&5
 # Check whether --enable-LEITCH or --disable-LEITCH was given.
 if test "${enable_LEITCH+set}" = set; then
   enableval="$enable_LEITCH"
@@ -8085,7 +8086,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking local clock reference""... $ac_c" 1>&6
-echo "configure:8089: checking local clock reference" >&5
+echo "configure:8090: checking local clock reference" >&5
 # Check whether --enable-LOCAL-CLOCK or --disable-LOCAL-CLOCK was given.
 if test "${enable_LOCAL_CLOCK+set}" = set; then
   enableval="$enable_LOCAL_CLOCK"
@@ -8104,7 +8105,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking EES M201 MSF receiver""... $ac_c" 1>&6
-echo "configure:8108: checking EES M201 MSF receiver" >&5
+echo "configure:8109: checking EES M201 MSF receiver" >&5
 # Check whether --enable-MSFEES or --disable-MSFEES was given.
 if test "${enable_MSFEES+set}" = set; then
   enableval="$enable_MSFEES"
@@ -8124,7 +8125,7 @@ echo "$ac_t""$ntp_ok" 1>&6
 
 # Not Ultrix
 echo $ac_n "checking Magnavox MX4200 GPS receiver""... $ac_c" 1>&6
-echo "configure:8128: checking Magnavox MX4200 GPS receiver" >&5
+echo "configure:8129: checking Magnavox MX4200 GPS receiver" >&5
 # Check whether --enable-MX4200 or --disable-MX4200 was given.
 if test "${enable_MX4200+set}" = set; then
   enableval="$enable_MX4200"
@@ -8151,7 +8152,7 @@ case "$ntp_ok$target" in
 esac
 
 echo $ac_n "checking NMEA GPS receiver""... $ac_c" 1>&6
-echo "configure:8155: checking NMEA GPS receiver" >&5
+echo "configure:8156: checking NMEA GPS receiver" >&5
 # Check whether --enable-NMEA or --disable-NMEA was given.
 if test "${enable_NMEA+set}" = set; then
   enableval="$enable_NMEA"
@@ -8170,7 +8171,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking for Palisade clock""... $ac_c" 1>&6
-echo "configure:8174: checking for Palisade clock" >&5
+echo "configure:8175: checking for Palisade clock" >&5
 # Check whether --enable-PALISADE or --disable-PALISADE was given.
 if test "${enable_PALISADE+set}" = set; then
   enableval="$enable_PALISADE"
@@ -8196,7 +8197,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking PST/Traconex 1020 WWV/WWVH receiver""... $ac_c" 1>&6
-echo "configure:8200: checking PST/Traconex 1020 WWV/WWVH receiver" >&5
+echo "configure:8201: checking PST/Traconex 1020 WWV/WWVH receiver" >&5
 # Check whether --enable-PST or --disable-PST was given.
 if test "${enable_PST+set}" = set; then
   enableval="$enable_PST"
@@ -8216,7 +8217,7 @@ echo "$ac_t""$ntp_ok" 1>&6
 
 # Not Ultrix
 echo $ac_n "checking Rockwell Jupiter GPS receiver""... $ac_c" 1>&6
-echo "configure:8220: checking Rockwell Jupiter GPS receiver" >&5
+echo "configure:8221: checking Rockwell Jupiter GPS receiver" >&5
 # Check whether --enable-JUPITER or --disable-JUPITER was given.
 if test "${enable_JUPITER+set}" = set; then
   enableval="$enable_JUPITER"
@@ -8244,14 +8245,14 @@ esac
 
 # Requires modem control
 echo $ac_n "checking PTB modem service""... $ac_c" 1>&6
-echo "configure:8248: checking PTB modem service" >&5
+echo "configure:8249: checking PTB modem service" >&5
 # Check whether --enable-PTBACTS or --disable-PTBACTS was given.
 if test "${enable_PTBACTS+set}" = set; then
   enableval="$enable_PTBACTS"
   ntp_ok=$enableval
 else
   cat > conftest.$ac_ext <<EOF
-#line 8255 "configure"
+#line 8256 "configure"
 #include "confdefs.h"
 #include <termios.h>
 #ifdef HAVE_SYS_IOCTL_H
@@ -8284,7 +8285,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking KSI/Odetics TPRO/S GPS receiver/IRIG interface""... $ac_c" 1>&6
-echo "configure:8288: checking KSI/Odetics TPRO/S GPS receiver/IRIG interface" >&5
+echo "configure:8289: checking KSI/Odetics TPRO/S GPS receiver/IRIG interface" >&5
 # Check whether --enable-TPRO or --disable-TPRO was given.
 if test "${enable_TPRO+set}" = set; then
   enableval="$enable_TPRO"
@@ -8312,7 +8313,7 @@ case "$ntp_ok$ac_cv_header_sys_tpro" in
 esac
 
 echo $ac_n "checking TRAK 8810 GPS receiver""... $ac_c" 1>&6
-echo "configure:8316: checking TRAK 8810 GPS receiver" >&5
+echo "configure:8317: checking TRAK 8810 GPS receiver" >&5
 # Check whether --enable-TRAK or --disable-TRAK was given.
 if test "${enable_TRAK+set}" = set; then
   enableval="$enable_TRAK"
@@ -8331,7 +8332,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking Chrono-log K-series WWVB receiver""... $ac_c" 1>&6
-echo "configure:8335: checking Chrono-log K-series WWVB receiver" >&5
+echo "configure:8336: checking Chrono-log K-series WWVB receiver" >&5
 # Check whether --enable-CHRONOLOG or --disable-CHRONOLOG was given.
 if test "${enable_CHRONOLOG+set}" = set; then
   enableval="$enable_CHRONOLOG"
@@ -8350,7 +8351,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking Dumb generic hh:mm:ss local clock""... $ac_c" 1>&6
-echo "configure:8354: checking Dumb generic hh:mm:ss local clock" >&5
+echo "configure:8355: checking Dumb generic hh:mm:ss local clock" >&5
 # Check whether --enable-DUMBCLOCK or --disable-DUMBCLOCK was given.
 if test "${enable_DUMBCLOCK+set}" = set; then
   enableval="$enable_DUMBCLOCK"
@@ -8370,7 +8371,7 @@ echo "$ac_t""$ntp_ok" 1>&6
 
 # Not on a vax-dec-bsd
 echo $ac_n "checking Kinemetrics/TrueTime receivers""... $ac_c" 1>&6
-echo "configure:8374: checking Kinemetrics/TrueTime receivers" >&5
+echo "configure:8375: checking Kinemetrics/TrueTime receivers" >&5
 # Check whether --enable-TRUETIME or --disable-TRUETIME was given.
 if test "${enable_TRUETIME+set}" = set; then
   enableval="$enable_TRUETIME"
@@ -8399,7 +8400,7 @@ case "$ntp_ok$target" in
 esac
 
 echo $ac_n "checking Spectracom 8170/Netclock/2 WWVB receiver""... $ac_c" 1>&6
-echo "configure:8403: checking Spectracom 8170/Netclock/2 WWVB receiver" >&5
+echo "configure:8404: checking Spectracom 8170/Netclock/2 WWVB receiver" >&5
 # Check whether --enable-WWVB or --disable-WWVB was given.
 if test "${enable_WWVB+set}" = set; then
   enableval="$enable_WWVB"
@@ -8419,14 +8420,14 @@ echo "$ac_t""$ntp_ok" 1>&6
 
 # Requires modem control
 echo $ac_n "checking USNO modem service""... $ac_c" 1>&6
-echo "configure:8423: checking USNO modem service" >&5
+echo "configure:8424: checking USNO modem service" >&5
 # Check whether --enable-USNO or --disable-USNO was given.
 if test "${enable_USNO+set}" = set; then
   enableval="$enable_USNO"
   ntp_ok=$enableval
 else
   cat > conftest.$ac_ext <<EOF
-#line 8430 "configure"
+#line 8431 "configure"
 #include "confdefs.h"
 #include <termios.h>
 #ifdef HAVE_SYS_IOCTL_H
@@ -8459,7 +8460,7 @@ fi
 echo "$ac_t""$ntp_ok" 1>&6
 
 echo $ac_n "checking for default inclusion of all suitable PARSE clocks""... $ac_c" 1>&6
-echo "configure:8463: checking for default inclusion of all suitable PARSE clocks" >&5
+echo "configure:8464: checking for default inclusion of all suitable PARSE clocks" >&5
 # Check whether --enable-parse-clocks or --disable-parse-clocks was given.
 if test "${enable_parse_clocks+set}" = set; then
   enableval="$enable_parse_clocks"
@@ -8489,7 +8490,7 @@ ntp_parseutil=no
 ntp_rawdcf=no
 
 echo $ac_n "checking Diem Computime Radio Clock""... $ac_c" 1>&6
-echo "configure:8493: checking Diem Computime Radio Clock" >&5
+echo "configure:8494: checking Diem Computime Radio Clock" >&5
 # Check whether --enable-COMPUTIME or --disable-COMPUTIME was given.
 if test "${enable_COMPUTIME+set}" = set; then
   enableval="$enable_COMPUTIME"
@@ -8514,7 +8515,7 @@ case "$ntp_ok$ntp_canparse" in
 esac
 
 echo $ac_n "checking ELV/DCF7000 clock""... $ac_c" 1>&6
-echo "configure:8518: checking ELV/DCF7000 clock" >&5
+echo "configure:8519: checking ELV/DCF7000 clock" >&5
 # Check whether --enable-DCF7000 or --disable-DCF7000 was given.
 if test "${enable_DCF7000+set}" = set; then
   enableval="$enable_DCF7000"
@@ -8539,7 +8540,7 @@ case "$ntp_ok$ntp_canparse" in
 esac
 
 echo $ac_n "checking HOPF 6021 clock""... $ac_c" 1>&6
-echo "configure:8543: checking HOPF 6021 clock" >&5
+echo "configure:8544: checking HOPF 6021 clock" >&5
 # Check whether --enable-HOPF6021 or --disable-HOPF6021 was given.
 if test "${enable_HOPF6021+set}" = set; then
   enableval="$enable_HOPF6021"
@@ -8564,7 +8565,7 @@ case "$ntp_ok$ntp_canparse" in
 esac
 
 echo $ac_n "checking Meinberg clocks""... $ac_c" 1>&6
-echo "configure:8568: checking Meinberg clocks" >&5
+echo "configure:8569: checking Meinberg clocks" >&5
 # Check whether --enable-MEINBERG or --disable-MEINBERG was given.
 if test "${enable_MEINBERG+set}" = set; then
   enableval="$enable_MEINBERG"
@@ -8589,7 +8590,7 @@ case "$ntp_ok$ntp_canparse" in
 esac
 
 echo $ac_n "checking DCF77 raw time code""... $ac_c" 1>&6
-echo "configure:8593: checking DCF77 raw time code" >&5
+echo "configure:8594: checking DCF77 raw time code" >&5
 # Check whether --enable-RAWDCF or --disable-RAWDCF was given.
 if test "${enable_RAWDCF+set}" = set; then
   enableval="$enable_RAWDCF"
@@ -8618,7 +8619,7 @@ esac
 case "$ntp_rawdcf" in
  yes)
     echo $ac_n "checking if we must enable parity for RAWDCF""... $ac_c" 1>&6
-echo "configure:8622: checking if we must enable parity for RAWDCF" >&5
+echo "configure:8623: checking if we must enable parity for RAWDCF" >&5
 if eval "test \"\${ac_cv_var_rawdcf_parity+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -8646,7 +8647,7 @@ EOF
 esac
 
 echo $ac_n "checking RCC 8000 clock""... $ac_c" 1>&6
-echo "configure:8650: checking RCC 8000 clock" >&5
+echo "configure:8651: checking RCC 8000 clock" >&5
 # Check whether --enable-RCC8000 or --disable-RCC8000 was given.
 if test "${enable_RCC8000+set}" = set; then
   enableval="$enable_RCC8000"
@@ -8671,7 +8672,7 @@ case "$ntp_ok$ntp_canparse" in
 esac
 
 echo $ac_n "checking Schmid DCF77 clock""... $ac_c" 1>&6
-echo "configure:8675: checking Schmid DCF77 clock" >&5
+echo "configure:8676: checking Schmid DCF77 clock" >&5
 # Check whether --enable-SCHMID or --disable-SCHMID was given.
 if test "${enable_SCHMID+set}" = set; then
   enableval="$enable_SCHMID"
@@ -8696,7 +8697,7 @@ case "$ntp_ok$ntp_canparse" in
 esac
 
 echo $ac_n "checking Trimble GPS receiver/TAIP protocol""... $ac_c" 1>&6
-echo "configure:8700: checking Trimble GPS receiver/TAIP protocol" >&5
+echo "configure:8701: checking Trimble GPS receiver/TAIP protocol" >&5
 # Check whether --enable-TRIMTAIP or --disable-TRIMTAIP was given.
 if test "${enable_TRIMTAIP+set}" = set; then
   enableval="$enable_TRIMTAIP"
@@ -8721,7 +8722,7 @@ case "$ntp_ok$ntp_canparse" in
 esac
 
 echo $ac_n "checking Trimble GPS receiver/TSIP protocol""... $ac_c" 1>&6
-echo "configure:8725: checking Trimble GPS receiver/TSIP protocol" >&5
+echo "configure:8726: checking Trimble GPS receiver/TSIP protocol" >&5
 # Check whether --enable-TRIMTSIP or --disable-TRIMTSIP was given.
 if test "${enable_TRIMTSIP+set}" = set; then
   enableval="$enable_TRIMTSIP"
@@ -8746,7 +8747,7 @@ case "$ntp_ok$ntp_canparse" in
 esac
 
 echo $ac_n "checking WHARTON 400A Series clock""... $ac_c" 1>&6
-echo "configure:8750: checking WHARTON 400A Series clock" >&5
+echo "configure:8751: checking WHARTON 400A Series clock" >&5
 # Check whether --enable-WHARTON or --disable-WHARTON was given.
 if test "${enable_WHARTON+set}" = set; then
   enableval="$enable_WHARTON"
@@ -8771,7 +8772,7 @@ case "$ntp_ok$ntp_canparse" in
 esac
 
 echo $ac_n "checking VARITEXT clock""... $ac_c" 1>&6
-echo "configure:8775: checking VARITEXT clock" >&5
+echo "configure:8776: checking VARITEXT clock" >&5
 # Check whether --enable-VARITEXT or --disable-VARITEXT was given.
 if test "${enable_VARITEXT+set}" = set; then
   enableval="$enable_VARITEXT"
@@ -8799,7 +8800,7 @@ esac
 
 
 echo $ac_n "checking if we need to make and use the parse libraries""... $ac_c" 1>&6
-echo "configure:8803: checking if we need to make and use the parse libraries" >&5
+echo "configure:8804: checking if we need to make and use the parse libraries" >&5
 ans=no
 case "$ntp_libparse" in
  yes)
@@ -8827,7 +8828,7 @@ echo "$ac_t""$ans" 1>&6
 
 
 echo $ac_n "checking if we need to make and use the RSAREF library""... $ac_c" 1>&6
-echo "configure:8831: checking if we need to make and use the RSAREF library" >&5
+echo "configure:8832: checking if we need to make and use the RSAREF library" >&5
 ans=no
 if test -f $srcdir/rsaref2/source/rsa.c
 then
@@ -8845,7 +8846,7 @@ echo "$ac_t""$ans" 1>&6
 
 
 echo $ac_n "checking if we can make dcf parse utilities""... $ac_c" 1>&6
-echo "configure:8849: checking if we can make dcf parse utilities" >&5
+echo "configure:8850: checking if we can make dcf parse utilities" >&5
 ans=no
 if test "$ntp_parseutil" = "yes"; then
     case "$target" in
@@ -8860,7 +8861,7 @@ echo "$ac_t""$ans" 1>&6
 
 
 echo $ac_n "checking if we can build kernel streams modules for parse""... $ac_c" 1>&6
-echo "configure:8864: checking if we can build kernel streams modules for parse" >&5
+echo "configure:8865: checking if we can build kernel streams modules for parse" >&5
 ans=no
 if test "$ntp_parseutil$ac_cv_header_sys_stropts_h" = "yesyes"; then
     case "$target" in
@@ -8885,7 +8886,7 @@ fi
 echo "$ac_t""$ans" 1>&6
 
 echo $ac_n "checking if we need basic refclock support""... $ac_c" 1>&6
-echo "configure:8889: checking if we need basic refclock support" >&5
+echo "configure:8890: checking if we need basic refclock support" >&5
 if test "$ntp_refclock" = "yes"; then
     cat >> confdefs.h <<\EOF
 #define REFCLOCK 1
@@ -8897,7 +8898,7 @@ echo "$ac_t""$ntp_refclock" 1>&6
                        
 
 echo $ac_n "checking if we want HP-UX adjtimed support""... $ac_c" 1>&6
-echo "configure:8901: checking if we want HP-UX adjtimed support" >&5
+echo "configure:8902: checking if we want HP-UX adjtimed support" >&5
 case "$target" in
  *-*-hpux[56789]*)
     ans=yes
@@ -8915,7 +8916,7 @@ fi
 echo "$ac_t""$ans" 1>&6
 
 echo $ac_n "checking if we can read kmem""... $ac_c" 1>&6
-echo "configure:8919: checking if we can read kmem" >&5
+echo "configure:8920: checking if we can read kmem" >&5
 if eval "test \"\${ac_cv_var_can_kmem+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -8968,7 +8969,7 @@ EOF
 esac
 
 echo $ac_n "checking if adjtime is accurate""... $ac_c" 1>&6
-echo "configure:8972: checking if adjtime is accurate" >&5
+echo "configure:8973: checking if adjtime is accurate" >&5
 if eval "test \"\${ac_cv_var_adjtime_is_accurate+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9020,7 +9021,7 @@ EOF
 esac
 
 echo $ac_n "checking the name of 'tick' in the kernel""... $ac_c" 1>&6
-echo "configure:9024: checking the name of 'tick' in the kernel" >&5
+echo "configure:9025: checking the name of 'tick' in the kernel" >&5
 if eval "test \"\${ac_cv_var_nlist_tick+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9064,7 +9065,7 @@ EOF
 esac
 #
 echo $ac_n "checking for the units of 'tick'""... $ac_c" 1>&6
-echo "configure:9068: checking for the units of 'tick'" >&5
+echo "configure:9069: checking for the units of 'tick'" >&5
 if eval "test \"\${ac_cv_var_tick_nano+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9088,7 +9089,7 @@ EOF
 esac
 #
 echo $ac_n "checking the name of 'tickadj' in the kernel""... $ac_c" 1>&6
-echo "configure:9092: checking the name of 'tickadj' in the kernel" >&5
+echo "configure:9093: checking the name of 'tickadj' in the kernel" >&5
 if eval "test \"\${ac_cv_var_nlist_tickadj+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9141,7 +9142,7 @@ EOF
 esac
 #
 echo $ac_n "checking for the units of 'tickadj'""... $ac_c" 1>&6
-echo "configure:9145: checking for the units of 'tickadj'" >&5
+echo "configure:9146: checking for the units of 'tickadj'" >&5
 if eval "test \"\${ac_cv_var_tickadj_nano+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9165,7 +9166,7 @@ EOF
 esac
 #
 echo $ac_n "checking half-heartedly for 'dosynctodr' in the kernel""... $ac_c" 1>&6
-echo "configure:9169: checking half-heartedly for 'dosynctodr' in the kernel" >&5
+echo "configure:9170: checking half-heartedly for 'dosynctodr' in the kernel" >&5
 if eval "test \"\${ac_cv_var_nlist_dosynctodr+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9218,7 +9219,7 @@ EOF
 esac
 #
 echo $ac_n "checking half-heartedly for 'noprintf' in the kernel""... $ac_c" 1>&6
-echo "configure:9222: checking half-heartedly for 'noprintf' in the kernel" >&5
+echo "configure:9223: checking half-heartedly for 'noprintf' in the kernel" >&5
 if eval "test \"\${ac_cv_var_nlist_noprintf+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9268,7 +9269,7 @@ esac
 
 
 echo $ac_n "checking for a default value for 'tick'""... $ac_c" 1>&6
-echo "configure:9272: checking for a default value for 'tick'" >&5
+echo "configure:9273: checking for a default value for 'tick'" >&5
 if eval "test \"\${ac_cv_var_tick+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9312,7 +9313,7 @@ EOF
 esac
 
 echo $ac_n "checking for a default value for 'tickadj'""... $ac_c" 1>&6
-echo "configure:9316: checking for a default value for 'tickadj'" >&5
+echo "configure:9317: checking for a default value for 'tickadj'" >&5
 if eval "test \"\${ac_cv_var_tickadj+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9419,7 +9420,7 @@ esac
 
 
 echo $ac_n "checking if we want and can make the tickadj utility""... $ac_c" 1>&6
-echo "configure:9423: checking if we want and can make the tickadj utility" >&5
+echo "configure:9424: checking if we want and can make the tickadj utility" >&5
 if eval "test \"\${ac_cv_make_tickadj+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9435,7 +9436,7 @@ esac
 
 
 echo $ac_n "checking if we want and can make the ntptime utility""... $ac_c" 1>&6
-echo "configure:9439: checking if we want and can make the ntptime utility" >&5
+echo "configure:9440: checking if we want and can make the ntptime utility" >&5
 if eval "test \"\${ac_cv_make_ntptime+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9464,7 +9465,7 @@ case "$ac_cv_make_ntptime" in
 esac
 
 echo $ac_n "checking if we want UDP wildcard delivery""... $ac_c" 1>&6
-echo "configure:9468: checking if we want UDP wildcard delivery" >&5
+echo "configure:9469: checking if we want UDP wildcard delivery" >&5
 if eval "test \"\${ac_cv_var_udp_wildcard_delivery+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9543,7 +9544,7 @@ case "$host" in
 esac
 
 echo $ac_n "checking if we should always slew the time""... $ac_c" 1>&6
-echo "configure:9547: checking if we should always slew the time" >&5
+echo "configure:9548: checking if we should always slew the time" >&5
 if eval "test \"\${ac_cv_var_slew_always+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9583,7 +9584,7 @@ EOF
 esac
 
 echo $ac_n "checking if we should step and slew the time""... $ac_c" 1>&6
-echo "configure:9587: checking if we should step and slew the time" >&5
+echo "configure:9588: checking if we should step and slew the time" >&5
 if eval "test \"\${ac_cv_var_step_slew+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9626,7 +9627,7 @@ EOF
 esac
 
 echo $ac_n "checking if ntpdate should step the time""... $ac_c" 1>&6
-echo "configure:9630: checking if ntpdate should step the time" >&5
+echo "configure:9631: checking if ntpdate should step the time" >&5
 if eval "test \"\${ac_cv_var_ntpdate_step+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9657,7 +9658,7 @@ EOF
 esac
 
 echo $ac_n "checking if we should sync TODR clock every hour""... $ac_c" 1>&6
-echo "configure:9661: checking if we should sync TODR clock every hour" >&5
+echo "configure:9662: checking if we should sync TODR clock every hour" >&5
 if eval "test \"\${ac_cv_var_sync_todr+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -9690,7 +9691,7 @@ EOF
 esac
 
 echo $ac_n "checking if we should avoid kernel FLL bug""... $ac_c" 1>&6
-echo "configure:9694: checking if we should avoid kernel FLL bug" >&5
+echo "configure:9695: checking if we should avoid kernel FLL bug" >&5
 if eval "test \"\${ac_cv_var_kernel_fll_bug+set}\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
index 97a74f8eb639c8caaab77673d88ce707e0db1cb2..d8958b090537e2d835ba0e767874c6f34abb0bbb 100644 (file)
@@ -767,6 +767,7 @@ case "$target" in
     AC_DEFINE(DECL_SIGVEC_0)
     case "`basename $ac_cv_prog_CC`" in
      acc*) ;;
+     gcc*) ;;
      *) AC_DEFINE(DECL_STDIO_0)
        ;;
     esac
index e4f507f6284a61f8c880299ccd44c2c155a0ee27..04241e7f7fd02bb42034089277bf33e99761e9d8 100644 (file)
--- a/dot.emacs
+++ b/dot.emacs
@@ -2,11 +2,11 @@
 
 (defconst ntp-c-style
   '((c-basic-offset . 8)
-    (c-offsets-alist . ((arglist-intro +)
-                       (case-label     *)
-                       (statement-case-intro *)
-                       (statement-cont *)
-                       (substatement-open 0))))
+    (c-offsets-alist . ((arglist-intro       . +)
+                       (case-label           . *)
+                       (statement-case-intro *)
+                       (statement-cont       . *)
+                       (substatement-open    . 0))))
   "Dave L. Mills; programming style for use with ntp")
 
 (defun ntp-c-mode-common-hook ()
index a5718350290e808323e316670a98e14953aa252d..875075c0813226e55a3c084199f386b808e1abdc 100644 (file)
@@ -8,8 +8,9 @@
 #include "l_stdlib.h"
 
 /*
- * Handle gcc __attribute__ if availabe.
+ * Handle gcc __attribute__ if available.
  */
+#ifndef NeXT
 #ifndef __attribute__
 /* This feature is available in gcc versions 2.5 and later.  */
 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
 #  define __printf__ printf
 # endif
 #endif
+#else
+#define __format__ format
+#define __printf__ printf
+#endif
 
 #if defined(__STDC__) || defined(HAVE_STDARG_H)
 # include <stdarg.h>
index c0c84caae61709642ae0443a4b986ef23d39f904..ba6c21f79463113b0025e16826564a5462cb9be6 100644 (file)
@@ -1,6 +1,7 @@
 #AUTOMAKE_OPTIONS = ../util/ansi2knr no-dependencies
 AUTOMAKE_OPTIONS = ../util/ansi2knr
-bin_PROGRAMS = ntpdate
+bin_PROGRAMS = ntpdate ntptimeset
+ntptimeset_SOURCES = ntptimeset.c ntptime_config.c
 INCLUDES = -I$(top_srcdir)/include
 # LDADD might need RESLIB and ADJLIB
 LDADD =        version.o ../libntp/libntp.a @LIBRSAREF@
index e63a7acff70d0ce4f5b9c74e176908d3fc22ff1b..0a38035d1c93c54332f036846ec633fb98d46b19 100644 (file)
@@ -98,7 +98,8 @@ VERSION = @VERSION@
 
 
 AUTOMAKE_OPTIONS = ../util/ansi2knr
-bin_PROGRAMS = ntpdate
+bin_PROGRAMS = ntpdate ntptimeset
+ntptimeset_SOURCES = ntptimeset.c ntptime_config.c
 INCLUDES = -I$(top_srcdir)/include
 # LDADD might need RESLIB and ADJLIB
 LDADD = version.o ../libntp/libntp.a @LIBRSAREF@
@@ -122,10 +123,15 @@ ntpdate_OBJECTS =  ntpdate$U.o
 ntpdate_LDADD = $(LDADD)
 ntpdate_DEPENDENCIES =  version.o ../libntp/libntp.a
 ntpdate_LDFLAGS = 
+am_ntptimeset_OBJECTS =  ntptimeset$U.o ntptime_config$U.o
+ntptimeset_OBJECTS =  $(am_ntptimeset_OBJECTS)
+ntptimeset_LDADD = $(LDADD)
+ntptimeset_DEPENDENCIES =  version.o ../libntp/libntp.a
+ntptimeset_LDFLAGS = 
 COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 CCLD = $(CC)
 LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
-DIST_SOURCES =  ntpdate.c
+DIST_SOURCES =  ntpdate.c $(ntptimeset_SOURCES)
 HEADERS =  $(noinst_HEADERS)
 
 DIST_COMMON =  README $(noinst_HEADERS) Makefile.am Makefile.in
@@ -134,9 +140,9 @@ DIST_COMMON =  README $(noinst_HEADERS) Makefile.am Makefile.in
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 
 GZIP_ENV = --best
-DEP_FILES =  .deps/ntpdate.P
-SOURCES = ntpdate.c
-OBJECTS = ntpdate$U.o
+DEP_FILES =  .deps/ntpdate.P .deps/ntptime_config.P .deps/ntptimeset.P
+SOURCES = ntpdate.c $(ntptimeset_SOURCES)
+OBJECTS = ntpdate$U.o $(am_ntptimeset_OBJECTS)
 
 all: all-redirect
 .SUFFIXES:
@@ -206,9 +212,19 @@ ntpdate$U.o:
 ntpdate: $(ntpdate_OBJECTS) $(ntpdate_DEPENDENCIES)
        @rm -f ntpdate
        $(LINK) $(ntpdate_LDFLAGS) $(ntpdate_OBJECTS) $(ntpdate_LDADD) $(LIBS)
+ntptimeset$U.o:
+ntptime_config$U.o:
+
+ntptimeset: $(ntptimeset_OBJECTS) $(ntptimeset_DEPENDENCIES)
+       @rm -f ntptimeset
+       $(LINK) $(ntptimeset_LDFLAGS) $(ntptimeset_OBJECTS) $(ntptimeset_LDADD) $(LIBS)
 ntpdate_.c: ntpdate.c $(ANSI2KNR)
        $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntpdate.c; then echo $(srcdir)/ntpdate.c; else echo ntpdate.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > ntpdate_.c
-ntpdate_.o : $(ANSI2KNR)
+ntptime_config_.c: ntptime_config.c $(ANSI2KNR)
+       $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntptime_config.c; then echo $(srcdir)/ntptime_config.c; else echo ntptime_config.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > ntptime_config_.c
+ntptimeset_.c: ntptimeset.c $(ANSI2KNR)
+       $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/ntptimeset.c; then echo $(srcdir)/ntptimeset.c; else echo ntptimeset.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > ntptimeset_.c
+ntpdate_.o ntptime_config_.o ntptimeset_.o : $(ANSI2KNR)
 
 tags: TAGS
 
index f7e20061d037f043163caea9d9ddd134b9cc93da..85e438e3307cfd95d703135aceba6cd73f15605d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * ntpdate.h - declarations for the ntpdate program
+ * ntpdate.h - declarations for the ntpdate and ntptimeset programs
  */
 
 #include "ntp_malloc.h"
@@ -12,7 +12,9 @@
  * remember about the server.
  */
 struct server {
+       struct server *next_server;     /* next server in build list */
        struct sockaddr_in srcadr;      /* address of remote host */
+       u_char version;                 /* version to use */
        u_char leap;                    /* leap indicator */
        u_char stratum;                 /* stratum of remote server */
        s_char precision;               /* server's clock precision */
@@ -22,7 +24,10 @@ struct server {
        u_int32 refid;                  /* peer reference ID */
        l_fp reftime;                   /* time of peer's last update */
        u_long event_time;              /* time for next timeout */
+       u_long last_xmit;               /* time of last transmit */
        u_short xmtcnt;                 /* number of packets transmitted */
+       u_short rcvcnt;                 /* number of packets received */
+       u_char reach;                   /* reachability, NTP_WINDOW bits */
        u_short filter_nextpt;          /* index into filter shift register */
        s_fp filter_delay[NTP_SHIFT];   /* delay part of shift register */
        l_fp filter_offset[NTP_SHIFT];  /* offset part of shift register */
@@ -76,6 +81,7 @@ struct server {
 #define        NTPDATE_DISTANCE        FP_SECOND       /* distance is 1 sec */
 #define        NTPDATE_DISP            FP_SECOND       /* so is the dispersion */
 #define        NTPDATE_REFID           (0)             /* reference ID to use */
+#define PEER_MAXDISP   (64*FP_SECOND)  /* maximum dispersion (fp 64) */
 
 
 /*
@@ -83,3 +89,7 @@ struct server {
  */
 #define        DEFTIMEOUT      5               /* 5 timer increments */
 #define        DEFSAMPLES      4               /* get 4 samples per server */
+#define        DEFPRECISION    (-5)            /* the precision we claim */
+#define        DEFMAXPERIOD    60              /* maximum time to wait */
+#define        DEFMINSERVERS   3               /* minimum responding servers */
+#define        DEFMINVALID     1               /* mimimum servers with valid time */
diff --git a/ntpdate/ntptime_config.c b/ntpdate/ntptime_config.c
new file mode 100644 (file)
index 0000000..ca8ed27
--- /dev/null
@@ -0,0 +1,556 @@
+/*
+ * ntptime_config.c
+ *
+ * What follows is a simplified version of the config parsing code
+ * in ntpd/ntp_config.c.  We only parse a subset of the configuration
+ * syntax, and don't bother whining about things we don't understand.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+#include <stdio.h>
+#include <signal.h>
+#include <ctype.h>
+#include <errno.h>
+#include <sys/time.h>
+
+
+#include "ntp_fp.h"
+#include "ntp.h"
+#include "ntp_io.h"
+#include "ntp_unixtime.h"
+#include "ntp_filegen.h"
+#include "ntpdate.h"
+#include "ntp_syslog.h"
+#include "ntp_stdlib.h"
+
+/*
+ * These routines are used to read the configuration file at
+ * startup time.  An entry in the file must fit on a single line.
+ * Entries are processed as multiple tokens separated by white space
+ * Lines are considered terminated when a '#' is encountered.  Blank
+ * lines are ignored.
+ */
+
+/*
+ * Configuration file name
+ */
+#ifndef CONFIG_FILE
+# ifndef SYS_WINNT
+#  define      CONFIG_FILE "/etc/ntp.conf"
+# else /* SYS_WINNT */
+#  define      CONFIG_FILE     "%windir%\\ntp.conf"
+#  define      ALT_CONFIG_FILE "%windir%\\ntp.ini"
+# endif /* SYS_WINNT */
+#endif /* not CONFIG_FILE */
+
+/*
+ *
+ * We understand the following configuration entries and defaults.
+ *
+ * peer [ addr ] [ version 3 ] [ key 0 ] [ minpoll 6 ] [ maxpoll 10 ]
+ * server [ addr ] [ version 3 ] [ key 0 ] [ minpoll 6 ] [ maxpoll 10 ]
+ * keys file_name
+ */
+
+#define CONFIG_UNKNOWN         0
+
+#define CONFIG_PEER            1
+#define CONFIG_SERVER          2
+#define CONFIG_KEYS            8
+
+#define CONF_MOD_VERSION       1
+#define CONF_MOD_KEY           2
+#define CONF_MOD_MINPOLL       3
+#define CONF_MOD_MAXPOLL       4
+#define CONF_MOD_PREFER        5
+#define CONF_MOD_BURST         6
+#define CONF_MOD_SKEY          7
+#define CONF_MOD_TTL           8
+#define CONF_MOD_MODE          9
+
+/*
+ * Translation table - keywords to function index
+ */
+struct keyword {
+       const char *text;
+       int keytype;
+};
+
+/*
+ * Command keywords
+ */
+static struct keyword keywords[] = {
+       { "peer",       CONFIG_PEER },
+       { "server",     CONFIG_SERVER },
+       { "keys",       CONFIG_KEYS },
+       { "",           CONFIG_UNKNOWN }
+};
+
+/*
+ * "peer", "server", "broadcast" modifier keywords
+ */
+static struct keyword mod_keywords[] = {
+       { "version",    CONF_MOD_VERSION },
+       { "key",    CONF_MOD_KEY },
+       { "minpoll",    CONF_MOD_MINPOLL },
+       { "maxpoll",    CONF_MOD_MAXPOLL },
+       { "prefer", CONF_MOD_PREFER },
+       { "burst",  CONF_MOD_BURST },
+       { "autokey",    CONF_MOD_SKEY },
+       { "mode",   CONF_MOD_MODE },    /* reference clocks */
+       { "ttl",    CONF_MOD_TTL },     /* NTP peers */
+       { "",       CONFIG_UNKNOWN }
+};
+
+/*
+ * Limits on things
+ */
+#define MAXTOKENS      20      /* 20 tokens on line */
+#define MAXLINE        1024    /* maximum length of line */
+#define MAXFILENAME 128 /* maximum length of a file name (alloca()?) */
+
+/*
+ * Miscellaneous macros
+ */
+#define STRSAME(s1, s2)        (*(s1) == *(s2) && strcmp((s1), (s2)) == 0)
+#define ISEOL(c)               ((c) == '#' || (c) == '\n' || (c) == '\0')
+#define ISSPACE(c)             ((c) == ' ' || (c) == '\t')
+#define STREQ(a, b)    (*(a) == *(b) && strcmp((a), (b)) == 0)
+
+/*
+ * Systemwide parameters and flags
+ */
+extern struct server **sys_servers;    /* the server list */
+extern int sys_numservers;     /* number of servers to poll */
+extern char *key_file;
+
+/*
+ * Function prototypes
+ */
+static int gettokens   P((FILE *, char *, char **, int *));
+static int matchkey    P((char *, struct keyword *));
+static int getnetnum   P((const char *num, struct sockaddr_in *addr,
+                          int complain));
+
+
+/*
+ * loadservers - load list of NTP servers from configuration file
+ */
+void
+loadservers(
+       char *cfgpath
+       )
+{
+       register int i;
+       int errflg;
+       int peerversion;
+       int minpoll;
+       int maxpoll;
+       int ttl;
+       int srvcnt;
+       u_long peerkey;
+       int peerflags;
+       struct sockaddr_in peeraddr;
+       FILE *fp;
+       char line[MAXLINE];
+       char *(tokens[MAXTOKENS]);
+       int ntokens;
+       int tok;
+       const char *config_file;
+#ifdef SYS_WINNT
+       char *alt_config_file;
+       LPTSTR temp;
+       char config_file_storage[MAX_PATH];
+       char alt_config_file_storage[MAX_PATH];
+#endif /* SYS_WINNT */
+       struct server *server, *srvlist;
+
+       /*
+        * Initialize, initialize
+        */
+       srvcnt = 0;
+       srvlist = 0;
+       errflg = 0;
+#ifdef DEBUG
+       debug = 0;
+#endif /* DEBUG */
+#ifndef SYS_WINNT
+       config_file = cfgpath ? cfgpath : CONFIG_FILE;
+#else
+       if (cfgpath) {
+               config_file = cfgpath;
+       } else {
+               temp = CONFIG_FILE;
+               if (!ExpandEnvironmentStrings((LPCTSTR)temp, (LPTSTR)config_file_storage, (DWORD)sizeof(config_file_storage))) {
+                       msyslog(LOG_ERR, "ExpandEnvironmentStrings CONFIG_FILE failed: %m\n");
+                       exit(1);
+               }
+               config_file = config_file_storage;
+       }
+
+       temp = ALT_CONFIG_FILE;
+       if (!ExpandEnvironmentStrings((LPCTSTR)temp, (LPTSTR)alt_config_file_storage, (DWORD)sizeof(alt_config_file_storage))) {
+               msyslog(LOG_ERR, "ExpandEnvironmentStrings ALT_CONFIG_FILE failed: %m\n");
+               exit(1);
+       }
+       alt_config_file = alt_config_file_storage;
+M
+#endif /* SYS_WINNT */
+
+       if ((fp = fopen(FindConfig(config_file), "r")) == NULL)
+       {
+               fprintf(stderr, "getconfig: Couldn't open <%s>\n", FindConfig(config_file));
+               msyslog(LOG_INFO, "getconfig: Couldn't open <%s>", FindConfig(config_file));
+#ifdef SYS_WINNT
+               /* Under WinNT try alternate_config_file name, first NTP.CONF, then NTP.INI */
+
+               if ((fp = fopen(FindConfig(alt_config_file), "r")) == NULL) {
+
+                       /*
+                        * Broadcast clients can sometimes run without
+                        * a configuration file.
+                        */
+
+                       fprintf(stderr, "getconfig: Couldn't open <%s>\n", FindConfig(alt_config_file));
+                       msyslog(LOG_INFO, "getconfig: Couldn't open <%s>", FindConfig(alt_config_file));
+                       return;
+               }
+#else  /* not SYS_WINNT */
+               return;
+#endif /* not SYS_WINNT */
+       }
+
+       while ((tok = gettokens(fp, line, tokens, &ntokens))
+              != CONFIG_UNKNOWN) {
+               switch(tok) {
+                   case CONFIG_PEER:
+                   case CONFIG_SERVER:
+                       
+                       if (ntokens < 2) {
+                               msyslog(LOG_ERR,
+                                       "No address for %s, line ignored",
+                                       tokens[0]);
+                               break;
+                       }
+                       
+                       if (!getnetnum(tokens[1], &peeraddr, 1)) {
+                               /* Resolve now, or lose! */
+                               break;
+                       } else {
+                               errflg = 0;
+                               
+                               /* Shouldn't be able to specify multicast */
+                               if (IN_CLASSD(ntohl(peeraddr.sin_addr.s_addr))
+                                   || ISBADADR(&peeraddr)) {
+                                       msyslog(LOG_ERR,
+                                               "attempt to configure invalid address %s",
+                                               ntoa(&peeraddr));
+                                       break;
+                               }
+                       }
+
+                       peerversion = NTP_VERSION;
+                       minpoll = NTP_MINDPOLL;
+                       maxpoll = NTP_MAXDPOLL;
+                       peerkey = 0;
+                       peerflags = 0;
+                       ttl = 0;
+                       for (i = 2; i < ntokens; i++)
+                           switch (matchkey(tokens[i], mod_keywords)) {
+                               case CONF_MOD_VERSION:
+                                   if (i >= ntokens-1) {
+                                           msyslog(LOG_ERR,
+                                                   "peer/server version requires an argument");
+                                           errflg = 1;
+                                           break;
+                                   }
+                                   peerversion = atoi(tokens[++i]);
+                                   if ((u_char)peerversion > NTP_VERSION
+                                       || (u_char)peerversion < NTP_OLDVERSION) {
+                                           msyslog(LOG_ERR,
+                                                   "inappropriate version number %s, line ignored",
+                                                   tokens[i]);
+                                           errflg = 1;
+                                   }
+                                   break;
+                                       
+                               case CONF_MOD_KEY:
+                                   if (i >= ntokens-1) {
+                                           msyslog(LOG_ERR,
+                                                   "key: argument required");
+                                           errflg = 1;
+                                           break;
+                                   }
+                                   peerkey = (int)atol(tokens[++i]);
+                                   peerflags |= FLAG_AUTHENABLE;
+                                   break;
+
+                               case CONF_MOD_MINPOLL:
+                                   if (i >= ntokens-1) {
+                                           msyslog(LOG_ERR,
+                                                   "minpoll: argument required");
+                                           errflg = 1;
+                                           break;
+                                   }
+                                   minpoll = atoi(tokens[++i]);
+                                   if (minpoll < NTP_MINPOLL)
+                                       minpoll = NTP_MINPOLL;
+                                   break;
+
+                               case CONF_MOD_MAXPOLL:
+                                   if (i >= ntokens-1) {
+                                           msyslog(LOG_ERR,
+                                                   "maxpoll: argument required"
+                                                   );
+                                           errflg = 1;
+                                           break;
+                                   }
+                                   maxpoll = atoi(tokens[++i]);
+                                   if (maxpoll > NTP_MAXPOLL)
+                                       maxpoll = NTP_MAXPOLL;
+                                   break;
+
+                               case CONF_MOD_PREFER:
+                                   peerflags |= FLAG_PREFER;
+                                   break;
+
+                               case CONF_MOD_BURST:
+                                   peerflags |= FLAG_BURST;
+                                   break;
+
+                               case CONF_MOD_SKEY:
+                                   peerflags |= FLAG_SKEY | FLAG_AUTHENABLE;
+                                   break;
+
+                               case CONF_MOD_TTL:
+                                   if (i >= ntokens-1) {
+                                           msyslog(LOG_ERR,
+                                                   "ttl: argument required");
+                                           errflg = 1;
+                                           break;
+                                   }
+                                   ttl = atoi(tokens[++i]);
+                                   break;
+
+                               case CONF_MOD_MODE:
+                                   if (i >= ntokens-1) {
+                                           msyslog(LOG_ERR,
+                                                   "mode: argument required");
+                                           errflg = 1;
+                                           break;
+                                   }
+                                   ttl = atoi(tokens[++i]);
+                                   break;
+
+                               case CONFIG_UNKNOWN:
+                                   errflg = 1;
+                                   break;
+                           }
+                       if (minpoll > maxpoll) {
+                               msyslog(LOG_ERR, "config error: minpoll > maxpoll");
+                               errflg = 1;
+                       }
+                       if (errflg == 0) {
+                               server = (struct server *)emalloc(sizeof(struct server));
+                               memset((char *)server, 0, sizeof(struct server));
+                               server->srcadr = peeraddr;
+                               server->version = peerversion;
+                               server->dispersion = PEER_MAXDISP;
+                               server->next_server = srvlist;
+                               srvlist = server;
+                               srvcnt++;
+                       }
+                       break;
+                       
+                       case CONFIG_KEYS:
+                       if (ntokens >= 2) {
+                               key_file = emalloc(strlen(tokens[1]) + 1);
+                               strcpy(key_file, tokens[1]);
+                       }
+                       break;
+               }
+       }
+       (void) fclose(fp);
+
+       /* build final list */
+       sys_numservers = srvcnt;
+       sys_servers = (struct server **) 
+           emalloc(sys_numservers * sizeof(struct server *));
+       for(i=0;i<sys_numservers;i++) {
+               sys_servers[i] = srvlist;
+               srvlist = srvlist->next_server;
+       }
+}
+
+
+
+/*
+ * gettokens - read a line and return tokens
+ */
+static int
+gettokens(
+       FILE *fp,
+       char *line,
+       char **tokenlist,
+       int *ntokens
+       )
+{
+       register char *cp;
+       register int eol;
+       register int ntok;
+       register int quoted = 0;
+
+       /*
+        * Find start of first token
+        */
+       again:
+       while ((cp = fgets(line, MAXLINE, fp)) != NULL) {
+               cp = line;
+               while (ISSPACE(*cp))
+                       cp++;
+               if (!ISEOL(*cp))
+                       break;
+       }
+       if (cp == NULL) {
+               *ntokens = 0;
+               return CONFIG_UNKNOWN;  /* hack.  Is recognized as EOF */
+       }
+
+       /*
+        * Now separate out the tokens
+        */
+       eol = 0;
+       ntok = 0;
+       while (!eol) {
+               tokenlist[ntok++] = cp;
+               while (!ISEOL(*cp) && (!ISSPACE(*cp) || quoted))
+                       quoted ^= (*cp++ == '"');
+
+               if (ISEOL(*cp)) {
+                       *cp = '\0';
+                       eol = 1;
+               } else {                /* must be space */
+                       *cp++ = '\0';
+                       while (ISSPACE(*cp))
+                               cp++;
+                       if (ISEOL(*cp))
+                               eol = 1;
+               }
+               if (ntok == MAXTOKENS)
+                       eol = 1;
+       }
+
+       /*
+        * Return the match
+        */
+       *ntokens = ntok;
+       ntok = matchkey(tokenlist[0], keywords);
+       if (ntok == CONFIG_UNKNOWN)
+               goto again;
+       return ntok;
+}
+
+
+
+/*
+ * matchkey - match a keyword to a list
+ */
+static int
+matchkey(
+       register char *word,
+       register struct keyword *keys
+       )
+{
+       for (;;) {
+               if (keys->keytype == CONFIG_UNKNOWN) {
+                       return CONFIG_UNKNOWN;
+               }
+               if (STRSAME(word, keys->text))
+                       return keys->keytype;
+               keys++;
+       }
+}
+
+
+/*
+ * getnetnum - return a net number (this is crude, but careful)
+ */
+static int
+getnetnum(
+       const char *num,
+       struct sockaddr_in *addr,
+       int complain
+       )
+{
+       register const char *cp;
+       register char *bp;
+       register int i;
+       register int temp;
+       char buf[80];           /* will core dump on really stupid stuff */
+       u_int32 netnum;
+
+       /* XXX ELIMINATE replace with decodenetnum */
+       cp = num;
+       netnum = 0;
+       for (i = 0; i < 4; i++) {
+               bp = buf;
+               while (isdigit((int)*cp))
+                       *bp++ = *cp++;
+               if (bp == buf)
+                       break;
+
+               if (i < 3) {
+                       if (*cp++ != '.')
+                               break;
+               } else if (*cp != '\0')
+                       break;
+
+               *bp = '\0';
+               temp = atoi(buf);
+               if (temp > 255)
+                       break;
+               netnum <<= 8;
+               netnum += temp;
+#ifdef DEBUG
+               if (debug > 3)
+                       printf("getnetnum %s step %d buf %s temp %d netnum %lu\n",
+                          num, i, buf, temp, (u_long)netnum);
+#endif
+       }
+
+       if (i < 4) {
+               if (complain)
+                       msyslog(LOG_ERR,
+                               "getnetnum: \"%s\" invalid host number, line ignored",
+                               num);
+#ifdef DEBUG
+               if (debug > 3)
+                       printf(
+                               "getnetnum: \"%s\" invalid host number, line ignored\n",
+                               num);
+#endif
+               return 0;
+       }
+
+       /*
+        * make up socket address.      Clear it out for neatness.
+        */
+       memset((void *)addr, 0, sizeof(struct sockaddr_in));
+       addr->sin_family = AF_INET;
+       addr->sin_port = htons(NTP_PORT);
+       addr->sin_addr.s_addr = htonl(netnum);
+#ifdef DEBUG
+       if (debug > 1)
+               printf("getnetnum given %s, got %s (%lx)\n",
+                  num, ntoa(addr), (u_long)netnum);
+#endif
+       return 1;
+}
diff --git a/ntpdate/ntptimeset.c b/ntpdate/ntptimeset.c
new file mode 100644 (file)
index 0000000..9544689
--- /dev/null
@@ -0,0 +1,2168 @@
+/*
+ * ntptimeset - get/set the time via ntp
+ *
+ * GOAL:
+ * The goal of ntptime is to set the current time on system startup
+ * to the best possible time using the network very wisely. It is assumed
+ * that after a resonable time has been sett then ntp daemon will
+ * maintain it.
+ *
+ * PROBLEM DOMAIN:
+ * We have three sets of issues related to acheiving the goal. The first
+ * issue is using the network when normal traffic is happening or when
+ * the entire network world is recovering from a campus wide power failure
+ * and is restarting. The second issue is the class of machine whether it
+ * is a user's office workstation being handled by an uneducated user or
+ * a server computer being handled by a trained operations staff. The third
+ * issue is whether the ratio of people to computers and whether the 
+ * environment is stable and viable or not.
+ *
+ * NETWORK USAGE:
+ * The first issue of using the network wisely is a question of whether
+ * the network load and time server load and state are normal. If things
+ * are normal ntptime can do what ntpdate does of sending out 4 packets
+ * quickly to each server (new transmit done with each ack). However
+ * if network or time load is high then this scheme will simply contribute
+ * to problems. Given we have minimal state, we simply weight lost packets
+ * significantly and make sure we throttle output as much as possible
+ * without performance lost for quick startups.
+ *
+ * TRAINING AND KNOWLEDGE:
+ * The second issue of uneducated user of a office workstation versus a
+ * trained operation staff of a server machine translates into simply an
+ * issue of untrained and trained users.
+ * 
+ * The training issue implies that for the sake of the users involved in the
+ * handling of their office workstation, problems and options should be
+ * communicated simply and effectively and not in terse expert related
+ * descriptions without possible options to be taken. The operator's training
+ * and education enables them to deal with either type of communication and
+ * control.
+ *
+ * AUTOMATION AND MANUAL CONTROL:
+ * The last issue boils down to a design problem. If the design tends to go
+ * into a manual mode when the environment is non-viable then one person
+ * handling many computers all at the same time will be heavily impacted. On
+ * the other hand, if the design tends to be automatic and does not indicate
+ * a way for the user to take over control then the computer will be
+ * unavailable for the user until the proble is resolved by someone else or
+ * the user.
+ *
+ * NOTE: Please do not have this program print out every minute some line,
+ *       of output. If this happens and the environment is in trouble then
+ *       many pages of paper on many different machines will be filled up.
+ *       Save some tress in your lifetime.
+ * 
+ * CONCLUSION:
+ * The behavior of the program derived from these three issues should be
+ * that during normal situations it quickly sets the time and allow the
+ * system to startup.
+ *
+ * However during abnormal conditions as detected by unresponsive servers,
+ * out-of-sync or bad responses and other detections, it should print out
+ * a simple but clear message and continue in a mellow way to get the best
+ * possible time. It may never get the time and if so should also indicate
+ * this.
+ *
+ * Rudy Nedved
+ * 18-May-1993
+ *
+ ****************************************************************
+ *
+ * Much of the above is confusing or no longer relevant.  For example,
+ * it is rare these days for a machine's console to be a printing terminal,
+ * so the comment about saving trees doesn't mean much.  Nonetheless,
+ * the basic principles still stand:
+ *
+ * - Work automatically, without human control or intervention.  To
+ *   this end, we use the same configuration file as ntpd itself, so
+ *   you don't have to specify servers or other information on the
+ *   command line.  We also recognize that sometimes we won't be able
+ *   to contact any servers, and give up in that event instead of
+ *   hanging forever.
+ *
+ * - Behave in a sane way, both internally and externally, even in the
+ *   face of insane conditions.  That means we back off quickly when
+ *   we don't hear a response, to avoid network congestion.  Like
+ *   ntpd, we verify responses from several servers before accepting
+ *   the new time data.
+ *
+ *   However, we don't assume that the local clock is right, or even
+ *   close, because it might not be at boot time, and we want to catch
+ *   and correct that situation.  This behaviour has saved us in several
+ *   instances.  On HP-UX 9.0x, there used to be a bug in adjtimed which
+ *   would cause the time to be set to some wild value, making the machine
+ *   essentially unusable (we use Kerberos authentication pervasively,
+ *   and it requires workstations and servers to have a time within five
+ *   minutes of the Kerberos server).  We also have problems on PC's
+ *   running both Linux and some Microsoft OS -- they tend to disagree
+ *   on what the BIOS clock should say, and who should update it, and
+ *   when.  On those systems, we not only run ntptimeset at boot, we
+ *   also reset the BIOS clock based on the result, so the correct
+ *   time will be retained across reboots.
+ *
+ * For these reasons, and others, we have continued to use this tool
+ * rather than ntpdate.  It is run automatically at boot time on every
+ * workstation and server in our facility.
+ *
+ * In the past, we called this program 'ntptime'.  Unfortunately, the
+ * ntp v4 distribution also includes a program with that name.  In
+ * order to avoid confusion, we have renamed our program 'ntptimeset',
+ * which more accurately describes what it does.
+ *
+ * Jeffrey T. Hutzelman (N3NHS) <jhutz+@cmu.edu>
+ * School of Computer Science - Research Computing Facility
+ * Carnegie Mellon University - Pittsburgh, PA
+ * 16-Aug-1999
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include <stdio.h>
+#include <signal.h>
+#include <ctype.h>
+#include <errno.h>
+#ifndef SYS_WINNT
+# include <netdb.h>
+# include <sys/signal.h>
+# include <sys/ioctl.h>
+#endif /* SYS_WINNT */
+#include <sys/time.h>
+#ifdef HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif /* HAVE_SYS_RESOURCE_H */
+
+#ifdef SYS_VXWORKS
+# include "ioLib.h"
+# include "sockLib.h"
+# include "timers.h"
+#endif
+
+
+#if defined(SYS_HPUX)
+# include <utmp.h>
+#endif
+
+#include "ntp_fp.h"
+#include "ntp.h"
+#include "ntp_io.h"
+#include "iosignal.h"
+#include "ntp_unixtime.h"
+#include "ntpdate.h"
+#include "ntp_string.h"
+#include "ntp_syslog.h"
+#include "ntp_select.h"
+#include "ntp_stdlib.h"
+#include "recvbuff.h"
+
+#ifdef SYS_WINNT
+# define TARGET_RESOLUTION 1  /* Try for 1-millisecond accuracy
+                               on Windows NT timers. */
+#pragma comment(lib, "winmm")
+#endif /* SYS_WINNT */
+
+/*
+ * Scheduling priority we run at
+ */
+#ifndef SYS_VXWORKS
+# define       NTPDATE_PRIO    (-12)
+#else
+# define       NTPDATE_PRIO    (100)
+#endif
+
+#if defined(HAVE_TIMER_SETTIME) || defined (HAVE_TIMER_CREATE)
+/* POSIX TIMERS - vxWorks doesn't have itimer - casey */
+static timer_t ntpdate_timerid;
+#endif
+
+/*
+ * Compatibility stuff for Version 2
+ */
+#define NTP_MAXSKW     0x28f   /* 0.01 sec in fp format */
+#define NTP_MINDIST 0x51f      /* 0.02 sec in fp format */
+#define NTP_INFIN      15      /* max stratum, infinity a la Bellman-Ford */
+#define NTP_MAXWGT     (8*FP_SECOND)   /* maximum select weight 8 seconds */
+#define NTP_MAXLIST 5  /* maximum select list size */
+#define PEER_SHIFT     8       /* 8 suitable for crystal time base */
+
+/*
+ * Debugging flag
+ */
+volatile int debug = 0;
+
+/*
+ * File descriptor masks etc. for call to select
+ */
+int fd;
+fd_set fdmask;
+
+/*
+ * Initializing flag.  All async routines watch this and only do their
+ * thing when it is clear.
+ */
+int initializing = 1;
+
+/*
+ * Alarm flag. Set when an alarm occurs
+ */
+volatile int alarm_flag = 0;
+
+/*
+ * Set the time if valid time determined
+ */
+int set_time = 0;
+
+/*
+ * transmission rate control
+ */
+#define        MINTRANSMITS    (3)     /* minimum total packets per server */
+#define        MAXXMITCOUNT    (2)     /* maximum packets per time interrupt */
+
+/*
+ * time setting constraints
+ */
+#define        DESIREDDISP     (4*FP_SECOND)   /* desired dispersion, (fp 4) */
+int max_period = DEFMAXPERIOD;
+int min_servers = DEFMINSERVERS;
+int min_valid = DEFMINVALID;
+
+/*
+ * counters related to time setting constraints
+ */
+int contacted = 0;             /* # of servers we have sent to */
+int responding = 0;            /* servers responding */
+int validcount = 0;            /* servers with valid time */
+int valid_n_low = 0;           /* valid time servers with low dispersion */
+
+/*
+ * Unpriviledged port flag.
+ */
+int unpriv_port = 0;
+
+/*
+ * Program name.
+ */
+char *progname;
+
+/*
+ * Systemwide parameters and flags
+ */
+struct server **sys_servers;   /* the server list */
+int sys_numservers = 0;        /* number of servers to poll */
+int sys_authenticate = 0;      /* true when authenticating */
+u_int32 sys_authkey = 0;       /* set to authentication key in use */
+u_long sys_authdelay = 0;      /* authentication delay */
+
+/*
+ * The current internal time
+ */
+u_long current_time = 0;
+
+/*
+ * File of encryption keys
+ */
+
+#ifndef KEYFILE
+# ifndef SYS_WINNT
+#define KEYFILE        "/etc/ntp.keys"
+# else
+#define KEYFILE        "%windir%\\ntp.keys"
+# endif /* SYS_WINNT */
+#endif /* KEYFILE */
+
+#ifndef SYS_WINNT
+const char *key_file = KEYFILE;
+#else
+char key_file_storage[MAX_PATH+1], *key_file ;
+#endif  /* SYS_WINNT */
+
+/*
+ * total packet counts
+ */
+u_long total_xmit = 0;
+u_long total_recv = 0;
+
+/*
+ * Miscellaneous flags
+ */
+int verbose = 0;
+#define        HORRIBLEOK      3       /* how many packets to let out */
+int horrible = 0;      /* how many packets we drop for testing */
+int secondhalf = 0;    /* second half of timeout period */
+int printmsg = 0;      /* print time response analysis */
+
+/*
+ * The half time and finish time in internal time
+ */
+u_long half_time = 0;
+u_long finish_time = 0;
+
+
+int    ntptimesetmain  P((int argc, char *argv[]));
+extern void    loadservers     P((char *cfgpath));
+static void    analysis        P((int final));
+static int     have_enough     P((void));
+static void    transmit        P((register struct server *server));
+static void    receive         P((struct recvbuf *rbufp));
+static void    clock_filter P((register struct server *server, s_fp d, l_fp *c));
+static void    clock_count     P((void));
+static struct server *clock_select P((void));
+static void    set_local_clock P((void));
+static struct server *findserver P((struct sockaddr_in *addr));
+static void    timer           P((void));
+#ifndef SYS_WINNT
+static RETSIGTYPE      alarming        P((int sig));
+#endif /* SYS_WINNT */
+static void    init_alarm      P((void));
+static void    init_io         P((void));
+static int     sendpkt         P((struct sockaddr_in *dest, struct pkt *pkt, int len));
+       void    input_handler   P((l_fp *xts));
+static void    printserver     P((register struct server *pp, FILE *fp));
+#if !defined(HAVE_VSPRINTF)
+int    vsprintf        P((char *str, const char *fmt, va_list ap));
+#endif
+
+
+#ifdef NO_MAIN_ALLOWED
+CALL(ntptimeset,"ntptimeset",ntptimesetmain);
+
+void clear_globals()
+{
+  /*
+   * Debugging flag
+   */
+  debug = 0;
+
+  ntp_optind = 0;
+
+  /*
+   * Initializing flag.  All async routines watch this and only do their
+   * thing when it is clear.
+   */
+  initializing = 1;
+
+  /*
+   * Alarm flag.  Set when an alarm occurs
+   */
+  alarm_flag = 0;
+
+  /*
+   * Unpriviledged port flag.
+   */
+  unpriv_port = 0;
+
+  /*
+   * Systemwide parameters and flags
+   */
+  sys_numservers = 0;    /* number of servers to poll */
+  sys_authenticate = 0;   /* true when authenticating */
+  sys_authkey = 0;        /* set to authentication key in use */
+  sys_authdelay = 0;   /* authentication delay */
+
+  /*
+   * The current internal time
+   */
+  current_time = 0;
+
+  verbose = 0;
+}
+#endif /* NO_MAIN_ALLOWED */
+
+/*
+ * Main program.  Initialize us and loop waiting for I/O and/or
+ * timer expiries.
+ */
+#ifndef NO_MAIN_ALLOWED
+int
+main(
+       int argc,
+       char *argv[]
+       )
+{
+       return ntptimesetmain(argc, argv);
+}
+#endif /* NO_MAIN_ALLOWED */
+          
+
+int
+ntptimesetmain(
+       int argc,
+       char *argv[]
+       )
+{
+       int was_alarmed;
+       struct recvbuf *rbuflist;
+       struct recvbuf *rbuf;
+       l_fp tmp;
+       int errflg;
+       int c;
+       extern char *ntp_optarg;
+       extern int ntp_optind;
+       int ltmp;
+       char *cfgpath;
+
+#ifdef SYS_WINNT
+       HANDLE process_handle;
+
+       wVersionRequested = MAKEWORD(1,1);
+       if (WSAStartup(wVersionRequested, &wsaData)) {
+               msyslog(LOG_ERR, "No useable winsock.dll: %m");
+               exit(1);
+       }
+#endif /* SYS_WINNT */
+
+#ifdef NO_MAIN_ALLOWED
+       clear_globals();
+#endif
+
+       errflg = 0;
+       cfgpath = 0;
+       progname = argv[0];
+       syslogit = 0;
+
+       /*
+        * Decode argument list
+        */
+       while ((c = ntp_getopt(argc, argv, "a:c:de:slt:uvHS:V:")) != EOF)
+               switch (c)
+               {
+               case 'a':
+                       c = atoi(ntp_optarg);
+                       sys_authenticate = 1;
+                       sys_authkey = c;
+                       break;
+               case 'c':
+                       cfgpath = ntp_optarg;
+                       break;
+               case 'd':
+                       ++debug;
+                       break;
+               case 'e':
+                       if (!atolfp(ntp_optarg, &tmp)
+                           || tmp.l_ui != 0) {
+                               (void) fprintf(stderr,
+                                   "%s: encryption delay %s is unlikely\n",
+                                   progname, ntp_optarg);
+                               errflg++;
+                       } else {
+                               sys_authdelay = tmp.l_uf;
+                       }
+                       break;
+               case 's':
+                       set_time = 1;
+                       break;
+               case 'l':
+                       syslogit = 1;
+                       break;
+               case 't':
+                       ltmp = atoi(ntp_optarg);
+                       if (ltmp <= 0) {
+                           (void) fprintf(stderr,
+                               "%s: maximum time period (%d) is invalid\n",
+                               progname, ltmp);
+                           errflg++;
+                       }
+                       else
+                           max_period = ltmp;
+                       break;
+               case 'u':
+                       unpriv_port = 1;
+                       break;
+               case 'v':
+                       ++verbose;
+                       break;
+               case 'H':
+                       horrible++;
+                       break;
+               case 'S':
+                       ltmp = atoi(ntp_optarg);
+                       if (ltmp <= 0) {
+                           (void) fprintf(stderr,
+                               "%s: minimum responding (%d) is invalid\n",
+                               progname, ltmp);
+                           errflg++;
+                       }
+                       else
+                           min_servers = ltmp;
+                       break;
+               case 'V':
+                       ltmp = atoi(ntp_optarg);
+                       if (ltmp <= 0) {
+                           (void) fprintf(stderr,
+                               "%s: minimum valid (%d) is invalid\n",
+                               progname, ltmp);
+                           errflg++;
+                       }
+                       else
+                           min_valid = ltmp;
+                       break;
+               case '?':
+                       ++errflg;
+                       break;
+               default:
+                       break;
+               }
+
+       
+       if (errflg || ntp_optind < argc) {
+               fprintf(stderr,"usage: %s [switches...]\n",progname);
+               fprintf(stderr,"  -v       (verbose)\n");
+               fprintf(stderr,"  -c path  (set config file path)\n");
+               fprintf(stderr,"  -a key   (authenticate using key)\n");
+               fprintf(stderr,"  -e delay (authentication delay)\n");
+               fprintf(stderr,"  -S num   (# of servers that must respond)\n");
+               fprintf(stderr,"  -V num   (# of servers that must valid)\n");
+               fprintf(stderr,"  -s       (set the time based if okay)\n");
+               fprintf(stderr,"  -t secs  (time period before ending)\n");
+               fprintf(stderr,"  -l       (use syslog facility)\n");
+               fprintf(stderr,"  -u       (use unprivileged port)\n");
+               fprintf(stderr,"  -H       (drop packets for debugging)\n");
+               fprintf(stderr,"  -d       (debug output)\n");
+               exit(2);
+       }
+
+       /*
+        * Logging.  Open the syslog if we have to
+        */
+       if (syslogit) {
+#if !defined (SYS_WINNT) && !defined (SYS_VXWORKS) && !defined SYS_CYGWIN32
+# ifndef       LOG_DAEMON
+               openlog("ntptimeset", LOG_PID);
+# else
+
+#  ifndef      LOG_NTP
+#      define  LOG_NTP LOG_DAEMON
+#  endif
+               openlog("ntptimeset", LOG_PID | LOG_NDELAY, LOG_NTP);
+               if (debug)
+                       setlogmask(LOG_UPTO(LOG_DEBUG));
+               else
+                       setlogmask(LOG_UPTO(LOG_INFO));
+# endif /* LOG_DAEMON */
+#endif /* SYS_WINNT */
+       }
+
+       if (debug || verbose)
+               msyslog(LOG_INFO, "%s", Version);
+
+       if (horrible)
+               msyslog(LOG_INFO, "Dropping %d out of %d packets",
+                       horrible,horrible+HORRIBLEOK);
+       /*
+        * Add servers we are going to be polling
+        */
+       loadservers(cfgpath);
+
+       if (sys_numservers < min_servers) {
+               msyslog(LOG_ERR, "Found %d servers, require %d servers",
+                       sys_numservers,min_servers);
+               exit(2);
+       }
+
+       /*
+        * determine when we will end at least
+        */
+       finish_time = max_period * TIMER_HZ;
+       half_time = finish_time >> 1;
+
+       /*
+        * Initialize the time of day routines and the I/O subsystem
+        */
+       if (sys_authenticate) {
+               init_auth();
+#ifdef SYS_WINNT
+               if (!key_file) key_file = KEYFILE;
+               if (!ExpandEnvironmentStrings(key_file, key_file_storage, MAX_PATH))
+               {
+                       msyslog(LOG_ERR, "ExpandEnvironmentStrings(%s) failed: %m\n",
+                               key_file);
+               } else {
+                       key_file = key_file_storage;
+               }
+#endif /* SYS_WINNT */
+
+               if (!authreadkeys(key_file)) {
+                       msyslog(LOG_ERR, "no key file, exiting");
+                       exit(1);
+               }
+               if (!authistrusted(sys_authkey)) {
+                       char buf[10];
+
+                       (void) sprintf(buf, "%lu", (unsigned long)sys_authkey);
+                       msyslog(LOG_ERR, "authentication key %s unknown", buf);
+                       exit(1);
+               }
+       }
+       init_io();
+       init_alarm();
+
+       /*
+        * Set the priority.
+        */
+#ifdef SYS_VXWORKS
+       taskPrioritySet( taskIdSelf(), NTPDATE_PRIO);
+#endif
+#if defined(HAVE_ATT_NICE)
+       nice (NTPDATE_PRIO);
+#endif
+#if defined(HAVE_BSD_NICE)
+       (void) setpriority(PRIO_PROCESS, 0, NTPDATE_PRIO);
+#endif
+#ifdef SYS_WINNT
+       process_handle = GetCurrentProcess();
+       if (!SetPriorityClass(process_handle, (DWORD) REALTIME_PRIORITY_CLASS)) {
+               msyslog(LOG_ERR, "SetPriorityClass failed: %m");
+       }
+#endif /* SYS_WINNT */
+
+       initializing = 0;
+
+       /*
+        * Use select() on all on all input fd's for unlimited
+        * time.  select() will terminate on SIGALARM or on the
+        * reception of input.  Using select() means we can't do
+        * robust signal handling and we get a potential race
+        * between checking for alarms and doing the select().
+        * Mostly harmless, I think.
+        * Keep going until we have enough information, or time is up.
+        */
+       /* On VMS, I suspect that select() can't be interrupted
+        * by a "signal" either, so I take the easy way out and
+        * have select() time out after one second.
+        * System clock updates really aren't time-critical,
+        * and - lacking a hardware reference clock - I have
+        * yet to learn about anything else that is.
+        */
+       was_alarmed = 0;
+       rbuflist = (struct recvbuf *)0;
+       while (finish_time > current_time) {
+#if !defined(HAVE_SIGNALED_IO) 
+               fd_set rdfdes;
+               int nfound;
+#elif defined(HAVE_SIGNALED_IO)
+               block_io_and_alarm();
+#endif
+
+               rbuflist = getrecvbufs();       /* get received buffers */
+               if (printmsg) {
+                       printmsg = 0;
+                       analysis(0);
+               }
+               if (alarm_flag) {               /* alarmed? */
+                       was_alarmed = 1;
+                       alarm_flag = 0;
+               }
+
+               if (!was_alarmed && rbuflist == (struct recvbuf *)0) {
+                       /*
+                        * Nothing to do.  Wait for something.
+                        */
+#ifndef HAVE_SIGNALED_IO
+                       rdfdes = fdmask;
+# if defined(VMS) || defined(SYS_VXWORKS)
+                       /* make select() wake up after one second */
+                       {
+                               struct timeval t1;
+
+                               t1.tv_sec = 1; t1.tv_usec = 0;
+                               nfound = select(fd+1, &rdfdes, (fd_set *)0,
+                                               (fd_set *)0, &t1);
+                       }
+# else
+                       nfound = select(fd+1, &rdfdes, (fd_set *)0,
+                                       (fd_set *)0, (struct timeval *)0);
+# endif /* VMS */
+                       if (nfound > 0) {
+                               l_fp ts;
+                               get_systime(&ts);
+                               (void)input_handler(&ts);
+                       }
+                       else if (nfound == -1 && errno != EINTR)
+                               msyslog(LOG_ERR, "select() error: %m");
+                       else if (debug) {
+# if !defined SYS_VXWORKS && !defined SYS_CYGWIN32 /* to unclutter log */
+                               msyslog(LOG_DEBUG, "select(): nfound=%d, error: %m", nfound);
+# endif
+                       }
+#else /* HAVE_SIGNALED_IO */
+                        
+                       wait_for_signal();
+#endif /* HAVE_SIGNALED_IO */
+                       if (alarm_flag)         /* alarmed? */
+                       {
+                               was_alarmed = 1;
+                               alarm_flag = 0;
+                       }
+                       rbuflist = getrecvbufs();  /* get received buffers */
+               }
+#ifdef HAVE_SIGNALED_IO
+               unblock_io_and_alarm();
+#endif /* HAVE_SIGNALED_IO */
+
+               /*
+                * Out here, signals are unblocked.  Call timer routine
+                * to process expiry.
+                */
+               if (was_alarmed)
+               {
+                       timer();
+                       was_alarmed = 0;
+               }
+
+               /*
+                * Call the data procedure to handle each received
+                * packet.
+                */
+               while (rbuflist != (struct recvbuf *)0)
+               {
+                       rbuf = rbuflist;
+                       rbuflist = rbuf->next;
+                       receive(rbuf);
+                       freerecvbuf(rbuf);
+               }
+#if defined DEBUG && defined SYS_WINNT
+               if (debug > 4)
+                   printf("getrecvbufs: %ld handler interrupts, %ld frames\n",
+                          handler_calls, handler_pkts);
+#endif
+
+               /*
+                * Do we have enough information to stop now?
+                */
+               if (have_enough())
+                       break;  /* time to end */
+
+               /*
+                * Go around again
+                */
+       }
+
+       /*
+        * adjust the clock and exit accordingly
+        */
+       set_local_clock();
+
+       /*
+        * if we get here then we are in trouble
+        */
+       exit(1);
+}
+
+
+/*
+ * analysis - print a message indicating what is happening with time service
+ *           must mimic have_enough() procedure.
+ */
+static void
+analysis(
+       int final
+       )
+{
+       if (contacted < sys_numservers) {
+               printf("%d servers of %d have been probed with %d packets\n",
+                      contacted,sys_numservers,MINTRANSMITS);
+               return;
+       }
+       if (!responding) {
+               printf("No response from any of %d servers, network problem?\n",
+                      sys_numservers);
+               return;
+       }
+       else if (responding < min_servers) {
+               printf("%d servers out of %d responding, need at least %d.\n",
+                      responding, sys_numservers, min_servers);
+               return;
+       }
+       if (!validcount) {
+               printf("%d servers responding but none have valid time\n",
+                      responding);
+               return;
+       }
+       else if (validcount < min_valid) {
+               printf("%d servers responding, %d are valid, need %d valid\n",
+                      responding,validcount,min_valid);
+               return;
+       }
+       if (!final && valid_n_low != validcount) {
+               printf("%d valid servers but only %d have low dispersion\n",
+                      validcount,valid_n_low);
+               return;
+       }
+}
+
+
+/* have_enough - see if we have enough information to terminate probing
+ */
+static int
+have_enough(void)
+{
+       /* have we contacted all servers yet? */
+       if (contacted < sys_numservers)
+               return 0;       /* no...try some more */
+
+       /* have we got at least minimum servers responding? */
+       if (responding < min_servers)
+               return 0;       /* no...try some more */
+
+       /* count the clocks */
+       (void) clock_count();
+
+       /* have we got at least minimum valid clocks? */
+       if (validcount <= 0 || validcount < min_valid)
+               return 0;       /* no...try some more */
+
+       /* do we have all valid servers with low dispersion */
+       if (!secondhalf && valid_n_low != validcount)
+               return 0;
+
+       /* if we get into the secondhalf then we ignore dispersion */
+
+       /* all conditions have been met...end */
+       return 1;
+}
+
+
+/*
+ * transmit - transmit a packet to the given server, or mark it completed.
+ *           This is called by the timeout routine and by the receive
+ *           procedure.
+ */
+static void
+transmit(
+       register struct server *server
+       )
+{
+       struct pkt xpkt;
+       int timeout;
+
+       if (debug > 2)
+               printf("transmit(%s)\n", ntoa(&server->srcadr));
+
+       if ((server->reach & 01) == 0) {
+               l_fp ts;
+               /*
+                * Last message to this server timed out.  Shift
+                * zeros into the filter.
+                */
+               L_CLR(&ts);
+               clock_filter(server, 0, &ts);
+       }
+
+       /*
+        * shift reachable register over
+        */
+       server->reach <<= 1;
+
+       /*
+        * If we're here, send another message to the server.  Fill in
+        * the packet and let 'er rip.
+        */
+       xpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOTINSYNC,
+               server->version, MODE_CLIENT);
+       xpkt.stratum = STRATUM_TO_PKT(STRATUM_UNSPEC);
+       xpkt.ppoll = NTP_MINPOLL;
+       xpkt.precision = NTPDATE_PRECISION;
+       xpkt.rootdelay = htonl(NTPDATE_DISTANCE);
+       xpkt.rootdispersion = htonl(NTPDATE_DISP);
+       xpkt.refid = htonl(NTPDATE_REFID);
+       L_CLR(&xpkt.reftime);
+       L_CLR(&xpkt.org);
+       L_CLR(&xpkt.rec);
+
+       /*
+        * Determine whether to authenticate or not.  If so,
+        * fill in the extended part of the packet and do it.
+        * If not, just timestamp it and send it away.
+        */
+       if (sys_authenticate) {
+               int len;
+
+               xpkt.keyid1 = htonl(sys_authkey);
+               get_systime(&server->xmt);
+               L_ADDUF(&server->xmt, sys_authdelay);
+               HTONL_FP(&server->xmt, &xpkt.xmt);
+               len = authencrypt(sys_authkey, (u_int32 *)&xpkt, LEN_PKT_NOMAC);
+               if (sendpkt(&(server->srcadr), &xpkt, LEN_PKT_NOMAC + len)) {
+                       if (debug > 1)
+                               printf("failed transmit auth to %s\n",
+                                   ntoa(&(server->srcadr)));
+                       return;
+               }
+
+               if (debug > 1)
+                       printf("transmit auth to %s\n",
+                           ntoa(&(server->srcadr)));
+       } else {
+               get_systime(&(server->xmt));
+               HTONL_FP(&server->xmt, &xpkt.xmt);
+               if (sendpkt(&(server->srcadr), &xpkt, LEN_PKT_NOMAC)) {
+                       if (debug > 1)
+                               printf("failed transmit to %s\n", 
+                                   ntoa(&(server->srcadr)));
+                       return;
+               }
+
+               if (debug > 1)
+                       printf("transmit to %s\n", ntoa(&(server->srcadr)));
+       }
+
+       /*
+        * count transmits, record contacted count and set transmit time
+        */
+       if (++server->xmtcnt == MINTRANSMITS)
+           contacted++;
+       server->last_xmit = current_time;
+
+       /*
+        * determine timeout for this packet. The more packets we send
+        * to the host, the slower we get. If the host indicates that
+        * it is not "sane" then we expect even less.
+        */
+       if (server->xmtcnt < MINTRANSMITS) {
+           /* we have not sent enough */
+           timeout = TIMER_HZ;         /* 1 second probe */
+       }
+       else if (server->rcvcnt <= 0) {
+           /* we have heard nothing */
+           if (secondhalf)
+               timeout = TIMER_HZ<<4;  /* 16 second probe */
+           else
+               timeout = TIMER_HZ<<3;  /* 8 second probe */
+       }
+       else {
+           /* if we have low dispersion then probe infrequently */
+           if (server->dispersion <= DESIREDDISP)
+               timeout = TIMER_HZ<<4;  /* 16 second probe */
+           /* if the server is not in sync then let it alone */
+           else if (server->leap == LEAP_NOTINSYNC)
+               timeout = TIMER_HZ<<4;  /* 16 second probe */
+           /* if the server looks broken ignore it */
+           else if (server->org.l_ui < server->reftime.l_ui)
+               timeout = TIMER_HZ<<5;  /* 32 second probe */
+           else if (secondhalf)
+               timeout = TIMER_HZ<<2;  /* 4 second probe */
+           else
+               timeout = TIMER_HZ<<1;  /* 2 second probe */
+       }
+
+       /*
+        * set next transmit time based on timeout
+        */
+       server->event_time = current_time + timeout;
+}
+
+
+/*
+ * receive - receive and process an incoming frame
+ */
+static void
+receive(
+       struct recvbuf *rbufp
+       )
+{
+       register struct pkt *rpkt;
+       register struct server *server;
+       register s_fp di;
+       l_fp t10, t23;
+       l_fp org;
+       l_fp rec;
+       l_fp ci;
+       int has_mac;
+       int is_authentic;
+
+       if (debug > 2)
+               printf("receive(%s)\n", ntoa(&rbufp->srcadr));
+       /*
+        * Check to see if the packet basically looks like something
+        * intended for us.
+        */
+       if (rbufp->recv_length == LEN_PKT_NOMAC)
+               has_mac = 0;
+       else if (rbufp->recv_length >= LEN_PKT_NOMAC)
+               has_mac = 1;
+       else {
+               if (debug > 2)
+                       printf("receive: packet length %d\n",
+                           rbufp->recv_length);
+               return;         /* funny length packet */
+       }
+
+       rpkt = &(rbufp->recv_pkt);
+       if (PKT_VERSION(rpkt->li_vn_mode) < NTP_OLDVERSION ||
+           PKT_VERSION(rpkt->li_vn_mode) > NTP_VERSION) {
+               if (debug > 1)
+                       printf("receive: bad version %d\n",
+                              PKT_VERSION(rpkt->li_vn_mode));
+               return;
+       }
+
+       if ((PKT_MODE(rpkt->li_vn_mode) != MODE_SERVER
+           && PKT_MODE(rpkt->li_vn_mode) != MODE_PASSIVE)
+           || rpkt->stratum > NTP_MAXSTRATUM) {
+               if (debug > 1)
+                       printf("receive: mode %d stratum %d\n",
+                           PKT_MODE(rpkt->li_vn_mode), rpkt->stratum);
+               return;
+       }
+       
+       /*
+        * So far, so good.  See if this is from a server we know.
+        */
+       server = findserver(&(rbufp->srcadr));
+       if (server == NULL) {
+               if (debug > 1)
+                       printf("receive: server not found\n");
+               return;
+       }
+
+       /*
+        * Decode the org timestamp and make sure we're getting a response
+        * to our last request.
+        */
+       NTOHL_FP(&rpkt->org, &org);
+       if (!L_ISEQU(&org, &server->xmt)) {
+               if (debug > 1)
+                       printf("receive: pkt.org and peer.xmt differ\n");
+               return;
+       }
+       
+       /*
+        * Check out the authenticity if we're doing that.
+        */
+       if (!sys_authenticate)
+               is_authentic = 1;
+       else {
+               is_authentic = 0;
+
+               if (debug > 3)
+                       printf("receive: rpkt keyid=%ld sys_authkey=%ld decrypt=%ld\n",
+                          (long int)ntohl(rpkt->keyid1), (long int)sys_authkey,
+                          (long int)authdecrypt(sys_authkey, (u_int32 *)rpkt,
+                               LEN_PKT_NOMAC, rbufp->recv_length - LEN_PKT_NOMAC));
+
+               if (has_mac && ntohl(rpkt->keyid1) == sys_authkey &&
+                       authdecrypt(sys_authkey, (u_int32 *)rpkt, LEN_PKT_NOMAC,
+                       rbufp->recv_length - LEN_PKT_NOMAC))
+                       is_authentic = 1;
+               if (debug)
+                       printf("receive: authentication %s\n",
+                          is_authentic ? "passed" : "failed");
+       }
+       server->trust <<= 1;
+       if (!is_authentic)
+               server->trust |= 1;
+       
+       /*
+        * Looks good.  Record info from the packet.
+        */
+       server->leap = PKT_LEAP(rpkt->li_vn_mode);
+       server->stratum = PKT_TO_STRATUM(rpkt->stratum);
+       server->precision = rpkt->precision;
+       server->rootdelay = ntohl(rpkt->rootdelay);
+       server->rootdispersion = ntohl(rpkt->rootdispersion);
+       server->refid = rpkt->refid;
+       NTOHL_FP(&rpkt->reftime, &server->reftime);
+       NTOHL_FP(&rpkt->rec, &rec);
+       NTOHL_FP(&rpkt->xmt, &server->org);
+
+       /*
+        * count this guy as responding
+        */
+       server->reach |= 1;
+       if (server->rcvcnt++ == 0)
+               responding++;
+
+       /*
+        * Make sure the server is at least somewhat sane.  If not, ignore
+        * it for later.
+        */
+       if (L_ISZERO(&rec) || !L_ISHIS(&server->org, &rec)) {
+               if (debug > 1)
+                       printf("receive: pkt insane\n");
+               return;
+       }
+
+       /*
+        * Calculate the round trip delay (di) and the clock offset (ci).
+        * We use the equations (reordered from those in the spec):
+        *
+        * d = (t2 - t3) - (t1 - t0)
+        * c = ((t2 - t3) + (t1 - t0)) / 2
+        */
+       t10 = server->org;              /* pkt.xmt == t1 */
+       L_SUB(&t10, &rbufp->recv_time); /* recv_time == t0*/
+
+       t23 = rec;                      /* pkt.rec == t2 */
+       L_SUB(&t23, &org);              /* pkt->org == t3 */
+
+       /* now have (t2 - t3) and (t0 - t1).  Calculate (ci) and (di) */
+       ci = t10;
+       L_ADD(&ci, &t23);
+       L_RSHIFT(&ci);
+
+       /*
+        * Calculate di in t23 in full precision, then truncate
+        * to an s_fp.
+        */
+       L_SUB(&t23, &t10);
+       di = LFPTOFP(&t23);
+
+       if (debug > 3)
+               printf("offset: %s, delay %s\n", lfptoa(&ci, 6), fptoa(di, 5));
+
+       di += (FP_SECOND >> (-(int)NTPDATE_PRECISION))
+           + (FP_SECOND >> (-(int)server->precision)) + NTP_MAXSKW;
+
+       if (di <= 0) {          /* value still too raunchy to use? */
+               L_CLR(&ci);
+               di = 0;
+       } else {
+               di = max(di, NTP_MINDIST);
+       }
+
+
+       /*
+        * This one is valid.  Give it to clock_filter(),
+        */
+       clock_filter(server, di, &ci);
+       if (debug > 1)
+               printf("receive from %s\n", ntoa(&rbufp->srcadr));
+
+       /*
+        * See if we should goes the transmission. If not return now
+        * otherwise have the next event time be shortened
+        */
+       if (server->stratum <= NTP_INFIN)
+           return;     /* server does not have a stratum */
+       if (server->leap == LEAP_NOTINSYNC)
+           return;     /* just booted server or out of sync */
+       if (!L_ISHIS(&server->org, &server->reftime))
+           return;     /* broken host */
+       if (server->trust != 0)
+           return;     /* can not trust it */
+
+       if (server->dispersion < DESIREDDISP)
+           return;     /* we have the desired dispersion */
+
+       server->event_time -= (TIMER_HZ+1);
+}
+
+
+/*
+ * clock_filter - add clock sample, determine a server's delay, dispersion
+ *                and offset
+ */
+static void
+clock_filter(
+       register struct server *server,
+       s_fp di,
+       l_fp *c
+       )
+{
+       register int i, j;
+       int ord[NTP_SHIFT];
+
+       /*
+        * Insert sample and increment nextpt
+        */
+
+       i = server->filter_nextpt;
+       server->filter_delay[i] = di;
+       server->filter_offset[i] = *c;
+       server->filter_soffset[i] = LFPTOFP(c);
+       server->filter_nextpt++;
+       if (server->filter_nextpt >= NTP_SHIFT)
+               server->filter_nextpt = 0;
+
+       /*
+        * Sort indices into increasing delay order
+        */
+       for (i = 0; i < NTP_SHIFT; i++)
+               ord[i] = i;
+       
+       for (i = 0; i < (NTP_SHIFT-1); i++) {
+               for (j = i+1; j < NTP_SHIFT; j++) {
+                       if (server->filter_delay[ord[j]] == 0)
+                               continue;
+                       if (server->filter_delay[ord[i]] == 0
+                           || (server->filter_delay[ord[i]]
+                           > server->filter_delay[ord[j]])) {
+                               register int tmp;
+
+                               tmp = ord[i];
+                               ord[i] = ord[j];
+                               ord[j] = tmp;
+                       }
+               }
+       }
+
+       /*
+        * Now compute the dispersion, and assign values to delay and
+        * offset.  If there are no samples in the register, delay and
+        * offset go to zero and dispersion is set to the maximum.
+        */
+       if (server->filter_delay[ord[0]] == 0) {
+               server->delay = 0;
+               L_CLR(&server->offset);
+               server->soffset = 0;
+               server->dispersion = PEER_MAXDISP;
+       } else {
+               register s_fp d;
+
+               server->delay = server->filter_delay[ord[0]];
+               server->offset = server->filter_offset[ord[0]];
+               server->soffset = LFPTOFP(&server->offset);
+               server->dispersion = 0;
+               for (i = 1; i < NTP_SHIFT; i++) {
+                       if (server->filter_delay[ord[i]] == 0)
+                               d = PEER_MAXDISP;
+                       else {
+                               d = server->filter_soffset[ord[i]]
+                                   - server->filter_soffset[ord[0]];
+                               if (d < 0)
+                                       d = -d;
+                               if (d > PEER_MAXDISP)
+                                       d = PEER_MAXDISP;
+                       }
+                       /*
+                        * XXX This *knows* PEER_FILTER is 1/2
+                        */
+                       server->dispersion += (u_fp)(d) >> i;
+               }
+       }
+       /*
+        * We're done
+        */
+}
+
+
+/* clock_count - count the clock sources we have
+ */
+static void
+clock_count(void)
+{
+       register struct server *server;
+       register int n;
+
+       /* reset counts */
+       validcount = valid_n_low = 0;
+
+       /* go through the list of servers and count the clocks we believe
+        * and that have low dispersion
+        */
+       for (n = 0; n < sys_numservers; n++) {
+               server = sys_servers[n];
+               if (server->delay == 0) {
+                       continue;       /* no data */
+               }
+               if (server->stratum > NTP_INFIN) {
+                       continue;       /* stratum no good */
+               }
+               if (server->delay > NTP_MAXWGT) {
+                       continue;       /* too far away */
+               }
+               if (server->leap == LEAP_NOTINSYNC)
+                       continue;       /* he's in trouble */
+               if (!L_ISHIS(&server->org, &server->reftime)) {
+                       continue;       /* very broken host */
+               }
+               if ((server->org.l_ui - server->reftime.l_ui) >= NTP_MAXAGE) {
+                       continue;       /* too long without sync */
+               }
+               if (server->trust != 0) {
+                       continue;
+               }
+
+               /*
+                * This one is a valid time source..
+                */
+               validcount++;
+
+               /*
+                * See if this one has a okay low dispersion
+                */
+               if (server->dispersion <= DESIREDDISP)
+                   valid_n_low++;
+       }
+
+       if (debug > 1)
+               printf("have %d, valid %d, low %d\n",
+                       responding, validcount, valid_n_low);
+}
+
+
+/*
+ * clock_select - select the pick-of-the-litter clock from the samples
+ *               we've got.
+ */
+static struct server *
+clock_select(void)
+{
+       register struct server *server;
+       register int i;
+       register int nlist;
+       register s_fp d;
+       register int j;
+       register int n;
+       s_fp local_threshold;
+       struct server *server_list[NTP_MAXCLOCK];
+       u_fp server_badness[NTP_MAXCLOCK];
+       struct server *sys_server;
+
+       /*
+        * This first chunk of code is supposed to go through all
+        * servers we know about to find the NTP_MAXLIST servers which
+        * are most likely to succeed.  We run through the list
+        * doing the sanity checks and trying to insert anyone who
+        * looks okay.  We are at all times aware that we should
+        * only keep samples from the top two strata and we only need
+        * NTP_MAXLIST of them.
+        */
+       nlist = 0;      /* none yet */
+       for (n = 0; n < sys_numservers; n++) {
+               server = sys_servers[n];
+               if (server->delay == 0)
+                       continue;       /* no data */
+               if (server->stratum > NTP_INFIN)
+                       continue;       /* stratum no good */
+               if (server->delay > NTP_MAXWGT) {
+                       continue;       /* too far away */
+               }
+               if (server->leap == LEAP_NOTINSYNC)
+                       continue;       /* he's in trouble */
+               if (!L_ISHIS(&server->org, &server->reftime)) {
+                       continue;       /* very broken host */
+               }
+               if ((server->org.l_ui - server->reftime.l_ui)
+                   >= NTP_MAXAGE) {
+                       continue;       /* too long without sync */
+               }
+               if (server->trust != 0) {
+                       continue;
+               }
+
+               /*
+                * This one seems sane.  Find where he belongs
+                * on the list.
+                */
+               d = server->dispersion + server->dispersion;
+               for (i = 0; i < nlist; i++)
+                       if (server->stratum <= server_list[i]->stratum)
+                               break;
+               for ( ; i < nlist; i++) {
+                       if (server->stratum < server_list[i]->stratum)
+                               break;
+                       if (d < (s_fp) server_badness[i])
+                               break;
+               }
+
+               /*
+                * If i points past the end of the list, this
+                * guy is a loser, else stick him in.
+                */
+               if (i >= NTP_MAXLIST)
+                       continue;
+               for (j = nlist; j > i; j--)
+                       if (j < NTP_MAXLIST) {
+                               server_list[j] = server_list[j-1];
+                               server_badness[j]
+                                   = server_badness[j-1];
+                       }
+
+               server_list[i] = server;
+               server_badness[i] = d;
+               if (nlist < NTP_MAXLIST)
+                       nlist++;
+       }
+
+       /*
+        * Got the five-or-less best.  Cut the list where the number of
+        * strata exceeds two.
+        */
+       j = 0;
+       for (i = 1; i < nlist; i++)
+               if (server_list[i]->stratum > server_list[i-1]->stratum)
+                       if (++j == 2) {
+                               nlist = i;
+                               break;
+                       }
+
+       /*
+        * Whew!  What we should have by now is 0 to 5 candidates for
+        * the job of syncing us.  If we have none, we're out of luck.
+        * If we have one, he's a winner.  If we have more, do falseticker
+        * detection.
+        */
+
+       if (nlist == 0)
+               sys_server = 0;
+       else if (nlist == 1) {
+               sys_server = server_list[0];
+       } else {
+               /*
+                * Re-sort by stratum, bdelay estimate quality and
+                * server.delay.
+                */
+               for (i = 0; i < nlist-1; i++)
+                       for (j = i+1; j < nlist; j++) {
+                               if (server_list[i]->stratum
+                                   < server_list[j]->stratum)
+                                       break;  /* already sorted by stratum */
+                               if (server_list[i]->delay
+                                   < server_list[j]->delay)
+                                       continue;
+                               server = server_list[i];
+                               server_list[i] = server_list[j];
+                               server_list[j] = server;
+                       }
+               
+               /*
+                * Calculate the fixed part of the dispersion limit
+                */
+               local_threshold = (FP_SECOND >> (-(int)NTPDATE_PRECISION))
+                   + NTP_MAXSKW;
+
+               /*
+                * Now drop samples until we're down to one.
+                */
+               while (nlist > 1) {
+                       for (n = 0; n < nlist; n++) {
+                               server_badness[n] = 0;
+                               for (j = 0; j < nlist; j++) {
+                                       if (j == n)     /* with self? */
+                                               continue;
+                                       d = server_list[j]->soffset
+                                           - server_list[n]->soffset;
+                                       if (d < 0)      /* absolute value */
+                                               d = -d;
+                                       /*
+                                        * XXX This code *knows* that
+                                        * NTP_SELECT is 3/4
+                                        */
+                                       for (i = 0; i < j; i++)
+                                               d = (d>>1) + (d>>2);
+                                       server_badness[n] += d;
+                               }
+                       }
+
+                       /*
+                        * We now have an array of nlist badness
+                        * coefficients.  Find the badest.  Find
+                        * the minimum precision while we're at
+                        * it.
+                        */
+                       i = 0;
+                       n = server_list[0]->precision;;
+                       for (j = 1; j < nlist; j++) {
+                               if (server_badness[j] >= server_badness[i])
+                                       i = j;
+                               if (n > server_list[j]->precision)
+                                       n = server_list[j]->precision;
+                       }
+                       
+                       /*
+                        * i is the index of the server with the worst
+                        * dispersion.  If his dispersion is less than
+                        * the threshold, stop now, else delete him and
+                        * continue around again.
+                        */
+                       if (server_badness[i] < (local_threshold
+                                                + (FP_SECOND >> (-n))))
+                               break;
+                       for (j = i + 1; j < nlist; j++)
+                               server_list[j-1] = server_list[j];
+                       nlist--;
+               }
+
+               /*
+                * What remains is a list of less than 5 servers.  Take
+                * the best.
+                */
+               sys_server = server_list[0];
+       }
+
+       /*
+        * That's it.  Return our server.
+        */
+       return sys_server;
+}
+
+
+/*
+ * set_local_clock -- handle setting the local clock or displaying info.
+ */
+static void
+set_local_clock(void)
+{
+       register int i;
+       register struct server *server;
+       time_t tmp;
+       double dtemp;
+
+       /*
+        * if setting time then print final analysis
+        */
+       if (set_time)
+           analysis(1);
+
+       /*
+        * pick a clock
+        */
+       server = clock_select();
+
+       /*
+        * do some display of information
+        */
+       if (debug || verbose) {
+               for (i = 0; i < sys_numservers; i++)
+                       printserver(sys_servers[i], stdout);
+               if (debug)
+                       printf("packets sent %ld, received %ld\n",
+                               total_xmit, total_recv);
+       }
+
+       /*
+        * see if we have a server to set the time with
+        */
+       if (server == 0) {
+           if (!set_time || verbose)
+               fprintf(stdout,"No servers available to sync time with\n");
+           exit(1);
+       }
+
+       /*
+        * we have a valid and selected time to use!!!!!
+        */
+
+       /*
+        * if we are not setting the time then display offset and exit
+        */
+       if (!set_time) {
+               fprintf(stdout,
+                       "Your clock is off by %s seconds. (%s) [%ld/%ld]\n",
+                       lfptoa(&server->offset, 7),
+                       ntoa(&server->srcadr),
+                       total_xmit, total_recv);
+               exit(0);
+       }
+
+       /*
+        * set the clock
+        * XXX: Examine the more flexible approach used by ntpdate.
+        * Note that a design consideration here is that we sometimes
+        * _want_ to step the clock by a _huge_ amount in either
+        * direction, because the local clock is completely bogus.
+        * This condition must be recognized and dealt with, so
+        * that we always get a good time when this completes.
+        * -- jhutz+@cmu.edu, 16-Aug-1999
+        */
+       LFPTOD(&server->offset, dtemp);
+       step_systime(dtemp);
+       time(&tmp);
+       fprintf(stdout,"Time set to %.20s [%s %s %ld/%ld]\n",
+               ctime(&tmp)+4,
+               ntoa(&server->srcadr),
+               lfptoa(&server->offset, 7),
+               total_xmit, total_recv);
+       exit(0);
+}
+
+
+/*
+ * findserver - find a server in the list given its address
+ */
+static struct server *
+findserver(
+       struct sockaddr_in *addr
+       )
+{
+       register int i;
+       register u_int32 netnum;
+
+       if (htons(addr->sin_port) != NTP_PORT)
+               return 0;
+       netnum = addr->sin_addr.s_addr;
+
+       for (i = 0; i < sys_numservers; i++) {
+               if (netnum == sys_servers[i]->srcadr.sin_addr.s_addr)
+                       return sys_servers[i];
+       }
+       return 0;
+}
+
+
+/*
+ * timer - process a timer interrupt
+ */
+static void
+timer(void)
+{
+       register int k;
+
+       /*
+        * Bump the current idea of the time
+        */
+       current_time++;
+
+       /*
+        * see if we have reached half time
+        */
+       if (current_time >= half_time && !secondhalf) {
+           secondhalf++;
+           if (debug)
+               printf("\nSecond Half of Timeout!\n");
+           printmsg++;
+       }
+
+       /*
+        * We only want to send a few packets per transmit interrupt
+        * to throttle things
+        */
+       for(k = 0;k < MAXXMITCOUNT;k++) {
+           register int i, oldi;
+           register u_long oldxtime;
+
+           /*
+            * We want to send a packet out for a server that has an
+            * expired event time. However to be mellow about this, we only
+            * use one expired event timer and to avoid starvation we use
+            * the one with the oldest last transmit time.
+            */
+           oldi = -1;
+           oldxtime = 0;
+           for (i = 0; i < sys_numservers; i++) {
+               if (sys_servers[i]->event_time <= current_time) {
+                   if (oldi < 0 || oldxtime > sys_servers[i]->last_xmit) {
+                       oldxtime = sys_servers[i]->last_xmit;
+                       oldi = i;
+                   }
+               }
+           }
+           if (oldi >= 0)
+               transmit(sys_servers[oldi]);
+           else
+               break;  /* no expired event */
+       } /* end of transmit loop */
+}
+
+
+#ifndef SYS_WINNT
+/*
+ * alarming - record the occurance of an alarm interrupt
+ */
+static RETSIGTYPE
+alarming(
+       int sig
+       )
+#else
+void CALLBACK 
+alarming(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
+#endif /* SYS_WINNT */
+{
+       alarm_flag++;
+}
+
+
+/*
+ * init_alarm - set up the timer interrupt
+ */
+static void
+init_alarm(void)
+{
+#ifndef SYS_WINNT
+# ifndef HAVE_TIMER_SETTIME
+       struct itimerval itimer;
+# else
+       struct itimerspec ntpdate_itimer;
+# endif
+#else
+       TIMECAPS tc;
+       UINT wTimerRes, wTimerID;
+# endif /* SYS_WINNT */
+#if defined SYS_CYGWIN32 || defined SYS_WINNT
+       HANDLE hToken;
+       TOKEN_PRIVILEGES tkp;
+       DWORD dwUser = 0;
+#endif /* SYS_WINNT */
+
+       alarm_flag = 0;
+
+#ifndef SYS_WINNT
+# if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME)
+       alarm_flag = 0;
+       /* this code was put in as setitimer() is non existant this us the
+        * POSIX "equivalents" setup - casey
+        */
+       /* ntpdate_timerid is global - so we can kill timer later */
+       if (timer_create (CLOCK_REALTIME, NULL, &ntpdate_timerid) ==
+#  ifdef SYS_VXWORKS
+               ERROR
+#  else
+               -1
+#  endif
+               )
+       {
+               fprintf (stderr, "init_alarm(): timer_create (...) FAILED\n");
+               return;
+       }
+
+       /*      TIMER_HZ = (5)
+        * Set up the alarm interrupt.  The first comes 1/(2*TIMER_HZ)
+        * seconds from now and they continue on every 1/TIMER_HZ seconds.
+        */
+       (void) signal_no_reset(SIGALRM, alarming);
+       ntpdate_itimer.it_interval.tv_sec = ntpdate_itimer.it_value.tv_sec = 0;
+       ntpdate_itimer.it_interval.tv_nsec = 1000000000/TIMER_HZ;
+       ntpdate_itimer.it_value.tv_nsec = 1000000000/(TIMER_HZ<<1);
+       timer_settime(ntpdate_timerid, 0 /* !TIMER_ABSTIME */, &ntpdate_itimer, NULL);
+# else
+       /*
+        * Set up the alarm interrupt.  The first comes 1/(2*TIMER_HZ)
+        * seconds from now and they continue on every 1/TIMER_HZ seconds.
+        */
+       (void) signal_no_reset(SIGALRM, alarming);
+       itimer.it_interval.tv_sec = itimer.it_value.tv_sec = 0;
+       itimer.it_interval.tv_usec = 1000000/TIMER_HZ;
+       itimer.it_value.tv_usec = 1000000/(TIMER_HZ<<1);
+       setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
+# endif
+#if defined SYS_CYGWIN32
+       /*
+        * Get previleges needed for fiddling with the clock
+        */
+
+       /* get the current process token handle */
+       if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
+               msyslog(LOG_ERR, "OpenProcessToken failed: %m");
+               exit(1);
+       }
+       /* get the LUID for system-time privilege. */
+       LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid);
+       tkp.PrivilegeCount = 1;  /* one privilege to set */
+       tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
+       /* get set-time privilege for this process. */
+       AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES) NULL, 0);
+       /* cannot test return value of AdjustTokenPrivileges. */
+       if (GetLastError() != ERROR_SUCCESS)
+               msyslog(LOG_ERR, "AdjustTokenPrivileges failed: %m");
+#endif
+#else  /* SYS_WINNT */
+       _tzset();
+
+       /*
+        * Get previleges needed for fiddling with the clock
+        */
+
+       /* get the current process token handle */
+       if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
+               msyslog(LOG_ERR, "OpenProcessToken failed: %m");
+               exit(1);
+       }
+       /* get the LUID for system-time privilege. */
+       LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid);
+       tkp.PrivilegeCount = 1;  /* one privilege to set */
+       tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
+       /* get set-time privilege for this process. */
+       AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES) NULL, 0);
+       /* cannot test return value of AdjustTokenPrivileges. */
+       if (GetLastError() != ERROR_SUCCESS)
+               msyslog(LOG_ERR, "AdjustTokenPrivileges failed: %m");
+
+       /*
+        * Set up timer interrupts for every 2**EVENT_TIMEOUT seconds
+        * Under Win/NT, expiry of timer interval leads to invocation
+        * of a callback function (on a different thread) rather than
+        * generating an alarm signal
+        */
+
+       /* determine max and min resolution supported */
+       if(timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
+               msyslog(LOG_ERR, "timeGetDevCaps failed: %m");
+               exit(1);
+       }
+       wTimerRes = min(max(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax);
+       /* establish the minimum timer resolution that we'll use */
+       timeBeginPeriod(wTimerRes);
+
+       /* start the timer event */
+       wTimerID = timeSetEvent(
+               (UINT) (1000/TIMER_HZ),    /* Delay */
+               wTimerRes,                       /* Resolution */
+               (LPTIMECALLBACK) alarming, /* Callback function */
+               (DWORD) dwUser,          /* User data */
+               TIME_PERIODIC);          /* Event type (periodic) */
+       if (wTimerID == 0) {
+               msyslog(LOG_ERR, "timeSetEvent failed: %m");
+               exit(1);
+       }
+#endif /* SYS_WINNT */
+}
+
+
+/*
+ * init_io - initialize I/O data and open socket
+ */
+static void
+init_io(void)
+{
+#ifdef SYS_WINNT
+       WORD wVersionRequested;
+       WSADATA wsaData;
+       init_transmitbuff();
+#endif /* SYS_WINNT */
+
+       /*
+        * Init buffer free list and stat counters
+        */
+       init_recvbuff(sys_numservers + 2);
+
+#if defined(HAVE_SIGNALED_IO)
+       set_signal();
+#endif
+
+#ifdef SYS_WINNT
+       wVersionRequested = MAKEWORD(1,1);
+       if (WSAStartup(wVersionRequested, &wsaData))
+       {
+               msyslog(LOG_ERR, "No useable winsock.dll: %m");
+               exit(1);
+       }
+#endif /* SYS_WINNT */
+
+       BLOCKIO();
+
+       /* create a datagram (UDP) socket */
+       if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+               msyslog(LOG_ERR, "socket() failed: %m");
+               exit(1);
+               /*NOTREACHED*/
+       }
+
+       /*
+        * bind the socket to the NTP port
+        */
+       if (!debug && set_time && !unpriv_port) {
+               struct sockaddr_in addr;
+
+               memset((char *)&addr, 0, sizeof addr);
+               addr.sin_family = AF_INET;
+               addr.sin_port = htons(NTP_PORT);
+               addr.sin_addr.s_addr = htonl(INADDR_ANY);
+               if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+#ifndef SYS_WINNT
+                       if (errno == EADDRINUSE)
+#else
+                       if (WSAGetLastError() == WSAEADDRINUSE)
+#endif
+                               msyslog(LOG_ERR,
+                                   "the NTP socket is in use, exiting");
+                       else
+                               msyslog(LOG_ERR, "bind() fails: %m");
+                       exit(1);
+               }
+       }
+
+       FD_ZERO(&fdmask);
+       FD_SET(fd, &fdmask);
+
+       /*
+        * set non-blocking,
+        */
+
+#ifdef USE_FIONBIO
+       /* in vxWorks we use FIONBIO, but the others are defined for old systems, so
+        * all hell breaks loose if we leave them defined
+        */
+#undef O_NONBLOCK
+#undef FNDELAY
+#undef O_NDELAY
+#endif
+
+#if defined(O_NONBLOCK) /* POSIX */
+       if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+       {
+               msyslog(LOG_ERR, "fcntl(O_NONBLOCK) fails: %m");
+               exit(1);
+               /*NOTREACHED*/
+       }
+#elif defined(FNDELAY)
+       if (fcntl(fd, F_SETFL, FNDELAY) < 0)
+       {
+               msyslog(LOG_ERR, "fcntl(FNDELAY) fails: %m");
+               exit(1);
+               /*NOTREACHED*/
+       }
+#elif defined(O_NDELAY) /* generally the same as FNDELAY */
+       if (fcntl(fd, F_SETFL, O_NDELAY) < 0)
+       {
+               msyslog(LOG_ERR, "fcntl(O_NDELAY) fails: %m");
+               exit(1);
+               /*NOTREACHED*/
+       }
+#elif defined(FIONBIO)
+       if (
+# if defined(VMS)
+               (ioctl(fd,FIONBIO,&1) < 0)
+# elif defined(SYS_WINNT)
+               (ioctlsocket(fd,FIONBIO,(u_long *) &on) == SOCKET_ERROR)
+# else
+               (ioctl(fd,FIONBIO,&on) < 0)
+# endif
+          )
+       {
+               msyslog(LOG_ERR, "ioctl(FIONBIO) fails: %m");
+               exit(1);
+               /*NOTREACHED*/
+       }
+#elif defined(FIOSNBIO)
+       if (ioctl(fd,FIOSNBIO,&on) < 0)
+       {
+               msyslog(LOG_ERR, "ioctl(FIOSNBIO) fails: %m");
+               exit(1);
+               /*NOTREACHED*/
+       }
+#else
+# include "Bletch: Need non-blocking I/O!"
+#endif
+
+#ifdef HAVE_SIGNALED_IO
+       init_socket_sig(fd);
+#endif /* not HAVE_SIGNALED_IO */
+
+       UNBLOCKIO();
+}
+
+
+/*
+ * sendpkt - send a packet to the specified destination
+ */
+static int
+sendpkt(
+       struct sockaddr_in *dest,
+       struct pkt *pkt,
+       int len
+       )
+{
+       int cc;
+       static int horriblecnt = 0;
+#ifdef SYS_WINNT
+       DWORD err;
+#endif /* SYS_WINNT */
+
+       total_xmit++;   /* count it */
+
+       if (horrible) {
+           if (++horriblecnt > HORRIBLEOK) {
+               if (debug > 3)
+                       printf("dropping send (%s)\n", ntoa(dest));
+               if (horriblecnt >= HORRIBLEOK+horrible)
+                   horriblecnt = 0;
+               return 0;
+           }
+       }
+
+
+       cc = sendto(fd, (char *)pkt, len, 0, (struct sockaddr *)dest,
+           sizeof(struct sockaddr_in));
+#ifndef SYS_WINNT
+       if (cc == -1) {
+               if (errno != EWOULDBLOCK && errno != ENOBUFS)
+#else
+       if (cc == SOCKET_ERROR) {
+               err = WSAGetLastError();
+               if (err != WSAEWOULDBLOCK && err != WSAENOBUFS)
+#endif /* SYS_WINNT */
+                       msyslog(LOG_ERR, "sendto(%s): %m", ntoa(dest));
+               return -1;
+       }
+       return 0;
+}
+
+
+/*
+ * input_handler - receive packets asynchronously
+ */
+void
+input_handler(l_fp *xts)
+{
+       register int n;
+       register struct recvbuf *rb;
+       struct timeval tvzero;
+       int fromlen;
+       l_fp ts = *xts; /* we ignore xts, but make the compiler happy */
+       fd_set fds;
+
+       /*
+        * Do a poll to see if we have data
+        */
+       for (;;) {
+               fds = fdmask;
+               tvzero.tv_sec = tvzero.tv_usec = 0;
+               n = select(fd+1, &fds, (fd_set *)0, (fd_set *)0, &tvzero);
+
+               /*
+                * If nothing to do, just return.  If an error occurred,
+                * complain and return.  If we've got some, freeze a
+                * timestamp.
+                */
+               if (n == 0)
+                       return;
+               else if (n == -1) {
+                       if (errno != EINTR) {
+                               msyslog(LOG_ERR, "select() error: %m");
+                       }
+                       return;
+               }
+               get_systime(&ts);
+
+               /*
+                * Get a buffer and read the frame.  If we
+                * haven't got a buffer, or this is received
+                * on the wild card socket, just dump the packet.
+                */
+               if (initializing || free_recvbuffs == 0) {
+                       char buf[100];
+
+#ifndef SYS_WINNT
+                       (void) read(fd, buf, sizeof buf);
+#else
+                       /* NT's _read does not operate on nonblocking sockets
+                        * either recvfrom or ReadFile() has to be used here.
+                        * ReadFile is used in [ntpd]ntp_intres() and ntpdc,
+                        * just to be different use recvfrom() here
+                        */
+                       recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)0, NULL);
+#endif /* SYS_WINNT */
+                       continue;
+               }
+
+               rb = get_free_recv_buffer();
+
+               fromlen = sizeof(struct sockaddr_in);
+               rb->recv_length = recvfrom(fd, (char *)&rb->recv_pkt,
+                   sizeof(rb->recv_pkt), 0,
+                   (struct sockaddr *)&rb->srcadr, &fromlen);
+               if (rb->recv_length == -1) {
+                       freerecvbuf(rb);
+                       continue;
+               }
+
+               /*
+                * Got one.  Mark how and when it got here,
+                * put it on the full list.
+                */
+               rb->recv_time = ts;
+               add_full_recv_buffer(rb);
+               total_recv++;   /* count it */
+       }
+}
+
+
+/* XXX ELIMINATE printserver similar in ntptrace.c, ntpdate.c */
+/*
+ * printserver - print detail information for a server
+ */
+static void
+printserver(
+       register struct server *pp,
+       FILE *fp
+       )
+{
+       register int i;
+       char junk[5];
+       char *str;
+
+       if (!debug) {
+           (void) fprintf(fp,
+               "%-15s %d/%d %03o v%d s%d offset %9s delay %s disp %s\n",
+               ntoa(&pp->srcadr),
+               pp->xmtcnt,pp->rcvcnt,pp->reach,
+               pp->version,pp->stratum,
+               lfptoa(&pp->offset, 6), ufptoa(pp->delay, 5),
+               ufptoa(pp->dispersion, 4));
+           return;
+       }
+
+       (void) fprintf(fp, "server %s, port %d\n",
+                          ntoa(&pp->srcadr), ntohs(pp->srcadr.sin_port));
+
+       (void) fprintf(fp, "stratum %d, precision %d, leap %c%c, trust %03o\n",
+                          pp->stratum, pp->precision,
+                          pp->leap & 0x2 ? '1' : '0',
+                          pp->leap & 0x1 ? '1' : '0',
+                          pp->trust);
+
+       if (pp->stratum == 1) {
+               junk[4] = 0;
+               memmove(junk, (char *)&pp->refid, 4);
+               str = junk;
+       } else {
+               str = numtoa(pp->refid);
+       }
+       (void) fprintf(fp,
+                          "refid [%s], delay %s, dispersion %s\n",
+                          str, fptoa(pp->delay, 5),
+                          ufptoa(pp->dispersion, 5));
+
+       (void) fprintf(fp, "transmitted %d, received %d, reachable %03o\n",
+           pp->xmtcnt, pp->rcvcnt, pp->reach);
+
+       (void) fprintf(fp, "reference time:    %s\n",
+                          prettydate(&pp->reftime));
+       (void) fprintf(fp, "originate timestamp: %s\n",
+                          prettydate(&pp->org));
+       (void) fprintf(fp, "transmit timestamp:  %s\n",
+                          prettydate(&pp->xmt));
+
+       (void) fprintf(fp, "filter delay: ");
+       for (i = 0; i < NTP_SHIFT; i++) {
+               (void) fprintf(fp, " %-8.8s", fptoa(pp->filter_delay[i], 5));
+               if (i == (NTP_SHIFT>>1)-1)
+                       (void) fprintf(fp, "\n        ");
+       }
+       (void) fprintf(fp, "\n");
+
+       (void) fprintf(fp, "filter offset:");
+       for (i = 0; i < PEER_SHIFT; i++) {
+               (void) fprintf(fp, " %-8.8s", lfptoa(&pp->filter_offset[i], 6));
+               if (i == (PEER_SHIFT>>1)-1)
+                       (void) fprintf(fp, "\n        ");
+       }
+       (void) fprintf(fp, "\n");
+
+       (void) fprintf(fp, "delay %s, dispersion %s\n",
+                          fptoa(pp->delay, 5), ufptoa(pp->dispersion, 5));
+
+       (void) fprintf(fp, "offset %s\n\n",
+                          lfptoa(&pp->offset, 6));
+}
+
+#if !defined(HAVE_VSPRINTF)
+int
+vsprintf(
+       char *str,
+       const char *fmt,
+       va_list ap
+       )
+{
+       FILE f;
+       int len;
+
+       f._flag = _IOWRT+_IOSTRG;
+       f._ptr = str;
+       f._cnt = 32767;
+       len = _doprnt(fmt, ap, &f);
+       *f._ptr = 0;
+       return (len);
+}
+#endif