本文整理汇总了C++中DNS类的典型用法代码示例。如果您正苦于以下问题:C++ DNS类的具体用法?C++ DNS怎么用?C++ DNS使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DNS类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setup
void setup()
{
ebox_init();
uart1.begin(115200);
ret = sizeof(long);
ret = sizeof(int);
ret = sizeof(short int);
ret = sizeof(short);
w5500.begin(2,mac,ip,sub,gw,dns);
attach_eth_to_socket(&w5500);
w5500.getMAC (buf);
uart1.printf("mac : %02x.%02x.%02x.%02x.%02x.%02x\r\n", buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]);
w5500.getIP (buf);
uart1.printf("IP : %d.%d.%d.%d\r\n", buf[0],buf[1],buf[2],buf[3]);
w5500.getSubnet(buf);
uart1.printf("mask : %d.%d.%d.%d\r\n", buf[0],buf[1],buf[2],buf[3]);
w5500.getGateway(buf);
uart1.printf("GW : %d.%d.%d.%d\r\n", buf[0],buf[1],buf[2],buf[3]);
uart1.printf("Network is ready.\r\n");
ddns.begin(SOCKET1,3000);
ret = ddns.query(name);
if(ret == DNS_RET_SUCCESS) /*发送DNS请求*/
uart1.printf("Get [%s]'s IP address [%d.%d.%d.%d] from %d.%d.%d.%d\r\n",name,ddns.domain_ip[0],ddns.domain_ip[1],ddns.domain_ip[2],ddns.domain_ip[3],dns[0],dns[1],dns[2],dns[3]);
else if(ret == DNS_RET_FAIL)
uart1.printf("获取超时\r\n");
else
uart1.printf("未知错误.\r\n");
}
示例2: TEST_F
TEST_F(DNSTest, Answers) {
DNS dns;
dns.add_answer(
DNS::Resource("www.example.com", "127.0.0.1", DNS::A, DNS::IN, 0x762)
);
dns.add_answer(
DNS::Resource("www.example2.com", "mail.example.com", DNS::MX, DNS::IN, 0x762)
);
ASSERT_EQ(dns.answers_count(), 2);
DNS::resources_type resources = dns.answers();
for(DNS::resources_type::const_iterator it = resources.begin(); it != resources.end(); ++it) {
EXPECT_TRUE(it->dname() == "www.example.com" || it->dname() == "www.example2.com");
if(it->dname() == "www.example.com") {
EXPECT_EQ(it->type(), DNS::A);
EXPECT_EQ(it->ttl(), 0x762U);
EXPECT_EQ(it->data(), "127.0.0.1");
EXPECT_EQ(it->query_class(), DNS::IN);
}
else if(it->dname() == "www.example2.com") {
EXPECT_EQ(it->type(), DNS::MX);
EXPECT_EQ(it->ttl(), 0x762U);
EXPECT_EQ(it->data(), "mail.example.com");
EXPECT_EQ(it->query_class(), DNS::IN);
}
}
}
示例3: batch_handler
DWORD WINAPI batch_handler(void* param)
{
DNS dns;
queue<string>* questions;
queue<string>* answers;
parameter* p = (parameter*)param;
CRITICAL_SECTION* cs = p->cs;
questions = p->questions;
answers = p->answers;
string question;
string answer;
while(1)
{
EnterCriticalSection(cs);
c++;
if(c>100000)
{
LeaveCriticalSection(cs);
return 0;
}
question = questions->front();
questions->pop();
LeaveCriticalSection(cs);
/*
EnterCriticalSection(&statistic_lock);
stat.total_queries++;
LeaveCriticalSection(&statistic_lock);
unsigned long start = GetTickCount();
if((gethostbyname(question.c_str())) != NULL)
{
//printf("Get host by name with error = %d\n",WSAGetLastError());
EnterCriticalSection(&statistic_lock);
stat.sucess++;
LeaveCriticalSection(&statistic_lock);
}
unsigned long end = GetTickCount();
EnterCriticalSection(&statistic_lock);
stat.delays.push_back(end - start);
LeaveCriticalSection(&statistic_lock);
*/
unsigned long start = GetTickCount();
answer = dns.resolve(question);
unsigned long end = GetTickCount();
EnterCriticalSection(&statistic_lock);
stat.delays.push_back(end - start);
LeaveCriticalSection(&statistic_lock);
EnterCriticalSection(cs);
if(answer != "")
answers->push(answer);
LeaveCriticalSection(cs);
}
return 0;
}
示例4: TEST_F
TEST_F(DNSTest, AnswersWithSameName) {
DNS dns;
dns.add_answer("www.example.com", DNS::make_info(DNS::A, DNS::IN, 0x762), IPv4Address("127.0.0.1"));
dns.add_answer("www.example.com", DNS::make_info(DNS::A, DNS::IN, 0x762), IPv4Address("127.0.0.2"));
ASSERT_EQ(dns.answers_count(), 2);
DNS::resources_type resources = dns.answers();
for(DNS::resources_type::const_iterator it = resources.begin(); it != resources.end(); ++it) {
EXPECT_TRUE(it->data() == "127.0.0.1" || it->data() == "127.0.0.2");
EXPECT_EQ(it->dname(), "www.example.com");
EXPECT_EQ(it->type(), DNS::A);
EXPECT_EQ(it->ttl(), 0x762U);
EXPECT_EQ(it->query_class(), DNS::IN);
}
}
示例5:
void CGUL::Network::HTTPRequest::Https(const String& url)
{
host = url;
DNS dns;
Vector< Network::IPAddress > lookup;
dns.Lookup(url, &lookup);
if (lookup.size() == 0)
{
return;
}
sock->ConnectSSL(IPAddress(lookup[0]), 443);
}
示例6: callback
bool callback(const PDU &pdu)
{
// The packet probably looks like this:
//
// EthernetII / IP / UDP / RawPDU
//
// So we retrieve the RawPDU layer, and construct a
// DNS PDU using its contents.
DNS dns = pdu.rfind_pdu<RawPDU>().to<DNS>();
// Retrieve the queries and print the domain name:
for(const auto &query : dns.queries())
std::cout << query.dname() << std::endl;
return true;
}
示例7: callback
bool callback(const PDU &pdu)
{
// The packet probably looks like this:
//
// EthernetII / IP / UDP / RawPDU
//
// So we retrieve each layer, and construct a
// DNS PDU from the RawPDU layer contents.
EthernetII eth = pdu.rfind_pdu<EthernetII>();
IP ip = eth.rfind_pdu<IP>();
UDP udp = ip.rfind_pdu<UDP>();
DNS dns = udp.rfind_pdu<RawPDU>().to<DNS>();
// Is it a DNS query?
if(dns.type() == DNS::QUERY) {
// Let's see if there's any query for an "A" record.
for(const auto &query : dns.queries()) {
if(query.type() == DNS::A) {
// Here's one! Let's add an answer.
dns.add_answer(
DNS::Resource(
query.dname(),
"127.0.0.1",
DNS::A,
query.query_class(),
// 777 is just a random TTL
777
)
);
}
}
// Have we added some answers?
if(dns.answers_count() > 0) {
// It's a response now
dns.type(DNS::RESPONSE);
// Recursion is available(just in case)
dns.recursion_available(1);
// Build our packet
auto pkt = EthernetII(eth.src_addr(), eth.dst_addr()) /
IP(ip.src_addr(), ip.dst_addr()) /
UDP(udp.sport(), udp.dport()) /
dns;
// Send it!
sender.send(pkt);
}
}
return true;
}
示例8: test_equals
void DNSTest::test_equals(const DNS &dns1, const DNS &dns2) {
EXPECT_EQ(dns1.id(), dns2.id());
EXPECT_EQ(dns1.type(), dns2.type());
EXPECT_EQ(dns1.opcode(), dns2.opcode());
EXPECT_EQ(dns1.authoritative_answer(), dns2.authoritative_answer());
EXPECT_EQ(dns1.truncated(), dns2.truncated());
EXPECT_EQ(dns1.recursion_desired(), dns2.recursion_desired());
EXPECT_EQ(dns1.recursion_available(), dns2.recursion_available());
EXPECT_EQ(dns1.z(), dns2.z());
EXPECT_EQ(dns1.authenticated_data(), dns2.authenticated_data());
EXPECT_EQ(dns1.checking_disabled(), dns2.checking_disabled());
EXPECT_EQ(dns1.rcode(), dns2.rcode());
EXPECT_EQ(dns1.questions_count(), dns2.questions_count());
EXPECT_EQ(dns1.answers_count(), dns2.answers_count());
EXPECT_EQ(dns1.authority_count(), dns2.authority_count());
EXPECT_EQ(dns1.additional_count(), dns2.additional_count());
EXPECT_EQ(dns1.pdu_type(), dns2.pdu_type());
EXPECT_EQ(dns1.header_size(), dns2.header_size());
EXPECT_EQ(bool(dns1.inner_pdu()), bool(dns2.inner_pdu()));
}
示例9: moreToCorrelate
int HTTPDNSCorrelator<ReaderType, WriterType, ResponseWriterType>::run() {
IPv4Network network;
DNS dns;
SearchDNSResult dnsResult;
SearchDNSResponseResult dnsResponseResult;
bool moreToCorrelate(true);
// prefetch the first DNS
ErrorStatus errorStatus;
if ((errorStatus = _reader->read(dns)) != E_SUCCESS) {
if (errorStatus != E_EOF) {
_error = true;
_errorMsg.assign("Reader: error reading ");
return 1;
}
// no more http data to read. we're done.
moreToCorrelate = false;
}
std::deque <DNS> _q;
TimeStamp windowSize(300, 0); // 5 minutes
uint32_t tmpRawSourceIP, tmpRawDestinationIP;
// for each SearchNeoflowResult
for (std::set<SearchHTTPResult>::const_iterator i(_set->begin());
i != _set->end();
++i)
{
// fill up the 5 minute window
while (!_q.empty() && _q.front().responseTime() < i->time() - windowSize) {
_q.pop_front();
}
while (moreToCorrelate && dns.responseTime() <= i->time()) {
if (dns.responseTime() >= i->time() - windowSize) {
// in range. push it into the deque
_q.push_back(dns);
}
if ((errorStatus = _reader->read(dns)) != E_SUCCESS) {
if (errorStatus != E_EOF) {
_error = true;
_errorMsg.assign("Reader: error reading");
return 1;
}
// no more http data to read. we're done.
moreToCorrelate = false;
}
}
// if there are HTTPs to look at, make flow matcher based on i
// FIXME this should make a matcher that matches DNS flows
// where the client is the INTERNAL address of the flow
// for now we just match either, as this will probably suffice
/*
IPv4FlowMatcher matcher, reverseMatcher;
if (!_q.empty()) {
network.rawSet(i->rawSourceIP(), 0xffffffff);
matcher.addDestinationNetwork(network);
network.rawSet(i->rawDestinationIP(), 0xffffffff);
reverseMatcher.addDestinationNetwork(network);
}
*/
if (i->request().time() != TimeStamp()) {
tmpRawSourceIP = i->request().raw_source_ip();
tmpRawDestinationIP = i->request().raw_destination_ip();
}
else {
tmpRawSourceIP = i->response().raw_source_ip();
tmpRawDestinationIP = i->response().raw_destination_ip();
}
// look for the correlated DNSs.
bool foundMatch(false);
DNS *serverDNS(NULL);
for (std::deque <DNS>::const_reverse_iterator it(_q.rbegin());
it != _q.rend();
++it)
{
if (tmpRawSourceIP != it->rawClientIP() &&
tmpRawDestinationIP != it->rawClientIP() &&
(_dnsServers == NULL || _dnsServers->find(it->rawClientIP()) == _dnsServers->end()))
{
continue;
}
const std::vector<DNS::DNSResponse*> &responses(it->responses());
foundMatch = false;
for (std::vector<DNS::DNSResponse*>::const_iterator r(responses.begin());
r != responses.end();
++r)
{
if ((*r)->type() == 1) {
if ((tmpRawSourceIP == it->rawClientIP()) &&
(tmpRawDestinationIP == *reinterpret_cast<const uint32_t *>((*r)->resourceData().data())))
{
foundMatch = true;
break;
}
else if ((tmpRawDestinationIP == it->rawClientIP()) &&
//.........这里部分代码省略.........
示例10: Tick
virtual void Tick(time_t)
{
dns->PruneCache();
}