INET Framework for OMNeT++/OMNEST
inet::TCPDump Class Reference

Dumps every packet using the PcapDump class and the PacketDump class. More...

#include <TCPDump.h>

Inheritance diagram for inet::TCPDump:

Public Member Functions

 TCPDump ()
 
 ~TCPDump ()
 
virtual void handleMessage (cMessage *msg) override
 
virtual void initialize () override
 
virtual void finish () override
 

Protected Attributes

PcapDump pcapDump
 
PacketDump tcpdump
 
unsigned int snaplen = 0
 
bool dumpBadFrames = false
 
bool dropBadFrames = false
 

Detailed Description

Dumps every packet using the PcapDump class and the PacketDump class.

Constructor & Destructor Documentation

inet::TCPDump::TCPDump ( )
inline
45 {}
inet::TCPDump::~TCPDump ( )
35 {
36 }

Member Function Documentation

void inet::TCPDump::finish ( )
overridevirtual
88 {
89  tcpdump.dump("", "tcpdump finished");
91 }
void closePcap()
Closes the output file if it is open.
Definition: PcapDump.cc:171
PcapDump pcapDump
Definition: TCPDump.h:38
PacketDump tcpdump
Definition: TCPDump.h:39
void dump(const char *label, const char *msg)
Writes the given text on the output stream.
Definition: PacketDump.cc:355
void inet::TCPDump::handleMessage ( cMessage *  msg)
overridevirtual
54 {
55  if (msg->isPacket()) {
56  bool l2r = msg->arrivedOn("hlIn");
57  tcpdump.dumpPacket(l2r, PK(msg));
58  }
59 
60 #ifdef WITH_IPv4
61  if (pcapDump.isOpen() && dynamic_cast<IPv4Datagram *>(msg)
62  && (dumpBadFrames || !PK(msg)->hasBitError()))
63  {
64  const simtime_t stime = simTime();
65  IPv4Datagram *ipPacket = check_and_cast<IPv4Datagram *>(msg);
66  pcapDump.writeFrame(stime, ipPacket);
67  }
68 #endif // ifdef WITH_IPv4
69 
70  if (PK(msg)->hasBitError() && dropBadFrames) {
71  delete msg;
72  return;
73  }
74 
75  // forward
76  int32 index = msg->getArrivalGate()->getIndex();
77  int32 id;
78 
79  if (msg->getArrivalGate()->isName("ifIn"))
80  id = findGate("hlOut", index);
81  else
82  id = findGate("ifOut", index);
83 
84  send(msg, id);
85 }
void writeFrame(simtime_t time, const IPv4Datagram *ipPacket)
Records the given packet into the output file if it is open, and throws an exception otherwise...
Definition: PcapDump.cc:101
PcapDump pcapDump
Definition: TCPDump.h:38
void dumpPacket(bool l2r, cPacket *packet)
Dumps info about the given packet.
Definition: PacketDump.cc:366
int32_t int32
Definition: Compat.h:31
bool dumpBadFrames
Definition: TCPDump.h:41
PacketDump tcpdump
Definition: TCPDump.h:39
#define PK(msg)
Definition: INETDefs.h:92
uint16_t id
Definition: TCP_NSC.cc:85
bool dropBadFrames
Definition: TCPDump.h:42
bool isOpen() const
Returns true if the pcap file is currently open.
Definition: PcapDump.h:66
void inet::TCPDump::initialize ( )
overridevirtual
39 {
40  const char *file = this->par("dumpFile");
41 
42  dumpBadFrames = par("dumpBadFrames").boolValue();
43  dropBadFrames = par("dropBadFrames").boolValue();
44 
45  snaplen = this->par("snaplen");
46  tcpdump.setVerbose(par("verbose").boolValue());
48 
49  if (*file)
50  pcapDump.openPcap(file, snaplen);
51 }
void openPcap(const char *filename, unsigned int snaplen)
Opens a PCAP file with the given file name.
Definition: PcapDump.cc:75
void setOutStream(std::ostream &o)
Sets the output stream.
Definition: PacketDump.h:62
void setVerbose(bool verb)
Enable/disable verbose output.
Definition: PacketDump.h:72
unsigned int snaplen
Definition: TCPDump.h:40
PcapDump pcapDump
Definition: TCPDump.h:38
bool dumpBadFrames
Definition: TCPDump.h:41
PacketDump tcpdump
Definition: TCPDump.h:39
#define EVSTREAM
Definition: Compat.h:36
bool dropBadFrames
Definition: TCPDump.h:42

Member Data Documentation

bool inet::TCPDump::dropBadFrames = false
protected

Referenced by handleMessage(), and initialize().

bool inet::TCPDump::dumpBadFrames = false
protected

Referenced by handleMessage(), and initialize().

PcapDump inet::TCPDump::pcapDump
protected

Referenced by finish(), handleMessage(), and initialize().

unsigned int inet::TCPDump::snaplen = 0
protected

Referenced by initialize().

PacketDump inet::TCPDump::tcpdump
protected

Referenced by finish(), handleMessage(), and initialize().


The documentation for this class was generated from the following files: