forked from PowerDNS/pdns
/
stubquery.cc
68 lines (56 loc) · 1.22 KB
/
stubquery.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "arguments.hh"
#include "dnsrecords.hh"
#include "dns_random.hh"
#include "stubresolver.hh"
#include "statbag.hh"
StatBag S;
ArgvMap &arg()
{
static ArgvMap theArg;
return theArg;
}
void usage() {
cerr<<"stubquery"<<endl;
cerr<<"Syntax: stubquery QUESTION [QUESTION-TYPE]"<<endl;
}
int main(int argc, char** argv)
try
{
DNSName qname;
QType qtype;
for(int i=1; i<argc; i++) {
if ((string) argv[i] == "--help") {
usage();
exit(EXIT_SUCCESS);
}
if ((string) argv[i] == "--version") {
cerr<<"stubquery "<<VERSION<<endl;
exit(EXIT_SUCCESS);
}
}
if(argc < 2) {
usage();
exit(EXIT_FAILURE);
}
::arg().set("recursor","If recursion is desired, IP address of a recursing nameserver")="no";
reportAllTypes();
dns_random_init("0123456789abcdef");
stubParseResolveConf();
vector<DNSResourceRecord> ret;
int res=stubDoResolve(argv[1], DNSRecordContent::TypeToNumber(argv[2]), ret);
cout<<"res: "<<res<<endl;
for(const auto& r : ret) {
cout<<r.getZoneRepresentation()<<endl;
}
}
catch(std::exception &e)
{
cerr<<"Fatal: "<<e.what()<<endl;
}
catch(PDNSException &e)
{
cerr<<"Fatal: "<<e.reason<<endl;
}