]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnspcap2calidns.cc
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
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.
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.
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.
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.
32 #include "dnsparser.hh"
39 cerr
<<"This program reads DNS queries from a PCAP file and outputs them in the calidns format."<<endl
;
40 cerr
<<"Usage: dnspcap2calidns PCAPFILE OUTFILE"<<endl
;
43 int main(int argc
, char **argv
)
46 for(int n
=1 ; n
< argc
; ++n
) {
47 if ((string
) argv
[n
] == "--help") {
52 if ((string
) argv
[n
] == "--version") {
53 cerr
<<"dnspcap2calidns "<<VERSION
<<endl
;
64 PcapPacketReader
pr(argv
[1]);
68 cerr
<<"Error opening output file "<<argv
[2]<<": "<<stringerror()<<endl
;
73 while (pr
.getUDPPacket()) {
74 if (pr
.d_len
< sizeof(dnsheader
)) {
78 const dnsheader
* dh
=reinterpret_cast<const dnsheader
*>(pr
.d_payload
);
91 uint16_t qtype
, qclass
;
94 qname
=DNSName(reinterpret_cast<const char*>(pr
.d_payload
), pr
.d_len
, sizeof(dnsheader
), false, &qtype
, &qclass
);
96 catch(const std::exception
& e
) {
97 cerr
<<"Error while parsing qname: "<<e
.what()<<endl
;
101 const ComboAddress requestor
= pr
.getSource();
103 fp
<< qname
<< " " << QType(qtype
).getName() << " " << requestor
.toString() << endl
;
106 catch (const std::exception
& e
) {
107 cerr
<<"Error while parsing the PCAP file: "<<e
.what()<<endl
;
115 catch(const std::exception
& e
) {
116 cerr
<<"Error opening PCAP file: "<<e
.what()<<endl
;