]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1169] quiet compiler warnings
authorDave Hart <hart@ntp.org>
Tue, 28 Apr 2009 06:59:44 +0000 (06:59 +0000)
committerDave Hart <hart@ntp.org>
Tue, 28 Apr 2009 06:59:44 +0000 (06:59 +0000)
Re-enable gcc -Wstrict-prototypes when not building with OpenSSL
Enable gcc -Wstrict-overflow
ntpq/ntpdc emit newline after accepting password on Windows

bk: 49f6a9608xgBUMpC9_sqXrYItlw8xA

40 files changed:
ChangeLog
configure.ac
gsoc_sntp/crypto.c
gsoc_sntp/crypto.h
gsoc_sntp/kod_management.c
gsoc_sntp/kod_management.h
gsoc_sntp/log.c
gsoc_sntp/log.h
gsoc_sntp/main.c
gsoc_sntp/networking.c
include/isc/file.h
include/isc/mem.h
include/ntp_config.h
include/ntp_stdlib.h
include/ntpsim.h
libisc/inet_ntop.c
libisc/inet_pton.c
libisc/mem.c
libntp/Makefile.am
libntp/machines.c
libntp/numtoa.c
libntp/numtohost.c
libntp/prettydate.c
libntp/statestr.c
libparse/parsesolaris.c
ntpd/ntp_config.c
ntpd/ntp_intres.c
ntpd/ntp_parser.y
ntpd/ntp_refclock.c
ntpd/ntp_util.c
ntpd/ntpsim.c
ntpd/refclock_mx4200.c
ntpd/refclock_palisade.c
ntpd/refclock_palisade.h
ntpq/ntpq.c
parseutil/dcfd.c
ports/winnt/libntp/libntp.vcproj
ports/winnt/ntpd/ntpd.vcproj
ports/winnt/ntpd/ntservice.c
util/ntp-keygen.c

index 22d16f4903f311641c7987773578b0e424d806c2..f326f71b0a8ba60479e7462788015a5e601833c5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+* [Bug 1169] quiet compiler warnings
+* Re-enable gcc -Wstrict-prototypes when not building with OpenSSL
+* Enable gcc -Wstrict-overflow
+* ntpq/ntpdc emit newline after accepting password on Windows
 (4.2.5p166) 2009/04/25 Released by Harlan Stenn <stenn@ntp.org>
 * [Bug 1165] Clean up small memory leaks in the  config file parser
 * Correct logconfig keyword declaration to MULTIPLE_ARG
index 72a0cf541543e4db99efb6542a3fae236b0ddadb..373742b10e235f8325810201346f151c5a41e70e 100644 (file)
@@ -255,24 +255,14 @@ case "$GCC" in
     CFLAGS="$CFLAGS -Wmissing-prototypes"
     CFLAGS="$CFLAGS -Wpointer-arith"
     CFLAGS="$CFLAGS -Wshadow"
-    #
-    # OpenSSL has a number of callback prototypes
-    # inside other function prototypes which trigger
-    # warnings with -Wstrict-prototypes, such as:
-    #
-    # int i2d_RSA_NET(const RSA *a, unsigned char **pp, 
-    #                 int (*cb)(), int sgckey);
-    #                 ^^^^^^^^^^^
-    #
-    CFLAGS="$CFLAGS -Wno-strict-prototypes"
     # CFLAGS="$CFLAGS -Wtraditional"
     # CFLAGS="$CFLAGS -Wwrite-strings"
     CFLAGS="$CFLAGS -Winit-self"
     case "$ac_cv_gcc_Wstrict_overflow" in
      yes)
-       #not yet: CFLAGS="$CFLAGS -Wstrict-overflow"
+       CFLAGS="$CFLAGS -Wstrict-overflow"
     esac
-    ;;
+    # if building with OpenSSL, -Wno-strict-prototypes is added later
 esac
 
 case "$host" in
@@ -3153,33 +3143,57 @@ case "$ans" in
 esac
 AC_MSG_RESULT([$ans])
 
+AC_MSG_CHECKING([if we will use crypto])
 AC_ARG_WITH(crypto,
        AC_HELP_STRING([--with-crypto], [+ =openssl]),
 [ans=$withval], [ans=yes])
 case "$ans" in
- no) ;;
+ no)
+    ;;
  yes|openssl)
     if test -z "$OPENSSL_LIB" -o -z "$OPENSSL_INC"
     then
        ans=no
     else
-       # We have OpenSSL inc/lib - use them.
-       ans=openssl
-       CPPFLAGS="$CPPFLAGS -I$OPENSSL_INC"
-       LDFLAGS="$LDFLAGS -L$OPENSSL_LIB"
-       case "$need_dash_r" in
-        1) LDFLAGS="$LDFLAGS -R$OPENSSL_LIB"
-           ;;
-       esac
-       AC_SUBST(LCRYPTO, [-lcrypto])
-       AC_DEFINE(OPENSSL, , [Use OpenSSL?])
-       AC_CHECK_FUNCS(EVP_md2 EVP_mdc2)
+       ans=yes
     fi
-    ;;
 esac
-AC_MSG_CHECKING(for the level of crypto support)
+ntp_openssl=$ans
 AC_MSG_RESULT([$ans])
 
+case "$ntp_openssl" in
+ yes)
+    # We have OpenSSL inc/lib - use them.
+    CPPFLAGS="$CPPFLAGS -I$OPENSSL_INC"
+    LDFLAGS="$LDFLAGS -L$OPENSSL_LIB"
+    case "$need_dash_r" in
+     1) LDFLAGS="$LDFLAGS -R$OPENSSL_LIB"
+    esac
+    AC_SUBST(LCRYPTO, [-lcrypto])
+    AC_DEFINE(OPENSSL, , [Use OpenSSL?])
+    AC_CHECK_FUNCS([EVP_md2 EVP_mdc2])
+esac
+
+#
+# OpenSSL has a number of callback prototypes inside other function
+# prototypes which trigger copious warnings with -Wstrict-prototypes,
+# (which is included in -Wall).
+#
+# An example:
+#
+# int i2d_RSA_NET(const RSA *a, unsigned char **pp, 
+#                 int (*cb)(), int sgckey);
+#                 ^^^^^^^^^^^
+#
+# The OpenSSL headers probably haven't been fixed in this regard
+# due to the hoops you have to jump through to stay compatible with
+# K&R C compilers.
+#
+case "$GCC$ntp_openssl" in
+ yesyes)
+    CFLAGS="$CFLAGS -Wno-strict-prototypes"
+esac
+
 AC_MSG_CHECKING([if we want to compile with ElectricFence])
 AC_ARG_WITH(electricfence,
        AC_HELP_STRING([--with-electricfence], [- compile with ElectricFence malloc debugger]),
index e3335dcb3d29bfa2a3d39c7e5578d8b1124ff97d..acf48a0b0713e05d6ad5ee2b820e15b4c6d9f92b 100644 (file)
@@ -67,7 +67,7 @@ auth_md5 (
  */
 int
 auth_init (
-               char *keyfile,
+               const char *keyfile,
                struct key **keys
                )
 {
@@ -75,7 +75,7 @@ auth_init (
        struct key *prev = NULL;
 
        register int a, line_limit;
-       int scan_cnt, line_cnt = 0, key_cnt = 0;
+       int scan_cnt, line_cnt = 0;
        char kbuf[96];
 
        if(keyf == NULL) {
@@ -104,7 +104,7 @@ auth_init (
                for(a=0; a<strlen(kbuf) && a < 96; a++) {
                        if(kbuf[a] == '#') {
                                line_limit = a;
-                               a = 96;
+                               break;
                        }
                }
 
index b89d206416953bf9a95ca65ab67522d840c6fb91..70018ef0c3c56a3f19bb090f39ed7ed940b45e21 100644 (file)
@@ -42,7 +42,7 @@ struct key {
 };
 
 int auth_md5(char *pkt_data, int mac_size, struct key *cmp_key);
-int auth_init(char *keyfile, struct key **keys);
+int auth_init(const char *keyfile, struct key **keys);
 void get_key(int key_id, struct key **d_key);
 
 
index cf5f8ee5c45fef4af2704cc0ceecbabdb404260c..51ce8b55e34c2add6812b66409c68a110a34b03f 100644 (file)
@@ -24,7 +24,7 @@
 #define DEBUG
 
 int kod_init = 0, entryc = 0;
-char *kod_db_file;
+const char *kod_db_file;
 struct kod_entry *kod_db;
 FILE *db_s;
 
@@ -163,7 +163,7 @@ write_kod_db (
                
 void 
 kod_init_kod_db (
-               char *db_file
+               const char *db_file
                )
 {
        if(kod_init)
index e1c6cc71d0e93cd91259ce598ec838656d795a47..3629dbd3763b2d38be4a8492029572f03f7a062a 100644 (file)
@@ -30,7 +30,7 @@ int kod_entry_exists (char *search_str);
 
 void add_entry (char *hostname, char *type);
 void delete_entry (char *hostname, char *type);
-void kod_init_kod_db (char *db_file);
+void kod_init_kod_db (const char *db_file);
 void write_kod_db (void);
 void kod_atexit (void);
 
index f105e5b0fb3db17e7d2719e6ae35983e806de523..1584e9669dedfc9360e0e0d905c880f05a957324 100644 (file)
@@ -67,7 +67,7 @@ void debug_msg(char *message) {
        }
 }
 
-void init_log(char *logfile) {
+void init_log(const char *logfile) {
        log_file = fopen(logfile, "a");
        
        if(log_file == NULL) {
index 0a8026297274204085105b3b6ab69b509aa1d75f..746c8a5d4e1a5c70792a0222d2c371e15490aa1d 100644 (file)
@@ -30,7 +30,7 @@
 void log_msg(char *message, char type);
 void debug_msg(char *message);
 
-void init_log(char *logfile);
+void init_log(const char *logfile);
 void cleanup_log(void);
 
 #endif
index 355c03423dabd35e7444da1d7b004bd882a0819e..c81e96a14a1103757e26b7f8f5647c700bed2454 100644 (file)
@@ -1,4 +1,5 @@
 #include <isc/result.h>
+#include <isc/net.h>
 #include <l_stdlib.h>
 #include <ntp_fp.h>
 #include <ntp.h>
@@ -85,18 +86,18 @@ sntp_main (
 
        /* Initialize logging system */
        if(HAVE_OPT(FILELOG)) {
-               init_log((char *)OPT_ARG(FILELOG));
+               init_log(OPT_ARG(FILELOG));
        }
 
        /* If there's a specified KOD file init KOD system. 
         * If not and system may save to HD use default file.
         */
        if(HAVE_OPT(KOD)) {
-               kod_init_kod_db((char *)OPT_ARG(KOD));
+               kod_init_kod_db(OPT_ARG(KOD));
        }
 
        if(HAVE_OPT(KEYFILE)) {
-               auth_init((char *)OPT_ARG(KEYFILE), &keys);
+               auth_init(OPT_ARG(KEYFILE), &keys);
        }
 
 
index a4472df1a7b85db8b929e885fec0dc551429da5a..1fa641b47650e3e9809d89181bde80f30887d4e6 100644 (file)
@@ -244,7 +244,7 @@ recv_bcst_data (
 {
        struct timeval timeout_tv;
        fd_set bcst_fd;
-
+       char *buf;
        int btrue = 1;
        int recv_bytes = 0;
 
@@ -252,22 +252,17 @@ recv_bcst_data (
        setsockopt(rsock, SOL_SOCKET, SO_REUSEADDR, &btrue, sizeof(btrue));
 
        if(sas->ss_family == AF_INET) {
-               struct sockaddr_in sin;
                struct ip_mreq mdevadr;
        
-               sin.sin_family = AF_INET;
-               sin.sin_addr.s_addr = htonl(INADDR_ANY);
-               sin.sin_port = htons(123);
-
                if(bind(rsock, (struct sockaddr *) sas, SOCKLEN(sas)) < 0) {}
 
 
                if(setsockopt(rsock, IPPROTO_IP, IP_MULTICAST_LOOP, &btrue, sizeof(btrue)) < 0) {
                        /* some error message regarding setting up multicast loop */
                        return BROADCAST_FAILED;
-           }
+               }
 
-               char *buf = ss_to_str(sas);
+               buf = ss_to_str(sas);
 
                mdevadr.imr_multiaddr.s_addr = inet_addr(buf); 
                mdevadr.imr_interface.s_addr = htonl(INADDR_ANY);
@@ -284,7 +279,7 @@ recv_bcst_data (
 
                if (setsockopt(rsock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mdevadr, sizeof(mdevadr)) < 0) {
                        if(ENABLED_OPT(NORMALVERBOSE)) {
-                               char *buf = ss_to_str(sas);
+                               buf = ss_to_str(sas);
 
                                printf("sntp recv_bcst_data: Couldn't add IP membership for %s\n", buf);
                                
@@ -295,13 +290,8 @@ recv_bcst_data (
                }
        }
        else if(sas->ss_family == AF_INET6) {
-               struct sockaddr_in6 sin6;
                struct ipv6_mreq mdevadr;
 
-               sin6.sin6_family = AF_INET6;
-               sin6.sin6_addr = in6addr_any;
-               sin6.sin6_port = htons(123);
-
                if(bind(rsock, (struct sockaddr *) sas, sizeof(sas)) < 0) {
                        if(ENABLED_OPT(NORMALVERBOSE))
                                printf("sntp recv_bcst_data: Couldn't bind() address.\n");
@@ -318,7 +308,7 @@ recv_bcst_data (
                                                                                                                 
                if(!IN6_IS_ADDR_MULTICAST((struct in6_addr *) &mdevadr.ipv6mr_multiaddr)) {
                        if(ENABLED_OPT(NORMALVERBOSE)) {
-                               char *buf = ss_to_str(sas); 
+                               buf = ss_to_str(sas); 
 
                                printf("sntp recv_bcst_data: %s is not a broad-/multicast address, aborting...\n", buf);
                                
@@ -330,7 +320,7 @@ recv_bcst_data (
 
                if (setsockopt(rsock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mdevadr, sizeof(mdevadr)) < 0) {
                        if(ENABLED_OPT(NORMALVERBOSE)) {
-                               char *buf = ss_to_str(sas); 
+                               buf = ss_to_str(sas); 
 
                                printf("sntp recv_bcst_data: Couldn't join group for %s\n", buf);
                                
@@ -361,7 +351,7 @@ recv_bcst_data (
 
                case 0:
                        if(ENABLED_OPT(NORMALVERBOSE))
-                               printf("sntp recv_bcst_data: select() reached timeout (%i sec), aborting.\n", timeout_tv.tv_sec);
+                               printf("sntp recv_bcst_data: select() reached timeout (%li sec), aborting.\n", timeout_tv.tv_sec);
 
                        return BROADCAST_FAILED;
                        break;
index 16b007572581e99cbddb86d5c292a48ee70514a0..b2d9e8f5126aaf1b747d603f9f87e21765a9689a 100644 (file)
 ISC_LANG_BEGINDECLS
 
 isc_result_t
-isc_file_settime(const char *file, isc_time_t *time);
+isc_file_settime(const char *file, isc_time_t *mtime);
 
 isc_result_t
-isc_file_getmodtime(const char *file, isc_time_t *time);
+isc_file_getmodtime(const char *file, isc_time_t *mtime);
 /*!<
  * \brief Get the time of last modication of a file.
  *
index f8e73d0e73d894285786c97c08c3205026f0d838..7881e18ec378c78c67c4ed3f11af12293c4362f2 100644 (file)
@@ -1,3 +1,7 @@
+/*
+ * short-circuited NTP-local imitation of isc/mem.h
+ */
+
 /*
  * Copyright (C) 1997-2001  Internet Software Consortium.
  *
 #ifndef ISC_MEM_H
 #define ISC_MEM_H 1
 
+#include <stdlib.h>
 #include <stdio.h>
-#include <isc/types.h>
 
-void *         
-isc_mem_get(isc_mem_t *, size_t);
-void           
-isc_mem_put(isc_mem_t *, void *, size_t);
+
+#define        isc_mem_get(c, cnt)             malloc((cnt) ? (cnt) : 1)
+#define        isc_mem_put(c, mem, cnt)        free(mem)
+#define isc_mem_free(c, mem)           free(mem)
+#define isc_mem_strdup(c, str)         strdup(str)
 
 #endif /* ISC_MEM_H */
index 58b8f5d2762923eace848d5911bdd2726bbe6070..e8845616f995b3c3a4ce90a31f54217d74b55f64 100644 (file)
@@ -177,6 +177,7 @@ struct REMOTE_CONFIG_INFO {
 struct peer_node *create_peer_node(int hmode, struct address_node *addr, queue *options);
 struct unpeer_node *create_unpeer_node(struct address_node *addr);
 struct address_node *create_address_node(char *addr, int type);
+void destroy_address_node(struct address_node *my_node);
 queue *enqueue_in_new_queue(void *my_node);
 struct attr_val *create_attr_dval(int attr, double value);
 struct attr_val *create_attr_ival(int attr, int value);
index 9496b5d6e4615b0e53065431724b6f320a7210f5..f6f26549efed5325c0164273817cda66d78bc4ef 100644 (file)
@@ -70,8 +70,8 @@ extern        char *  inttoa          (long);
 extern char *  mfptoa          (u_long, u_long, short);
 extern char *  mfptoms         (u_long, u_long, short);
 extern const char * modetoa    (int);
-extern  const char * eventstr   (int);
-extern  const char * ceventstr  (int);
+extern  const char * eventstr  (int);
+extern  const char * ceventstr (int);
 extern char *  statustoa       (int, int);
 extern  const char * sysstatstr (int);
 extern  const char * peerstatstr (int);
@@ -79,8 +79,8 @@ extern  const char * clockstatstr (int);
 extern struct sockaddr_storage* netof (struct sockaddr_storage*);
 extern char *  numtoa          (u_int32);
 extern char *  numtohost       (u_int32);
-extern char * socktoa           (struct sockaddr_storage *);
-extern char * socktohost        (struct sockaddr_storage *);
+extern char *  socktoa         (struct sockaddr_storage *);
+extern char *  socktohost      (struct sockaddr_storage *);
 extern int     octtoint        (const char *, u_long *);
 extern u_long  ranp2           (int);
 extern char *  refnumtoa       (struct sockaddr_storage *);
@@ -89,7 +89,7 @@ extern        char *  uinttoa         (u_long);
 
 extern int     decodenetnum    (const char *, struct sockaddr_storage *);
 
-extern const char *    FindConfig      (const char *);
+extern const char * FindConfig (const char *);
 
 extern void    signal_no_reset (int, RETSIGTYPE (*func)(int));
 
index 9be8f299014f9bc9d5223088aff419434424745f..1d9e6d7ca97363f06487104fba99300eea728387 100644 (file)
@@ -125,6 +125,7 @@ extern sim_info simulation;         /* Simulation Control Variables */
 
 /* Function Prototypes */
 
+int     ntpsim                  (int argc, char *argv[]);
 Event    *event                  (double t, funcTkn f);
 void     sim_event_timer         (Event *e);
 int      simulate_server         (struct sockaddr_storage *serv_addr,
index 395d0e50db60d66154ac8010bf756c0010b069c2..feb85f1351eaa97b8eed16629a6e2915dc93d23f 100644 (file)
@@ -22,6 +22,8 @@ static char rcsid[] =
 
 #include <config.h>
 
+#ifdef ISC_PLATFORM_NEEDNTOP
+
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
@@ -196,3 +198,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
        return (dst);
 }
 #endif /* AF_INET6 */
+
+#else
+int inet_ntop_c_not_empty;
+#endif /* ISC_PLATFORM_NEEDNTOP */
index afda394cab22b1727fefcd19da1745b61a4ff034..3416dffda6c4a8f50c74ffb1ad76eb99bebae676 100644 (file)
@@ -22,6 +22,8 @@ static char rcsid[] =
 
 #include <config.h>
 
+#ifdef ISC_PLATFORM_NEEDPTON
+
 #include <errno.h>
 #include <string.h>
 
@@ -209,3 +211,7 @@ inet_pton6(const char *src, unsigned char *dst) {
        memcpy(dst, tmp, NS_IN6ADDRSZ);
        return (1);
 }
+
+#else
+int inet_pton_c_not_empty;
+#endif /* ISC_PLATFORM_NEEDPTON */
index 39f1e5c7ce45dc36e605eba6f1fdb34aced60762..f503c84fa0bdaf38bf691cfd019f4a37ecb1d9f3 100644 (file)
@@ -1,3 +1,8 @@
+/*
+ * this file is leaving the NTP build in favor of
+ * inline macros in isc/mem.h for now
+ */
+
 /*
  * Copyright (C) 1997-2002  Internet Software Consortium.
  *
index 5da1af1fda3b9c502f3d32ebffb7892ab42e6de2..790a8fb81e7ba8ea660e8c1ce53a14d2a0e52342 100644 (file)
@@ -17,11 +17,9 @@ libntp_a_SRCS = a_md5encrypt.c adjtime.c atoint.c atolfp.c atouint.c \
        uglydate.c uinttoa.c ymd2yd.c \
        $(srcdir)/../libisc/assertions.c $(srcdir)/../libisc/error.c \
        $(srcdir)/../libisc/interfaceiter.c $(srcdir)/../libisc/lib.c \
-       $(srcdir)/../libisc/log.c $(srcdir)/../libisc/md5.c \
-       $(srcdir)/../libisc/mem.c $(srcdir)/../libisc/msgcat.c \
+       $(srcdir)/../libisc/md5.c $(srcdir)/../libisc/msgcat.c \
        $(srcdir)/../libisc/net.c $(srcdir)/../libisc/isc_strerror.c \
-       $(srcdir)/../libisc/inet_ntop.c \
-       $(srcdir)/../libisc/inet_pton.c \
+       $(srcdir)/../libisc/inet_ntop.c $(srcdir)/../libisc/inet_pton.c \
        $(srcdir)/../libisc/netaddr.c $(srcdir)/../libisc/sockaddr.c \
        $(srcdir)/../libisc/netscope.c
 libntp_a_SOURCES = systime.c $(libntp_a_SRCS)
index c8e4e07c9c0ec271e3d4c399b98656ded9615afc..481837af1ac35b1acbe0c8f5afed4716cdc27fe1 100644 (file)
@@ -509,6 +509,9 @@ getpass(const char * prompt)
        }
        password[i] = '\0';
 
+       fputc('\n', stderr);
+       fflush(stderr);
+
        return password;
 }
 #endif /* SYS_WINNT */
index de95118afe0467708635680af0c7830d164504e7..4ec6036ec74e459760239a6cf3233d28e67c8f7c 100644 (file)
@@ -1,6 +1,14 @@
 /*
  * numtoa - return asciized network numbers store in local array space
  */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if HAVE_NETINET_IN_H
+#include <netinet/in.h>                /* ntohl */
+#endif
+
 #include <stdio.h>
 
 #include "ntp_fp.h"
index dd51c5d01313fcc2e142ce4fd1713b06727e3827..e81dd42ac0a54850dbe7937236a9a483a9ef5ff0 100644 (file)
@@ -2,6 +2,14 @@
  * numtohost - convert network number to host name.
  */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if HAVE_NETINET_IN_H
+#include <netinet/in.h>                /* ntohl */
+#endif
+
 #include "ntp_fp.h"
 #include "ntp_stdlib.h"
 #include "lib_strbuf.h"
index 77458f00b303c6b4211683e577eb100b60430427..09f358fe53ca226b0c344cd3b7532665675044e4 100644 (file)
@@ -9,6 +9,8 @@
 #include "ntp_stdlib.h"
 #include "ntp_assert.h"
 
+static char *common_prettydate(l_fp *, int);
+
 const char *months[] = {
   "Jan", "Feb", "Mar", "Apr", "May", "Jun",
   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
@@ -151,7 +153,7 @@ ntp2unix_tm(
 }
 
 
-char *
+static char *
 common_prettydate(
        l_fp *ts,
        int local
index 8a051215fbad1da7cb7f6b9c9b96f20dcec3abbc..b809b2028c372dcc979a3584ee0502346f45d632 100644 (file)
@@ -82,8 +82,10 @@ struct codestring clock_codes[] = {
        { -1,                   "clk" }
 };
 
+
+#ifdef FLASH_CODES_UNUSED
 /*
- * Flash bits
+ * Flash bits -- see ntpq.c tstflags & tstflagnames
  */
 static
 struct codestring flash_codes[] = {
@@ -102,6 +104,8 @@ struct codestring flash_codes[] = {
        { TEST13,               "peer_unreach" },
        { -1,                   "flash" }
 };
+#endif
+
 
 /*
  * System events (sys)
index 32ae1444494461f83d49a4cba5771cc170efd684..2d499f0f68cef69aca17922c6990499d98fa5911 100644 (file)
@@ -264,7 +264,7 @@ ntp_memset(
 static void
 pprintf(
        int lev,
-       const char *form,
+       char *form,
        ...
        )
 {
@@ -273,7 +273,7 @@ pprintf(
        va_start(ap, form);
 
        if (lev & parsedebug)
-           vcmn_err(CE_CONT, (char *)form, ap);
+               vcmn_err(CE_CONT, form, ap);
 
        va_end(ap);
 }
@@ -641,15 +641,15 @@ parserput(
                            register parsestream_t * parse = (parsestream_t *)q->q_ptr;
                            register mblk_t *nmp;
                            register unsigned long ch;
-                           timestamp_t ctime;
+                           timestamp_t c_time;
                            timespec_t hres_time;
 
                            /*
                             * get time on packet delivery
                             */
                            gethrestime(&hres_time);
-                           ctime.tv.tv_sec  = hres_time.tv_sec;
-                           ctime.tv.tv_usec = hres_time.tv_nsec / 1000;
+                           c_time.tv.tv_sec  = hres_time.tv_sec;
+                           c_time.tv.tv_usec = hres_time.tv_nsec / 1000;
 
                            if (!(parse->parse_status & PARSE_ENABLE))
                            {
@@ -672,7 +672,7 @@ parserput(
                                            while (mp != (mblk_t *)NULL)
                                            {
                                                    ch = rdchar(&mp);
-                                                   if (ch != ~0 && parse_ioread(&parse->parse_io, (unsigned int)ch, &ctime))
+                                                   if (ch != ~0 && parse_ioread(&parse->parse_io, (unsigned int)ch, &c_time))
                                                    {
                                                            /*
                                                             * up up and away (hopefully ...)
@@ -693,7 +693,7 @@ parserput(
                                    }
                                    else
                                    {
-                                           if (parse_ioread(&parse->parse_io, (unsigned int)0, &ctime))
+                                           if (parse_ioread(&parse->parse_io, (unsigned int)0, &c_time))
                                            {
                                                    /*
                                                     * up up and away (hopefully ...)
@@ -723,19 +723,19 @@ parserput(
            case M_UNHANGUP:
                    {
                            register parsestream_t * parse = (parsestream_t *)q->q_ptr;
-                           timestamp_t ctime;
+                           timestamp_t c_time;
                            timespec_t hres_time;
                            register mblk_t *nmp;
                            register int status = cd_invert ^ (type == M_UNHANGUP);
 
                            gethrestime(&hres_time);
-                           ctime.tv.tv_sec  = hres_time.tv_sec;
-                           ctime.tv.tv_usec = hres_time.tv_nsec / 1000;
+                           c_time.tv.tv_sec  = hres_time.tv_sec;
+                           c_time.tv.tv_usec = hres_time.tv_nsec / 1000;
        
                            pprintf(DD_RPUT, "parse: parserput - M_%sHANGUP\n", (type == M_HANGUP) ? "" : "UN");
 
                            if ((parse->parse_status & PARSE_ENABLE) &&
-                               parse_iopps(&parse->parse_io, status ? SYNC_ONE : SYNC_ZERO, &ctime))
+                               parse_iopps(&parse->parse_io, status ? SYNC_ONE : SYNC_ZERO, &c_time))
                            {
                                    nmp = (mblk_t *)NULL;
                                    if (canputnext(parse->parse_queue) && (nmp = allocb(sizeof(parsetime_t), BPRI_MED)))
@@ -759,7 +759,7 @@ parserput(
        
                            if (status)
                            {
-                                   parse->parse_ppsclockev.tv = ctime.tv;
+                                   parse->parse_ppsclockev.tv = c_time.tv;
                                    ++(parse->parse_ppsclockev.serial);
                            }
                    }
index bba74974ea7bc526b6c53020d7c2314d815a5f80..a2bea6717222de71dd6076c884d35cd44b543d62 100644 (file)
@@ -215,7 +215,9 @@ static void free_auth_node(void);
 #endif
 double *create_dval(double val);
 void destroy_restrict_node(struct restrict_node *my_node);
+#if !defined(SIM)
 static struct sockaddr_storage *get_next_address(struct address_node *addr);
+#endif
 
 static void config_other_modes(void);
 static void config_auth(void);
@@ -372,6 +374,7 @@ void
 free_syntax_tree(void)
 {
        DESTROY_QUEUE(my_config.peers);
+       DESTROY_QUEUE(my_config.unpeers);
        DESTROY_QUEUE(my_config.orphan_cmds);
 
        DESTROY_QUEUE(my_config.manycastserver);
@@ -805,6 +808,8 @@ create_sim_script_info(
 }
 
 
+#if !defined(SIM)
+
 #define ADDR_LENGTH 16 + 1
 
 static struct sockaddr_storage *
@@ -841,6 +846,7 @@ get_next_address(
        freeaddrinfo(ptr);
        return final_addr;
 }
+#endif /* !SIM */
 
 
 server_info *
index 1ff059aac5cbec43b7b4f8315cbffbfc599483f4..29a4996ea84fdcd9f5e0a4e8bae43f43a083f312 100644 (file)
@@ -142,7 +142,6 @@ char *req_file;             /* name of the file with configuration info */
 /* end stuff to be filled in */
 
 
-static RETSIGTYPE bong         (int);
 static void    checkparent     (void);
 static void    removeentry     (struct conf_entry *);
 static void    addentry        (char *, int, int, int, int, u_int,
index 9f02427c2922efcc4bdffb0735d081646086b627..1822e88062eac419049d132b709616b924688eb8 100644 (file)
@@ -395,8 +395,8 @@ unpeer_command
                }
        ;       
 unpeer_keyword 
-       :       T_Unconfig      { $$ = T_Unconfig }
-       |       T_Unpeer        { $$ = T_Unpeer }
+       :       T_Unconfig      { $$ = T_Unconfig; }
+       |       T_Unpeer        { $$ = T_Unpeer; }
        ;
        
        
index c04813361658c2323930d8c57b5b9e090292ed68..cd1e51f35b85d9469f0c43f533a48f5ec24474df 100644 (file)
@@ -1215,7 +1215,7 @@ refclock_ppsapi(
        struct refclock_atom *ap        /* atom structure pointer */
        )
 {
-       if (ap->handle == NULL) {
+       if (!ap->handle) {
                if (time_pps_create(fddev, &ap->handle) < 0) {
                        msyslog(LOG_ERR,
                            "refclock_atom: time_pps_create failed: %m");
@@ -1301,7 +1301,7 @@ refclock_pps(
         * most recent PPS timestamp.
         */ 
        pp = peer->procptr;
-       if (ap->handle == NULL)
+       if (!ap->handle)
                return (0);
 
        if (ap->pps_params.mode == 0 && sys_leap != LEAP_NOTINSYNC) {
index cf11521bca795204a28504abfe689719628b27b1..36fa10150b5ccc3f26389072df6a360a10cb9286 100644 (file)
@@ -110,6 +110,13 @@ static double prev_drift_comp;             /* last frequency update */
 static int leap_file(FILE *);
 static void record_sys_stats(void);
 
+/* 
+ * Prototypes
+ */
+#ifdef DEBUG
+void   uninit_util(void);
+#endif
+
 
 /*
  * uninit_util - free memory allocated by init_util
index 4556f206c8d1339eec6fb1c95081354d5a69d232..f7479313cfd52ad36f8cbead1cd13c0b214e86a9 100644 (file)
@@ -77,7 +77,6 @@ void create_server_associations()
 
 
 /* Main Simulator Code */
-int ntpsim(int argc, char *argv[]);
 
 int ntpsim(int argc, char *argv[])
 {
index d65187c44d281178a964837bca1dda60405f4ad3..77ccedd6cfe2c1990cabf170ada3f090bc822f9c 100644 (file)
@@ -961,18 +961,18 @@ mx4200_parse_t(
        char   time_mark_valid, time_sync, op_mode;
        int    sentence_type, valid;
        int    year, day_of_year, month, day_of_month;
-       int    hour, minute, second, leapsec;
+       int    hour, minute, second, leapsec_warn;
        int    oscillator_offset, time_mark_error, time_bias;
 
        pp = peer->procptr;
        up = (struct mx4200unit *)pp->unitptr;
 
-       leapsec = 0;  /* Not all receivers output leap second warnings (!) */
+       leapsec_warn = 0;  /* Not all receivers output leap second warnings (!) */
        sscanf(pp->a_lastcode,
                "$PMVXG,%d,%c,%d,%d,%d,%d:%d:%d,%c,%c,%d,%d,%d,%d",
                &sentence_type, &time_mark_valid, &year, &month, &day_of_month,
                &hour, &minute, &second, &time_sync, &op_mode,
-               &oscillator_offset, &time_mark_error, &time_bias, &leapsec);
+               &oscillator_offset, &time_mark_error, &time_bias, &leapsec_warn);
 
        if (sentence_type != PMVXG_D_TRECOVOUT)
                return ("wrong rec-type");
@@ -1005,8 +1005,8 @@ mx4200_parse_t(
                mx4200_debug(peer,
                    "mx4200_parse_t: bad time %02d:%02d:%02d",
                    hour, minute, second);
-               if (leapsec != 0)
-                       mx4200_debug(peer, " (leap %+d\n)", leapsec);
+               if (leapsec_warn != 0)
+                       mx4200_debug(peer, " (leap %+d\n)", leapsec_warn);
                mx4200_debug(peer, "\n");
                refclock_report(peer, CEVNT_BADTIME);
                return ("bad time");
@@ -1068,7 +1068,7 @@ mx4200_parse_t(
        /*
         * Setup leap second indicator
         */
-       switch (leapsec) {
+       switch (leapsec_warn) {
                case 0:
                        pp->leap = LEAP_NOWARNING;
                        break;
@@ -1085,12 +1085,12 @@ mx4200_parse_t(
        /*
         * Any change to the leap second warning status?
         */
-       if (leapsec != up->last_leap ) {
+       if (leapsec_warn != up->last_leap ) {
                msyslog(LOG_DEBUG,
                    "mx4200: leap second warning: %d to %d (%d)",
-                   up->last_leap, leapsec, pp->leap);
+                   up->last_leap, leapsec_warn, pp->leap);
        }
-       up->last_leap = leapsec;
+       up->last_leap = leapsec_warn;
 
        /*
         * Copy time data for billboard monitoring.
@@ -1520,14 +1520,14 @@ mx4200_pps(
        if (time_pps_fetch(up->pps_h, PPS_TSFMT_TSPEC, &(up->pps_i),
                        &timeout) < 0) {
                mx4200_debug(peer,
-                 "mx4200_pps: time_pps_fetch: serial=%ul, %s\n",
+                 "mx4200_pps: time_pps_fetch: serial=%lu, %s\n",
                     (unsigned long)up->pps_i.assert_sequence, strerror(errno));
                refclock_report(peer, CEVNT_FAULT);
                return(1);
        }
        if (temp_serial == up->pps_i.assert_sequence) {
                mx4200_debug(peer,
-                  "mx4200_pps: assert_sequence serial not incrementing: %ul\n",
+                  "mx4200_pps: assert_sequence serial not incrementing: %lu\n",
                        (unsigned long)up->pps_i.assert_sequence);
                refclock_report(peer, CEVNT_FAULT);
                return(1);
@@ -1540,7 +1540,7 @@ mx4200_pps(
                if (up->pps_i.assert_sequence == up->lastserial) {
                        mx4200_debug(peer, "mx4200_pps: no new pps event\n");
                } else {
-                       mx4200_debug(peer, "mx4200_pps: missed %ul pps events\n",
+                       mx4200_debug(peer, "mx4200_pps: missed %lu pps events\n",
                            up->pps_i.assert_sequence - up->lastserial - 1UL);
                }
                refclock_report(peer, CEVNT_FAULT);
index d92758b55dd0da55380b3dc7cf78184cfb02247a..d443c0ae6c256f3a11b62f5a222fa8a326b3a626 100644 (file)
@@ -121,6 +121,7 @@ static void praecis_parse(struct recvbuf *rbufp, struct peer *peer);
  * They are taken from Markus Prosch
  */
 
+#ifdef UNUSED
 /*
  * sendcmd - Build data packet for sending
  */
@@ -130,10 +131,11 @@ sendcmd (
        int c
        )
 {
-        buffer->data[0] = DLE;
-        buffer->data[1] = (unsigned char)c;
-        buffer->size = 2;
+       buffer->data[0] = DLE;
+       buffer->data[1] = (unsigned char)c;
+       buffer->size = 2;
 }
+#endif
 
 /*
  * sendsupercmd - Build super data packet for sending
index 9c2ae9272e583fd10c2b03410e1ea7e341ea9c22..a2b4bb7a8577d9e928637c23de66442e0e206251 100644 (file)
@@ -189,7 +189,9 @@ short               getint                  (u_char *);
 long           getlong                 (u_char *);
 
 /* Thunderbolt specific function prototypes */
+#ifdef UNUSED
 static  void    sendcmd                 (struct packettx *buffer, int c);
+#endif
 static  void    sendsupercmd            (struct packettx *buffer, int c1, int c2);
 static  void    sendbyte                (struct packettx *buffer, int b);
 static  void    sendint                 (struct packettx *buffer, int a);
index 389ddffa305906f1d540c41d1151023a10d2fe3a..5f74200852858c3b7c71854f8c095f59f2692d08 100644 (file)
@@ -256,12 +256,16 @@ static    int     sendpkt         (char *, int);
 static int     getresponse     (int, int, u_short *, int *, char **, int);
 static int     sendrequest     (int, int, int, int, char *);
 static char *  tstflags        (u_long);
+#ifndef BUILD_AS_LIB
 static void    getcmds         (void);
+#ifndef SYS_WINNT
 static RETSIGTYPE abortcmd     (int);
+#endif /* SYS_WINNT */
 static void    docmd           (const char *);
 static void    tokenize        (const char *, char **, int *);
-static int     findcmd         (char *, struct xcmd *, struct xcmd *, struct xcmd **);
 static int     getarg          (char *, int, arg_v *);
+#endif /* BUILD_AS_LIB */
+static int     findcmd         (char *, struct xcmd *, struct xcmd *, struct xcmd **);
 static int     rtdatetolfp     (char *, l_fp *);
 static int     decodearr       (char *, int *, l_fp *);
 static void    help            (struct parse *, FILE *);
@@ -382,7 +386,7 @@ struct xcmd builtins[] = {
 #define        MAXVARLEN       256             /* maximum length of a variable name */
 #define        MAXVALLEN       400             /* maximum length of a variable value */
 #define        MAXOUTLINE      72              /* maximum length of an output line */
-#define SCREENWIDTH     76              /* nominal screen width in columns */
+#define SCREENWIDTH    76              /* nominal screen width in columns */
 
 /*
  * Some variables used and manipulated locally
@@ -479,20 +483,20 @@ volatile int debug;
 #ifdef NO_MAIN_ALLOWED
 #ifndef BUILD_AS_LIB
 CALL(ntpq,"ntpq",ntpqmain);
-#endif
 
 void clear_globals(void)
 {
-    extern int ntp_optind;
-    showhostnames = 0;                         /* don'tshow host names by default */
-    ntp_optind = 0;
-    server_entry = NULL;            /* server entry for ntp */
-    havehost = 0;                              /* set to 1 when host open */
-    numassoc = 0;              /* number of cached associations */
-    numcmds = 0;
-    numhosts = 0;
+       extern int ntp_optind;
+       showhostnames = 0;      /* don'tshow host names by default */
+       ntp_optind = 0;
+       server_entry = NULL;    /* server entry for ntp */
+       havehost = 0;           /* set to 1 when host open */
+       numassoc = 0;           /* number of cached associations */
+       numcmds = 0;
+       numhosts = 0;
 }
-#endif
+#endif /* !BUILD_AS_LIB */
+#endif /* NO_MAIN_ALLOWED */
 
 /*
  * main - parse arguments and handle options
@@ -621,7 +625,7 @@ ntpqmain(
                ADDHOST(DEFHOST);
        } else {
                for (; ntp_optind < argc; ntp_optind++)
-                   ADDHOST(argv[ntp_optind]);
+                       ADDHOST(argv[ntp_optind]);
        }
 
        if (numcmds == 0 && interactive == 0
@@ -643,8 +647,8 @@ ntpqmain(
 
                for (ihost = 0; ihost < numhosts; ihost++) {
                        if (openhost(chosts[ihost]))
-                           for (icmd = 0; icmd < numcmds; icmd++)
-                               docmd(ccmds[icmd]);
+                               for (icmd = 0; icmd < numcmds; icmd++)
+                                       docmd(ccmds[icmd]);
                }
        }
 #ifdef SYS_WINNT
@@ -652,7 +656,7 @@ ntpqmain(
 #endif /* SYS_WINNT */
        return 0;
 }
-#endif // build as lib
+#endif /* !BUILD_AS_LIB */
 
 /*
  * openhost - open a socket to a host
@@ -724,21 +728,21 @@ openhost(
        }
 
        if (ai->ai_canonname == NULL) {
-               strncpy(temphost, stoa((struct sockaddr_storage *)ai->ai_addr),
-                   LENHOSTNAME);
-               temphost[LENHOSTNAME-1] = '\0';
+               strncpy(temphost, 
+                       stoa((struct sockaddr_storage *)ai->ai_addr),
+                       LENHOSTNAME);
 
        } else {
                strncpy(temphost, ai->ai_canonname, LENHOSTNAME);
-               temphost[LENHOSTNAME-1] = '\0';
        }
+       temphost[LENHOSTNAME-1] = '\0';
 
        if (debug > 2)
-           printf("Opening host %s\n", temphost);
+               printf("Opening host %s\n", temphost);
 
        if (havehost == 1) {
                if (debug > 2)
-                   printf("Closing old host %s\n", currenthost);
+                       printf("Closing old host %s\n", currenthost);
                (void) closesocket(sockfd);
                havehost = 0;
        }
@@ -761,9 +765,13 @@ openhost(
                int optionValue = SO_SYNCHRONOUS_NONALERT;
                int err;
 
-               err = setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&optionValue, sizeof(optionValue));
-               if (err != NO_ERROR) {
-                       (void) fprintf(stderr, "cannot open nonoverlapped sockets\n");
+               err = setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
+                                (char *)&optionValue, sizeof(optionValue));
+               if (err) {
+                       err = WSAGetLastError();
+                       fprintf(stderr,
+                               "setsockopt(SO_SYNCHRONOUS_NONALERT) "
+                               "error: %s\n", strerror(err));
                        exit(1);
                }
        }
@@ -1440,6 +1448,7 @@ doquery(
 }
 
 
+#ifndef BUILD_AS_LIB
 /*
  * getcmds - read commands from the standard input and execute them
  */
@@ -1447,35 +1456,36 @@ static void
 getcmds(void)
 {
 #if defined(HAVE_LIBREADLINE)
-        char *line;
-
-        for (;;) {
-                if ((line = readline(interactive?prompt:"")) == NULL) return;
-                if (*line) add_history(line);
-                docmd(line);
-                free(line);
-        }
+       char *line;
+
+       for (;;) {
+               if ((line = readline(interactive?prompt:"")) == NULL) return;
+               if (*line) add_history(line);
+               docmd(line);
+               free(line);
+       }
 #else /* not (HAVE_LIBREADLINE) */
-        char line[MAXLINE];
+       char line[MAXLINE];
 
-        for (;;) {
-                if (interactive) {
-#ifdef VMS      /* work around a problem with mixing stdout & stderr */
-                        fputs("",stdout);
+       for (;;) {
+               if (interactive) {
+#ifdef VMS     /* work around a problem with mixing stdout & stderr */
+                       fputs("",stdout);
 #endif
-                        (void) fputs(prompt, stderr);
-                        (void) fflush(stderr);
-                }
+                       (void) fputs(prompt, stderr);
+                       (void) fflush(stderr);
+               }
 
-                if (fgets(line, sizeof line, stdin) == NULL)
-                    return;
+               if (fgets(line, sizeof line, stdin) == NULL)
+                       return;
 
-                docmd(line);
-        }
+               docmd(line);
+       }
 #endif /* not (HAVE_LIBREADLINE || HAVE_LIBEDIT) */
 }
+#endif /* !BUILD_AS_LIB */
 
-#ifndef SYS_WINNT /* Under NT cannot handle SIGINT, WIN32 spawns a handler */
+#if !defined(SYS_WINNT) && !defined(BUILD_AS_LIB)
 /*
  * abortcmd - catch interrupts and abort the current command
  */
@@ -1490,8 +1500,10 @@ abortcmd(
        (void) fflush(stderr);
        if (jump) longjmp(interrupt_buf, 1);
 }
-#endif /* SYS_WINNT */
+#endif /* !SYS_WINNT && !BUILD_AS_LIB */
 
+
+#ifndef        BUILD_AS_LIB
 /*
  * docmd - decode the command line and execute a command
  */
@@ -1542,9 +1554,9 @@ docmd(
                        break;
                }
                if ((xcmd->arg[i] & OPT) && (*tokens[i+1] == '>'))
-                   break;
+                       break;
                if (!getarg(tokens[i+1], (int)xcmd->arg[i], &pcmd.argval[i]))
-                   return;
+                       return;
                pcmd.nargs++;
        }
 
@@ -1553,9 +1565,9 @@ docmd(
                char *fname;
 
                if (*(tokens[i]+1) != '\0')
-                   fname = tokens[i]+1;
+                       fname = tokens[i]+1;
                else if ((i+1) < ntok)
-                   fname = tokens[i+1];
+                       fname = tokens[i+1];
                else {
                        (void) fprintf(stderr, "***No file for redirect\n");
                        return;
@@ -1632,88 +1644,21 @@ tokenize(
                 * If yes, continue reading till the next double quote
                 */
                else if (*cp == '\"') {
-                   ++cp;
-                   do {
-                        *sp++ = *cp++;
-                    } while ((*cp != '\"') && !ISEOL(*cp));
-                   /* HMS: a missing closing " should be an error */
-                }
-                else {
-                    do {
-                       *sp++ = *cp++;
-                    } while ((*cp != '\"') && !ISSPACE(*cp) && !ISEOL(*cp));
-                   /* HMS: Why check for a " in the previous line? */
-                }
-
-               *sp++ = '\0';
-       }
-}
-
-
-/*
- * findcmd - find a command in a command description table
- */
-static int
-findcmd(
-       register char *str,
-       struct xcmd *clist1,
-       struct xcmd *clist2,
-       struct xcmd **cmd
-       )
-{
-       register struct xcmd *cl;
-       register int clen;
-       int nmatch;
-       struct xcmd *nearmatch = NULL;
-       struct xcmd *clist;
-
-       clen = strlen(str);
-       nmatch = 0;
-       if (clist1 != 0)
-           clist = clist1;
-       else if (clist2 != 0)
-           clist = clist2;
-       else
-           return 0;
-
-    again:
-       for (cl = clist; cl->keyword != 0; cl++) {
-               /* do a first character check, for efficiency */
-               if (*str != *(cl->keyword))
-                   continue;
-               if (strncmp(str, cl->keyword, (unsigned)clen) == 0) {
-                       /*
-                        * Could be extact match, could be approximate.
-                        * Is exact if the length of the keyword is the
-                        * same as the str.
-                        */
-                       if (*((cl->keyword) + clen) == '\0') {
-                               *cmd = cl;
-                               return 1;
-                       }
-                       nmatch++;
-                       nearmatch = cl;
+                       ++cp;
+                       do {
+                               *sp++ = *cp++;
+                       } while ((*cp != '\"') && !ISEOL(*cp));
+                       /* HMS: a missing closing " should be an error */
+               }
+               else {
+                       do {
+                               *sp++ = *cp++;
+                       } while ((*cp != '\"') && !ISSPACE(*cp) && !ISEOL(*cp));
+                       /* HMS: Why check for a " in the previous line? */
                }
-       }
-
-       /*
-        * See if there is more to do.  If so, go again.  Sorry about the
-        * goto, too much looking at BSD sources...
-        */
-       if (clist == clist1 && clist2 != 0) {
-               clist = clist2;
-               goto again;
-       }
 
-       /*
-        * If we got extactly 1 near match, use it, else return number
-        * of matches.
-        */
-       if (nmatch == 1) {
-               *cmd = nearmatch;
-               return 1;
+               *sp++ = '\0';
        }
-       return nmatch;
 }
 
 
@@ -1807,6 +1752,74 @@ getarg(
 
        return 1;
 }
+#endif /* !BUILD_AS_LIB */
+
+
+/*
+ * findcmd - find a command in a command description table
+ */
+static int
+findcmd(
+       register char *str,
+       struct xcmd *clist1,
+       struct xcmd *clist2,
+       struct xcmd **cmd
+       )
+{
+       register struct xcmd *cl;
+       register int clen;
+       int nmatch;
+       struct xcmd *nearmatch = NULL;
+       struct xcmd *clist;
+
+       clen = strlen(str);
+       nmatch = 0;
+       if (clist1 != 0)
+           clist = clist1;
+       else if (clist2 != 0)
+           clist = clist2;
+       else
+           return 0;
+
+    again:
+       for (cl = clist; cl->keyword != 0; cl++) {
+               /* do a first character check, for efficiency */
+               if (*str != *(cl->keyword))
+                   continue;
+               if (strncmp(str, cl->keyword, (unsigned)clen) == 0) {
+                       /*
+                        * Could be extact match, could be approximate.
+                        * Is exact if the length of the keyword is the
+                        * same as the str.
+                        */
+                       if (*((cl->keyword) + clen) == '\0') {
+                               *cmd = cl;
+                               return 1;
+                       }
+                       nmatch++;
+                       nearmatch = cl;
+               }
+       }
+
+       /*
+        * See if there is more to do.  If so, go again.  Sorry about the
+        * goto, too much looking at BSD sources...
+        */
+       if (clist == clist1 && clist2 != 0) {
+               clist = clist2;
+               goto again;
+       }
+
+       /*
+        * If we got extactly 1 near match, use it, else return number
+        * of matches.
+        */
+       if (nmatch == 1) {
+               *cmd = nearmatch;
+               return 1;
+       }
+       return nmatch;
+}
 
 
 /*
@@ -1863,10 +1876,11 @@ nntohost(
        )
 {
        if (!showhostnames)
-           return stoa(netnum);
-       if ((netnum->ss_family == AF_INET) && ISREFCLOCKADR(netnum))
-               return refnumtoa(netnum);
-       return socktohost(netnum);
+               return stoa(netnum);
+       else if ((netnum->ss_family == AF_INET) && ISREFCLOCKADR(netnum))
+               return refnumtoa(netnum);
+       else
+               return socktohost(netnum);
 }
 
 
@@ -2010,7 +2024,7 @@ decodets(
         * If it starts with a 0x, decode as hex.
         */
        if (*str == '0' && (*(str+1) == 'x' || *(str+1) == 'X'))
-           return hextolfp(str+2, lfp);
+               return hextolfp(str+2, lfp);
 
        /*
         * If it starts with a '"', try it as an RT-11 date.
@@ -2022,7 +2036,7 @@ decodets(
 
                bp = buf;
                while (*cp != '"' && *cp != '\0' && bp < &buf[29])
-                   *bp++ = *cp++;
+                       *bp++ = *cp++;
                *bp = '\0';
                return rtdatetolfp(buf, lfp);
        }
@@ -2032,14 +2046,15 @@ decodets(
         * about heuristics!
         */
        if ((*str >= 'A' && *str <= 'F') || (*str >= 'a' && *str <= 'f'))
-           return hextolfp(str, lfp);
+               return hextolfp(str, lfp);
 
        /*
         * Try it as a decimal.  If this fails, try as an unquoted
         * RT-11 date.  This code should go away eventually.
         */
        if (atolfp(str, lfp))
-           return 1;
+               return 1;
+
        return rtdatetolfp(str, lfp);
 }
 
@@ -2144,21 +2159,21 @@ help(
        FILE *fp
        )
 {
-       struct xcmd *xcp;
+       struct xcmd *xcp = NULL;        /* quiet warning */
        char *cmd;
        const char *list[100];
-        int word, words;
-        int row, rows;
-        int col, cols;
+       int word, words;
+       int row, rows;
+       int col, cols;
 
        if (pcmd->nargs == 0) {
                words = 0;
                for (xcp = builtins; xcp->keyword != 0; xcp++) {
                        if (*(xcp->keyword) != '?')
-                           list[words++] = xcp->keyword;
+                               list[words++] = xcp->keyword;
                }
                for (xcp = opcmds; xcp->keyword != 0; xcp++)
-                   list[words++] = xcp->keyword;
+                       list[words++] = xcp->keyword;
 
                qsort(
 #ifdef QSORT_USES_VOID_P
@@ -2171,21 +2186,22 @@ help(
                for (word = 0; word < words; word++) {
                        int length = strlen(list[word]);
                        if (col < length) {
-                           col = length;
-                        }
+                               col = length;
+                       }
                }
 
                cols = SCREENWIDTH / ++col;
-                rows = (words + cols - 1) / cols;
+               rows = (words + cols - 1) / cols;
 
                (void) fprintf(fp, "ntpq commands:\n");
 
                for (row = 0; row < rows; row++) {
-                        for (word = row; word < words; word += rows) {
-                               (void) fprintf(fp, "%-*.*s", col, col-1, list[word]);
-                        }
-                        (void) fprintf(fp, "\n");
-                }
+                       for (word = row; word < words; word += rows) {
+                               (void) fprintf(fp, "%-*.*s", col, 
+                                                  col-1, list[word]);
+                       }
+                       (void) fprintf(fp, "\n");
+               }
        } else {
                cmd = pcmd->argval[0].string;
                words = findcmd(cmd, builtins, opcmds, &xcp);
@@ -2322,9 +2338,10 @@ host(
 
        if (pcmd->nargs == 0) {
                if (havehost)
-                   (void) fprintf(fp, "current host is %s\n", currenthost);
+                       (void) fprintf(fp, "current host is %s\n",
+                                          currenthost);
                else
-                   (void) fprintf(fp, "no current host\n");
+                       (void) fprintf(fp, "no current host\n");
                return;
        }
 
@@ -2338,7 +2355,8 @@ host(
                else {
                        if (havehost)
                                (void) fprintf(fp,
-                                   "current host remains %s\n", currenthost);
+                                              "current host remains %s\n",
+                                              currenthost);
                        else
                                (void) fprintf(fp, "still no current host\n");
                        return;
@@ -2350,10 +2368,11 @@ host(
                numassoc = 0;
        } else {
                if (havehost)
-                   (void) fprintf(fp,
-                                  "current host remains %s\n", currenthost);
+                       (void) fprintf(fp,
+                                      "current host remains %s\n", 
+                                      currenthost);
                else
-                   (void) fprintf(fp, "still no current host\n");
+                       (void) fprintf(fp, "still no current host\n");
        }
 }
 
@@ -2442,10 +2461,10 @@ passwd(
        }
        pass = getpass("MD5 Password: ");
        if (*pass == '\0')
-           (void) fprintf(fp, "Password unchanged\n");
+               (void) fprintf(fp, "Password unchanged\n");
        else {
-           authusekey(info_auth_keyid, info_auth_keytype, (u_char *)pass);
-           authtrust(info_auth_keyid, 1);
+               authusekey(info_auth_keyid, info_auth_keytype, (u_char *)pass);
+               authtrust(info_auth_keyid, 1);
        }
 }
 
@@ -3365,9 +3384,9 @@ assoccmp(
        const struct association *ass2 = (const struct association *)t2;
 
        if (ass1->assid < ass2->assid)
-           return -1;
+               return -1;
        if (ass1->assid > ass2->assid)
-           return 1;
+               return 1;
        return 0;
 }
 #else
index d086683730386cc57ce381e66e0b661f5e1edacc..449d24fba57a763e18dfa4e41e0d4375217322b8 100644 (file)
@@ -185,7 +185,7 @@ static char pat[] = "-\\|/";
 
 #define R_SHIFT(_X_, _Y_) (((_X_) < 0) ? -(-(_X_) >> (_Y_)) : ((_X_) >> (_Y_)))
 
-static struct timeval max_adj_offset = { 0, 128000 };
+static long max_adj_offset_usec = 128000;
 
 static long clock_adjust = 0;  /* current adjustment value (usec * 2^USECSCALE) */
 static long accum_drift   = 0; /* accumulated drift value  (usec / ADJINTERVAL) */
@@ -195,8 +195,8 @@ static char skip_adjust  = 1;       /* discard first adjustment (bad samples) */
 /*
  * DCF77 state flags
  */
-#define DCFB_ANNOUNCE           0x0001 /* switch time zone warning (DST switch) */
-#define DCFB_DST                0x0002 /* DST in effect */
+#define DCFB_ANNOUNCE          0x0001 /* switch time zone warning (DST switch) */
+#define DCFB_DST               0x0002 /* DST in effect */
 #define DCFB_LEAP              0x0004 /* LEAP warning (1 hour prior to occurrence) */
 #define DCFB_ALTERNATE         0x0008 /* alternate antenna used */
 
@@ -1042,7 +1042,8 @@ adjust_clock(
        toffset = *offset;
        toffset.tv_sec  = l_abs(toffset.tv_sec);
        toffset.tv_usec = l_abs(toffset.tv_usec);
-       if (timercmp(&toffset, &max_adj_offset, >))
+       if (toffset.tvsec ||
+           (!toffset.tv_sec && toffset.tv_usec > max_adj_offset_usec))
        {
                /*
                 * hopeless - set the clock - and clear the timing
index b61634ae917bbfb7fac0bd9143bea438536b0d98..53f637ac375fd4bedf412fee6e48f2ade5f8394b 100644 (file)
                                RelativePath="..\..\..\libisc\md5.c"
                                >
                        </File>
-                       <File
-                               RelativePath="..\..\..\libisc\mem.c"
-                               >
-                               <FileConfiguration
-                                       Name="Debug|Win32"
-                                       >
-                                       <Tool
-                                               Name="VCCLCompilerTool"
-                                               AdditionalIncludeDirectories=""
-                                               PreprocessorDefinitions=""
-                                       />
-                               </FileConfiguration>
-                               <FileConfiguration
-                                       Name="Release|Win32"
-                                       >
-                                       <Tool
-                                               Name="VCCLCompilerTool"
-                                               AdditionalIncludeDirectories=""
-                                               PreprocessorDefinitions=""
-                                       />
-                               </FileConfiguration>
-                       </File>
                        <File
                                RelativePath="..\..\..\libntp\memmove.c"
                                >
index 6290f75a3b40de1c4992ae2c4fcca00899d39e86..68f4116ba739300c4c7210f94d8b09991fc62f63 100644 (file)
                                RelativePath="..\..\..\include\ntpd.h"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\..\include\ntpsim.h"
+                               >
+                       </File>
                        <File
                                RelativePath="..\include\ntservice.h"
                                >
index 2624711abcd38a45e855d306a1ae39e313d6074f..34b8693a41d83cd44d82bde82d4537eba4c804a9 100644 (file)
@@ -148,7 +148,7 @@ ntservice_init() {
                SetConsoleTitle(ConsoleTitle);
        }
 
-       #ifdef _DEBUG
+       #if defined(_MSC_VER) && defined(_DEBUG)
                /* ask the runtime to dump memory leaks at exit */
                _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
                #ifdef WANT_LEAK_CHECK_ON_STDERR_TOO
@@ -158,7 +158,7 @@ ntservice_init() {
                        /* the file being stderr */
                        _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
                #endif
-       #endif /* _DEBUG */
+       #endif /* _MSC_VER && _DEBUG */
 
        atexit( ntservice_exit );
 }
@@ -190,7 +190,7 @@ ntservice_exit( void )
 
        msyslog(LOG_INFO, "ntservice: The Network Time Protocol Service is stopping.");
 
-#ifdef _DEBUG
+#ifdef DEBUG
        FormatErrorFreeMem();
 #endif 
 
@@ -229,7 +229,7 @@ ServiceControl(DWORD dwCtrlCode) {
        case SERVICE_CONTROL_PAUSE:
        case SERVICE_CONTROL_CONTINUE:
        case SERVICE_CONTROL_INTERROGATE:
-        default:
+       default:
                break;
        }
        UpdateSCM(SERVICE_RUNNING);
@@ -301,6 +301,6 @@ OnConsoleEvent(
        }
 
        /* we've handled it, no more handlers should be called */
-       return TRUE;;
+       return TRUE;
 }
 
index 787cf4d7c218afc2ed543262d132e78f24013f5f..243af4e0417ce1cda3b95875345773ccbfa89b3d 100644 (file)
@@ -295,16 +295,16 @@ main(
 #ifdef OPENSSL
        passwd1 = hostbuf;
        if (HAVE_OPT( PVT_PASSWD ))
-               passwd1 = OPT_ARG( PVT_PASSWD );
+               passwd1 = strdup(OPT_ARG( PVT_PASSWD ));
 
        if (HAVE_OPT( GET_PVT_PASSWD ))
-               passwd2 = OPT_ARG( GET_PVT_PASSWD );
+               passwd2 = strdup(OPT_ARG( GET_PVT_PASSWD ));
 
        if (HAVE_OPT( HOST_KEY ))
                hostkey++;
 
        if (HAVE_OPT( SIGN_KEY ))
-               sign = OPT_ARG( SIGN_KEY );
+               sign = strdup(OPT_ARG( SIGN_KEY ));
 
        if (HAVE_OPT( GQ_PARAMS ))
                gqkey++;
@@ -327,10 +327,10 @@ main(
                scheme = OPT_ARG( CERTIFICATE );
 
        if (HAVE_OPT( SUBJECT_NAME ))
-               hostname = OPT_ARG( SUBJECT_NAME );
+               hostname = strdup(OPT_ARG( SUBJECT_NAME ));
 
        if (HAVE_OPT( ISSUER_NAME ))
-               groupname = OPT_ARG( ISSUER_NAME );
+               groupname = strdup(OPT_ARG( ISSUER_NAME ));
 
        if (HAVE_OPT( PVT_CERT ))
                exten = EXT_KEY_PRIVATE;
@@ -716,7 +716,7 @@ gen_md5(
        int     i, j;
 
        str = fheader("MD5key", id, groupname);
-       ntp_srandom(epoch);
+       ntp_srandom((u_long)epoch);
        for (i = 1; i <= MD5KEYS; i++) {
                for (j = 0; j < 16; j++) {
                        int temp;
@@ -1825,7 +1825,7 @@ x509      (
        cert = X509_new();
        X509_set_version(cert, 2L);
        serial = ASN1_INTEGER_new();
-       ASN1_INTEGER_set(serial, epoch + JAN_1970);
+       ASN1_INTEGER_set(serial, (long)epoch + JAN_1970);
        X509_set_serialNumber(cert, serial);
        ASN1_INTEGER_free(serial);
        X509_time_adj(X509_get_notBefore(cert), 0L, &epoch);