summaryrefslogtreecommitdiff
path: root/libopie2/opienet
authormickeyl <mickeyl>2003-04-09 21:37:05 (UTC)
committer mickeyl <mickeyl>2003-04-09 21:37:05 (UTC)
commitb055856776807f0a459a86b1e1f62902d2d3a9c3 (patch) (side-by-side diff)
tree46bee28833c363607d20f4db93eef0166a45852d /libopie2/opienet
parentc8401f7ebb9e9314ed48517da38b949c24800c50 (diff)
downloadopie-b055856776807f0a459a86b1e1f62902d2d3a9c3.zip
opie-b055856776807f0a459a86b1e1f62902d2d3a9c3.tar.gz
opie-b055856776807f0a459a86b1e1f62902d2d3a9c3.tar.bz2
implements a statistic interface for OPacketCapturer
Diffstat (limited to 'libopie2/opienet') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp40
-rw-r--r--libopie2/opienet/opcap.h7
2 files changed, 43 insertions, 4 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 5c464cf..6a3dc26 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -41,2 +41,3 @@
#include <qsocketnotifier.h>
+#include <qobjectlist.h>
@@ -89,2 +90,15 @@ int OPacket::caplen() const
+void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )
+{
+ if (!l) return;
+ QObject* o = l->first();
+ while ( o )
+ {
+ stats[o->name()]++;
+ updateStats( stats, const_cast<QObjectList*>( o->children() ) );
+ o = l->next();
+ }
+}
+
+
QString OPacket::dump( int bpl ) const
@@ -129,3 +143,2 @@ QString OPacket::dump( int bpl ) const
-
int OPacket::len() const
@@ -135,2 +148,3 @@ int OPacket::len() const
+
/*======================================================================================
@@ -774,2 +788,9 @@ void OPacketCapturer::close()
}
+
+ qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." );
+ qDebug( "--------------------------------------------------" );
+ for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it )
+ qDebug( "%s : %d", (const char*) it.key(), it.data() );
+ qDebug( "--------------------------------------------------" );
+
}
@@ -795,3 +816,2 @@ int OPacketCapturer::fileno() const
-
OPacket* OPacketCapturer::next()
@@ -805,3 +825,3 @@ OPacket* OPacketCapturer::next()
{
- return new OPacket( dataLink(), header, pdata, 0 );
+ OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
// packets shouldn't be inserted in the QObject child-parent hierarchy,
@@ -810,2 +830,7 @@ OPacket* OPacketCapturer::next()
// by emit() [ see below ]
+
+ //TODO: make gathering statistics optional, because it takes time
+ p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
+
+ return p;
}
@@ -841,2 +866,3 @@ bool OPacketCapturer::open( const QString& name )
_open = true;
+ _stats.clear();
@@ -868,3 +894,3 @@ void OPacketCapturer::readyToReceive()
{
- qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(...)'" );
+ qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" );
OPacket* p = next();
@@ -875 +901,7 @@ void OPacketCapturer::readyToReceive()
+
+const QMap<QString,int>& OPacketCapturer::statistics() const
+{
+ return _stats;
+}
+
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h
index ddef278..c9b0624 100644
--- a/libopie2/opienet/opcap.h
+++ b/libopie2/opienet/opcap.h
@@ -48,2 +48,3 @@ extern "C" // work around a bpf/pcap conflict in recent headers
/* QT */
+#include <qevent.h>
#include <qhostaddress.h>
@@ -51,2 +52,3 @@ extern "C" // work around a bpf/pcap conflict in recent headers
#include <qstring.h>
+#include <qmap.h>
@@ -82,2 +84,4 @@ class OPacket : public QObject
+ void updateStats( QMap<QString,int>&, QObjectList* );
+
private:
@@ -436,2 +440,4 @@ class OPacketCapturer : public QObject
+ const QMap<QString,int>& statistics() const;
+
signals:
@@ -448,2 +454,3 @@ class OPacketCapturer : public QObject
mutable char _errbuf[PCAP_ERRBUF_SIZE];
+ QMap<QString, int> _stats; // statistics;
};