summaryrefslogtreecommitdiff
path: root/libopie2
Side-by-side diff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp21
-rw-r--r--libopie2/opienet/opcap.h20
2 files changed, 33 insertions, 8 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 4081d4f..c5df041 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -58,5 +58,5 @@ OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char*
:QObject( parent, "Generic" ), _hdr( header ), _data( data )
{
- //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
+ qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
_end = (unsigned char*) data + header.len;
@@ -88,4 +88,5 @@ OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char*
OPacket::~OPacket()
{
+ qDebug( "OPacket::~OPacket( %s )", name() );
}
@@ -1064,5 +1065,5 @@ QString OWaveLanControlPacket::controlType() const
OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
- :QObject( parent, name ), _name( QString::null ), _open( false ), _pch( 0 ), _pcd( 0 ), _sn( 0 )
+ :QObject( parent, name ), _name( QString::null ), _open( false ), _pch( 0 ), _pcd( 0 ), _sn( 0 ), _autodelete( true )
{
}
@@ -1079,4 +1080,16 @@ OPacketCapturer::~OPacketCapturer()
+void OPacketCapturer::setAutoDelete( bool b )
+{
+ _autodelete = b;
+}
+
+
+bool OPacketCapturer::autoDelete() const
+{
+ return _autodelete;
+}
+
+
void OPacketCapturer::setBlocking( bool b )
{
@@ -1322,6 +1335,6 @@ void OPacketCapturer::readyToReceive()
OPacket* p = next();
emit receivedPacket( p );
- // emit is synchronous - packet has been dealt with, now it's safe to delete
- delete p;
+ // emit is synchronous - packet has been dealt with, now it's safe to delete (if enabled)
+ if ( _autodelete ) delete p;
}
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h
index 72a78de..4ff8495 100644
--- a/libopie2/opienet/opcap.h
+++ b/libopie2/opienet/opcap.h
@@ -135,7 +135,6 @@ class OPacket : public QObject
void updateStats( QMap<QString,int>&, QObjectList* );
- private:
-
QString dumpStructure() const;
+ private:
QString _dumpStructure( QObjectList* ) const;
@@ -694,4 +693,16 @@ class OPacketCapturer : public QObject
*/
const QMap<QString,int>& statistics() const;
+ /**
+ * Enable or disable the auto-delete option.
+ * If auto-delete is enabled, then the packet capturer will delete a packet right
+ * after it has been emit'ted. This is the default, which is useful if the packet
+ * capturer has the only reference to the packets. If you pass the packet for adding
+ * into a collection or do processing after the SLOT, the auto delete must be disabled.
+ */
+ void setAutoDelete( bool enable );
+ /**
+ * @returns the auto-delete value.
+ */
+ bool autoDelete() const;
signals:
@@ -712,6 +723,7 @@ class OPacketCapturer : public QObject
mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap
QMap<QString, int> _stats; // statistics;
- class Private; // Private Forward declaration
- Private *d; // if we need to add data
+ bool _autodelete; // if we auto delete packets after emit
+ class Private; // Private Forward declaration
+ Private *d; // if we need to add data
};
}