client: avoid casting to long
Use the PRI*32 specifiers in printf formats to avoid casting received values to unsigned long.
This commit is contained in:
parent
5508b01bd8
commit
cf98551ea1
1 changed files with 45 additions and 47 deletions
92
client.c
92
client.c
|
@ -1473,24 +1473,24 @@ request_reply(CMD_Request *request, CMD_Reply *reply, int requested_reply, int v
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_seconds(unsigned long s)
|
print_seconds(uint32_t s)
|
||||||
{
|
{
|
||||||
unsigned long d;
|
uint32_t d;
|
||||||
|
|
||||||
if (s == (uint32_t)-1) {
|
if (s == (uint32_t)-1) {
|
||||||
printf(" -");
|
printf(" -");
|
||||||
} else if (s < 1200) {
|
} else if (s < 1200) {
|
||||||
printf("%4lu", s);
|
printf("%4"PRIu32, s);
|
||||||
} else if (s < 36000) {
|
} else if (s < 36000) {
|
||||||
printf("%3lum", s / 60);
|
printf("%3"PRIu32"m", s / 60);
|
||||||
} else if (s < 345600) {
|
} else if (s < 345600) {
|
||||||
printf("%3luh", s / 3600);
|
printf("%3"PRIu32"h", s / 3600);
|
||||||
} else {
|
} else {
|
||||||
d = s / 86400;
|
d = s / 86400;
|
||||||
if (d > 999) {
|
if (d > 999) {
|
||||||
printf("%3luy", d / 365);
|
printf("%3"PRIu32"y", d / 365);
|
||||||
} else {
|
} else {
|
||||||
printf("%3lud", d);
|
printf("%3"PRIu32"d", d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1621,9 +1621,9 @@ print_report(const char *format, ...)
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int i, field, sign, width, prec, spec;
|
int i, field, sign, width, prec, spec;
|
||||||
const char *string;
|
const char *string;
|
||||||
unsigned long long_uinteger;
|
|
||||||
unsigned int uinteger;
|
unsigned int uinteger;
|
||||||
uint64_t uinteger64;
|
uint64_t uinteger64;
|
||||||
|
uint32_t uinteger32;
|
||||||
int integer;
|
int integer;
|
||||||
struct timespec *ts;
|
struct timespec *ts;
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
|
@ -1721,9 +1721,9 @@ print_report(const char *format, ...)
|
||||||
spec == 'O' ? "seconds" : "ppm",
|
spec == 'O' ? "seconds" : "ppm",
|
||||||
(dbl > 0.0) ^ (spec != 'O') ? "slow" : "fast");
|
(dbl > 0.0) ^ (spec != 'O') ? "slow" : "fast");
|
||||||
break;
|
break;
|
||||||
case 'I': /* interval with unit */
|
case 'I': /* uint32_t interval with unit */
|
||||||
long_uinteger = va_arg(ap, unsigned long);
|
uinteger32 = va_arg(ap, uint32_t);
|
||||||
print_seconds(long_uinteger);
|
print_seconds(uinteger32);
|
||||||
break;
|
break;
|
||||||
case 'L': /* leap status */
|
case 'L': /* leap status */
|
||||||
integer = va_arg(ap, int);
|
integer = va_arg(ap, int);
|
||||||
|
@ -1790,8 +1790,8 @@ print_report(const char *format, ...)
|
||||||
print_freq_ppm(dbl);
|
print_freq_ppm(dbl);
|
||||||
break;
|
break;
|
||||||
case 'R': /* reference ID in hexdecimal */
|
case 'R': /* reference ID in hexdecimal */
|
||||||
long_uinteger = va_arg(ap, unsigned long);
|
uinteger32 = va_arg(ap, uint32_t);
|
||||||
printf("%08lX", long_uinteger);
|
printf("%08"PRIX32, uinteger32);
|
||||||
break;
|
break;
|
||||||
case 'S': /* offset with unit */
|
case 'S': /* offset with unit */
|
||||||
dbl = va_arg(ap, double);
|
dbl = va_arg(ap, double);
|
||||||
|
@ -1808,9 +1808,9 @@ print_report(const char *format, ...)
|
||||||
strftime(buf, sizeof (buf), "%a %b %d %T %Y", tm);
|
strftime(buf, sizeof (buf), "%a %b %d %T %Y", tm);
|
||||||
printf("%s", buf);
|
printf("%s", buf);
|
||||||
break;
|
break;
|
||||||
case 'U': /* unsigned long in decimal */
|
case 'U': /* uint32_t in decimal */
|
||||||
long_uinteger = va_arg(ap, unsigned long);
|
uinteger32 = va_arg(ap, uint32_t);
|
||||||
printf("%*lu", width, long_uinteger);
|
printf("%*"PRIu32, width, uinteger32);
|
||||||
break;
|
break;
|
||||||
case 'V': /* timespec as seconds since epoch */
|
case 'V': /* timespec as seconds since epoch */
|
||||||
ts = va_arg(ap, struct timespec *);
|
ts = va_arg(ap, struct timespec *);
|
||||||
|
@ -2067,7 +2067,7 @@ process_cmd_sources(char *line)
|
||||||
ntohs(reply.data.source_data.stratum),
|
ntohs(reply.data.source_data.stratum),
|
||||||
(int16_t)ntohs(reply.data.source_data.poll),
|
(int16_t)ntohs(reply.data.source_data.poll),
|
||||||
ntohs(reply.data.source_data.reachability),
|
ntohs(reply.data.source_data.reachability),
|
||||||
(unsigned long)ntohl(reply.data.source_data.since_sample),
|
ntohl(reply.data.source_data.since_sample),
|
||||||
UTI_FloatNetworkToHost(reply.data.source_data.latest_meas),
|
UTI_FloatNetworkToHost(reply.data.source_data.latest_meas),
|
||||||
UTI_FloatNetworkToHost(reply.data.source_data.orig_latest_meas),
|
UTI_FloatNetworkToHost(reply.data.source_data.orig_latest_meas),
|
||||||
UTI_FloatNetworkToHost(reply.data.source_data.latest_meas_err),
|
UTI_FloatNetworkToHost(reply.data.source_data.latest_meas_err),
|
||||||
|
@ -2128,9 +2128,9 @@ process_cmd_sourcestats(char *line)
|
||||||
|
|
||||||
print_report("%-25s %3U %3U %I %+P %P %+S %S\n",
|
print_report("%-25s %3U %3U %I %+P %P %+S %S\n",
|
||||||
name,
|
name,
|
||||||
(unsigned long)ntohl(reply.data.sourcestats.n_samples),
|
ntohl(reply.data.sourcestats.n_samples),
|
||||||
(unsigned long)ntohl(reply.data.sourcestats.n_runs),
|
ntohl(reply.data.sourcestats.n_runs),
|
||||||
(unsigned long)ntohl(reply.data.sourcestats.span_seconds),
|
ntohl(reply.data.sourcestats.span_seconds),
|
||||||
UTI_FloatNetworkToHost(reply.data.sourcestats.resid_freq_ppm),
|
UTI_FloatNetworkToHost(reply.data.sourcestats.resid_freq_ppm),
|
||||||
UTI_FloatNetworkToHost(reply.data.sourcestats.skew_ppm),
|
UTI_FloatNetworkToHost(reply.data.sourcestats.skew_ppm),
|
||||||
UTI_FloatNetworkToHost(reply.data.sourcestats.est_offset),
|
UTI_FloatNetworkToHost(reply.data.sourcestats.est_offset),
|
||||||
|
@ -2178,7 +2178,7 @@ process_cmd_tracking(char *line)
|
||||||
"Root dispersion : %.9f seconds\n"
|
"Root dispersion : %.9f seconds\n"
|
||||||
"Update interval : %.1f seconds\n"
|
"Update interval : %.1f seconds\n"
|
||||||
"Leap status : %L\n",
|
"Leap status : %L\n",
|
||||||
(unsigned long)ref_id, name,
|
ref_id, name,
|
||||||
ntohs(reply.data.tracking.stratum),
|
ntohs(reply.data.tracking.stratum),
|
||||||
&ref_time,
|
&ref_time,
|
||||||
UTI_FloatNetworkToHost(reply.data.tracking.current_correction),
|
UTI_FloatNetworkToHost(reply.data.tracking.current_correction),
|
||||||
|
@ -2266,10 +2266,10 @@ process_cmd_authdata(char *line)
|
||||||
|
|
||||||
print_report("%-27s %4s %5U %4d %4d %I %4d %4d %4d %4d\n",
|
print_report("%-27s %4s %5U %4d %4d %I %4d %4d %4d %4d\n",
|
||||||
name, mode_str,
|
name, mode_str,
|
||||||
(unsigned long)ntohl(reply.data.auth_data.key_id),
|
ntohl(reply.data.auth_data.key_id),
|
||||||
ntohs(reply.data.auth_data.key_type),
|
ntohs(reply.data.auth_data.key_type),
|
||||||
ntohs(reply.data.auth_data.key_length),
|
ntohs(reply.data.auth_data.key_length),
|
||||||
(unsigned long)ntohl(reply.data.auth_data.last_ke_ago),
|
ntohl(reply.data.auth_data.last_ke_ago),
|
||||||
ntohs(reply.data.auth_data.ke_attempts),
|
ntohs(reply.data.auth_data.ke_attempts),
|
||||||
ntohs(reply.data.auth_data.nak),
|
ntohs(reply.data.auth_data.nak),
|
||||||
ntohs(reply.data.auth_data.cookies),
|
ntohs(reply.data.auth_data.cookies),
|
||||||
|
@ -2364,17 +2364,16 @@ process_cmd_ntpdata(char *line)
|
||||||
"Total RX : %U\n"
|
"Total RX : %U\n"
|
||||||
"Total valid RX : %U\n"
|
"Total valid RX : %U\n"
|
||||||
"Total good RX : %U\n",
|
"Total good RX : %U\n",
|
||||||
UTI_IPToString(&remote_addr), (unsigned long)UTI_IPToRefid(&remote_addr),
|
UTI_IPToString(&remote_addr), UTI_IPToRefid(&remote_addr),
|
||||||
ntohs(reply.data.ntp_data.remote_port),
|
ntohs(reply.data.ntp_data.remote_port),
|
||||||
UTI_IPToString(&local_addr), (unsigned long)UTI_IPToRefid(&local_addr),
|
UTI_IPToString(&local_addr), UTI_IPToRefid(&local_addr),
|
||||||
reply.data.ntp_data.leap, reply.data.ntp_data.version,
|
reply.data.ntp_data.leap, reply.data.ntp_data.version,
|
||||||
reply.data.ntp_data.mode, reply.data.ntp_data.stratum,
|
reply.data.ntp_data.mode, reply.data.ntp_data.stratum,
|
||||||
reply.data.ntp_data.poll, UTI_Log2ToDouble(reply.data.ntp_data.poll),
|
reply.data.ntp_data.poll, UTI_Log2ToDouble(reply.data.ntp_data.poll),
|
||||||
reply.data.ntp_data.precision, UTI_Log2ToDouble(reply.data.ntp_data.precision),
|
reply.data.ntp_data.precision, UTI_Log2ToDouble(reply.data.ntp_data.precision),
|
||||||
UTI_FloatNetworkToHost(reply.data.ntp_data.root_delay),
|
UTI_FloatNetworkToHost(reply.data.ntp_data.root_delay),
|
||||||
UTI_FloatNetworkToHost(reply.data.ntp_data.root_dispersion),
|
UTI_FloatNetworkToHost(reply.data.ntp_data.root_dispersion),
|
||||||
(unsigned long)ntohl(reply.data.ntp_data.ref_id),
|
ntohl(reply.data.ntp_data.ref_id), reply.data.ntp_data.stratum <= 1 ?
|
||||||
reply.data.ntp_data.stratum <= 1 ?
|
|
||||||
UTI_RefidToString(ntohl(reply.data.ntp_data.ref_id)) : "",
|
UTI_RefidToString(ntohl(reply.data.ntp_data.ref_id)) : "",
|
||||||
&ref_time,
|
&ref_time,
|
||||||
UTI_FloatNetworkToHost(reply.data.ntp_data.offset),
|
UTI_FloatNetworkToHost(reply.data.ntp_data.offset),
|
||||||
|
@ -2388,10 +2387,10 @@ process_cmd_ntpdata(char *line)
|
||||||
ntohs(reply.data.ntp_data.flags) & RPY_NTP_FLAG_INTERLEAVED,
|
ntohs(reply.data.ntp_data.flags) & RPY_NTP_FLAG_INTERLEAVED,
|
||||||
ntohs(reply.data.ntp_data.flags) & RPY_NTP_FLAG_AUTHENTICATED,
|
ntohs(reply.data.ntp_data.flags) & RPY_NTP_FLAG_AUTHENTICATED,
|
||||||
reply.data.ntp_data.tx_tss_char, reply.data.ntp_data.rx_tss_char,
|
reply.data.ntp_data.tx_tss_char, reply.data.ntp_data.rx_tss_char,
|
||||||
(unsigned long)ntohl(reply.data.ntp_data.total_tx_count),
|
ntohl(reply.data.ntp_data.total_tx_count),
|
||||||
(unsigned long)ntohl(reply.data.ntp_data.total_rx_count),
|
ntohl(reply.data.ntp_data.total_rx_count),
|
||||||
(unsigned long)ntohl(reply.data.ntp_data.total_valid_count),
|
ntohl(reply.data.ntp_data.total_valid_count),
|
||||||
(unsigned long)ntohl(reply.data.ntp_data.total_good_count),
|
ntohl(reply.data.ntp_data.total_good_count),
|
||||||
REPORT_END);
|
REPORT_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2463,7 +2462,7 @@ process_cmd_selectdata(char *line)
|
||||||
eff_options & RPY_SD_OPTION_TRUST ? 'T' : '-',
|
eff_options & RPY_SD_OPTION_TRUST ? 'T' : '-',
|
||||||
eff_options & RPY_SD_OPTION_REQUIRE ? 'R' : '-',
|
eff_options & RPY_SD_OPTION_REQUIRE ? 'R' : '-',
|
||||||
'-',
|
'-',
|
||||||
(unsigned long)ntohl(reply.data.select_data.last_sample_ago),
|
ntohl(reply.data.select_data.last_sample_ago),
|
||||||
UTI_FloatNetworkToHost(reply.data.select_data.score),
|
UTI_FloatNetworkToHost(reply.data.select_data.score),
|
||||||
UTI_FloatNetworkToHost(reply.data.select_data.lo_limit),
|
UTI_FloatNetworkToHost(reply.data.select_data.lo_limit),
|
||||||
UTI_FloatNetworkToHost(reply.data.select_data.hi_limit),
|
UTI_FloatNetworkToHost(reply.data.select_data.hi_limit),
|
||||||
|
@ -2601,7 +2600,7 @@ process_cmd_rtcreport(char *line)
|
||||||
&ref_time,
|
&ref_time,
|
||||||
ntohs(reply.data.rtc.n_samples),
|
ntohs(reply.data.rtc.n_samples),
|
||||||
ntohs(reply.data.rtc.n_runs),
|
ntohs(reply.data.rtc.n_runs),
|
||||||
(unsigned long)ntohl(reply.data.rtc.span_seconds),
|
ntohl(reply.data.rtc.span_seconds),
|
||||||
UTI_FloatNetworkToHost(reply.data.rtc.rtc_seconds_fast),
|
UTI_FloatNetworkToHost(reply.data.rtc.rtc_seconds_fast),
|
||||||
UTI_FloatNetworkToHost(reply.data.rtc.rtc_gain_rate_ppm),
|
UTI_FloatNetworkToHost(reply.data.rtc.rtc_gain_rate_ppm),
|
||||||
REPORT_END);
|
REPORT_END);
|
||||||
|
@ -2676,16 +2675,15 @@ process_cmd_clients(char *line)
|
||||||
|
|
||||||
print_report("%-25s %6U %5U %C %C %I %6U %5U %C %I\n",
|
print_report("%-25s %6U %5U %C %C %I %6U %5U %C %I\n",
|
||||||
name,
|
name,
|
||||||
(unsigned long)ntohl(client->ntp_hits),
|
ntohl(client->ntp_hits),
|
||||||
(unsigned long)ntohl(client->ntp_drops),
|
ntohl(client->ntp_drops),
|
||||||
client->ntp_interval,
|
client->ntp_interval,
|
||||||
client->ntp_timeout_interval,
|
client->ntp_timeout_interval,
|
||||||
(unsigned long)ntohl(client->last_ntp_hit_ago),
|
ntohl(client->last_ntp_hit_ago),
|
||||||
(unsigned long)ntohl(nke ? client->nke_hits : client->cmd_hits),
|
ntohl(nke ? client->nke_hits : client->cmd_hits),
|
||||||
(unsigned long)ntohl(nke ? client->nke_drops : client->cmd_drops),
|
ntohl(nke ? client->nke_drops : client->cmd_drops),
|
||||||
nke ? client->nke_interval : client->cmd_interval,
|
nke ? client->nke_interval : client->cmd_interval,
|
||||||
(unsigned long)ntohl(nke ? client->last_nke_hit_ago :
|
ntohl(nke ? client->last_nke_hit_ago : client->last_cmd_hit_ago),
|
||||||
client->last_cmd_hit_ago),
|
|
||||||
REPORT_END);
|
REPORT_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2716,7 +2714,7 @@ process_cmd_manual_list(const char *line)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
n_samples = ntohl(reply.data.manual_list.n_samples);
|
n_samples = ntohl(reply.data.manual_list.n_samples);
|
||||||
print_info_field("210 n_samples = %lu\n", (unsigned long)n_samples);
|
print_info_field("210 n_samples = %"PRIu32"\n", n_samples);
|
||||||
|
|
||||||
print_header("# Date Time(UTC) Slewed Original Residual");
|
print_header("# Date Time(UTC) Slewed Original Residual");
|
||||||
|
|
||||||
|
@ -2836,11 +2834,11 @@ process_cmd_activity(const char *line)
|
||||||
"%U sources doing burst (return to online)\n"
|
"%U sources doing burst (return to online)\n"
|
||||||
"%U sources doing burst (return to offline)\n"
|
"%U sources doing burst (return to offline)\n"
|
||||||
"%U sources with unknown address\n",
|
"%U sources with unknown address\n",
|
||||||
(unsigned long)ntohl(reply.data.activity.online),
|
ntohl(reply.data.activity.online),
|
||||||
(unsigned long)ntohl(reply.data.activity.offline),
|
ntohl(reply.data.activity.offline),
|
||||||
(unsigned long)ntohl(reply.data.activity.burst_online),
|
ntohl(reply.data.activity.burst_online),
|
||||||
(unsigned long)ntohl(reply.data.activity.burst_offline),
|
ntohl(reply.data.activity.burst_offline),
|
||||||
(unsigned long)ntohl(reply.data.activity.unresolved),
|
ntohl(reply.data.activity.unresolved),
|
||||||
REPORT_END);
|
REPORT_END);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -3003,7 +3001,7 @@ process_cmd_waitsync(char *line)
|
||||||
skew_ppm = UTI_FloatNetworkToHost(reply.data.tracking.skew_ppm);
|
skew_ppm = UTI_FloatNetworkToHost(reply.data.tracking.skew_ppm);
|
||||||
|
|
||||||
print_report("try: %d, refid: %R, correction: %.9f, skew: %.3f\n",
|
print_report("try: %d, refid: %R, correction: %.9f, skew: %.3f\n",
|
||||||
i, (unsigned long)ref_id, correction, skew_ppm, REPORT_END);
|
i, ref_id, correction, skew_ppm, REPORT_END);
|
||||||
|
|
||||||
if ((ip_addr.family != IPADDR_UNSPEC ||
|
if ((ip_addr.family != IPADDR_UNSPEC ||
|
||||||
(ref_id != 0 && ref_id != 0x7f7f0101L /* LOCAL refid */)) &&
|
(ref_id != 0 && ref_id != 0x7f7f0101L /* LOCAL refid */)) &&
|
||||||
|
|
Loading…
Reference in a new issue