Branch data Line data Source code
1 : : // $Id:$
2 : : //
3 : : // See the file "COPYING" in the main distribution directory for copyright.
4 : :
5 : :
6 : : #include "config.h"
7 : :
8 : : #include <assert.h>
9 : : #include <stdlib.h>
10 : :
11 : : #include "Event.h"
12 : : #include "Net.h"
13 : : #include "PacketDumper.h"
14 : :
15 : 0 : PacketDumper::PacketDumper(pcap_dumper_t* arg_pkt_dump)
16 : : {
17 : 0 : last_timestamp.tv_sec = last_timestamp.tv_usec = 0;
18 : :
19 : 0 : pkt_dump = arg_pkt_dump;
20 [ # # ][ # # ]: 0 : if ( ! pkt_dump )
21 : 0 : internal_error("PacketDumper: nil dump file");
22 : 0 : }
23 : :
24 : : void PacketDumper::DumpPacket(const struct pcap_pkthdr* hdr,
25 : 0 : const u_char* pkt, int len)
26 : : {
27 [ # # ]: 0 : if ( pkt_dump )
28 : : {
29 : 0 : struct pcap_pkthdr h = *hdr;
30 : 0 : h.caplen = len;
31 [ # # ]: 0 : if ( h.caplen > hdr->caplen )
32 : 0 : internal_error("bad modified caplen");
33 : :
34 : 0 : pcap_dump((u_char*) pkt_dump, &h, pkt);
35 : : }
36 : 0 : }
37 : :
38 : 0 : void PacketDumper::SortTimeStamp(struct timeval* timestamp)
39 : : {
40 [ # # ]: 0 : if ( time_compare(&last_timestamp, timestamp) > 0 )
41 : 0 : *timestamp = last_timestamp;
42 : : else
43 : 0 : last_timestamp = *timestamp;
44 [ + - ][ + - ]: 6 : }
|