]>
Commit | Line | Data |
---|---|---|
ff6a1e7b BH |
1 | #include "dnsparser.hh" |
2 | #include "sstuff.hh" | |
3 | #include "misc.hh" | |
a0a276c2 BH |
4 | #include "dnswriter.hh" |
5 | #include "dnsrecords.hh" | |
b0d4fb45 BH |
6 | #include "statbag.hh" |
7 | StatBag S; | |
ff6a1e7b BH |
8 | |
9 | int main(int argc, char** argv) | |
10 | try | |
11 | { | |
ee6c3a6b PD |
12 | bool dnssec=false; |
13 | ||
b0d4fb45 | 14 | reportAllTypes(); |
a0a276c2 | 15 | |
ee6c3a6b PD |
16 | if(argc < 5) { |
17 | cerr<<"Syntax: sdig IP-address port question question-type [dnssec]\n"; | |
a8ad4624 BH |
18 | exit(EXIT_FAILURE); |
19 | } | |
a0a276c2 | 20 | |
ee6c3a6b PD |
21 | if(argc > 5 && strcmp(argv[5], "dnssec")==0) |
22 | { | |
23 | dnssec=true; | |
24 | } | |
25 | ||
a0a276c2 | 26 | vector<uint8_t> packet; |
bca6643b | 27 | |
a0a276c2 BH |
28 | DNSPacketWriter pw(packet, argv[3], DNSRecordContent::TypeToNumber(argv[4])); |
29 | ||
ee6c3a6b PD |
30 | if(dnssec) |
31 | { | |
32 | pw.addOpt(2800, 0, EDNSOpts::DNSSECOK); | |
33 | pw.commit(); | |
34 | } | |
bca6643b | 35 | // pw.setRD(true); |
bca6643b BH |
36 | |
37 | /* | |
38 | pw.startRecord("powerdns.com", DNSRecordContent::TypeToNumber("NS")); | |
39 | NSRecordContent nrc("ns1.powerdns.com"); | |
a0a276c2 | 40 | nrc.toPacket(pw); |
878435ce | 41 | |
bca6643b BH |
42 | pw.startRecord("powerdns.com", DNSRecordContent::TypeToNumber("NS")); |
43 | NSRecordContent nrc2("ns2.powerdns.com"); | |
44 | nrc2.toPacket(pw); | |
bca6643b | 45 | */ |
edb1c9ee | 46 | |
fdf05fd4 | 47 | string ping("hallo!"); |
edb1c9ee | 48 | /* DNSPacketWriter::optvect_t opts; |
fdf05fd4 BH |
49 | |
50 | opts.push_back(make_pair(5, ping)); | |
0c70797e BH |
51 | pw.addOpt(5200, 0, 0x8000, opts); |
52 | pw.commit(); | |
edb1c9ee | 53 | */ |
fdf05fd4 | 54 | |
ff6a1e7b | 55 | Socket sock(InterNetwork, Datagram); |
fdf05fd4 | 56 | ComboAddress dest(argv[1] + (*argv[1]=='@'), atoi(argv[2])); |
a0a276c2 | 57 | sock.sendTo(string((char*)&*packet.begin(), (char*)&*packet.end()), dest); |
ff6a1e7b BH |
58 | |
59 | string reply; | |
60 | sock.recvFrom(reply, dest); | |
61 | ||
62 | MOADNSParser mdp(reply); | |
2a09f6a1 | 63 | cout<<"Reply to question for qname='"<<mdp.d_qname<<"', qtype="<<DNSRecordContent::NumberToType(mdp.d_qtype)<<endl; |
0c70797e | 64 | cout<<"Rcode: "<<mdp.d_header.rcode<<", RD: "<<mdp.d_header.rd<<", QR: "<<mdp.d_header.qr; |
7fc69fd0 | 65 | cout<<", TC: "<<mdp.d_header.tc<<", AA: "<<mdp.d_header.aa<<", opcode: "<<mdp.d_header.opcode<<endl; |
945a9ad4 | 66 | |
ff6a1e7b | 67 | for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) { |
2a09f6a1 | 68 | cout<<i->first.d_place-1<<"\t"<<i->first.d_label<<"\tIN\t"<<DNSRecordContent::NumberToType(i->first.d_type); |
b0d4fb45 | 69 | cout<<"\t"<<i->first.d_ttl<<"\t"<< i->first.d_content->getZoneRepresentation()<<"\n"; |
ff6a1e7b | 70 | } |
fdf05fd4 | 71 | |
0c70797e BH |
72 | EDNSOpts edo; |
73 | if(getEDNSOpts(mdp, &edo)) { | |
74 | ||
75 | cerr<<"Have "<<edo.d_options.size()<<" options!"<<endl; | |
76 | for(vector<pair<uint16_t, string> >::const_iterator iter = edo.d_options.begin(); | |
4957a608 BH |
77 | iter != edo.d_options.end(); |
78 | ++iter) { | |
fdf05fd4 | 79 | if(iter->first == 5) {// 'EDNS PING' |
4957a608 BH |
80 | cerr<<"Have ednsping: '"<<iter->second<<"'\n"; |
81 | if(iter->second == ping) | |
82 | cerr<<"It is correct!"<<endl; | |
0c70797e | 83 | } |
fdf05fd4 | 84 | else { |
4957a608 | 85 | cerr<<"Have unknown option "<<(int)iter->first<<endl; |
fdf05fd4 | 86 | } |
0c70797e BH |
87 | } |
88 | ||
89 | } | |
fdf05fd4 | 90 | |
ff6a1e7b | 91 | } |
0c70797e | 92 | catch(std::exception &e) |
ff6a1e7b BH |
93 | { |
94 | cerr<<"Fatal: "<<e.what()<<endl; | |
95 | } |