|
|
|
@ -721,6 +721,112 @@ TEST_F(LibraryTest, DNSRecord) { |
|
|
|
|
EXPECT_EQ(ancount, ares_dns_record_rr_cnt(dnsrec, ARES_SECTION_ANSWER)); |
|
|
|
|
EXPECT_EQ(nscount, ares_dns_record_rr_cnt(dnsrec, ARES_SECTION_AUTHORITY)); |
|
|
|
|
EXPECT_EQ(arcount, ares_dns_record_rr_cnt(dnsrec, ARES_SECTION_ADDITIONAL)); |
|
|
|
|
|
|
|
|
|
/* Iterate and print */ |
|
|
|
|
ares__buf_t *printmsg = ares__buf_create(); |
|
|
|
|
ares__buf_append_str(printmsg, ";; ->>HEADER<<- opcode: "); |
|
|
|
|
ares__buf_append_str(printmsg, ares_dns_opcode_tostr(ares_dns_record_get_opcode(dnsrec))); |
|
|
|
|
ares__buf_append_str(printmsg, ", status: "); |
|
|
|
|
ares__buf_append_str(printmsg, ares_dns_rcode_tostr(ares_dns_record_get_rcode(dnsrec))); |
|
|
|
|
ares__buf_append_str(printmsg, ", id: "); |
|
|
|
|
ares__buf_append_num_dec(printmsg, (size_t)ares_dns_record_get_id(dnsrec), 0); |
|
|
|
|
ares__buf_append_str(printmsg, "\n;; flags: "); |
|
|
|
|
ares__buf_append_num_hex(printmsg, (size_t)ares_dns_record_get_flags(dnsrec), 0); |
|
|
|
|
ares__buf_append_str(printmsg, "; QUERY: "); |
|
|
|
|
ares__buf_append_num_dec(printmsg, ares_dns_record_query_cnt(dnsrec), 0); |
|
|
|
|
ares__buf_append_str(printmsg, ", ANSWER: "); |
|
|
|
|
ares__buf_append_num_dec(printmsg, ares_dns_record_rr_cnt(dnsrec, ARES_SECTION_ANSWER), 0); |
|
|
|
|
ares__buf_append_str(printmsg, ", AUTHORITY: "); |
|
|
|
|
ares__buf_append_num_dec(printmsg, ares_dns_record_rr_cnt(dnsrec, ARES_SECTION_AUTHORITY), 0); |
|
|
|
|
ares__buf_append_str(printmsg, ", ADDITIONAL: "); |
|
|
|
|
ares__buf_append_num_dec(printmsg, ares_dns_record_rr_cnt(dnsrec, ARES_SECTION_ADDITIONAL), 0); |
|
|
|
|
ares__buf_append_str(printmsg, "\n\n"); |
|
|
|
|
ares__buf_append_str(printmsg, ";; QUESTION SECTION:\n"); |
|
|
|
|
for (size_t i = 0; i < ares_dns_record_query_cnt(dnsrec); i++) { |
|
|
|
|
const char *name; |
|
|
|
|
ares_dns_rec_type_t qtype; |
|
|
|
|
ares_dns_class_t qclass; |
|
|
|
|
ares_dns_record_query_get(dnsrec, i, &name, &qtype, &qclass); |
|
|
|
|
ares__buf_append_str(printmsg, ";"); |
|
|
|
|
ares__buf_append_str(printmsg, name); |
|
|
|
|
ares__buf_append_str(printmsg, ".\t\t\t"); |
|
|
|
|
ares__buf_append_str(printmsg, ares_dns_class_tostr(qclass)); |
|
|
|
|
ares__buf_append_str(printmsg, "\t"); |
|
|
|
|
ares__buf_append_str(printmsg, ares_dns_rec_type_tostr(qtype)); |
|
|
|
|
ares__buf_append_str(printmsg, "\n"); |
|
|
|
|
} |
|
|
|
|
ares__buf_append_str(printmsg, "\n"); |
|
|
|
|
for (size_t i = ARES_SECTION_ANSWER; i < ARES_SECTION_ADDITIONAL + 1; i++) { |
|
|
|
|
ares__buf_append_str(printmsg, ";; "); |
|
|
|
|
ares__buf_append_str(printmsg, ares_dns_section_tostr((ares_dns_section_t)i)); |
|
|
|
|
ares__buf_append_str(printmsg, " SECTION:\n"); |
|
|
|
|
for (size_t j = 0; j < ares_dns_record_rr_cnt(dnsrec, (ares_dns_section_t)i); j++) { |
|
|
|
|
const ares_dns_rr_t *rr = ares_dns_record_rr_get(dnsrec, (ares_dns_section_t)i, j); |
|
|
|
|
ares__buf_append_str(printmsg, ares_dns_rr_get_name(rr)); |
|
|
|
|
ares__buf_append_str(printmsg, ".\t\t\t"); |
|
|
|
|
ares__buf_append_str(printmsg, ares_dns_class_tostr(ares_dns_rr_get_class(rr))); |
|
|
|
|
ares__buf_append_str(printmsg, "\t"); |
|
|
|
|
ares__buf_append_str(printmsg, ares_dns_rec_type_tostr(ares_dns_rr_get_type(rr))); |
|
|
|
|
ares__buf_append_str(printmsg, "\t"); |
|
|
|
|
ares__buf_append_num_dec(printmsg, ares_dns_rr_get_ttl(rr), 0); |
|
|
|
|
ares__buf_append_str(printmsg, "\t"); |
|
|
|
|
|
|
|
|
|
size_t keys_cnt; |
|
|
|
|
const ares_dns_rr_key_t *keys = ares_dns_rr_get_keys(ares_dns_rr_get_type(rr), &keys_cnt); |
|
|
|
|
for (size_t k = 0; k<keys_cnt; k++) { |
|
|
|
|
char buf[256] = ""; |
|
|
|
|
ares__buf_append_str(printmsg, ares_dns_rr_key_tostr(keys[k])); |
|
|
|
|
ares__buf_append_str(printmsg, "="); |
|
|
|
|
switch (ares_dns_rr_key_datatype(keys[k])) { |
|
|
|
|
case ARES_DATATYPE_INADDR: |
|
|
|
|
ares_inet_ntop(AF_INET, ares_dns_rr_get_addr(rr, keys[k]), buf, sizeof(buf)); |
|
|
|
|
ares__buf_append_str(printmsg, buf); |
|
|
|
|
break; |
|
|
|
|
case ARES_DATATYPE_INADDR6: |
|
|
|
|
ares_inet_ntop(AF_INET6, ares_dns_rr_get_addr6(rr, keys[k]), buf, sizeof(buf)); |
|
|
|
|
ares__buf_append_str(printmsg, buf); |
|
|
|
|
break; |
|
|
|
|
case ARES_DATATYPE_U8: |
|
|
|
|
ares__buf_append_num_dec(printmsg, ares_dns_rr_get_u8(rr, keys[k]), 0); |
|
|
|
|
break; |
|
|
|
|
case ARES_DATATYPE_U16: |
|
|
|
|
ares__buf_append_num_dec(printmsg, ares_dns_rr_get_u16(rr, keys[k]), 0); |
|
|
|
|
break; |
|
|
|
|
case ARES_DATATYPE_U32: |
|
|
|
|
ares__buf_append_num_dec(printmsg, ares_dns_rr_get_u32(rr, keys[k]), 0); |
|
|
|
|
break; |
|
|
|
|
case ARES_DATATYPE_NAME: |
|
|
|
|
case ARES_DATATYPE_STR: |
|
|
|
|
ares__buf_append_byte(printmsg, '"'); |
|
|
|
|
ares__buf_append_str(printmsg, ares_dns_rr_get_str(rr, keys[k])); |
|
|
|
|
ares__buf_append_byte(printmsg, '"'); |
|
|
|
|
break; |
|
|
|
|
case ARES_DATATYPE_BIN: |
|
|
|
|
/* TODO */ |
|
|
|
|
break; |
|
|
|
|
case ARES_DATATYPE_BINP: |
|
|
|
|
ares__buf_append_byte(printmsg, '"'); |
|
|
|
|
size_t templen; |
|
|
|
|
ares__buf_append_str(printmsg, (const char *)ares_dns_rr_get_bin(rr, keys[k], &templen)); |
|
|
|
|
ares__buf_append_byte(printmsg, '"'); |
|
|
|
|
break; |
|
|
|
|
case ARES_DATATYPE_OPT: |
|
|
|
|
/* TODO */ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
ares__buf_append_str(printmsg, " "); |
|
|
|
|
} |
|
|
|
|
ares__buf_append_str(printmsg, "\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ares__buf_append_str(printmsg, ";; SIZE: "); |
|
|
|
|
ares__buf_append_num_dec(printmsg, msglen, 0); |
|
|
|
|
ares__buf_append_str(printmsg, "\n\n"); |
|
|
|
|
|
|
|
|
|
char *printdata = ares__buf_finish_str(printmsg, NULL); |
|
|
|
|
//printf("%s", printdata);
|
|
|
|
|
ares_free(printdata); |
|
|
|
|
|
|
|
|
|
ares_dns_record_destroy(dnsrec); |
|
|
|
|
ares_free(msg); |
|
|
|
|
} |
|
|
|
|