Skip to content

Instantly share code, notes, and snippets.

@ytakano
Last active December 20, 2015 12:18
Show Gist options
  • Select an option

  • Save ytakano/6129644 to your computer and use it in GitHub Desktop.

Select an option

Save ytakano/6129644 to your computer and use it in GitHub Desktop.
example of cdpi_dns
#include "cdpi_dns.hpp"
#include <iostream>
using namespace std;
void
decode_a(char *buf, int len) {
cdpi_dns dns_decoder;
if (dns_decoder.decode(buf, len)) {
// print questions
const std::list<cdpi_dns_question> &que = dns_decoder.get_question();
std::list<cdpi_dns_question>::const_iterator it_que;
for (it_que = que.begin(); it_que != que.end(); ++it_que) {
cout << it_que->m_qname
<< ", type = " << ntohs(it_que->m_qtype)
<< ", class = " << ntohs(it_que->m_qclass)
<< endl;
}
// print answers of A record
const std::list<cdpi_dns_rr> &answer = dns_decoder.get_answer();
std::list<cdpi_dns_rr>::const_iterator it_ans;
for (it_ans = answer.begin(); it_ans != answer.end(); ++it_ans) {
if (ntohs(it_ans->m_type) == DNS_TYPE_A &&
ntohs(it_ans->m_class) == DNS_CLASS_IN) {
ptr_cdpi_dns_a p_a = DNS_RDATA_TO_A(it_ans->m_rdata);
cout << p_a->m_a << endl;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment