-rw-r--r-- | libopie2/opienet/opcap.cpp | 40 |
1 files changed, 30 insertions, 10 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 | |||
@@ -864,6 +864,17 @@ bool OPacketCapturer::blocking() const | |||
864 | } | 864 | } |
865 | 865 | ||
866 | 866 | ||
867 | void OPacketCapturer::closeDumpFile() | ||
868 | { | ||
869 | if ( _pcd ) | ||
870 | { | ||
871 | pcap_dump_close( _pcd ); | ||
872 | _pcd = 0; | ||
873 | } | ||
874 | pcap_close( _pch ); | ||
875 | } | ||
876 | |||
877 | |||
867 | void OPacketCapturer::close() | 878 | void OPacketCapturer::close() |
868 | { | 879 | { |
869 | if ( _open ) | 880 | if ( _open ) |
@@ -873,12 +884,7 @@ void OPacketCapturer::close() | |||
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 | { | ||
878 | pcap_dump_close( _pcd ); | ||
879 | _pcd = 0; | ||
880 | } | ||
881 | pcap_close( _pch ); | ||
882 | _open = false; | 888 | _open = false; |
883 | } | 889 | } |
884 | 890 | ||
@@ -897,6 +903,17 @@ int OPacketCapturer::dataLink() const | |||
897 | } | 903 | } |
898 | 904 | ||
899 | 905 | ||
906 | void 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 | |||
900 | int OPacketCapturer::fileno() const | 917 | int OPacketCapturer::fileno() const |
901 | { | 918 | { |
902 | if ( _open ) | 919 | if ( _open ) |
@@ -915,8 +932,6 @@ OPacket* OPacketCapturer::next() | |||
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 | { |
@@ -938,7 +953,7 @@ OPacket* OPacketCapturer::next() | |||
938 | } | 953 | } |
939 | 954 | ||
940 | 955 | ||
941 | bool OPacketCapturer::open( const QString& name, const QString& filename ) | 956 | bool OPacketCapturer::open( const QString& name ) |
942 | { | 957 | { |
943 | if ( _open ) | 958 | if ( _open ) |
944 | { | 959 | { |
@@ -975,7 +990,12 @@ bool OPacketCapturer::open( const QString& name, const QString& filename ) | |||
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 | |||
997 | bool 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 | { |