summaryrefslogtreecommitdiff
path: root/libopie2/opienet/opcap.cpp
Unidiff
Diffstat (limited to 'libopie2/opienet/opcap.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 30f6208..04b1bb1 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -736,3 +736,3 @@ OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
736 :QObject( parent, name ), _name( QString::null ), _open( false ), 736 :QObject( parent, name ), _name( QString::null ), _open( false ),
737 _pch( 0 ), _sn( 0 ) 737 _pch( 0 ), _pcd( 0 ), _sn( 0 )
738{ 738{
@@ -785,2 +785,7 @@ void OPacketCapturer::close()
785 } 785 }
786 if ( _pcd )
787 {
788 pcap_dump_close( _pcd );
789 _pcd = 0;
790 }
786 pcap_close( _pch ); 791 pcap_close( _pch );
@@ -822,2 +827,4 @@ OPacket* OPacketCapturer::next()
822 qDebug( "<== OPacketCapturer::next()" ); 827 qDebug( "<== OPacketCapturer::next()" );
828 if ( _pcd )
829 pcap_dump( (u_char*) _pcd, &header, pdata );
823 830
@@ -842,3 +849,3 @@ OPacket* OPacketCapturer::next()
842 849
843bool OPacketCapturer::open( const QString& name ) 850bool OPacketCapturer::open( const QString& name, const QString& filename )
844{ 851{
@@ -858,7 +865,12 @@ bool OPacketCapturer::open( const QString& name )
858 865
866 // open libpcap
859 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 867 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
860 868
861 if ( handle ) 869 if ( !handle )
862 { 870 {
863 qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); 871 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
872 return false;
873 }
874
875 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name );
864 _pch = handle; 876 _pch = handle;
@@ -868,3 +880,3 @@ bool OPacketCapturer::open( const QString& name )
868 // in case we have an application object, create a socket notifier 880 // in case we have an application object, create a socket notifier
869 if ( qApp ) 881 if ( qApp ) //TODO: I don't like this here...
870 { 882 {
@@ -874,10 +886,13 @@ bool OPacketCapturer::open( const QString& name )
874 886
875 return true; 887 // if requested, open a dump
876 } 888 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) );
877 else 889 if ( !dump )
878 { 890 {
879 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 891 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf );
880 return false; 892 return false;
881 } 893 }
894 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename );
895 _pcd = dump;
882 896
897 return true;
883} 898}