aboutsummaryrefslogtreecommitdiff
path: root/ntpq/ntpq.c
diff options
context:
space:
mode:
Diffstat (limited to 'ntpq/ntpq.c')
-rw-r--r--ntpq/ntpq.c76
1 files changed, 46 insertions, 30 deletions
diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c
index 91364de4ba8b..547f3cc5d22b 100644
--- a/ntpq/ntpq.c
+++ b/ntpq/ntpq.c
@@ -374,7 +374,7 @@ u_int numassoc; /* number of cached associations */
/*
* For commands typed on the command line (with the -c option)
*/
-int numcmds = 0;
+size_t numcmds = 0;
const char *ccmds[MAXCMDS];
#define ADDCMD(cp) if (numcmds < MAXCMDS) ccmds[numcmds++] = (cp)
@@ -458,7 +458,7 @@ ntpqmain(
)
{
u_int ihost;
- int icmd;
+ size_t icmd;
#ifdef SYS_VXWORKS
@@ -776,31 +776,42 @@ dump_hex_printable(
size_t len
)
{
- const char * cdata;
- const char * rowstart;
- size_t idx;
- size_t rowlen;
- u_char uch;
-
- cdata = data;
- while (len > 0) {
- rowstart = cdata;
- rowlen = min(16, len);
- for (idx = 0; idx < rowlen; idx++) {
- uch = *(cdata++);
- printf("%02x ", uch);
- }
- for ( ; idx < 16 ; idx++)
- printf(" ");
- cdata = rowstart;
- for (idx = 0; idx < rowlen; idx++) {
- uch = *(cdata++);
- printf("%c", (isprint(uch))
- ? uch
- : '.');
- }
- printf("\n");
+ /* every line shows at most 16 bytes, so we need a buffer of
+ * 4 * 16 (2 xdigits, 1 char, one sep for xdigits)
+ * + 2 * 1 (block separators)
+ * + <LF> + <NUL>
+ *---------------
+ * 68 bytes
+ */
+ static const char s_xdig[16] = "0123456789ABCDEF";
+
+ char lbuf[68];
+ int ch, rowlen;
+ const u_char * cdata = data;
+ char *xptr, *pptr;
+
+ while (len) {
+ memset(lbuf, ' ', sizeof(lbuf));
+ xptr = lbuf;
+ pptr = lbuf + 3*16 + 2;
+
+ rowlen = (len > 16) ? 16 : (int)len;
len -= rowlen;
+
+ do {
+ ch = *cdata++;
+
+ *xptr++ = s_xdig[ch >> 4 ];
+ *xptr++ = s_xdig[ch & 0x0F];
+ if (++xptr == lbuf + 3*8)
+ ++xptr;
+
+ *pptr++ = isprint(ch) ? (char)ch : '.';
+ } while (--rowlen);
+
+ *pptr++ = '\n';
+ *pptr = '\0';
+ fputs(lbuf, stdout);
}
}
@@ -862,6 +873,9 @@ getresponse(
uint32_t tospan; /* timeout span (max delay) */
uint32_t todiff; /* current delay */
+ memset(offsets, 0, sizeof(offsets));
+ memset(counts , 0, sizeof(counts ));
+
/*
* This is pretty tricky. We may get between 1 and MAXFRAG packets
* back in response to the request. We peel the data out of
@@ -922,10 +936,12 @@ getresponse(
todiff = (((uint32_t)time(NULL)) - tobase) & 0x7FFFFFFFu;
if ((n > 0) && (todiff > tospan)) {
n = recv(sockfd, (char *)&rpkt, sizeof(rpkt), 0);
- n = 0; /* faked timeout return from 'select()'*/
+ n -= n; /* faked timeout return from 'select()',
+ * execute RMW cycle on 'n'
+ */
}
- if (n == 0) {
+ if (n <= 0) {
/*
* Timed out. Return what we have
*/
@@ -960,7 +976,7 @@ getresponse(
}
n = recv(sockfd, (char *)&rpkt, sizeof(rpkt), 0);
- if (n == -1) {
+ if (n < 0) {
warning("read");
return -1;
}
@@ -3595,7 +3611,7 @@ static void list_md_fn(const EVP_MD *m, const char *from, const char *to, void *
/* Lowercase names aren't accepted by keytype_from_text in ssl_init.c */
for( cp = name; *cp; cp++ ) {
- if( islower(*cp) )
+ if( islower((unsigned char)*cp) )
return;
}
len = (cp - name) + 1;