+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
#ifndef PDNS_DNSPCAP_HH
#define PDNS_DNSPCAP_HH
#include <cstdio>
#include <stdexcept>
+#include "iputils.hh"
#include <string>
#include "misc.hh"
#include <iostream>
#define __FAVOR_BSD
#include <netinet/in_systm.h>
#include <netinet/ip.h>
+#include <netinet/ip6.h>
#include <netinet/udp.h>
#if defined(__NetBSD__)
#include <net/if.h>
struct pdns_timeval
{
- uint32_t tv_sec;
- uint32_t tv_usec;
+ uint32_t tv_sec{0};
+ uint32_t tv_usec{0};
};
struct pdns_pcap_pkthdr {
struct pdns_timeval ts; /* time stamp */
- uint32_t caplen; /* length of portion present */
- uint32_t len; /* length this packet (off wire) */
+ uint32_t caplen{0}; /* length of portion present */
+ uint32_t len{0}; /* length this packet (off wire) */
};
struct pdns_lcc_header {
bool getUDPPacket();
- struct pdns_lcc_header* d_lcc;
- struct ether_header* d_ether;
- struct ip *d_ip;
- const struct tcphdr *d_tcp;
- const struct udphdr *d_udp;
- const uint8_t* d_payload;
- unsigned int d_len;
+ ComboAddress getSource() const;
+ ComboAddress getDest() const;
+
+ struct pdns_lcc_header* d_lcc{nullptr};
+ struct ether_header* d_ether{nullptr};
+ struct ip *d_ip{nullptr};
+ struct ip6_hdr *d_ip6{nullptr};
+ const struct tcphdr *d_tcp{nullptr};
+ const struct udphdr *d_udp{nullptr};
+ const uint8_t* d_payload{nullptr};
+ unsigned int d_len{0};
struct pdns_pcap_pkthdr d_pheader;
pdns_pcap_file_header d_pfh;
private:
FILE* d_fp;
string d_fname;
- int d_skipMediaHeader;
+ unsigned int d_skipMediaHeader;
};
class PcapPacketWriter
{
public:
- PcapPacketWriter(const string& fname, PcapPacketReader& ppr);
+ PcapPacketWriter(const string& fname, const PcapPacketReader& ppr);
+ PcapPacketWriter(const string& fname);
void write();
-
+ void setPPR(const PcapPacketReader& ppr) { d_ppr = &ppr; }
~PcapPacketWriter();
private:
string d_fname;
- const PcapPacketReader& d_ppr;
+ const PcapPacketReader* d_ppr{nullptr};
FILE *d_fp;
+ bool d_first{true};
};
#endif // DNSPCAP_HH