summaryrefslogtreecommitdiff
path: root/libopie2/opienet/opcap.cpp
authormickeyl <mickeyl>2003-04-10 15:47:23 (UTC)
committer mickeyl <mickeyl>2003-04-10 15:47:23 (UTC)
commit3733471135ea180709fcf4695607cce0c5fc7fb5 (patch) (side-by-side diff)
tree792c96ad5351b9396a0c129738b5cff9e2b00614 /libopie2/opienet/opcap.cpp
parent101e039ba53d4ccbe5b46575bb56c07f6f544db6 (diff)
downloadopie-3733471135ea180709fcf4695607cce0c5fc7fb5.zip
opie-3733471135ea180709fcf4695607cce0c5fc7fb5.tar.gz
opie-3733471135ea180709fcf4695607cce0c5fc7fb5.tar.bz2
add support for working with capture files (e.g. from tcpdump, ethereal, et.al.)
Diffstat (limited to 'libopie2/opienet/opcap.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp48
1 files changed, 46 insertions, 2 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 6a3dc26..30f6208 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -828,7 +828,6 @@ OPacket* OPacketCapturer::next()
// because due to memory constraints they will be deleted as soon
// as possible - that is right after they have been processed
// by emit() [ see below ]
-
//TODO: make gathering statistics optional, because it takes time
p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
@@ -877,7 +876,52 @@ bool OPacketCapturer::open( const QString& name )
}
else
{
- qDebug( "OPacketCapturer::open(): can't open libpcap: %s", _errbuf );
+ qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
+ return false;
+ }
+
+}
+
+
+bool OPacketCapturer::open( const QFile& file )
+{
+ QString name = file.name();
+
+ if ( _open )
+ {
+ close();
+ if ( name == _name ) // ignore opening an already openend device
+ {
+ return true;
+ }
+ else // close the last opened device
+ {
+ close();
+ }
+ }
+
+ _name = name;
+
+ pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] );
+
+ if ( handle )
+ {
+ qDebug( "OPacketCapturer::open(): libpcap opened successfully." );
+ _pch = handle;
+ _open = true;
+
+ // in case we have an application object, create a socket notifier
+ if ( qApp )
+ {
+ _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
+ connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
+ }
+
+ return true;
+ }
+ else
+ {
+ qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
return false;
}