code enhancement

This commit is contained in:
Nick Peng
2019-02-02 19:28:31 +08:00
parent 05a24264aa
commit 7add2b82ae
2 changed files with 31 additions and 9 deletions

View File

@@ -1650,10 +1650,16 @@ static int _dns_client_send_query(struct dns_query_struct *query, char *doamin)
head.ra = 0;
head.rcode = 0;
dns_packet_init(packet, DNS_PACKSIZE, &head);
if(dns_packet_init(packet, DNS_PACKSIZE, &head) != 0) {
tlog(TLOG_ERROR, "init packet failed.");
return -1;
}
/* add question */
dns_add_domain(packet, doamin, query->qtype, DNS_C_IN);
if (dns_add_domain(packet, doamin, query->qtype, DNS_C_IN) != 0) {
tlog(TLOG_ERROR, "add domain to packet failed.");
return -1;
}
dns_set_OPT_payload_size(packet, DNS_IN_PACKSIZE);
@@ -1669,6 +1675,12 @@ static int _dns_client_send_query(struct dns_query_struct *query, char *doamin)
return -1;
}
if (encode_len > DNS_IN_PACKSIZE) {
tlog(TLOG_ERROR, "size is invalid.");
abort();
return -1;
}
/* send query packet */
return _dns_client_send_packet(query, inpacket, encode_len);
}