client: don't require address in ntpdata command
If no address is specified, use the SOURCE_DATA command to get addresses of NTP sources, and request NTP_DATA for all of them.
This commit is contained in:
parent
2e311d1766
commit
967f3e4f77
2 changed files with 96 additions and 64 deletions
34
client.c
34
client.c
|
@ -1191,7 +1191,7 @@ give_help(void)
|
|||
"\0\0"
|
||||
"NTP sources:\0\0"
|
||||
"activity\0Check how many NTP sources are online/offline\0"
|
||||
"ntpdata <address>\0Display information about last valid measurement\0"
|
||||
"ntpdata [<address>]\0Display information about last valid measurement\0"
|
||||
"add server <address> [options]\0Add new NTP server\0"
|
||||
"add peer <address> [options]\0Add new NTP peer\0"
|
||||
"delete <address>\0Remove server or peer\0"
|
||||
|
@ -2244,11 +2244,39 @@ process_cmd_ntpdata(char *line)
|
|||
CMD_Reply reply;
|
||||
IPAddr remote_addr, local_addr;
|
||||
struct timespec ref_time;
|
||||
uint32_t i, n_sources;
|
||||
uint16_t mode;
|
||||
int specified_addr;
|
||||
|
||||
if (*line) {
|
||||
specified_addr = 1;
|
||||
n_sources = 1;
|
||||
} else {
|
||||
specified_addr = 0;
|
||||
request.command = htons(REQ_N_SOURCES);
|
||||
if (!request_reply(&request, &reply, RPY_N_SOURCES, 0))
|
||||
return 0;
|
||||
n_sources = ntohl(reply.data.n_sources.n_sources);
|
||||
}
|
||||
|
||||
for (i = 0; i < n_sources; i++) {
|
||||
if (specified_addr) {
|
||||
if (DNS_Name2IPAddress(line, &remote_addr, 1) != DNS_Success) {
|
||||
LOG(LOGS_ERR, LOGF_Client, "Could not get address for hostname");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
request.command = htons(REQ_SOURCE_DATA);
|
||||
request.data.source_data.index = htonl(i);
|
||||
if (!request_reply(&request, &reply, RPY_SOURCE_DATA, 0))
|
||||
return 0;
|
||||
|
||||
mode = ntohs(reply.data.source_data.mode);
|
||||
if (mode != RPY_SD_MD_CLIENT && mode != RPY_SD_MD_PEER)
|
||||
continue;
|
||||
|
||||
UTI_IPNetworkToHost(&reply.data.source_data.ip_addr, &remote_addr);
|
||||
}
|
||||
|
||||
request.command = htons(REQ_NTP_DATA);
|
||||
UTI_IPHostToNetwork(&remote_addr, &request.data.ntp_data.ip_addr);
|
||||
|
@ -2259,6 +2287,9 @@ process_cmd_ntpdata(char *line)
|
|||
UTI_IPNetworkToHost(&reply.data.ntp_data.local_addr, &local_addr);
|
||||
UTI_TimespecNetworkToHost(&reply.data.ntp_data.ref_time, &ref_time);
|
||||
|
||||
if (!specified_addr && !csv_mode)
|
||||
printf("\n");
|
||||
|
||||
print_report("Remote address : %s (%R)\n"
|
||||
"Remote port : %u\n"
|
||||
"Local address : %s (%R)\n"
|
||||
|
@ -2309,6 +2340,7 @@ process_cmd_ntpdata(char *line)
|
|||
(unsigned long)ntohl(reply.data.ntp_data.total_rx_count),
|
||||
(unsigned long)ntohl(reply.data.ntp_data.total_valid_count),
|
||||
REPORT_END);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -441,10 +441,10 @@ the offline state.
|
|||
the name of the server or peer was not resolved to an address yet; this source is
|
||||
not visible in the *sources* and *sourcestats* reports.
|
||||
|
||||
[[ntpdata]]*ntpdata* _address_::
|
||||
[[ntpdata]]*ntpdata* [_address_]::
|
||||
The *ntpdata* command displays the last valid measurement and other
|
||||
NTP-specific information about the NTP source. An example of the output is
|
||||
shown below.
|
||||
NTP-specific information about the specified NTP source, or all NTP sources if
|
||||
no address was specified. An example of the output is shown below.
|
||||
+
|
||||
----
|
||||
Remote address : 203.0.113.15 (CB00710F)
|
||||
|
|
Loading…
Reference in a new issue