* [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.
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])
*-*-kfreebsd*)
ans=no
;;
+ m68k-*-mint*)
+ ans=no
+ ;;
esac
;;
esac
RUNTIME_CHECK(isc_once_do(&once_ipv6only,
try_ipv6only) == ISC_R_SUCCESS);
}
-#endif /* WANT_IPV6 */
#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
static void
try_ipv6pktinfo) == ISC_R_SUCCESS);
}
#endif /* ISC_PLATFORM_HAVEIN6PKTINFO */
+#endif /* WANT_IPV6 */
#endif /* ISC_PLATFORM_HAVEIPV6 */
isc_result_t
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
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;
}
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
/*
* Compare two doubles - used with qsort()
*/
-#ifdef QSORT_USES_VOID_P
static int
refclock_cmpl_fp(
const void *p1,
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 */
/*
struct refclockproc *pp /* refclock structure pointer */
)
{
- int i, j, k, m, n;
+ size_t i, j, k, m, n;
double off[MAXSTAGE];
double offset;
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
"refclock_sample: n %d offset %.6f disp %.6f jitter %.6f\n",
n, pp->offset, pp->disp, pp->jitter);
#endif
- return (n);
+ return (int)n;
}
#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
# 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);
)
{
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
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];
* 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;
+ }
}
/*
* 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 {
/*
*/
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;
* 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
*/
for (i = 0; i < j; i++)
d = (d>>1) + (d>>2);
- server_badness[n] += d;
+ server_badness[k] += d;
}
}
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 *);
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);
}
}
/*
* 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
/*
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)
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);
}
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;
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));
} 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);
}
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;
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;
}
}
}
} 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 {
}
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;
/* 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;
* 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;
}
int
ntpq_read_assoc_peervars(
- int associd,
+ associd_t associd,
char *resultbuf,
int maxsize
)
* 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 );
}
* 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;
+ }
}
int
ntpq_read_assoc_clockvars(
- int associd,
- char * resultbuf,
- int maxsize
+ associd_t associd,
+ char * resultbuf,
+ int maxsize
)
{
const char *datap;
* 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;
}
* 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;
+ }
}
/* 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 );
****************************************************************************/
-#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
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);
}
/*
* 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 *);
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 *);
/*
* 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;
}
doquerylist(
struct varlist *vlist,
int op,
- int associd,
+ associd_t associd,
int auth,
u_short *rstatus,
int *dsize,
static int
dolist(
struct varlist *vlist,
- int associd,
+ associd_t associd,
int op,
int type,
FILE *fp
FILE *fp
)
{
- int associd;
+ associd_t associd;
+ int type;
if (pcmd->nargs == 0) {
associd = 0;
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);
}
{
const char *datap;
int res;
- int associd;
+ associd_t associd;
int dsize;
u_short rstatus;
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)
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);
}
{
const char *datap;
int res;
- int associd;
+ associd_t associd;
+ int type;
int dsize;
u_short rstatus;
struct varlist tmplist[MAXLIST];
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;
}
FILE *fp
)
{
- int associd;
+ associd_t associd;
/* HMS: uval? */
if (pcmd->nargs == 0) {
return;
}
- (void) dolist(g_varlist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp);
+ dolist(g_varlist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp);
}
FILE *fp
)
{
- int associd;
+ associd_t associd;
struct varlist tmplist[MAXLIST];
/* HMS: uval? */
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);
}
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;
}
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);
{
const char *datap;
int res;
- int associd;
+ associd_t associd;
int dsize;
u_short rstatus;
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);
}
static int
dogetpeers(
struct varlist *pvl,
- int associd,
+ associd_t associd,
FILE *fp,
int af
)
/*
* 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
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);
}
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 *);
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 *);
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
*/
*rsize = 0;
if (rstatus)
- *rstatus = 0;
+ *rstatus = 0;
*rdata = (char *)pktdata;
numfrags = 0;
"%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);
}
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) {
*/
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;
}
*/
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) {
}
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, "
}
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;
}
* 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;
}
* 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++;
/*
if (!CTL_ISMORE(rpkt.r_m_e_op)) {
seenlastfrag = 1;
if (rstatus != 0)
- *rstatus = ntohs(rpkt.status);
+ *rstatus = ntohs(rpkt.status);
}
/*
* 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;
}
l_fp *lfp
)
{
+ char *cp;
+ char buf[30];
+ size_t b;
+
/*
* If it starts with a 0x, decode as hex.
*/
* 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);
}
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);
}
}
/*
* 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
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)
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);
}
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;
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
* Structure to hold association data
*/
struct association {
- u_short assid;
+ associd_t assid;
u_short status;
};
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;
/* 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 {
}
free(resh);
- if (sync_data_suc)
- return 0;
- else
+ if (!sync_data_suc)
return 1;
+ return 0;
}
static union {
# 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"