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.cpp42
1 files changed, 31 insertions, 11 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index bef9182..1de7124 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -863,8 +863,19 @@ bool OPacketCapturer::blocking() const
863 return !b; 863 return !b;
864} 864}
865 865
866 866
867void OPacketCapturer::closeDumpFile()
868{
869 if ( _pcd )
870 {
871 pcap_dump_close( _pcd );
872 _pcd = 0;
873 }
874 pcap_close( _pch );
875}
876
877
867void OPacketCapturer::close() 878void OPacketCapturer::close()
868{ 879{
869 if ( _open ) 880 if ( _open )
870 { 881 {
@@ -872,15 +883,10 @@ void OPacketCapturer::close()
872 { 883 {
873 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 884 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
874 delete _sn; 885 delete _sn;
875 } 886 }
876 if ( _pcd ) 887 closeDumpFile();
877 { 888 _open = false;
878 pcap_dump_close( _pcd );
879 _pcd = 0;
880 }
881 pcap_close( _pch );
882 _open = false;
883 } 889 }
884 890
885 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); 891 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." );
886 qDebug( "--------------------------------------------------" ); 892 qDebug( "--------------------------------------------------" );
@@ -896,8 +902,19 @@ int OPacketCapturer::dataLink() const
896 return pcap_datalink( _pch ); 902 return pcap_datalink( _pch );
897} 903}
898 904
899 905
906void OPacketCapturer::dump( OPacket* p )
907{
908 if ( !_pcd )
909 {
910 qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" );
911 return;
912 }
913 pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data );
914}
915
916
900int OPacketCapturer::fileno() const 917int OPacketCapturer::fileno() const
901{ 918{
902 if ( _open ) 919 if ( _open )
903 { 920 {
@@ -914,10 +931,8 @@ OPacket* OPacketCapturer::next()
914 packetheaderstruct header; 931 packetheaderstruct header;
915 qDebug( "==> OPacketCapturer::next()" ); 932 qDebug( "==> OPacketCapturer::next()" );
916 const unsigned char* pdata = pcap_next( _pch, &header ); 933 const unsigned char* pdata = pcap_next( _pch, &header );
917 qDebug( "<== OPacketCapturer::next()" ); 934 qDebug( "<== OPacketCapturer::next()" );
918 if ( _pcd )
919 pcap_dump( (u_char*) _pcd, &header, pdata );
920 935
921 if ( pdata && header.len ) 936 if ( pdata && header.len )
922 { 937 {
923 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 938 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
@@ -937,9 +952,9 @@ OPacket* OPacketCapturer::next()
937 } 952 }
938} 953}
939 954
940 955
941bool OPacketCapturer::open( const QString& name, const QString& filename ) 956bool OPacketCapturer::open( const QString& name )
942{ 957{
943 if ( _open ) 958 if ( _open )
944 { 959 {
945 if ( name == _name ) // ignore opening an already openend device 960 if ( name == _name ) // ignore opening an already openend device
@@ -974,9 +989,14 @@ bool OPacketCapturer::open( const QString& name, const QString& filename )
974 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 989 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
975 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 990 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
976 } 991 }
977 992
978 // if requested, open a dump 993 return true;
994}
995
996
997bool OPacketCapturer::openDumpFile( const QString& filename )
998{
979 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); 999 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) );
980 if ( !dump ) 1000 if ( !dump )
981 { 1001 {
982 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); 1002 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf );