1 #ifndef PDNS_DNSPCAP_HH
2 #define PDNS_DNSPCAP_HH
10 #include <netinet/in_systm.h>
11 #include <netinet/ip.h>
12 #include <netinet/udp.h>
13 #include <net/ethernet.h>
15 #include <boost/format.hpp>
18 struct pdns_pcap_file_header {
20 uint16_t version_major;
21 uint16_t version_minor;
22 uint32_t thiszone; /* gmt to local correction */
23 uint32_t sigfigs; /* accuracy of timestamps */
24 uint32_t snaplen; /* max length saved portion of each pkt */
25 uint32_t linktype; /* data link type (LINKTYPE_*) */
29 struct pdns_pcap_pkthdr {
30 struct timeval ts; /* time stamp */
31 uint32_t caplen; /* length of portion present */
32 uint32_t len; /* length this packet (off wire) */
35 class PcapPacketReader
38 class EofException : public runtime_error
41 EofException(const string& str="") : runtime_error(str)
46 PcapPacketReader(const string& fname);
51 void checkedFread(T* ptr)
53 checkedFreadSize(ptr, sizeof(*ptr));
56 void checkedFreadSize(void* ptr, size_t size) ;
60 struct ether_header* d_ether;
62 const struct tcphdr *d_tcp;
63 const struct udphdr *d_udp;
64 const uint8_t* d_payload;
66 struct pdns_pcap_pkthdr d_pheader;
68 pdns_pcap_file_header d_pfh;
69 unsigned int d_runts, d_oversized, d_correctpackets, d_nonetheripudp;
76 class PcapPacketWriter
79 PcapPacketWriter(const string& fname, PcapPacketReader& ppr);
87 const PcapPacketReader& d_ppr;