#define RPY_CLIENT_ACCESSES_BY_INDEX2 15
#define RPY_NTP_DATA 16
#define RPY_MANUAL_TIMESTAMP2 17
-#define N_REPLY_TYPES 18
+#define RPY_MANUAL_LIST2 18
+#define N_REPLY_TYPES 19
/* Status codes */
#define STT_SUCCESS 0
DEBUG_LOG("Received %d bytes", recv_status);
read_length = recv_status;
- expected_length = PKL_ReplyLength(reply, read_length);
+ if (read_length >= offsetof(CMD_Reply, data)) {
+ expected_length = PKL_ReplyLength(reply);
+ } else {
+ expected_length = 0;
+ }
- bad_length = !expected_length || read_length < expected_length;
+ bad_length = (read_length < expected_length ||
+ expected_length < offsetof(CMD_Reply, data));
if (!bad_length) {
bad_sequence = reply->sequence != request->sequence;
struct timespec when;
request.command = htons(REQ_MANUAL_LIST);
- if (!request_reply(&request, &reply, RPY_MANUAL_LIST, 0))
+ if (!request_reply(&request, &reply, RPY_MANUAL_LIST2, 0))
return 0;
n_samples = ntohl(reply.data.manual_list.n_samples);
print_header("# Date Time(UTC) Slewed Original Residual");
- for (i = 0; i < n_samples; i++) {
+ for (i = 0; i < n_samples && i < MAX_MANUAL_LIST_SAMPLES; i++) {
sample = &reply.data.manual_list.samples[i];
UTI_TimespecNetworkToHost(&sample->when, &when);
for (i = 1; i < N_REPLY_TYPES; i++) {
reply.reply = htons(i);
reply.status = STT_SUCCESS;
- reply.data.manual_list.n_samples = htonl(MAX_MANUAL_LIST_SAMPLES);
- reply_length = PKL_ReplyLength(&reply, sizeof (reply));
+ reply_length = PKL_ReplyLength(&reply);
if ((reply_length && reply_length < offsetof(CMD_Reply, data)) ||
reply_length > sizeof (CMD_Reply))
assert(0);
assert(0);
}
- tx_message_length = PKL_ReplyLength(msg, sizeof (*msg));
+ tx_message_length = PKL_ReplyLength(msg);
status = sendto(sock_fd, (void *) msg, tx_message_length, 0,
&where_to->sa, addrlen);
RPY_ManualListSample *sample;
RPT_ManualSamplesReport report[MAX_MANUAL_LIST_SAMPLES];
- tx_message->reply = htons(RPY_MANUAL_LIST);
+ tx_message->reply = htons(RPY_MANUAL_LIST2);
MNL_ReportSamples(report, MAX_MANUAL_LIST_SAMPLES, &n_samples);
tx_message->data.manual_list.n_samples = htonl(n_samples);
+
+ memset(tx_message->data.manual_list.samples, 0,
+ sizeof (tx_message->data.manual_list.samples));
+
for (i=0; i<n_samples; i++) {
sample = &tx_message->data.manual_list.samples[i];
UTI_TimespecHostToNetwork(&report[i].when, &sample->when);
0, /* SUBNETS_ACCESSED - not supported */
0, /* CLIENT_ACCESSES - not supported */
0, /* CLIENT_ACCESSES_BY_INDEX - not supported */
- 0, /* MANUAL_LIST - variable length */
+ 0, /* MANUAL_LIST - not supported */
RPY_LENGTH_ENTRY(activity), /* ACTIVITY */
RPY_LENGTH_ENTRY(smoothing), /* SMOOTHING */
RPY_LENGTH_ENTRY(server_stats), /* SERVER_STATS */
RPY_LENGTH_ENTRY(client_accesses_by_index), /* CLIENT_ACCESSES_BY_INDEX2 */
RPY_LENGTH_ENTRY(ntp_data), /* NTP_DATA */
RPY_LENGTH_ENTRY(manual_timestamp), /* MANUAL_TIMESTAMP2 */
+ RPY_LENGTH_ENTRY(manual_list), /* MANUAL_LIST2 */
};
/* ================================================== */
/* ================================================== */
int
-PKL_ReplyLength(CMD_Reply *r, int read_length)
+PKL_ReplyLength(CMD_Reply *r)
{
uint32_t type;
assert(sizeof (reply_lengths) / sizeof (reply_lengths[0]) == N_REPLY_TYPES);
- if (read_length < (int)offsetof(CMD_Reply, data))
- return 0;
-
type = ntohs(r->reply);
/* Note that reply type codes start from 1, not 0 */
if (type < 1 || type >= N_REPLY_TYPES)
return 0;
- /* Length of MANUAL_LIST depends on number of samples stored in it */
- if (type == RPY_MANUAL_LIST) {
- uint32_t ns;
-
- if (r->status != htons(STT_SUCCESS))
- return offsetof(CMD_Reply, data);
-
- if (read_length < (int)offsetof(CMD_Reply, data.manual_list.samples))
- return 0;
-
- ns = ntohl(r->data.manual_list.n_samples);
- if (ns > MAX_MANUAL_LIST_SAMPLES)
- return 0;
-
- return offsetof(CMD_Reply, data.manual_list.samples) +
- ns * sizeof (RPY_ManualListSample);
- }
-
return reply_lengths[type];
}
extern int PKL_CommandPaddingLength(CMD_Request *r);
-extern int PKL_ReplyLength(CMD_Reply *r, int read_length);
+extern int PKL_ReplyLength(CMD_Reply *r);
#endif /* GOT_PKTLENGTH_H */