]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1751] Support for Atari FreeMiNT OS.
authorDave Hart <hart@ntp.org>
Tue, 14 Dec 2010 19:40:18 +0000 (19:40 +0000)
committerDave Hart <hart@ntp.org>
Tue, 14 Dec 2010 19:40:18 +0000 (19:40 +0000)
bk: 4d07c8223bZ5AsENQ228crIyR2XmbA

20 files changed:
ChangeLog
configure.ac
lib/isc/unix/net.c
m4/ntp_openssl.m4
ntpd/ntp_config.c
ntpd/ntp_control.c
ntpd/ntp_refclock.c
ntpd/refclock_conf.c
ntpd/refclock_palisade.c
ntpdate/ntpdate.c
ntpdc/ntpdc.c
ntpdc/ntpdc_ops.c
ntpq/libntpq.c
ntpq/libntpq.h
ntpq/libntpq_subs.c
ntpq/ntpq-subs.c
ntpq/ntpq.c
ntpq/ntpq.h
sntp/main.c
util/tickadj.c

index ca2aec0bcef6c360a765949d6e6ad057a4b562d2..bed7f2f47a52aeaecda46d6169a5beefed47adeb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
 * [Bug 1742] Fix a typo in an error message in the "build" script.
 * [Bug 1743] Display timezone offset when showing time for sntp in the
   local timezone.
+* [Bug 1751] Support for Atari FreeMiNT OS.
 * Clean up m4 quoting in configure.ac, *.m4 files, resolving
   intermittent AC_LANG_PROGRAM possibly undefined errors.
 * Clean up the SNTP documentation.
index 037dff9a6a793058dc906d42596aa8ee78e64ead..1e85d216d0b48a2059a4af8394eb03e36eaceeea 100644 (file)
@@ -692,7 +692,7 @@ case "$ac_cv_func___adjtimex" in
     AC_CHECK_LIB([kvm], [main])                dnl We already know about -lelf here...
     AC_CHECK_LIB([ld], [nlist])
     AC_CHECK_LIB([mld], [nlist])
-    AC_CHECK_HEADER([nlist.h])
+    AC_CHECK_HEADERS([nlist.h sys/var.h])
     case "$ac_cv_header_nlist_h" in
      yes)
        AC_DEFINE([NLIST_STRUCT], [1], [nlist stuff])
@@ -2217,6 +2217,9 @@ AC_CACHE_CHECK(
             *-*-kfreebsd*)
                ans=no
                ;;
+            m68k-*-mint*)
+               ans=no
+               ;;
            esac
            ;;
        esac
index a21dbc946cc3d2309212b6afee631e9711c77ae0..669a5be897ca87b52849064da697c06d63be5ccf 100644 (file)
@@ -317,7 +317,6 @@ initialize_ipv6only(void) {
        RUNTIME_CHECK(isc_once_do(&once_ipv6only,
                                  try_ipv6only) == ISC_R_SUCCESS);
 }
-#endif /* WANT_IPV6 */
 
 #ifdef ISC_PLATFORM_HAVEIN6PKTINFO
 static void
@@ -373,6 +372,7 @@ initialize_ipv6pktinfo(void) {
                                  try_ipv6pktinfo) == ISC_R_SUCCESS);
 }
 #endif /* ISC_PLATFORM_HAVEIN6PKTINFO */
+#endif /* WANT_IPV6 */
 #endif /* ISC_PLATFORM_HAVEIPV6 */
 
 isc_result_t
index 0d88fad0c9b09ac35c4d0feb99965ea533055986..58400a254df9f54ef187cb70a1b543f7ef019d54 100644 (file)
@@ -153,6 +153,58 @@ case "$ntp_openssl" in
     AC_DEFINE([OPENSSL], [1], [Use OpenSSL?])
 esac
 
+#
+# check for linking with -lcrypto failure, and try -lz -lcrypto.
+# Helps m68k-atari-mint
+#
+case "$ntp_openssl" in
+ yes)
+    NTP_SAVED_LDFLAGS="$LDFLAGS"
+    LDFLAGS="$NTP_SAVED_LDFLAGS $LCRYPTO"
+    AC_CACHE_CHECK(
+       [if linking with $LCRYPTO alone works],
+       [ntp_cv_bare_lcrypto],
+       [AC_LINK_IFELSE(
+           [AC_LANG_PROGRAM(
+               [[
+                   #include "openssl/err.h"
+               ]],
+               [[
+                   ERR_load_crypto_strings();
+               ]]
+           )],
+           [ntp_cv_bare_lcrypto=yes],
+           [ntp_cv_bare_lcrypto=no]
+       )]
+    )
+    case "$ntp_cv_bare_lcrypto" in
+     no)
+       LDFLAGS="$NTP_SAVED_LDFLAGS $LCRYPTO -lz"
+       AC_CACHE_CHECK(
+           [if linking with $LCRYPTO -lz works],
+           [ntp_cv_lcrypto_lz],
+           [AC_LINK_IFELSE(
+               [AC_LANG_PROGRAM(
+                   [[
+                       #include "openssl/err.h"
+                   ]],
+                   [[
+                       ERR_load_crypto_strings();
+                   ]]
+               )],
+               [ntp_cv_lcrypto_lz=yes],
+               [ntp_cv_lcrypto_lz=no]
+           )]
+       )
+       case "$ntp_cv_lz_lcrypto" in
+        yes)
+            LCRYPTO="$LCRYPTO -lz"
+       esac
+    esac
+    LDFLAGS="$NTP_SAVED_LDFLAGS"
+    AS_UNSET([NTP_SAVED_LDFLAGS])
+esac
+
 #
 # Older OpenSSL headers have a number of callback prototypes inside
 # other function prototypes which trigger copious warnings with gcc's
index 613578faf1441a533145d9139dbb1a08b2ef37cc..981728938e243118211645b73b356ae6e4b67ee0 100644 (file)
@@ -2723,17 +2723,16 @@ config_phone(
 
        s = queue_head(ptree->phone);
        while (s != NULL) {
-               if (i < COUNTOF(sys_phone) - 1)
+               if (i < COUNTOF(sys_phone) - 1) {
                        sys_phone[i++] = estrdup(*s);
-               else
+                       sys_phone[i] = NULL;
+               } else {
                        msyslog(LOG_INFO,
                                "phone: Number of phone entries exceeds %lu. Ignoring phone %s...",
                                (u_long)(COUNTOF(sys_phone) - 1), *s);
+               }
                s = next_node(s);
        }
-
-       if (i)
-               sys_phone[i] = NULL;
 }
 
 
index a4d4afefc23059a7e8e2a140613743f124ba8995..faef3c5fb635e6c3bafb82033d8f238b722ad7ac 100644 (file)
@@ -2451,7 +2451,9 @@ static void configure(
        int restrict_mask
        )
 {
-       int data_count, retval, replace_nl;
+       size_t data_count;
+       int retval;
+       int replace_nl;
 
        /* I haven't yet implemented changes to an existing association.
         * Hence check if the association id is 0
index 125057011612339825d6c90f1cf441910f02d286..08c0e40a9c1d491b0c4cfec27361f7f080d6c818 100644 (file)
@@ -351,7 +351,6 @@ refclock_transmit(
 /*
  * Compare two doubles - used with qsort()
  */
-#ifdef QSORT_USES_VOID_P
 static int
 refclock_cmpl_fp(
        const void *p1,
@@ -362,30 +361,11 @@ refclock_cmpl_fp(
        const double *dp2 = (const double *)p2;
 
        if (*dp1 < *dp2)
-               return (-1);
-
-       if (*dp1 > *dp2)
-               return (1);
-
-       return (0);
-}
-
-#else
-static int
-refclock_cmpl_fp(
-       const double *dp1,
-       const double *dp2
-       )
-{
-       if (*dp1 < *dp2)
-               return (-1);
-
+               return -1;
        if (*dp1 > *dp2)
-               return (1);
-
-       return (0);
+               return 1;
+       return 0;
 }
-#endif /* QSORT_USES_VOID_P */
 
 
 /*
@@ -482,7 +462,7 @@ refclock_sample(
        struct refclockproc *pp         /* refclock structure pointer */
        )
 {
-       int     i, j, k, m, n;
+       size_t  i, j, k, m, n;
        double  off[MAXSTAGE];
        double  offset;
 
@@ -500,13 +480,7 @@ refclock_sample(
                return (0);
 
        if (n > 1)
-               qsort(
-#ifdef QSORT_USES_VOID_P
-                   (void *)
-#else
-                   (char *)
-#endif
-                   off, (size_t)n, sizeof(double), refclock_cmpl_fp);
+               qsort((void *)off, n, sizeof(off[0]), refclock_cmpl_fp);
 
        /*
         * Reject the furthest from the median of the samples until
@@ -540,7 +514,7 @@ refclock_sample(
                    "refclock_sample: n %d offset %.6f disp %.6f jitter %.6f\n",
                    n, pp->offset, pp->disp, pp->jitter);
 #endif
-       return (n);
+       return (int)n;
 }
 
 
index c046d012dd9b4a4c6137132b0feafdb2ca5b7e63..80e50d1880b00c00be08093f0c7a2debe3580655 100644 (file)
@@ -168,7 +168,7 @@ extern      struct refclock refclock_shm;
 #define refclock_shm refclock_none
 #endif
 
-#ifdef CLOCK_PALISADE
+#if defined(CLOCK_PALISADE) && defined(TIOCMSET)
 extern  struct refclock refclock_palisade;
 #else
 #define refclock_palisade refclock_none
index 7e9f59fbcf71ef56828dbf2ffe435d32501a5fdc..21f0714e287ffc4f04eeb254361b49992c4023d3 100644 (file)
 # include "config.h"
 #endif
 
-#if defined(REFCLOCK) && (defined(PALISADE) || defined(CLOCK_PALISADE))
+#if defined(REFCLOCK) && defined(CLOCK_PALISADE)
+
+#include <termios.h>
+
+# ifdef TIOCMSET
 
 #ifdef SYS_WINNT
 extern int async_write(int, const void *, unsigned int);
@@ -1266,10 +1270,12 @@ getlong(
        )
 {
        return (long) (bp[0] << 24) | 
-           (bp[1] << 16) |
-           (bp[2] << 8) |
-           bp[3];
+                     (bp[1] << 16) |
+                     (bp[2] << 8) |
+                      bp[3];
 }
 
-int refclock_palisade_bs;
-#endif /* REFCLOCK */
+# endif        /* TIOCMSET */
+#else  /* REFCLOCK && CLOCK_PALISADE*/
+int refclock_palisade_c_notempty;
+#endif
index 76ac6126a6778472824cb012e6a885d16c8be682..ec3bd7e862d7049e6cc895f8ef9615f2ddc83588 100644 (file)
@@ -1029,12 +1029,14 @@ clock_filter(
 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;
+       struct server *server;
+       u_int nlist;
+       s_fp d;
+       u_int count;
+       u_int i;
+       u_int j;
+       u_int k;
+       int n;
        s_fp local_threshold;
        struct server *server_list[NTP_MAXCLOCK];
        u_fp server_badness[NTP_MAXCLOCK];
@@ -1130,12 +1132,14 @@ clock_select(void)
         * Got the five-or-less best.    Cut the list where the number of
         * strata exceeds two.
         */
-       j = 0;
+       count = 0;
        for (i = 1; i < nlist; i++)
-               if (server_list[i]->stratum > server_list[i-1]->stratum)
-               if (++j == 2) {
-                       nlist = i;
-                       break;
+               if (server_list[i]->stratum > server_list[i-1]->stratum) {
+                       count++;
+                       if (2 == count) {
+                               nlist = i;
+                               break;
+                       }
                }
 
        /*
@@ -1145,9 +1149,9 @@ clock_select(void)
         * detection.
         */
 
-       if (nlist == 0)
-               sys_server = 0;
-       else if (nlist == 1) {
+       if (0 == nlist)
+               sys_server = NULL;
+       else if (1 == nlist) {
                sys_server = server_list[0];
        } else {
                /*
@@ -1156,12 +1160,13 @@ clock_select(void)
                 */
                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;
+                               if (server_list[i]->stratum <
+                                   server_list[j]->stratum)
+                                       /* already sorted by stratum */
+                                       break;
+                               if (server_list[i]->delay <
+                                   server_list[j]->delay)
+                                       continue;
                                server = server_list[i];
                                server_list[i] = server_list[j];
                                server_list[j] = server;
@@ -1177,14 +1182,14 @@ clock_select(void)
                 * Now drop samples until we're down to one.
                 */
                while (nlist > 1) {
-                       for (n = 0; n < nlist; n++) {
-                               server_badness[n] = 0;
+                       for (k = 0; k < nlist; k++) {
+                               server_badness[k] = 0;
                                for (j = 0; j < nlist; j++) {
-                                       if (j == n) /* with self? */
+                                       if (j == k) /* with self? */
                                                continue;
-                                       d = server_list[j]->soffset
-                                               - server_list[n]->soffset;
-                                       if (d < 0)      /* absolute value */
+                                       d = server_list[j]->soffset -
+                                           server_list[k]->soffset;
+                                       if (d < 0)      /* abs value */
                                                d = -d;
                                        /*
                                         * XXX This code *knows* that
@@ -1192,7 +1197,7 @@ clock_select(void)
                                         */
                                        for (i = 0; i < j; i++)
                                                d = (d>>1) + (d>>2);
-                                       server_badness[n] += d;
+                                       server_badness[k] += d;
                                }
                        }
 
index 21a8f783857117adc207c525c9e30056a6ae0260..027c5f4a5eae1044c69373e7da6460e6bb3f5df6 100644 (file)
@@ -76,11 +76,7 @@ static       int     findcmd         (char *, struct xcmd *, struct xcmd *, struct xcmd **);
 static int     getarg          (char *, int, arg_v *);
 static int     getnetnum       (const char *, sockaddr_u *, char *, int);
 static void    help            (struct parse *, FILE *);
-#ifdef QSORT_USES_VOID_P
 static int     helpsort        (const void *, const void *);
-#else
-static int     helpsort        (char **, char **);
-#endif
 static void    printusage      (struct xcmd *, FILE *);
 static void    timeout         (struct parse *, FILE *);
 static void    my_delay        (struct parse *, FILE *);
@@ -1542,58 +1538,51 @@ help(
        struct xcmd *xcp;
        char *cmd;
        const char *list[100];
-       int word, words;     
-        int row, rows;
-       int col, cols;
+       size_t word, words;
+       size_t row, rows;
+       size_t col, cols;
+       size_t length;
 
        if (pcmd->nargs == 0) {
                words = 0;
                for (xcp = builtins; xcp->keyword != 0; xcp++) {
                        if (*(xcp->keyword) != '?')
-                           list[words++] = xcp->keyword;
+                               list[words++] = xcp->keyword;
                }
-                for (xcp = opcmds; xcp->keyword != 0; xcp++)
-                   list[words++] = xcp->keyword;
+               for (xcp = opcmds; xcp->keyword != 0; xcp++)
+                       list[words++] = xcp->keyword;
 
-               qsort(
-#ifdef QSORT_USES_VOID_P
-                   (void *)
-#else
-                   (char *)
-#endif
-                       (list), (size_t)(words), sizeof(char *), helpsort);
+               qsort((void *)list, (size_t)words, sizeof(list[0]),
+                     helpsort);
                col = 0;
                for (word = 0; word < words; word++) {
-                       int length = strlen(list[word]);
-                       if (col < length) {
-                           col = length;
-                        }
+                       length = strlen(list[word]);
+                       col = max(col, length);
                }
 
                cols = SCREENWIDTH / ++col;
-                rows = (words + cols - 1) / cols;
+               rows = (words + cols - 1) / cols;
 
-               (void) fprintf(fp, "ntpdc commands:\n");
+               fprintf(fp, "ntpdc commands:\n");
 
                for (row = 0; row < rows; row++) {
-                        for (word = row; word < words; word += rows) {
-                               (void) fprintf(fp, "%-*.*s", col, col-1, list[word]);
-                        }
-                       (void) fprintf(fp, "\n");
+                       for (word = row; word < words; word += rows)
+                               fprintf(fp, "%-*.*s", col, col-1, list[word]);
+                       fprintf(fp, "\n");
                }
        } else {
                cmd = pcmd->argval[0].string;
                words = findcmd(cmd, builtins, opcmds, &xcp);
                if (words == 0) {
-                       (void) fprintf(stderr,
-                                      "Command `%s' is unknown\n", cmd);
+                       fprintf(stderr,
+                               "Command `%s' is unknown\n", cmd);
                        return;
                } else if (words >= 2) {
-                       (void) fprintf(stderr,
-                                      "Command `%s' is ambiguous\n", cmd);
+                       fprintf(stderr,
+                               "Command `%s' is ambiguous\n", cmd);
                        return;
                }
-               (void) fprintf(fp, "function: %s\n", xcp->comment);
+               fprintf(fp, "function: %s\n", xcp->comment);
                printusage(xcp, fp);
        }
 }
@@ -1602,28 +1591,17 @@ help(
 /*
  * helpsort - do hostname qsort comparisons
  */
-#ifdef QSORT_USES_VOID_P
 static int
 helpsort(
        const void *t1,
        const void *t2
        )
 {
-       char const * const * name1 = (char const * const *)t1;
-       char const * const * name2 = (char const * const *)t2;
+       const char * const *    name1 = t1;
+       const char * const *    name2 = t2;
 
        return strcmp(*name1, *name2);
 }
-#else
-static int
-helpsort(
-       char **name1,
-       char **name2
-       )
-{
-       return strcmp(*name1, *name2);
-}
-#endif
 
 
 /*
@@ -1976,10 +1954,11 @@ getkeyid(
        const char *keyprompt
        )
 {
-       register char *p;
-       register int c;
+       int c;
        FILE *fi;
        char pbuf[20];
+       size_t i;
+       size_t ilim;
 
 #ifndef SYS_WINNT
        if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
@@ -1987,15 +1966,16 @@ getkeyid(
        if ((fi = _fdopen(open("CONIN$", _O_TEXT), "r")) == NULL)
 #endif /* SYS_WINNT */
                fi = stdin;
-           else
+       else
                setbuf(fi, (char *)NULL);
        fprintf(stderr, "%s", keyprompt); fflush(stderr);
-       for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
-               if (p < &pbuf[18])
-                   *p++ = (char) c;
-       }
-       *p = '\0';
+       for (i = 0, ilim = COUNTOF(pbuf) - 1;
+            i < ilim && (c = getc(fi)) != '\n' && c != EOF;
+            )
+               pbuf[i++] = (char)c;
+       pbuf[i] = '\0';
        if (fi != stdin)
-           fclose(fi);
-       return (u_int32)atoi(pbuf);
+               fclose(fi);
+
+       return (u_long) atoi(pbuf);
 }
index b1d9a04299fc7ed7731a999aaa7da37f0ba15f27..eac081c56e616fd48c8744d0e386c61145a024cb 100644 (file)
@@ -1348,12 +1348,13 @@ doconfig(
        int res;
        int sendsize;
        int numtyp;
+       long val;
 
 again:
        keyid = 0;
        version = 3;
        flags = 0;
-       res = 0;
+       res = FALSE;
        cmode = 0;
        minpoll = NTP_MINDPOLL;
        maxpoll = NTP_MAXDPOLL;
@@ -1369,82 +1370,80 @@ again:
        items = 1;
        while (pcmd->nargs > items) {
                if (STREQ(pcmd->argval[items].string, "prefer"))
-                   flags |= CONF_FLAG_PREFER;
+                       flags |= CONF_FLAG_PREFER;
                else if (STREQ(pcmd->argval[items].string, "burst"))
-                   flags |= CONF_FLAG_BURST;
+                       flags |= CONF_FLAG_BURST;
                else if (STREQ(pcmd->argval[items].string, "iburst"))
-                   flags |= CONF_FLAG_IBURST;
+                       flags |= CONF_FLAG_IBURST;
                else if (!refc && STREQ(pcmd->argval[items].string, "keyid"))
-                   numtyp = 1;
+                       numtyp = 1;
                else if (!refc && STREQ(pcmd->argval[items].string, "version"))
-                   numtyp = 2;
+                       numtyp = 2;
                else if (STREQ(pcmd->argval[items].string, "minpoll"))
-                   numtyp = 3;
+                       numtyp = 3;
                else if (STREQ(pcmd->argval[items].string, "maxpoll"))
-                   numtyp = 4;
+                       numtyp = 4;
                else {
-                       long val;
                        if (!atoint(pcmd->argval[items].string, &val))
-                            numtyp = 0;                                  
+                               numtyp = 0;
                        switch (numtyp) {
                        case 1:
-                            keyid = val;
-                            numtyp = 2;                                  
-                            break;
-                            
+                               keyid = val;
+                               numtyp = 2;
+                               break;
+
                        case 2:
-                            version = (u_int) val;
-                            numtyp = 0;                                  
-                            break;
+                               version = (u_int)val;
+                               numtyp = 0;
+                               break;
 
                        case 3:
-                            minpoll = (u_char)val;
-                            numtyp = 0;                                  
-                            break;
+                               minpoll = (u_char)val;
+                               numtyp = 0;
+                               break;
 
                        case 4:
-                            maxpoll = (u_char)val;
-                            numtyp = 0;                                  
-                            break;
+                               maxpoll = (u_char)val;
+                               numtyp = 0;
+                               break;
 
                        case 5:
-                            cmode = (u_char)val;
-                            numtyp = 0;                                  
-                            break;
+                               cmode = (u_char)val;
+                               numtyp = 0;
+                               break;
 
                        default:
-                            (void) fprintf(fp, "*** '%s' not understood\n",
-                                           pcmd->argval[items].string);
-                            res++;
-                            numtyp = 0;                                  
+                               fprintf(fp, "*** '%s' not understood\n",
+                                       pcmd->argval[items].string);
+                               res = TRUE;
+                               numtyp = 0;
                        }
                        if (val < 0) {
-                            (void) fprintf(stderr,
-                                    "***Value '%s' should be unsigned\n",
-                                     pcmd->argval[items].string);
-                            res++;
+                               fprintf(stderr,
+                                       "*** Value '%s' should be unsigned\n",
+                                       pcmd->argval[items].string);
+                               res = TRUE;
                        }
-                  }
-            items++;
+               }
+               items++;
        }
        if (keyid > 0)
-            flags |= CONF_FLAG_AUTHENABLE;
-       if (version > NTP_VERSION ||
-           version < NTP_OLDVERSION) {
-            (void)fprintf(fp, "***invalid version number: %u\n",
-                          version);
-            res++;
+               flags |= CONF_FLAG_AUTHENABLE;
+       if (version > NTP_VERSION || version < NTP_OLDVERSION) {
+               fprintf(fp, "***invalid version number: %u\n",
+                       version);
+               res = TRUE;
        }
        if (minpoll < NTP_MINPOLL || minpoll > NTP_MAXPOLL || 
            maxpoll < NTP_MINPOLL || maxpoll > NTP_MAXPOLL || 
            minpoll > maxpoll) {
-            (void) fprintf(fp, "***min/max-poll must be within %d..%d\n",
-                           NTP_MINPOLL, NTP_MAXPOLL);
-            res++;
+               fprintf(fp, "***min/max-poll must be within %d..%d\n",
+                       NTP_MINPOLL, NTP_MAXPOLL);
+               res = TRUE;
        }                                       
 
        if (res)
-           return;
+               return;
 
        memset(&cpeer, 0, sizeof(cpeer));
 
@@ -1876,7 +1875,7 @@ again:
        } else {
                if (impl_ver == IMPL_XNTPD_OLD) {
                        fprintf(stderr,
-                           "***Server doesn't understand IPv6 addresses\n");
+                               "***Server doesn't understand IPv6 addresses\n");
                        return;
                }
                cres.addr6 = SOCK_ADDR6(&pcmd->argval[0].netnum);
@@ -1884,7 +1883,7 @@ again:
        }
        cres.flags = 0;
        cres.mflags = 0;
-       err = 0;
+       err = FALSE;
        for (res = 2; res < pcmd->nargs; res++) {
                if (STREQ(pcmd->argval[res].string, "ntpport")) {
                        cres.mflags |= RESM_NTPONLY;
@@ -1892,20 +1891,20 @@ again:
                        for (i = 0; resflagsV3[i].bit != 0; i++) {
                                if (STREQ(pcmd->argval[res].string,
                                          resflagsV3[i].str))
-                                   break;
+                                       break;
                        }
                        if (resflagsV3[i].bit != 0) {
                                cres.flags |= resflagsV3[i].bit;
                                if (req_code == REQ_UNRESTRICT) {
-                                       (void) fprintf(fp,
-                                                      "Flag %s inappropriate\n",
-                                                      resflagsV3[i].str);
-                                       err++;
+                                       fprintf(fp,
+                                               "Flag %s inappropriate\n",
+                                               resflagsV3[i].str);
+                                       err = TRUE;
                                }
                        } else {
-                               (void) fprintf(fp, "Unknown flag %s\n",
-                                              pcmd->argval[res].string);
-                               err++;
+                               fprintf(fp, "Unknown flag %s\n",
+                                       pcmd->argval[res].string);
+                               err = TRUE;
                        }
                }
        }
@@ -1922,15 +1921,15 @@ again:
                } else {
                        num = ntohl(cres.mask);
                        for (bit = 0x80000000; bit != 0; bit >>= 1)
-                           if ((num & bit) == 0)
-                               break;
+                               if ((num & bit) == 0)
+                                       break;
                        for ( ; bit != 0; bit >>= 1)
-                           if ((num & bit) != 0)
-                               break;
+                               if ((num & bit) != 0)
+                                       break;
                        if (bit != 0) {
-                               (void) fprintf(fp, "Invalid mask %s\n",
-                                              numtoa(cres.mask));
-                               err++;
+                               fprintf(fp, "Invalid mask %s\n",
+                                       numtoa(cres.mask));
+                               err = TRUE;
                        }
                }
        } else {
@@ -1938,11 +1937,10 @@ again:
        }
 
        if (err)
-           return;
+               return;
 
-       res = doquery(impl_ver, req_code, 1, 1,
-                     sendsize, (char *)&cres, &items,
-                     &itemsize, &dummy, 0, sizeof(struct conf_restrict));
+       res = doquery(impl_ver, req_code, 1, 1, sendsize, (char *)&cres,
+                     &items, &itemsize, &dummy, 0, sizeof(cres));
        
        if (res == INFO_ERR_IMPL && impl_ver == IMPL_XNTPD) {
                impl_ver = IMPL_XNTPD_OLD;
index 401af80e512043600a27e62ab21a3850c8e7c097..27a15dc4b500c59fc21601851d7267263896bb4e 100644 (file)
@@ -24,7 +24,7 @@ const char *Version = "libntpq 0.3beta";
 /* global variables used for holding snapshots of data */
 char peervars[NTPQ_BUFLEN];
 int peervarlen = 0;
-int peervar_assoc = 0;
+associd_t peervar_assoc = 0;
 char clockvars[NTPQ_BUFLEN];
 int clockvarlen = 0;
 int clockvar_assoc = 0;
@@ -363,16 +363,16 @@ int ntpq_closehost(void)
  *                     ID has been found
  ****************************************************************************/
  
-int ntpq_get_assoc_number ( int associd )
+int ntpq_get_assoc_number ( associd_t associd )
 {
-   int i = 0;
+       int i;
 
-   for (i=0;i<numassoc;i++) {
-     if (assoc_cache[i].assid == associd)
-       return i;
-    }
+       for (i=0;i<numassoc;i++) {
+               if (assoc_cache[i].assid == associd)
+                       return i;
+       }
 
-   return (-1);
+       return -1;
 
 }
 
@@ -405,7 +405,7 @@ int ntpq_get_assoc_number ( int associd )
 
 int
 ntpq_read_assoc_peervars(
-       int associd,
+       associd_t associd,
        char *resultbuf,
        int maxsize
        )
@@ -537,9 +537,10 @@ ntpq_read_sysvars(
  *                     0 (zero) if an error occured and both variable sets
  *                     could not be read
  ****************************************************************************/
- int  ntpq_get_assoc_allvars( int associd  )
+ int  ntpq_get_assoc_allvars( associd_t associd  )
 {
-    return ( ntpq_get_assoc_peervars ( associd ) & ntpq_get_assoc_clockvars( associd ) );
+       return ntpq_get_assoc_peervars ( associd ) &
+              ntpq_get_assoc_clockvars( associd );
 }
 
 
@@ -620,16 +621,17 @@ int ntpq_get_peervar( const char *varname, char *varvalue, int maxlen)
  *                     0 (zero) if an error occured and the variable set
  *                     could not be read
  ****************************************************************************/
- int  ntpq_get_assoc_peervars( int associd )
+ int  ntpq_get_assoc_peervars( associd_t associd )
 {
-        peervarlen = ( ntpq_read_assoc_peervars( associd, peervars, sizeof(peervars )) );
-        if ( peervarlen <= 0 ) {
-            peervar_assoc = 0;
-            return 0;
-        } else {
-            peervar_assoc = associd;
-            return 1;
-        }
+       peervarlen = ntpq_read_assoc_peervars( associd, peervars, 
+                                              sizeof(peervars ) );
+       if ( peervarlen <= 0 ) {
+               peervar_assoc = 0;
+               return 0;
+       } else {
+               peervar_assoc = associd;
+               return 1;
+       }
 }
 
 
@@ -661,9 +663,9 @@ int ntpq_get_peervar( const char *varname, char *varvalue, int maxlen)
 
 int
 ntpq_read_assoc_clockvars(
-       int     associd,
-       char *  resultbuf,
-       int     maxsize
+       associd_t       associd,
+       char *          resultbuf,
+       int             maxsize
        )
 {
        const char *datap;
@@ -704,46 +706,33 @@ ntpq_read_assoc_clockvars(
  *  NTP_CLOCKTYPE_MULTICAST Multicast server
  * 
  ****************************************************************************/
- int ntpq_get_assoc_clocktype ( int assoc_number )
+int ntpq_get_assoc_clocktype ( associd_t assoc_number )
 {
-    int type = 0;
-    int i, rc = 0;
-    sockaddr_u dum_store;
-    char value[LENHOSTNAME];
-    char resultbuf[1024];
-
-
-    if ( assoc_number < 0 || assoc_number > numassoc ) {
-        return -1;
-    } else {
-        if ( peervar_assoc != assoc_cache[assoc_number].assid ) {
-
-            i=ntpq_read_assoc_peervars(assoc_cache[assoc_number].assid, resultbuf, sizeof(resultbuf));
-            if ( i <= 0 ) {
-                return -1;
-            }
-
-            rc = ntpq_getvar(resultbuf, i, "dstadr", value, LENHOSTNAME );
-
-
-        } else {
-            
-            rc = ntpq_get_peervar("dstadr",value,LENHOSTNAME);
-
-        }
+       int type = 0;
+       int i, rc = 0;
+       sockaddr_u dum_store;
+       char value[LENHOSTNAME];
+       char resultbuf[1024];
+
+       if ( assoc_number < 0 || assoc_number > numassoc )
+               return -1;
+       if ( peervar_assoc != assoc_cache[assoc_number].assid ) {
+               i = ntpq_read_assoc_peervars(
+                   assoc_cache[assoc_number].assid, resultbuf,
+                   sizeof(resultbuf));
+               if ( i <= 0 )
+                       return -1;
+               rc = ntpq_getvar(resultbuf, i, "dstadr", value,
+                                LENHOSTNAME );
+       } else {
+               rc = ntpq_get_peervar("dstadr",value,LENHOSTNAME);
+       }
 
-        if ( rc ) {
-            if (decodenetnum(value, &dum_store)) {
+       if (0 != rc && decodenetnum(value, &dum_store)) {
                type = ntpq_decodeaddrtype(&dum_store);
-                return type;
-            }
-        }
-
-        return -1;
-    }
-
-    return -1;
-
+               return type;
+       }
+       return -1;
 }
 
 
@@ -768,20 +757,20 @@ ntpq_read_assoc_clockvars(
  *                     0 (zero) if an error occured and the variable set
  *                     could not be read
  ****************************************************************************/
- int  ntpq_get_assoc_clockvars( int associd )
+int  ntpq_get_assoc_clockvars( associd_t associd )
 {
-        
-        if ( ntpq_get_assoc_clocktype(ntpq_get_assoc_number(associd)) != NTP_CLOCKTYPE_LOCAL )
-            return 0;
-  
-        clockvarlen = ( ntpq_read_assoc_clockvars( associd, clockvars, sizeof(clockvars )) );
-        if ( clockvarlen <= 0 ) {
-            clockvar_assoc = 0;
-            return 0;
-        } else {
-            clockvar_assoc = associd;
-            return 1;
-        }
+       if (NTP_CLOCKTYPE_LOCAL != ntpq_get_assoc_clocktype(
+           ntpq_get_assoc_number(associd)))
+               return 0;
+       clockvarlen = ntpq_read_assoc_clockvars( associd, clockvars,
+                                                sizeof(clockvars) );
+       if ( clockvarlen <= 0 ) {
+               clockvar_assoc = 0;
+               return 0;
+       } else {
+               clockvar_assoc = associd;
+               return 1;
+       }
 }
 
 
index 5bf35f4aab4c87de9b4fae5a4e084073c3591c92..e97f4b380edfa918e4b01206c878e9dfd0f92123 100644 (file)
@@ -82,29 +82,27 @@ extern struct ntpq_varlist ntpq_varlist[MAXLIST];
 /* from libntpq.c */
 extern int ntpq_openhost(char *);
 extern int ntpq_closehost(void);
-extern int ntpq_queryhost(unsigned short VARSET, unsigned short association, char *resultbuf, int maxlen);
+extern int ntpq_queryhost(unsigned short VARSET, associd_t association, char *resultbuf, int maxlen);
 extern size_t ntpq_getvar(const char *resultbuf, size_t datalen,
                          const char *varname, char *varvalue,
                          size_t maxlen);
 extern int ntpq_stripquotes ( char *resultbuf, char *srcbuf, int datalen, int maxlen );
-extern int ntpq_queryhost_peervars(unsigned short association, char *resultbuf, int maxlen);
+extern int ntpq_queryhost_peervars(associd_t association, char *resultbuf, int maxlen);
 extern int ntpq_get_peervar( const char *varname, char *varvalue, int maxlen);
 extern size_t ntpq_read_sysvars(char *resultbuf, size_t maxsize);
 extern int ntpq_get_sysvars( void );
 extern int ntpq_read_associations ( unsigned short resultbuf[], int max_entries );
 extern int ntpq_get_assocs ( void );
-extern int ntpq_get_assoc_number ( int associd );
-extern int ntpq_get_assoc_peervars( int associd );
-extern int ntpq_get_assoc_clockvars( int associd );
-extern int ntpq_get_assoc_allvars( int associd  );
-extern int ntpq_get_assoc_clocktype ( int assoc_number );
-extern int ntpq_read_assoc_peervars( int associd, char *resultbuf, int maxsize );
-extern int ntpq_read_assoc_clockvars( int associd, char *resultbuf, int maxsize );
+extern int ntpq_get_assoc_number ( associd_t associd );
+extern int ntpq_get_assoc_peervars( associd_t associd );
+extern int ntpq_get_assoc_clockvars( associd_t associd );
+extern int ntpq_get_assoc_allvars( associd_t associd  );
+extern int ntpq_get_assoc_clocktype ( associd_t assoc_number );
+extern int ntpq_read_assoc_peervars( associd_t associd, char *resultbuf, int maxsize );
+extern int ntpq_read_assoc_clockvars( associd_t associd, char *resultbuf, int maxsize );
 
 /* in libntpq_subs.c */
-#ifndef _LIBNTPQSUBSC
 extern int ntpq_dogetassoc(void);
 extern char ntpq_decodeaddrtype(sockaddr_u *sock);
-extern int ntpq_doquerylist(struct ntpq_varlist *, int , int , int , u_short *, int *, const char **datap );
-#endif
+extern int ntpq_doquerylist(struct ntpq_varlist *, int , associd_t , int , u_short *, int *, const char **datap );
 
index b30ee3d6260bc25c2eef7c04a37997e98bb63daf..09b99bd482900ff8bed8f8ec89716eff3028a3b3 100644 (file)
  ****************************************************************************/
 
 
-#define _LIBNTPQSUBSC
 #include "ntpq-subs.c"
 #include "libntpq.h"
 
-/* Function Prototypes */
-int ntpq_dogetassoc(void);
-char ntpq_decodeaddrtype(sockaddr_u *sock);
-int ntpq_doquerylist(struct varlist *, int , int , int , u_short *, int *, const char **datap);
-
 
 /* the following functions are required internally by a number of libntpq functions 
  * and since they are defined as static in ntpq-subs.c, they need to be exported here
@@ -45,16 +39,16 @@ char ntpq_decodeaddrtype(sockaddr_u *sock)
 
 int
 ntpq_doquerylist(
-       struct varlist *vlist,
+       struct ntpq_varlist *vlist,
        int op,
-       int associd,
+       associd_t associd,
        int auth,
        u_short *rstatus,
        int *dsize,
        const char **datap
        )
 {
-       return doquerylist(vlist, op, associd, auth, rstatus, dsize,
-                          datap);
+       return doquerylist((struct varlist *)vlist, op, associd, auth,
+                          rstatus, dsize, datap);
 }
 
index a5c230824143298845bde4bb59eb3eeae5801337..8a53612814c3814c05d82191bd20e43c77655c1c 100644 (file)
@@ -19,20 +19,20 @@ int         maxhostlen;
 /*
  * Declarations for command handlers in here
  */
-static int     checkassocid    (u_int32);
+static associd_t checkassocid  (u_int32);
 static struct varlist *findlistvar (struct varlist *, char *);
 static void    doaddvlist      (struct varlist *, const char *);
 static void    dormvlist       (struct varlist *, const char *);
 static void    doclearvlist    (struct varlist *);
 static void    makequerydata   (struct varlist *, int *, char *);
-static int     doquerylist     (struct varlist *, int, int, int, 
+static int     doquerylist     (struct varlist *, int, associd_t, int,
                                 u_short *, int *, const char **);
 static void    doprintvlist    (struct varlist *, FILE *);
 static void    addvars         (struct parse *, FILE *);
 static void    rmvars          (struct parse *, FILE *);
 static void    clearvars       (struct parse *, FILE *);
 static void    showvars        (struct parse *, FILE *);
-static int     dolist          (struct varlist *, int, int, int,
+static int     dolist          (struct varlist *, associd_t, int, int,
                                 FILE *);
 static void    readlist        (struct parse *, FILE *);
 static void    writelist       (struct parse *, FILE *);
@@ -58,7 +58,7 @@ static        void    pstatus         (struct parse *, FILE *);
 static long    when            (l_fp *, l_fp *, l_fp *);
 static char *  prettyinterval  (char *, size_t, long);
 static int     doprintpeers    (struct varlist *, int, int, int, const char *, FILE *, int);
-static int     dogetpeers      (struct varlist *, int, FILE *, int);
+static int     dogetpeers      (struct varlist *, associd_t, FILE *, int);
 static void    dopeers         (int, FILE *, int);
 static void    peers           (struct parse *, FILE *);
 static void    lpeers          (struct parse *, FILE *);
@@ -218,16 +218,24 @@ extern struct ctl_var peer_var[];
 /*
  * checkassocid - return the association ID, checking to see if it is valid
  */
-static int
+static associd_t
 checkassocid(
        u_int32 value
        )
 {
-       if (value == 0 || value >= 65536) {
-               (void) fprintf(stderr, "***Invalid association ID specified\n");
+       associd_t       associd;
+       u_long          ulvalue;
+
+       associd = (associd_t)value;
+       if (0 == associd || value != associd) {
+               ulvalue = value;
+               fprintf(stderr,
+                       "***Invalid association ID %lu specified\n",
+                       ulvalue);
                return 0;
        }
-       return (int)value;
+
+       return associd;
 }
 
 
@@ -391,7 +399,7 @@ static int
 doquerylist(
        struct varlist *vlist,
        int op,
-       int associd,
+       associd_t associd,
        int auth,
        u_short *rstatus,
        int *dsize,
@@ -496,7 +504,7 @@ showvars(
 static int
 dolist(
        struct varlist *vlist,
-       int associd,
+       associd_t associd,
        int op,
        int type,
        FILE *fp
@@ -551,7 +559,8 @@ readlist(
        FILE *fp
        )
 {
-       int associd;
+       associd_t       associd;
+       int             type;
 
        if (pcmd->nargs == 0) {
                associd = 0;
@@ -563,8 +572,10 @@ readlist(
                        return;
        }
 
-       (void) dolist(g_varlist, associd, CTL_OP_READVAR,
-                         (associd == 0) ? TYPE_SYS : TYPE_PEER, fp);
+       type = (0 == associd)
+                  ? TYPE_SYS
+                  : TYPE_PEER;
+       dolist(g_varlist, associd, CTL_OP_READVAR, type, fp);
 }
 
 
@@ -579,7 +590,7 @@ writelist(
 {
        const char *datap;
        int res;
-       int associd;
+       associd_t associd;
        int dsize;
        u_short rstatus;
 
@@ -621,8 +632,10 @@ readvar(
        FILE *fp
        )
 {
-       int associd;
-       struct varlist tmplist[MAXLIST];
+       associd_t       associd;
+       int             type;
+       struct varlist  tmplist[MAXLIST];
+
 
        /* HMS: uval? */
        if (pcmd->nargs == 0 || pcmd->argval[0].uval == 0)
@@ -630,12 +643,14 @@ readvar(
        else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0)
                return;
 
-       memset((char *)tmplist, 0, sizeof(tmplist));
+       memset(tmplist, 0, sizeof(tmplist));
        if (pcmd->nargs >= 2)
                doaddvlist(tmplist, pcmd->argval[1].string);
 
-       (void) dolist(tmplist, associd, CTL_OP_READVAR,
-                         (associd == 0) ? TYPE_SYS : TYPE_PEER, fp);
+       type = (0 == associd)
+                  ? TYPE_SYS
+                  : TYPE_PEER;
+       dolist(tmplist, associd, CTL_OP_READVAR, type, fp);
 
        doclearvlist(tmplist);
 }
@@ -652,7 +667,8 @@ writevar(
 {
        const char *datap;
        int res;
-       int associd;
+       associd_t associd;
+       int type;
        int dsize;
        u_short rstatus;
        struct varlist tmplist[MAXLIST];
@@ -675,16 +691,15 @@ writevar(
                return;
 
        if (numhosts > 1)
-               (void) fprintf(fp, "server=%s ", currenthost);
+               fprintf(fp, "server=%s ", currenthost);
        if (dsize == 0)
-               (void) fprintf(fp, "done! (no data returned)\n");
+               fprintf(fp, "done! (no data returned)\n");
        else {
-               (void) fprintf(fp,"associd=%d ",associd);
-               printvars(dsize, datap, (int)rstatus,
-                         (associd != 0)
-                             ? TYPE_PEER 
-                             : TYPE_SYS, 
-                         0, fp);
+               fprintf(fp,"associd=%d ",associd);
+               type = (0 == associd)
+                          ? TYPE_SYS
+                          : TYPE_PEER;
+               printvars(dsize, datap, (int)rstatus, type, 0, fp);
        }
        return;
 }
@@ -699,7 +714,7 @@ clocklist(
        FILE *fp
        )
 {
-       int associd;
+       associd_t associd;
 
        /* HMS: uval? */
        if (pcmd->nargs == 0) {
@@ -711,7 +726,7 @@ clocklist(
                        return;
        }
 
-       (void) dolist(g_varlist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp);
+       dolist(g_varlist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp);
 }
 
 
@@ -724,7 +739,7 @@ clockvar(
        FILE *fp
        )
 {
-       int associd;
+       associd_t associd;
        struct varlist tmplist[MAXLIST];
 
        /* HMS: uval? */
@@ -733,11 +748,11 @@ clockvar(
        else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0)
                return;
 
-       memset((char *)tmplist, 0, sizeof(tmplist));
+       memset(tmplist, 0, sizeof(tmplist));
        if (pcmd->nargs >= 2)
                doaddvlist(tmplist, pcmd->argval[1].string);
 
-       (void) dolist(tmplist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp);
+       dolist(tmplist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp);
 
        doclearvlist(tmplist);
 }
@@ -754,48 +769,38 @@ findassidrange(
        int *to
        )
 {
-       register int i;
-       int f, t;
+       associd_t       assids[2];
+       int             ind[COUNTOF(assids)];
+       int             i;
+       size_t          a;
 
-       if (assid1 == 0 || assid1 > 65535) {
-               (void) fprintf(stderr,
-                                  "***Invalid association ID %lu specified\n", (u_long)assid1);
+       assids[0] = checkassocid(assid1);
+       if (0 == assids[0])
                return 0;
-       }
-
-       if (assid2 == 0 || assid2 > 65535) {
-       fprintf(stderr,
-           "***Invalid association ID %lu specified\n", (u_long)assid2);
+       assids[1] = checkassocid(assid2);
+       if (0 == assids[1])
                return 0;
-       }
 
-       f = t = -1;
-       for (i = 0; i < numassoc; i++) {
-               if (assoc_cache[i].assid == assid1) {
-                       f = i;
-                       if (t != -1)
-                               break;
-               }
-               if (assoc_cache[i].assid == assid2) {
-                       t = i;
-                       if (f != -1)
-                               break;
-               }
-       }
-
-       if (f == -1 || t == -1) {
-               (void) fprintf(stderr,
-                                  "***Association ID %lu not found in list\n",
-                                  (f == -1) ? (u_long)assid1 : (u_long)assid2);
-               return 0;
+       for (a = 0; a < COUNTOF(assids); a++) {
+               ind[a] = -1;
+               for (i = 0; i < numassoc; i++)
+                       if (assoc_cache[i].assid == assids[a])
+                               ind[a] = i;
        }
+       for (a = 0; a < COUNTOF(assids); a++)
+               if (-1 == ind[a]) {
+                       fprintf(stderr,
+                               "***Association ID %u not found in list\n",
+                               assids[a]);
+                       return 0;
+               }
 
-       if (f < t) {
-               *from = f;
-               *to = t;
+       if (ind[0] < ind[1]) {
+               *from = ind[0];
+               *to = ind[1];
        } else {
-               *from = t;
-               *to = f;
+               *to = ind[0];
+               *from = ind[1];
        }
        return 1;
 }
@@ -844,21 +849,26 @@ mreadvar(
        int from;
        int to;
        struct varlist tmplist[MAXLIST];
+       struct varlist *pvars;
 
        /* HMS: uval? */
        if (!findassidrange(pcmd->argval[0].uval, pcmd->argval[1].uval,
                                &from, &to))
                return;
 
-       memset((char *)tmplist, 0, sizeof(tmplist));
-       if (pcmd->nargs >= 3)
+       if (pcmd->nargs >= 3) {
+               memset(tmplist, 0, sizeof(tmplist));
                doaddvlist(tmplist, pcmd->argval[2].string);
+               pvars = tmplist;
+       } else {
+               pvars = g_varlist;
+       }
 
        for (i = from; i <= to; i++) {
                if (i != from)
-                       (void) fprintf(fp, "\n");
-               if (!dolist(g_varlist, (int)assoc_cache[i].assid,
-                               CTL_OP_READVAR, TYPE_PEER, fp))
+                       fprintf(fp, "\n");
+               if (!dolist(pvars, (int)assoc_cache[i].assid,
+                           CTL_OP_READVAR, TYPE_PEER, fp))
                        break;
        }
        doclearvlist(tmplist);
@@ -1239,7 +1249,7 @@ pstatus(
 {
        const char *datap;
        int res;
-       int associd;
+       associd_t associd;
        int dsize;
        u_short rstatus;
 
@@ -1247,22 +1257,22 @@ pstatus(
        if ((associd = checkassocid(pcmd->argval[0].uval)) == 0)
                return;
 
-       res = doquery(CTL_OP_READSTAT, associd, 0, 0, (char *)0, &rstatus,
-                         &dsize, &datap);
+       res = doquery(CTL_OP_READSTAT, associd, 0, 0, NULL, &rstatus,
+                     &dsize, &datap);
 
        if (res != 0)
                return;
 
        if (numhosts > 1)
-               (void) fprintf(fp, "server=%s ", currenthost);
+               fprintf(fp, "server=%s ", currenthost);
        if (dsize == 0) {
-               (void) fprintf(fp,
-                                  "No information returned for association %u\n",
-                                  associd);
+               fprintf(fp,
+                       "No information returned for association %u\n",
+                       associd);
                return;
        }
 
-       (void) fprintf(fp,"associd=%d ",associd);
+       fprintf(fp, "associd=%u ", associd);
        printvars(dsize, datap, (int)rstatus, TYPE_PEER, 0, fp);
 }
 
@@ -1636,7 +1646,7 @@ doprintpeers(
 static int
 dogetpeers(
        struct varlist *pvl,
-       int associd,
+       associd_t associd,
        FILE *fp,
        int af
        )
@@ -1653,7 +1663,7 @@ dogetpeers(
        /*
         * Damn fuzzballs
         */
-       res = doquery(CTL_OP_READVAR, associd, 0, 0, (char *)0, &rstatus,
+       res = doquery(CTL_OP_READVAR, associd, 0, 0, NULL, &rstatus,
                          &dsize, &datap);
 #endif
 
@@ -1662,14 +1672,15 @@ dogetpeers(
 
        if (dsize == 0) {
                if (numhosts > 1)
-                       (void) fprintf(stderr, "server=%s ", currenthost);
-               (void) fprintf(stderr,
-                                  "***No information returned for association %d\n",
-                                  associd);
+                       fprintf(stderr, "server=%s ", currenthost);
+               fprintf(stderr,
+                       "***No information returned for association %u\n",
+                       associd);
                return 0;
        }
 
-       return doprintpeers(pvl, associd, (int)rstatus, dsize, datap, fp, af);
+       return doprintpeers(pvl, associd, (int)rstatus, dsize, datap,
+                           fp, af);
 }
 
 
index 5000bb624fc57913aac555c3771dee3fe3ef9010..c1b175f727db9abd79fd35fafbc046aec186cf3b 100644 (file)
@@ -260,11 +260,7 @@ 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 *);
-#ifdef QSORT_USES_VOID_P
 static int     helpsort        (const void *, const void *);
-#else
-static int     helpsort        (char **, char **);
-#endif
 static void    printusage      (struct xcmd *, FILE *);
 static void    timeout         (struct parse *, FILE *);
 static void    auth_delay      (struct parse *, FILE *);
@@ -291,11 +287,7 @@ static     void    startoutput     (void);
 static void    output          (FILE *, char *, char *);
 static void    endoutput       (FILE *);
 static void    outputarr       (FILE *, char *, int, l_fp *);
-#ifdef QSORT_USES_VOID_P
 static int     assoccmp        (const void *, const void *);
-#else
-static int     assoccmp        (struct association *, struct association *);
-#endif /* sgi || bsdi */
 void   ntpq_custom_opt_handler (tOptions *, tOptDesc *);
 
 
@@ -831,11 +823,16 @@ getresponse(
        u_short counts[MAXFRAGS+1];
        u_short offset;
        u_short count;
-       int numfrags;
+       size_t numfrags;
+       size_t f;
+       size_t ff;
        int seenlastfrag;
        int shouldbesize;
        fd_set fds;
        int n;
+       int len;
+       int first;
+       char *data;
 
        /*
         * This is pretty tricky.  We may get between 1 and MAXFRAG packets
@@ -846,7 +843,7 @@ getresponse(
         */
        *rsize = 0;
        if (rstatus)
-           *rstatus = 0;
+               *rstatus = 0;
        *rdata = (char *)pktdata;
 
        numfrags = 0;
@@ -882,29 +879,28 @@ getresponse(
                                                "%s: timed out, nothing received\n",
                                                currenthost);
                                return ERR_TIMEOUT;
-                       } else {
-                               if (timeo)
-                                       fprintf(stderr,
-                                                  "%s: timed out with incomplete data\n",
-                                                  currenthost);
-                               if (debug) {
-                                       fprintf(stderr,
-                                               "ERR_INCOMPLETE: Received fragments:\n");
-                                       for (n = 0; n < numfrags; n++)
-                                               fprintf(stderr,
-                                                       "%2d: %5d %5d\t%3d octets\n",
-                                                       n, offsets[n],
-                                                       offsets[n] +
-                                                       counts[n],
-                                                       counts[n]);
+                       }
+                       if (timeo)
+                               fprintf(stderr,
+                                       "%s: timed out with incomplete data\n",
+                                       currenthost);
+                       if (debug) {
+                               fprintf(stderr,
+                                       "ERR_INCOMPLETE: Received fragments:\n");
+                               for (f = 0; f < numfrags; f++)
                                        fprintf(stderr,
-                                               "last fragment %sreceived\n",
-                                               (seenlastfrag)
-                                                   ? ""
-                                                   : "not ");
-                               }
-                               return ERR_INCOMPLETE;
+                                               "%2u: %5d %5d\t%3d octets\n",
+                                               f, offsets[f],
+                                               offsets[f] +
+                                               counts[f],
+                                               counts[f]);
+                               fprintf(stderr,
+                                       "last fragment %sreceived\n",
+                                       (seenlastfrag)
+                                           ? ""
+                                           : "not ");
                        }
+                       return ERR_INCOMPLETE;
                }
 
                n = recv(sockfd, (char *)&rpkt, sizeof(rpkt), 0);
@@ -914,8 +910,9 @@ getresponse(
                }
 
                if (debug >= 4) {
-                       int len = n, first = 8;
-                       char *data = (char *)&rpkt;
+                       len = n;
+                       first = 8;
+                       data = (char *)&rpkt;
 
                        printf("Packet data:\n");
                        while (len-- > 0) {
@@ -933,25 +930,25 @@ getresponse(
                 */
                if (n < CTL_HEADER_LEN) {
                        if (debug)
-                           printf("Short (%d byte) packet received\n", n);
+                               printf("Short (%d byte) packet received\n", n);
                        continue;
                }
                if (PKT_VERSION(rpkt.li_vn_mode) > NTP_VERSION
                    || PKT_VERSION(rpkt.li_vn_mode) < NTP_OLDVERSION) {
                        if (debug)
-                           printf("Packet received with version %d\n",
-                                  PKT_VERSION(rpkt.li_vn_mode));
+                               printf("Packet received with version %d\n",
+                                      PKT_VERSION(rpkt.li_vn_mode));
                        continue;
                }
                if (PKT_MODE(rpkt.li_vn_mode) != MODE_CONTROL) {
                        if (debug)
-                           printf("Packet received with mode %d\n",
-                                  PKT_MODE(rpkt.li_vn_mode));
+                               printf("Packet received with mode %d\n",
+                                      PKT_MODE(rpkt.li_vn_mode));
                        continue;
                }
                if (!CTL_ISRESPONSE(rpkt.r_m_e_op)) {
                        if (debug)
-                           printf("Received request packet, wanted response\n");
+                               printf("Received request packet, wanted response\n");
                        continue;
                }
 
@@ -961,9 +958,8 @@ getresponse(
                 */
                if (ntohs(rpkt.sequence) != sequence) {
                        if (debug)
-                           printf(
-                                   "Received sequnce number %d, wanted %d\n",
-                                   ntohs(rpkt.sequence), sequence);
+                               printf("Received sequnce number %d, wanted %d\n",
+                                      ntohs(rpkt.sequence), sequence);
                        continue;
                }
                if (CTL_OP(rpkt.r_m_e_op) != opcode) {
@@ -1076,7 +1072,7 @@ getresponse(
                }
 
                if (debug >= 2)
-                   printf("Got packet, size = %d\n", n);
+                       printf("Got packet, size = %d\n", n);
                if ((int)count > (n - CTL_HEADER_LEN)) {
                        if (debug)
                                printf("Received count of %d octets, "
@@ -1086,18 +1082,18 @@ getresponse(
                }
                if (count == 0 && CTL_ISMORE(rpkt.r_m_e_op)) {
                        if (debug)
-                           printf("Received count of 0 in non-final fragment\n");
+                               printf("Received count of 0 in non-final fragment\n");
                        continue;
                }
                if (offset + count > sizeof(pktdata)) {
                        if (debug)
-                           printf("Offset %d, count %d, too big for buffer\n",
-                                  offset, count);
+                               printf("Offset %d, count %d, too big for buffer\n",
+                                      offset, count);
                        return ERR_TOOMUCH;
                }
                if (seenlastfrag && !CTL_ISMORE(rpkt.r_m_e_op)) {
                        if (debug)
-                           printf("Received second last fragment packet\n");
+                               printf("Received second last fragment packet\n");
                        continue;
                }
 
@@ -1106,11 +1102,12 @@ getresponse(
                 * overlap anything.
                 */
                if (debug >= 2)
-                   printf("Packet okay\n");;
+                       printf("Packet okay\n");;
 
                if (numfrags > (MAXFRAGS - 1)) {
                        if (debug)
-                           printf("Number of fragments exceeds maximum\n");
+                               printf("Number of fragments exceeds maximum %d\n",
+                                      MAXFRAGS - 1);
                        return ERR_TOOMUCH;
                }
 
@@ -1118,56 +1115,41 @@ getresponse(
                 * Find the position for the fragment relative to any
                 * previously received.
                 */
-               for (n = 0; 
-                    n < numfrags && offsets[n] < offset; 
-                    n++) {
+               for (f = 0; 
+                    f < numfrags && offsets[f] < offset; 
+                    f++) {
                        /* empty body */ ;
                }
 
-               if (n < numfrags && offset == offsets[n]) {
+               if (f < numfrags && offset == offsets[f]) {
                        if (debug)
-                               printf("duplicate %u octets at %u "
-                                       "ignored, prior %u at %u\n",
-                                       count,
-                                       offset,
-                                       counts[n],
-                                       offsets[n]
-                                       );
+                               printf("duplicate %u octets at %u ignored, prior %u at %u\n",
+                                      count, offset, counts[f],
+                                      offsets[f]);
                        continue;
                }
 
-               if (n > 0 && (offsets[n-1] + counts[n-1]) > offset) {
+               if (f > 0 && (offsets[f-1] + counts[f-1]) > offset) {
                        if (debug)
-                               printf("received frag at %u overlaps "
-                                       "with %u octet frag at %u\n",
-                                       offset,
-                                       counts[n-1],
-                                       offsets[n-1]
-                                       );
+                               printf("received frag at %u overlaps with %u octet frag at %u\n",
+                                      offset, counts[f-1],
+                                      offsets[f-1]);
                        continue;
                }
 
-               if (n < numfrags && (offset + count) > offsets[n]) {
+               if (f < numfrags && (offset + count) > offsets[f]) {
                        if (debug)
-                               printf("received %u octet frag at %u "
-                                       "overlaps with frag at %u\n",
-                                       count,
-                                       offset,
-                                       offsets[n]
-                                       );
+                               printf("received %u octet frag at %u overlaps with frag at %u\n",
+                                      count, offset, offsets[f]);
                        continue;
                }
 
-               {
-                       register int i;
-                       
-                       for (i = numfrags; i > n; i--) {
-                               offsets[i] = offsets[i-1];
-                               counts[i] = counts[i-1];
-                       }
+               for (ff = numfrags; ff > f; ff--) {
+                       offsets[ff] = offsets[ff-1];
+                       counts[ff] = counts[ff-1];
                }
-               offsets[n] = offset;
-               counts[n] = count;
+               offsets[f] = offset;
+               counts[f] = count;
                numfrags++;
 
                /*
@@ -1177,7 +1159,7 @@ getresponse(
                if (!CTL_ISMORE(rpkt.r_m_e_op)) {
                        seenlastfrag = 1;
                        if (rstatus != 0)
-                           *rstatus = ntohs(rpkt.status);
+                               *rstatus = ntohs(rpkt.status);
                }
 
                /*
@@ -1190,15 +1172,15 @@ getresponse(
                 * If there aren't any, we're done.
                 */
                if (seenlastfrag && offsets[0] == 0) {
-                       for (n = 1; n < numfrags; n++) {
-                               if (offsets[n-1] + counts[n-1] != offsets[n])
+                       for (f = 1; f < numfrags; f++)
+                               if (offsets[f-1] + counts[f-1] !=
+                                   offsets[f])
                                        break;
-                       }
-                       if (n == numfrags) {
-                               *rsize = offsets[numfrags-1] + counts[numfrags-1];
+                       if (f == numfrags) {
+                               *rsize = offsets[f-1] + counts[f-1];
                                if (debug)
                                        fprintf(stderr,
-                                               "%d packets reassembled into response\n",
+                                               "%u packets reassembled into response\n",
                                                numfrags);
                                return 0;
                        }
@@ -2033,6 +2015,10 @@ decodets(
        l_fp *lfp
        )
 {
+       char *cp;
+       char buf[30];
+       size_t b;
+
        /*
         * If it starts with a 0x, decode as hex.
         */
@@ -2043,14 +2029,12 @@ decodets(
         * If it starts with a '"', try it as an RT-11 date.
         */
        if (*str == '"') {
-               register char *cp = str+1;
-               register char *bp;
-               char buf[30];
-
-               bp = buf;
-               while (*cp != '"' && *cp != '\0' && bp < &buf[29])
-                       *bp++ = *cp++;
-               *bp = '\0';
+               cp = str + 1;
+               b = 0;
+               while ('"' != *cp && '\0' != *cp &&
+                      b < COUNTOF(buf) - 1)
+                       buf[b++] = *cp++;
+               buf[b] = '\0';
                return rtdatetolfp(buf, lfp);
        }
 
@@ -2175,59 +2159,52 @@ help(
        struct xcmd *xcp = NULL;        /* quiet warning */
        char *cmd;
        const char *list[100];
-       int word, words;
-       int row, rows;
-       int col, cols;
+       size_t word, words;
+       size_t row, rows;
+       size_t col, cols;
+       size_t length;
 
        if (pcmd->nargs == 0) {
                words = 0;
-               for (xcp = builtins; xcp->keyword != 0; xcp++) {
+               for (xcp = builtins; xcp->keyword != NULL; xcp++) {
                        if (*(xcp->keyword) != '?')
                                list[words++] = xcp->keyword;
                }
-               for (xcp = opcmds; xcp->keyword != 0; xcp++)
+               for (xcp = opcmds; xcp->keyword != NULL; xcp++)
                        list[words++] = xcp->keyword;
 
-               qsort(
-#ifdef QSORT_USES_VOID_P
-                   (void *)
-#else
-                   (char *)
-#endif
-                       (list), (size_t)(words), sizeof(char *), helpsort);
+               qsort((void *)list, (size_t)words, sizeof(list[0]),
+                     helpsort);
                col = 0;
                for (word = 0; word < words; word++) {
-                       int length = strlen(list[word]);
-                       if (col < length) {
-                               col = length;
-                       }
+                       length = strlen(list[word]);
+                       col = max(col, length);
                }
 
                cols = SCREENWIDTH / ++col;
                rows = (words + cols - 1) / cols;
 
-               (void) fprintf(fp, "ntpq commands:\n");
+               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)
+                               fprintf(fp, "%-*.*s", col,  col-1,
+                                       list[word]);
+                       fprintf(fp, "\n");
                }
        } else {
                cmd = pcmd->argval[0].string;
                words = findcmd(cmd, builtins, opcmds, &xcp);
                if (words == 0) {
-                       (void) fprintf(stderr,
-                                      "Command `%s' is unknown\n", cmd);
+                       fprintf(stderr,
+                               "Command `%s' is unknown\n", cmd);
                        return;
                } else if (words >= 2) {
-                       (void) fprintf(stderr,
-                                      "Command `%s' is ambiguous\n", cmd);
+                       fprintf(stderr,
+                               "Command `%s' is ambiguous\n", cmd);
                        return;
                }
-               (void) fprintf(fp, "function: %s\n", xcp->comment);
+               fprintf(fp, "function: %s\n", xcp->comment);
                printusage(xcp, fp);
        }
 }
@@ -2236,29 +2213,18 @@ help(
 /*
  * helpsort - do hostname qsort comparisons
  */
-#ifdef QSORT_USES_VOID_P
 static int
 helpsort(
        const void *t1,
        const void *t2
        )
 {
-       char const * const * name1 = (char const * const *)t1;
-       char const * const * name2 = (char const * const *)t2;
+       const char * const *    name1 = t1;
+       const char * const *    name2 = t2;
 
        return strcmp(*name1, *name2);
 }
 
-#else
-static int
-helpsort(
-       char **name1,
-       char **name2
-       )
-{
-       return strcmp(*name1, *name2);
-}
-#endif
 
 /*
  * printusage - print usage information for a command
@@ -2704,10 +2670,11 @@ getkeyid(
        const char *keyprompt
        )
 {
-       register char *p;
-       register int c;
+       int c;
        FILE *fi;
        char pbuf[20];
+       size_t i;
+       size_t ilim;
 
 #ifndef SYS_WINNT
        if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
@@ -2715,18 +2682,16 @@ getkeyid(
        if ((fi = _fdopen(open("CONIN$", _O_TEXT), "r")) == NULL)
 #endif /* SYS_WINNT */
                fi = stdin;
-           else
+       else
                setbuf(fi, (char *)NULL);
        fprintf(stderr, "%s", keyprompt); fflush(stderr);
-       for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
-               if (p < &pbuf[18])
-                   *p++ = (char)c;
-       }
-       *p = '\0';
+       for (i = 0, ilim = COUNTOF(pbuf) - 1;
+            i < ilim && (c = getc(fi)) != '\n' && c != EOF;
+            )
+               pbuf[i++] = (char)c;
+       pbuf[i] = '\0';
        if (fi != stdin)
-           fclose(fi);
-       if (strcmp(pbuf, "0") == 0)
-           return 0;
+               fclose(fi);
 
        return (u_long) atoi(pbuf);
 }
@@ -3410,29 +3375,22 @@ void
 sortassoc(void)
 {
        if (numassoc > 1)
-           qsort(
-#ifdef QSORT_USES_VOID_P
-                   (void *)
-#else
-                   (char *)
-#endif
-                   assoc_cache, (size_t)numassoc,
-                   sizeof(struct association), assoccmp);
+               qsort((void *)assoc_cache, (size_t)numassoc,
+                   sizeof(assoc_cache[0]), assoccmp);
 }
 
 
 /*
  * assoccmp - compare two associations
  */
-#ifdef QSORT_USES_VOID_P
 static int
 assoccmp(
        const void *t1,
        const void *t2
        )
 {
-       const struct association *ass1 = (const struct association *)t1;
-       const struct association *ass2 = (const struct association *)t2;
+       const struct association *ass1 = t1;
+       const struct association *ass2 = t2;
 
        if (ass1->assid < ass2->assid)
                return -1;
@@ -3440,20 +3398,7 @@ assoccmp(
                return 1;
        return 0;
 }
-#else
-static int
-assoccmp(
-       struct association *ass1,
-       struct association *ass2
-       )
-{
-       if (ass1->assid < ass2->assid)
-           return -1;
-       if (ass1->assid > ass2->assid)
-           return 1;
-       return 0;
-}
-#endif /* not QSORT_USES_VOID_P */
+
 
 /*
  * ntpq_custom_opt_handler - autoopts handler for -c and -p
index d03a5b26a92de9bcc8eafa18aa0443c166699983..4abc0aaefbadf0fe472aebf0b041dcc934085dca 100644 (file)
@@ -63,7 +63,7 @@ struct xcmd {
  * Structure to hold association data
  */
 struct association {
-       u_short assid;
+       associd_t assid;
        u_short status;
 };
 
index 6ce262536bf1640a4810617526dbed32b7b4a757..b96a0cab8c3b11832d410c00937df505b129a44b 100644 (file)
@@ -40,7 +40,8 @@ sntp_main (
        register int c;
        struct kod_entry *reason = NULL;
        int optct;
-       int sync_data_suc = 0;
+       /* boolean, u_int quiets gcc4 signed overflow warning */
+       u_int sync_data_suc;
        struct addrinfo **bcastaddr = NULL;
        struct addrinfo **resh = NULL;
        struct addrinfo *ai;
@@ -125,6 +126,7 @@ sntp_main (
        /* Select a certain ntp server according to simple criteria? For now
         * let's just pay attention to previous KoDs.
         */
+       sync_data_suc = FALSE;
        for (c = 0; c < resc && !sync_data_suc; c++) {
                ai = resh[c];
                do {
@@ -147,10 +149,9 @@ sntp_main (
        }
        free(resh);
 
-       if (sync_data_suc)
-               return 0;
-       else
+       if (!sync_data_suc)
                return 1;
+       return 0;
 }
 
 static union {
index d71eebcd604fa175def11f81aafc50ea1572b918..7bfde4d288644fbdffd5c412c30b70d63819781c 100644 (file)
@@ -180,7 +180,9 @@ main(
 # include <sys/resource.h>
 # include <sys/file.h>
 # include <a.out.h>
-# include <sys/var.h>
+# ifdef HAVE_SYS_VAR_H
+#  include <sys/var.h>
+# endif
 #endif
 
 #include "ntp_stdlib.h"