summaryrefslogtreecommitdiff
path: root/libopie2/opienet
Unidiff
Diffstat (limited to 'libopie2/opienet') (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
@@ -57,7 +57,7 @@ namespace Net {
57OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) 57OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
58 :QObject( parent, "Generic" ), _hdr( header ), _data( data ) 58 :QObject( parent, "Generic" ), _hdr( header ), _data( data )
59{ 59{
60 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); 60 qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
61 61
62 _end = (unsigned char*) data + header.len; 62 _end = (unsigned char*) data + header.len;
63 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); 63 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end );
@@ -87,6 +87,7 @@ OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char*
87 87
88OPacket::~OPacket() 88OPacket::~OPacket()
89{ 89{
90 qDebug( "OPacket::~OPacket( %s )", name() );
90} 91}
91 92
92 93
@@ -1063,7 +1064,7 @@ QString OWaveLanControlPacket::controlType() const
1063 *======================================================================================*/ 1064 *======================================================================================*/
1064 1065
1065OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) 1066OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
1066 :QObject( parent, name ), _name( QString::null ), _open( false ), _pch( 0 ), _pcd( 0 ), _sn( 0 ) 1067 :QObject( parent, name ), _name( QString::null ), _open( false ), _pch( 0 ), _pcd( 0 ), _sn( 0 ), _autodelete( true )
1067{ 1068{
1068} 1069}
1069 1070
@@ -1078,6 +1079,18 @@ OPacketCapturer::~OPacketCapturer()
1078} 1079}
1079 1080
1080 1081
1082void OPacketCapturer::setAutoDelete( bool b )
1083{
1084 _autodelete = b;
1085}
1086
1087
1088bool OPacketCapturer::autoDelete() const
1089{
1090 return _autodelete;
1091}
1092
1093
1081void OPacketCapturer::setBlocking( bool b ) 1094void OPacketCapturer::setBlocking( bool b )
1082{ 1095{
1083 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 1096 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
@@ -1321,8 +1334,8 @@ void OPacketCapturer::readyToReceive()
1321 odebug << "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" << oendl; 1334 odebug << "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" << oendl;
1322 OPacket* p = next(); 1335 OPacket* p = next();
1323 emit receivedPacket( p ); 1336 emit receivedPacket( p );
1324 // emit is synchronous - packet has been dealt with, now it's safe to delete 1337 // emit is synchronous - packet has been dealt with, now it's safe to delete (if enabled)
1325 delete p; 1338 if ( _autodelete ) delete p;
1326} 1339}
1327 1340
1328 1341
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
@@ -134,9 +134,8 @@ class OPacket : public QObject
134 134
135 void updateStats( QMap<QString,int>&, QObjectList* ); 135 void updateStats( QMap<QString,int>&, QObjectList* );
136 136
137 private:
138
139 QString dumpStructure() const; 137 QString dumpStructure() const;
138 private:
140 QString _dumpStructure( QObjectList* ) const; 139 QString _dumpStructure( QObjectList* ) const;
141 140
142 private: 141 private:
@@ -693,6 +692,18 @@ class OPacketCapturer : public QObject
693 * @see QMap 692 * @see QMap
694 */ 693 */
695 const QMap<QString,int>& statistics() const; 694 const QMap<QString,int>& statistics() const;
695 /**
696 * Enable or disable the auto-delete option.
697 * If auto-delete is enabled, then the packet capturer will delete a packet right
698 * after it has been emit'ted. This is the default, which is useful if the packet
699 * capturer has the only reference to the packets. If you pass the packet for adding
700 * into a collection or do processing after the SLOT, the auto delete must be disabled.
701 */
702 void setAutoDelete( bool enable );
703 /**
704 * @returns the auto-delete value.
705 */
706 bool autoDelete() const;
696 707
697 signals: 708 signals:
698 /** 709 /**
@@ -711,8 +722,9 @@ class OPacketCapturer : public QObject
711 QSocketNotifier* _sn; // socket notifier for main loop 722 QSocketNotifier* _sn; // socket notifier for main loop
712 mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap 723 mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap
713 QMap<QString, int> _stats; // statistics; 724 QMap<QString, int> _stats; // statistics;
714 class Private; // Private Forward declaration 725 bool _autodelete; // if we auto delete packets after emit
715 Private *d; // if we need to add data 726 class Private; // Private Forward declaration
727 Private *d; // if we need to add data
716}; 728};
717} 729}
718} 730}