summaryrefslogtreecommitdiff
path: root/libopie2/opienet/opcap.cpp
Unidiff
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
@@ -830,3 +830,2 @@ OPacket* OPacketCapturer::next()
830 // by emit() [ see below ] 830 // by emit() [ see below ]
831
832 //TODO: make gathering statistics optional, because it takes time 831 //TODO: make gathering statistics optional, because it takes time
@@ -879,3 +878,48 @@ bool OPacketCapturer::open( const QString& name )
879 { 878 {
880 qDebug( "OPacketCapturer::open(): can't open libpcap: %s", _errbuf ); 879 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
880 return false;
881 }
882
883}
884
885
886bool OPacketCapturer::open( const QFile& file )
887{
888 QString name = file.name();
889
890 if ( _open )
891 {
892 close();
893 if ( name == _name ) // ignore opening an already openend device
894 {
895 return true;
896 }
897 else // close the last opened device
898 {
899 close();
900 }
901 }
902
903 _name = name;
904
905 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] );
906
907 if ( handle )
908 {
909 qDebug( "OPacketCapturer::open(): libpcap opened successfully." );
910 _pch = handle;
911 _open = true;
912
913 // in case we have an application object, create a socket notifier
914 if ( qApp )
915 {
916 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
917 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
918 }
919
920 return true;
921 }
922 else
923 {
924 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
881 return false; 925 return false;