1 #ifndef PDNS_DNSPCAP_HH
2 #define PDNS_DNSPCAP_HH
11 #include <netinet/in_systm.h>
12 #include <netinet/ip.h>
13 #include <netinet/ip6.h>
14 #include <netinet/udp.h>
15 #if defined(__NetBSD__)
17 #include <net/if_ether.h>
18 #elif defined (__OpenBSD__)
20 #include <netinet/if_ether.h>
21 #elif defined (__SVR4) && defined (__sun)
22 #include <sys/ethernet.h>
24 #include <net/ethernet.h>
27 #include <boost/format.hpp>
28 #include "namespaces.hh"
30 struct pdns_pcap_file_header {
32 uint16_t version_major;
33 uint16_t version_minor;
34 uint32_t thiszone; /* gmt to local correction */
35 uint32_t sigfigs; /* accuracy of timestamps */
36 uint32_t snaplen; /* max length saved portion of each pkt */
37 uint32_t linktype; /* data link type (LINKTYPE_*) */
47 struct pdns_pcap_pkthdr {
48 struct pdns_timeval ts; /* time stamp */
49 uint32_t caplen; /* length of portion present */
50 uint32_t len; /* length this packet (off wire) */
53 struct pdns_lcc_header {
54 uint16_t lcc_pkttype;/* packet type */
55 uint16_t lcc_hatype;/* link-layer address type */
56 uint16_t lcc_halen;/* link-layer address length */
57 uint8_t lcc_addr[8];/* link-layer address */
58 uint16_t lcc_protocol;/* protocol */
61 class PcapPacketReader
64 class EofException : public runtime_error
67 EofException(const string& str="") : runtime_error(str)
72 PcapPacketReader(const string& fname);
77 void checkedFread(T* ptr)
79 checkedFreadSize(ptr, sizeof(*ptr));
82 void checkedFreadSize(void* ptr, size_t size) ;
87 ComboAddress getSource() const;
88 ComboAddress getDest() const;
90 struct pdns_lcc_header* d_lcc;
91 struct ether_header* d_ether;
93 struct ip6_hdr *d_ip6;
94 const struct tcphdr *d_tcp;
95 const struct udphdr *d_udp;
96 const uint8_t* d_payload;
98 struct pdns_pcap_pkthdr d_pheader;
100 pdns_pcap_file_header d_pfh;
101 unsigned int d_runts, d_oversized, d_correctpackets, d_nonetheripudp;
102 char d_buffer[32768];
106 int d_skipMediaHeader;
109 class PcapPacketWriter
112 PcapPacketWriter(const string& fname, PcapPacketReader& ppr);
120 const PcapPacketReader& d_ppr;