{
struct timespec t_start, t_query, t_query_full, t_end, t_end_full;
time_t timestamp;
- knot_pkt_t *reply;
+ knot_pkt_t *reply = NULL;
uint8_t in[MAX_PACKET_SIZE];
int in_len;
int ret;
// Receive a reply message.
in_len = net_receive(net, in, sizeof(in));
if (in_len <= 0) {
- net_close(net);
- return -1;
+ goto fail;
}
// Get stop message time.
reply = knot_pkt_new(in, in_len, NULL);
if (reply == NULL) {
ERR("internal error (%s)\n", knot_strerror(KNOT_ENOMEM));
- net_close(net);
- return -1;
+ goto fail;
}
// Parse reply to the packet structure.
WARN("malformed reply packet (%s)\n", knot_strerror(ret));
} else if (ret != KNOT_EOK) {
ERR("malformed reply packet from %s\n", net->remote_str);
- knot_pkt_free(reply);
- net_close(net);
- return -1;
+ goto fail;
}
// Compare reply header id.
if (check_reply_id(reply, query) == false) {
ERR("reply ID mismatch from %s\n", net->remote_str);
- knot_pkt_free(reply);
- net_close(net);
- return -1;
+ goto fail;
}
// Print leading transfer information.
if (knot_pkt_ext_rcode(reply) != KNOT_RCODE_NOERROR) {
ERR("server replied with error '%s'\n",
knot_pkt_ext_rcode_name(reply));
- knot_pkt_free(reply);
- net_close(net);
- return -1;
+ goto fail;
}
// The first message has a special treatment.
ERR("reply verification for %s (%s)\n",
net->remote_str, knot_strerror(ret));
- knot_pkt_free(reply);
- net_close(net);
- return -1;
+ goto fail;
}
}
if (serial < 0) {
ERR("first answer record from %s isn't SOA\n",
net->remote_str);
- knot_pkt_free(reply);
- net_close(net);
- return -1;
+ goto fail;
}
// Check for question sections equality.
}
knot_pkt_free(reply);
+ reply = NULL;
}
- // Get stop reply time.
+ // Print full transfer information.
t_end = time_now();
-
- // Print trailing transfer information.
print_footer_xfr(total_len, msg_count, rr_count, net,
time_diff_ms(&t_query, &t_end), timestamp, style);
net_close_keepopen(net, query_ctx);
return 0;
+
+fail:
+ // Print partial transfer information.
+ t_end = time_now();
+ print_footer_xfr(total_len, msg_count, rr_count, net,
+ time_diff_ms(&t_query, &t_end), timestamp, style);
+
+ knot_pkt_free(reply);
+ net_close(net);
+
+ return -1;
}
static int process_xfr(const query_t *query, net_t *net)