"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/dns-proto.cc" between
c-ares-1.17.1.tar.gz and c-ares-1.17.2.tar.gz

About: c-ares is a C library for asynchronous DNS requests (including name resolves).

dns-proto.cc  (c-ares-1.17.1):dns-proto.cc  (c-ares-1.17.2)
#include "dns-proto.h"
// Include ares internal file for DNS protocol details // Include ares internal file for DNS protocol details
#include "ares_setup.h" #include "ares_setup.h"
#include "ares.h" #include "ares.h"
#include "ares_dns.h" #include "ares_dns.h"
#include "dns-proto.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sstream> #include <sstream>
namespace ares { namespace ares {
std::string HexDump(std::vector<byte> data) { std::string HexDump(std::vector<byte> data) {
std::stringstream ss; std::stringstream ss;
skipping to change at line 66 skipping to change at line 66
case ARES_ENOTINITIALIZED: return "ARES_ENOTINITIALIZED"; case ARES_ENOTINITIALIZED: return "ARES_ENOTINITIALIZED";
case ARES_ELOADIPHLPAPI: return "ARES_ELOADIPHLPAPI"; case ARES_ELOADIPHLPAPI: return "ARES_ELOADIPHLPAPI";
case ARES_EADDRGETNETWORKPARAMS: return "ARES_EADDRGETNETWORKPARAMS"; case ARES_EADDRGETNETWORKPARAMS: return "ARES_EADDRGETNETWORKPARAMS";
case ARES_ECANCELLED: return "ARES_ECANCELLED"; case ARES_ECANCELLED: return "ARES_ECANCELLED";
default: return "UNKNOWN"; default: return "UNKNOWN";
} }
} }
std::string RcodeToString(int rcode) { std::string RcodeToString(int rcode) {
switch (rcode) { switch (rcode) {
case ns_r_noerror: return "NOERROR"; case NOERROR: return "NOERROR";
case ns_r_formerr: return "FORMERR"; case FORMERR: return "FORMERR";
case ns_r_servfail: return "SERVFAIL"; case SERVFAIL: return "SERVFAIL";
case ns_r_nxdomain: return "NXDOMAIN"; case NXDOMAIN: return "NXDOMAIN";
case ns_r_notimpl: return "NOTIMPL"; case NOTIMP: return "NOTIMP";
case ns_r_refused: return "REFUSED"; case REFUSED: return "REFUSED";
case ns_r_yxdomain: return "YXDOMAIN"; case YXDOMAIN: return "YXDOMAIN";
case ns_r_yxrrset: return "YXRRSET"; case YXRRSET: return "YXRRSET";
case ns_r_nxrrset: return "NXRRSET"; case NXRRSET: return "NXRRSET";
case ns_r_notauth: return "NOTAUTH"; case NOTAUTH: return "NOTAUTH";
case ns_r_notzone: return "NOTZONE"; case NOTZONE: return "NOTZONE";
case ns_r_badsig: return "BADSIG"; case TSIG_BADSIG: return "BADSIG";
case ns_r_badkey: return "BADKEY"; case TSIG_BADKEY: return "BADKEY";
case ns_r_badtime: return "BADTIME"; case TSIG_BADTIME: return "BADTIME";
default: return "UNKNOWN"; default: return "UNKNOWN";
} }
} }
std::string RRTypeToString(int rrtype) { std::string RRTypeToString(int rrtype) {
switch (rrtype) { switch (rrtype) {
case ns_t_a: return "A"; case T_A: return "A";
case ns_t_ns: return "NS"; case T_NS: return "NS";
case ns_t_md: return "MD"; case T_MD: return "MD";
case ns_t_mf: return "MF"; case T_MF: return "MF";
case ns_t_cname: return "CNAME"; case T_CNAME: return "CNAME";
case ns_t_soa: return "SOA"; case T_SOA: return "SOA";
case ns_t_mb: return "MB"; case T_MB: return "MB";
case ns_t_mg: return "MG"; case T_MG: return "MG";
case ns_t_mr: return "MR"; case T_MR: return "MR";
case ns_t_null: return "NULL"; case T_NULL: return "NULL";
case ns_t_wks: return "WKS"; case T_WKS: return "WKS";
case ns_t_ptr: return "PTR"; case T_PTR: return "PTR";
case ns_t_hinfo: return "HINFO"; case T_HINFO: return "HINFO";
case ns_t_minfo: return "MINFO"; case T_MINFO: return "MINFO";
case ns_t_mx: return "MX"; case T_MX: return "MX";
case ns_t_txt: return "TXT"; case T_TXT: return "TXT";
case ns_t_rp: return "RP"; case T_RP: return "RP";
case ns_t_afsdb: return "AFSDB"; case T_AFSDB: return "AFSDB";
case ns_t_x25: return "X25"; case T_X25: return "X25";
case ns_t_isdn: return "ISDN"; case T_ISDN: return "ISDN";
case ns_t_rt: return "RT"; case T_RT: return "RT";
case ns_t_nsap: return "NSAP"; case T_NSAP: return "NSAP";
case ns_t_nsap_ptr: return "NSAP_PTR"; case T_NSAP_PTR: return "NSAP_PTR";
case ns_t_sig: return "SIG"; case T_SIG: return "SIG";
case ns_t_key: return "KEY"; case T_KEY: return "KEY";
case ns_t_px: return "PX"; case T_PX: return "PX";
case ns_t_gpos: return "GPOS"; case T_GPOS: return "GPOS";
case ns_t_aaaa: return "AAAA"; case T_AAAA: return "AAAA";
case ns_t_loc: return "LOC"; case T_LOC: return "LOC";
case ns_t_nxt: return "NXT"; case T_NXT: return "NXT";
case ns_t_eid: return "EID"; case T_EID: return "EID";
case ns_t_nimloc: return "NIMLOC"; case T_NIMLOC: return "NIMLOC";
case ns_t_srv: return "SRV"; case T_SRV: return "SRV";
case ns_t_atma: return "ATMA"; case T_ATMA: return "ATMA";
case ns_t_naptr: return "NAPTR"; case T_NAPTR: return "NAPTR";
case ns_t_kx: return "KX"; case T_KX: return "KX";
case ns_t_cert: return "CERT"; case T_CERT: return "CERT";
case ns_t_a6: return "A6"; case T_A6: return "A6";
case ns_t_dname: return "DNAME"; case T_DNAME: return "DNAME";
case ns_t_sink: return "SINK"; case T_SINK: return "SINK";
case ns_t_opt: return "OPT"; case T_OPT: return "OPT";
case ns_t_apl: return "APL"; case T_APL: return "APL";
case ns_t_ds: return "DS"; case T_DS: return "DS";
case ns_t_sshfp: return "SSHFP"; case T_SSHFP: return "SSHFP";
case ns_t_rrsig: return "RRSIG"; case T_RRSIG: return "RRSIG";
case ns_t_nsec: return "NSEC"; case T_NSEC: return "NSEC";
case ns_t_dnskey: return "DNSKEY"; case T_DNSKEY: return "DNSKEY";
case ns_t_tkey: return "TKEY"; case T_TKEY: return "TKEY";
case ns_t_tsig: return "TSIG"; case T_TSIG: return "TSIG";
case ns_t_ixfr: return "IXFR"; case T_IXFR: return "IXFR";
case ns_t_axfr: return "AXFR"; case T_AXFR: return "AXFR";
case ns_t_mailb: return "MAILB"; case T_MAILB: return "MAILB";
case ns_t_maila: return "MAILA"; case T_MAILA: return "MAILA";
case ns_t_any: return "ANY"; case T_ANY: return "ANY";
case ns_t_zxfr: return "ZXFR"; case T_ZXFR: return "ZXFR";
case ns_t_max: return "MAX"; case T_MAX: return "MAX";
default: return "UNKNOWN"; default: return "UNKNOWN";
} }
} }
std::string ClassToString(int qclass) { std::string ClassToString(int qclass) {
switch (qclass) { switch (qclass) {
case ns_c_in: return "IN"; case C_IN: return "IN";
case ns_c_chaos: return "CHAOS"; case C_CHAOS: return "CHAOS";
case ns_c_hs: return "HESIOD"; case C_HS: return "HESIOD";
case ns_c_none: return "NONE"; case C_NONE: return "NONE";
case ns_c_any: return "ANY"; case C_ANY: return "ANY";
default: return "UNKNOWN"; default: return "UNKNOWN";
} }
} }
std::string AddressToString(const void* vaddr, int len) { std::string AddressToString(const void* vaddr, int len) {
const byte* addr = reinterpret_cast<const byte*>(vaddr); const byte* addr = reinterpret_cast<const byte*>(vaddr);
std::stringstream ss; std::stringstream ss;
if (len == 4) { if (len == 4) {
char buffer[4*4 + 3 + 1]; char buffer[4*4 + 3 + 1];
sprintf(buffer, "%u.%u.%u.%u", sprintf(buffer, "%u.%u.%u.%u",
skipping to change at line 191 skipping to change at line 191
std::string PacketToString(const std::vector<byte>& packet) { std::string PacketToString(const std::vector<byte>& packet) {
const byte* data = packet.data(); const byte* data = packet.data();
int len = packet.size(); int len = packet.size();
std::stringstream ss; std::stringstream ss;
if (len < NS_HFIXEDSZ) { if (len < NS_HFIXEDSZ) {
ss << "(too short, len " << len << ")"; ss << "(too short, len " << len << ")";
return ss.str(); return ss.str();
} }
ss << ((DNS_HEADER_QR(data) == 0) ? "REQ " : "RSP "); ss << ((DNS_HEADER_QR(data) == 0) ? "REQ " : "RSP ");
switch (DNS_HEADER_OPCODE(data)) { switch (DNS_HEADER_OPCODE(data)) {
case ns_o_query: ss << "QRY "; break; case O_QUERY: ss << "QRY "; break;
case ns_o_iquery: ss << "IQRY "; break; case O_IQUERY: ss << "IQRY "; break;
case ns_o_status: ss << "STATUS "; break; case O_STATUS: ss << "STATUS "; break;
case ns_o_notify: ss << "NOTIFY "; break; case O_NOTIFY: ss << "NOTIFY "; break;
case ns_o_update: ss << "UPDATE "; break; case O_UPDATE: ss << "UPDATE "; break;
default: ss << "UNKNOWN(" << DNS_HEADER_OPCODE(data) << ") "; break; default: ss << "UNKNOWN(" << DNS_HEADER_OPCODE(data) << ") "; break;
} }
if (DNS_HEADER_AA(data)) ss << "AA "; if (DNS_HEADER_AA(data)) ss << "AA ";
if (DNS_HEADER_TC(data)) ss << "TC "; if (DNS_HEADER_TC(data)) ss << "TC ";
if (DNS_HEADER_RD(data)) ss << "RD "; if (DNS_HEADER_RD(data)) ss << "RD ";
if (DNS_HEADER_RA(data)) ss << "RA "; if (DNS_HEADER_RA(data)) ss << "RA ";
if (DNS_HEADER_Z(data)) ss << "Z "; if (DNS_HEADER_Z(data)) ss << "Z ";
if (DNS_HEADER_QR(data) == 1) ss << RcodeToString(DNS_HEADER_RCODE(data)); if (DNS_HEADER_QR(data) == 1) ss << RcodeToString(DNS_HEADER_RCODE(data));
int nquestions = DNS_HEADER_QDCOUNT(data); int nquestions = DNS_HEADER_QDCOUNT(data);
skipping to change at line 295 skipping to change at line 295
*data += enclen; *data += enclen;
ss << "'" << name << "' "; ss << "'" << name << "' ";
ares_free_string(name); ares_free_string(name);
name = nullptr; name = nullptr;
if (*len < NS_RRFIXEDSZ) { if (*len < NS_RRFIXEDSZ) {
ss << "(too short, len left " << *len << ")"; ss << "(too short, len left " << *len << ")";
return ss.str(); return ss.str();
} }
int rrtype = DNS_RR_TYPE(*data); int rrtype = DNS_RR_TYPE(*data);
if (rrtype == ns_t_opt) { if (rrtype == T_OPT) {
ss << "MAXUDP=" << DNS_RR_CLASS(*data) << " "; ss << "MAXUDP=" << DNS_RR_CLASS(*data) << " ";
ss << RRTypeToString(rrtype) << " "; ss << RRTypeToString(rrtype) << " ";
ss << "RCODE2=" << DNS_RR_TTL(*data); ss << "RCODE2=" << DNS_RR_TTL(*data);
} else { } else {
ss << ClassToString(DNS_RR_CLASS(*data)) << " "; ss << ClassToString(DNS_RR_CLASS(*data)) << " ";
ss << RRTypeToString(rrtype) << " "; ss << RRTypeToString(rrtype) << " ";
ss << "TTL=" << DNS_RR_TTL(*data); ss << "TTL=" << DNS_RR_TTL(*data);
} }
int rdatalen = DNS_RR_LEN(*data); int rdatalen = DNS_RR_LEN(*data);
*data += NS_RRFIXEDSZ; *data += NS_RRFIXEDSZ;
*len -= NS_RRFIXEDSZ; *len -= NS_RRFIXEDSZ;
if (*len < rdatalen) { if (*len < rdatalen) {
ss << "(RR too long at " << rdatalen << ", len left " << *len << ")"; ss << "(RR too long at " << rdatalen << ", len left " << *len << ")";
} else { } else {
switch (rrtype) { switch (rrtype) {
case ns_t_a: case T_A:
case ns_t_aaaa: case T_AAAA:
ss << " " << AddressToString(*data, rdatalen); ss << " " << AddressToString(*data, rdatalen);
break; break;
case ns_t_txt: { case T_TXT: {
const byte* p = *data; const byte* p = *data;
while (p < (*data + rdatalen)) { while (p < (*data + rdatalen)) {
int len = *p++; int len = *p++;
if ((p + len) <= (*data + rdatalen)) { if ((p + len) <= (*data + rdatalen)) {
std::string txt(p, p + len); std::string txt(p, p + len);
ss << " " << len << ":'" << txt << "'"; ss << " " << len << ":'" << txt << "'";
} else { } else {
ss << "(string too long)"; ss << "(string too long)";
} }
p += len; p += len;
} }
break; break;
} }
case ns_t_cname: case T_CNAME:
case ns_t_ns: case T_NS:
case ns_t_ptr: { case T_PTR: {
int rc = ares_expand_name(*data, packet.data(), packet.size(), &name, &enc len); int rc = ares_expand_name(*data, packet.data(), packet.size(), &name, &enc len);
if (rc != ARES_SUCCESS) { if (rc != ARES_SUCCESS) {
ss << "(error from ares_expand_name)"; ss << "(error from ares_expand_name)";
break; break;
} }
ss << " '" << name << "'"; ss << " '" << name << "'";
ares_free_string(name); ares_free_string(name);
break; break;
} }
case ns_t_mx: case T_MX:
if (rdatalen > 2) { if (rdatalen > 2) {
int rc = ares_expand_name(*data + 2, packet.data(), packet.size(), &name , &enclen); int rc = ares_expand_name(*data + 2, packet.data(), packet.size(), &name , &enclen);
if (rc != ARES_SUCCESS) { if (rc != ARES_SUCCESS) {
ss << "(error from ares_expand_name)"; ss << "(error from ares_expand_name)";
break; break;
} }
ss << " " << DNS__16BIT(*data) << " '" << name << "'"; ss << " " << DNS__16BIT(*data) << " '" << name << "'";
ares_free_string(name); ares_free_string(name);
} else { } else {
ss << "(RR too short)"; ss << "(RR too short)";
} }
break; break;
case ns_t_srv: { case T_SRV: {
if (rdatalen > 6) { if (rdatalen > 6) {
const byte* p = *data; const byte* p = *data;
unsigned long prio = DNS__16BIT(p); unsigned long prio = DNS__16BIT(p);
unsigned long weight = DNS__16BIT(p + 2); unsigned long weight = DNS__16BIT(p + 2);
unsigned long port = DNS__16BIT(p + 4); unsigned long port = DNS__16BIT(p + 4);
p += 6; p += 6;
int rc = ares_expand_name(p, packet.data(), packet.size(), &name, &encle n); int rc = ares_expand_name(p, packet.data(), packet.size(), &name, &encle n);
if (rc != ARES_SUCCESS) { if (rc != ARES_SUCCESS) {
ss << "(error from ares_expand_name)"; ss << "(error from ares_expand_name)";
break; break;
} }
ss << prio << " " << weight << " " << port << " '" << name << "'"; ss << prio << " " << weight << " " << port << " '" << name << "'";
ares_free_string(name); ares_free_string(name);
} else { } else {
ss << "(RR too short)"; ss << "(RR too short)";
} }
break; break;
} }
case ns_t_soa: { case T_SOA: {
const byte* p = *data; const byte* p = *data;
int rc = ares_expand_name(p, packet.data(), packet.size(), &name, &enclen) ; int rc = ares_expand_name(p, packet.data(), packet.size(), &name, &enclen) ;
if (rc != ARES_SUCCESS) { if (rc != ARES_SUCCESS) {
ss << "(error from ares_expand_name)"; ss << "(error from ares_expand_name)";
break; break;
} }
ss << " '" << name << "'"; ss << " '" << name << "'";
ares_free_string(name); ares_free_string(name);
p += enclen; p += enclen;
rc = ares_expand_name(p, packet.data(), packet.size(), &name, &enclen); rc = ares_expand_name(p, packet.data(), packet.size(), &name, &enclen);
skipping to change at line 404 skipping to change at line 404
unsigned long refresh = DNS__32BIT(p + 4); unsigned long refresh = DNS__32BIT(p + 4);
unsigned long retry = DNS__32BIT(p + 8); unsigned long retry = DNS__32BIT(p + 8);
unsigned long expire = DNS__32BIT(p + 12); unsigned long expire = DNS__32BIT(p + 12);
unsigned long minimum = DNS__32BIT(p + 16); unsigned long minimum = DNS__32BIT(p + 16);
ss << " " << serial << " " << refresh << " " << retry << " " << expire < < " " << minimum; ss << " " << serial << " " << refresh << " " << retry << " " << expire < < " " << minimum;
} else { } else {
ss << "(RR too short)"; ss << "(RR too short)";
} }
break; break;
} }
case ns_t_naptr: { case T_NAPTR: {
if (rdatalen > 7) { if (rdatalen > 7) {
const byte* p = *data; const byte* p = *data;
unsigned long order = DNS__16BIT(p); unsigned long order = DNS__16BIT(p);
unsigned long pref = DNS__16BIT(p + 2); unsigned long pref = DNS__16BIT(p + 2);
p += 4; p += 4;
ss << order << " " << pref; ss << order << " " << pref;
int len = *p++; int len = *p++;
std::string flags(p, p + len); std::string flags(p, p + len);
ss << " " << flags; ss << " " << flags;
 End of changes. 14 change blocks. 
92 lines changed or deleted 92 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)