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
@@ -819,25 +819,24 @@ OPacket* OPacketCapturer::next()
819 packetheaderstruct header; 819 packetheaderstruct header;
820 qDebug( "==> OPacketCapturer::next()" ); 820 qDebug( "==> OPacketCapturer::next()" );
821 const unsigned char* pdata = pcap_next( _pch, &header ); 821 const unsigned char* pdata = pcap_next( _pch, &header );
822 qDebug( "<== OPacketCapturer::next()" ); 822 qDebug( "<== OPacketCapturer::next()" );
823 823
824 if ( header.len ) 824 if ( header.len )
825 { 825 {
826 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 826 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
827 // packets shouldn't be inserted in the QObject child-parent hierarchy, 827 // packets shouldn't be inserted in the QObject child-parent hierarchy,
828 // because due to memory constraints they will be deleted as soon 828 // because due to memory constraints they will be deleted as soon
829 // as possible - that is right after they have been processed 829 // as possible - that is right after they have been processed
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
833 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); 832 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
834 833
835 return p; 834 return p;
836 } 835 }
837 else 836 else
838 { 837 {
839 return 0; 838 return 0;
840 } 839 }
841} 840}
842 841
843 842
@@ -868,25 +867,70 @@ bool OPacketCapturer::open( const QString& name )
868 867
869 // in case we have an application object, create a socket notifier 868 // in case we have an application object, create a socket notifier
870 if ( qApp ) 869 if ( qApp )
871 { 870 {
872 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 871 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
873 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 872 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
874 } 873 }
875 874
876 return true; 875 return true;
877 } 876 }
878 else 877 else
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;
882 } 926 }
883 927
884} 928}
885 929
886 930
887bool OPacketCapturer::isOpen() const 931bool OPacketCapturer::isOpen() const
888{ 932{
889 return _open; 933 return _open;
890} 934}
891 935
892 936