]>
Commit | Line | Data |
---|---|---|
12471842 PL |
1 | /* |
2 | * This file is part of PowerDNS or dnsdist. | |
3 | * Copyright -- PowerDNS.COM B.V. and its contributors | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of version 2 of the GNU General Public License as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * In addition, for the avoidance of any doubt, permission is granted to | |
10 | * link this program with OpenSSL and to (re)distribute the binaries | |
11 | * produced as the result of such linking. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
21 | */ | |
870a0fe4 AT |
22 | #ifdef HAVE_CONFIG_H |
23 | #include "config.h" | |
24 | #endif | |
2353fffa BH |
25 | #include <bitset> |
26 | #include "statbag.hh" | |
27 | #include "dnspcap.hh" | |
28 | #include "sstuff.hh" | |
29 | #include "anadns.hh" | |
30 | ||
31 | // this is needed because boost multi_index also uses 'L', as do we (which is sad enough) | |
32 | #undef L | |
33 | ||
2353fffa BH |
34 | #include <set> |
35 | #include <deque> | |
36 | ||
37 | #include <boost/format.hpp> | |
38 | #include <boost/utility.hpp> | |
39 | #include <boost/multi_index_container.hpp> | |
40 | #include <boost/multi_index/ordered_index.hpp> | |
41 | #include <boost/multi_index/key_extractors.hpp> | |
42 | #include <cctype> | |
43 | ||
61b26744 | 44 | #include "namespaces.hh" |
2353fffa | 45 | using namespace ::boost::multi_index; |
10f4eea8 | 46 | #include "namespaces.hh" |
2353fffa BH |
47 | StatBag S; |
48 | ||
c18c244b PL |
49 | void usage() { |
50 | cerr<<"syntax: dnsscan INFILE ..."<<endl; | |
51 | } | |
52 | ||
2353fffa BH |
53 | int main(int argc, char** argv) |
54 | try | |
55 | { | |
528b753d | 56 | Socket sock(AF_INET, SOCK_DGRAM); |
2353fffa | 57 | |
809fe23f | 58 | /* |
2353fffa | 59 | IPEndpoint remote(argc > 2 ? argv[2] : "127.0.0.1", |
232f0877 | 60 | argc > 3 ? atoi(argv[3]) : 5300); |
2353fffa | 61 | |
809fe23f | 62 | */ |
2353fffa | 63 | |
809fe23f | 64 | if(argc<2) { |
c18c244b PL |
65 | usage(); |
66 | exit(EXIT_SUCCESS); | |
67 | } | |
68 | ||
69 | for(int n=1; n < argc; ++n) { | |
70 | if ((string) argv[n] == "--help") { | |
71 | usage(); | |
72 | return EXIT_SUCCESS; | |
73 | } | |
74 | ||
75 | if ((string) argv[n] == "--version") { | |
76 | cerr<<"dnsscan "<<VERSION<<endl; | |
77 | return EXIT_SUCCESS; | |
78 | } | |
809fe23f | 79 | } |
88338f52 BH |
80 | |
81 | unsigned int counts[256]; | |
82 | for(unsigned int n=0 ; n < 256; ++n) | |
83 | counts[n]=0; | |
809fe23f BH |
84 | |
85 | for(int n=1; n < argc; ++n) { | |
86 | PcapPacketReader pr(argv[n]); | |
87 | ||
88 | while(pr.getUDPPacket()) { | |
89 | try { | |
27c0050c | 90 | MOADNSParser mdp(false, (const char*)pr.d_payload, pr.d_len); |
4957a608 BH |
91 | if(mdp.d_qtype < 256) |
92 | counts[mdp.d_qtype]++; | |
88338f52 | 93 | |
2353fffa | 94 | } |
809fe23f | 95 | catch(MOADNSException &e) { |
6199d624 | 96 | cout<<"Error from remote "<<pr.getSource().toString()<<": "<<e.what()<<"\n"; |
232f0877 | 97 | // sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote); |
2353fffa | 98 | } |
2353fffa BH |
99 | } |
100 | } | |
88338f52 BH |
101 | for(unsigned int n=0 ; n < 256; ++n) { |
102 | if(counts[n]) | |
103 | cout << n << "\t" << counts[n] << "\n"; | |
104 | } | |
105 | ||
2353fffa | 106 | } |
adc10f99 | 107 | catch(std::exception& e) |
2353fffa | 108 | { |
629eaf49 | 109 | cout<<"Fatal: "<<e.what()<<endl; |
2353fffa BH |
110 | } |
111 |