-rw-r--r-- | libopie2/opienet/opcap.cpp | 48 |
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 | |||
@@ -825,13 +825,12 @@ OPacket* OPacketCapturer::next() | |||
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 |
@@ -874,13 +873,58 @@ bool OPacketCapturer::open( const QString& name ) | |||
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 | |||
886 | bool 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 | ||