From 3733471135ea180709fcf4695607cce0c5fc7fb5 Mon Sep 17 00:00:00 2001 From: mickeyl Date: Thu, 10 Apr 2003 15:47:23 +0000 Subject: add support for working with capture files (e.g. from tcpdump, ethereal, et.al.) --- (limited to 'libopie2/opienet/opcap.cpp') 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( 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( (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; } -- cgit v0.9.0.2