Skip to content

Instantly share code, notes, and snippets.

@RichardWithnell
Forked from thehajime/pcap-flush.patch
Last active August 29, 2015 14:14
Show Gist options
  • Save RichardWithnell/13dff5f7a939f94310f1 to your computer and use it in GitHub Desktop.
Save RichardWithnell/13dff5f7a939f94310f1 to your computer and use it in GitHub Desktop.
diff --git a/src/network/utils/pcap-file-wrapper.cc b/src/network/utils/pcap-file-wrapper.cc
--- a/src/network/utils/pcap-file-wrapper.cc
+++ b/src/network/utils/pcap-file-wrapper.cc
@@ -55,6 +55,18 @@
Close ();
}
+void
+PcapFileWrapper::DoDispose (void)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ Close ();
+}
+void
+PcapFileWrapper::NotifyNewAggregate ()
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ Object::NotifyNewAggregate ();
+}
bool
PcapFileWrapper::Fail (void) const
diff --git a/src/network/utils/pcap-file-wrapper.h b/src/network/utils/pcap-file-wrapper.h
--- a/src/network/utils/pcap-file-wrapper.h
+++ b/src/network/utils/pcap-file-wrapper.h
@@ -44,6 +44,8 @@
PcapFileWrapper ();
~PcapFileWrapper ();
+ void DoDispose (void);
+ void NotifyNewAggregate ();
/**
* \return true if the 'fail' bit is set in the underlying iostream, false otherwise.
diff --git a/src/point-to-point/helper/point-to-point-helper.cc b/src/point-to-point/helper/point-to-point-helper.cc
--- a/src/point-to-point/helper/point-to-point-helper.cc
+++ b/src/point-to-point/helper/point-to-point-helper.cc
@@ -103,6 +103,13 @@
Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out,
PcapHelper::DLT_PPP);
pcapHelper.HookDefaultSink<PointToPointNetDevice> (device, "PromiscSniffer", file);
+
+ Ptr<Node> node = device->GetNode ();
+ if (!node->GetObject <PcapFileWrapper>())
+ {
+ node->AggregateObject (file);
+ }
+
}
void
diff --git a/src/csma/helper/csma-helper.cc b/src/csma/helper/csma-helper.cc
--- a/src/csma/helper/csma-helper.cc.backup
+++ b/src/csma/helper/csma-helper.cc
@@ -100,6 +100,13 @@
Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out,
PcapHelper::DLT_EN10MB);
+
+ Ptr<Node> node = device->GetNode ();
+ if (!node->GetObject <PcapFileWrapper>())
+ {
+ node->AggregateObject (file);
+ }
+
if (promiscuous)
{
pcapHelper.HookDefaultSink<CsmaNetDevice> (device, "PromiscSniffer", file);
diff --git a/src/wifi/helper/yans-wifi-helper.cc b/src/wifi/helper/yans-wifi-helper.cc
--- a/src/wifi/helper/yans-wifi-helper.cc 2015-01-23 13:03:20.290224892 +0000
+++ b/src/wifi/helper/yans-wifi-helper.cc 2015-01-23 13:04:07.090224904 +0000
@@ -451,6 +451,12 @@
Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, m_pcapDlt);
+ Ptr<Node> node = device->GetNode ();
+ if (!node->GetObject <PcapFileWrapper>())
+ {
+ node->AggregateObject (file);
+ }
+
phy->TraceConnectWithoutContext ("MonitorSnifferTx", MakeBoundCallback (&PcapSniffTxEvent, file));
phy->TraceConnectWithoutContext ("MonitorSnifferRx", MakeBoundCallback (&PcapSniffRxEvent, file));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment