From c9e6a15196a87fd1aa923b9ee0f6ff736ad6d33b Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 22 Jul 2004 23:54:24 -0400 Subject: Add support to store less than the full packet in an etherdump and actually default to only storing a max of 96 bytes per packet since that should be plenty to fit all of the headers in. --HG-- extra : convert_revision : 0c4a6571d80536477ed166e695d957e39da0334e --- dev/etherdump.cc | 15 +++++++++------ dev/etherdump.hh | 3 ++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dev/etherdump.cc b/dev/etherdump.cc index 54e573be4..27817d456 100644 --- a/dev/etherdump.cc +++ b/dev/etherdump.cc @@ -32,6 +32,7 @@ #include +#include #include #include "base/misc.hh" @@ -41,8 +42,8 @@ using std::string; -EtherDump::EtherDump(const string &name, const string &file) - : SimObject(name) +EtherDump::EtherDump(const string &name, const string &file, int max) + : SimObject(name), maxlen(max) { if (!file.empty()) stream.open(file.c_str()); @@ -113,22 +114,24 @@ EtherDump::dumpPacket(PacketPtr &packet) pcap_pkthdr pkthdr; pkthdr.seconds = curtime + (curTick / s_freq); pkthdr.microseconds = (curTick / us_freq) % ULL(1000000); - pkthdr.caplen = packet->length; + pkthdr.caplen = std::min(packet->length, maxlen); pkthdr.len = packet->length; stream.write(reinterpret_cast(&pkthdr), sizeof(pkthdr)); - stream.write(reinterpret_cast(packet->data), packet->length); + stream.write(reinterpret_cast(packet->data), pkthdr.caplen); stream.flush(); } BEGIN_DECLARE_SIM_OBJECT_PARAMS(EtherDump) Param file; + Param maxlen; END_DECLARE_SIM_OBJECT_PARAMS(EtherDump) BEGIN_INIT_SIM_OBJECT_PARAMS(EtherDump) - INIT_PARAM(file, "file to dump packets to") + INIT_PARAM(file, "file to dump packets to"), + INIT_PARAM_DFLT(maxlen, "max portion of packet data to dump", 96) END_INIT_SIM_OBJECT_PARAMS(EtherDump) @@ -148,7 +151,7 @@ CREATE_SIM_OBJECT(EtherDump) } } - return new EtherDump(getInstanceName(), filename); + return new EtherDump(getInstanceName(), filename, maxlen); } REGISTER_SIM_OBJECT("EtherDump", EtherDump) diff --git a/dev/etherdump.hh b/dev/etherdump.hh index ef4399e1a..62364359e 100644 --- a/dev/etherdump.hh +++ b/dev/etherdump.hh @@ -44,6 +44,7 @@ class EtherDump : public SimObject { private: std::ofstream stream; + const int maxlen; void dumpPacket(PacketPtr &packet); void init(); @@ -52,7 +53,7 @@ class EtherDump : public SimObject Tick us_freq; public: - EtherDump(const std::string &name, const std::string &file); + EtherDump(const std::string &name, const std::string &file, int max); inline void dump(PacketPtr &pkt) { if (stream.is_open()) dumpPacket(pkt); } }; -- cgit v1.2.3