summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2003-04-16 13:19:32 (UTC)
committer mickeyl <mickeyl>2003-04-16 13:19:32 (UTC)
commit05b76911ab2082436c577c1461f0d1210ce0aa33 (patch) (unidiff)
treed8219eb138ca46f355651152d471664037be372b /libopie2
parent5b9d1ddde859ff783f95babf1887fa40e6bfe0be (diff)
downloadopie-05b76911ab2082436c577c1461f0d1210ce0aa33.zip
opie-05b76911ab2082436c577c1461f0d1210ce0aa33.tar.gz
opie-05b76911ab2082436c577c1461f0d1210ce0aa33.tar.bz2
add sanity check for last packet when capturing from capture file
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 04b1bb1..e362883 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -799,78 +799,79 @@ void OPacketCapturer::close()
799 qDebug( "--------------------------------------------------" ); 799 qDebug( "--------------------------------------------------" );
800 800
801} 801}
802 802
803 803
804int OPacketCapturer::dataLink() const 804int OPacketCapturer::dataLink() const
805{ 805{
806 return pcap_datalink( _pch ); 806 return pcap_datalink( _pch );
807} 807}
808 808
809 809
810int OPacketCapturer::fileno() const 810int OPacketCapturer::fileno() const
811{ 811{
812 if ( _open ) 812 if ( _open )
813 { 813 {
814 return pcap_fileno( _pch ); 814 return pcap_fileno( _pch );
815 } 815 }
816 else 816 else
817 { 817 {
818 return -1; 818 return -1;
819 } 819 }
820} 820}
821 821
822OPacket* OPacketCapturer::next() 822OPacket* OPacketCapturer::next()
823{ 823{
824 packetheaderstruct header; 824 packetheaderstruct header;
825 qDebug( "==> OPacketCapturer::next()" ); 825 qDebug( "==> OPacketCapturer::next()" );
826 const unsigned char* pdata = pcap_next( _pch, &header ); 826 const unsigned char* pdata = pcap_next( _pch, &header );
827 qDebug( "<== OPacketCapturer::next()" ); 827 qDebug( "<== OPacketCapturer::next()" );
828 if ( _pcd ) 828 if ( _pcd )
829 pcap_dump( (u_char*) _pcd, &header, pdata ); 829 pcap_dump( (u_char*) _pcd, &header, pdata );
830 830
831 if ( header.len ) 831 if ( pdata && header.len )
832 { 832 {
833 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 833 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
834 // packets shouldn't be inserted in the QObject child-parent hierarchy, 834 // packets shouldn't be inserted in the QObject child-parent hierarchy,
835 // because due to memory constraints they will be deleted as soon 835 // because due to memory constraints they will be deleted as soon
836 // as possible - that is right after they have been processed 836 // as possible - that is right after they have been processed
837 // by emit() [ see below ] 837 // by emit() [ see below ]
838 //TODO: make gathering statistics optional, because it takes time 838 //TODO: make gathering statistics optional, because it takes time
839 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); 839 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
840 840
841 return p; 841 return p;
842 } 842 }
843 else 843 else
844 { 844 {
845 qWarning( "OPacketCapturer::next() - no packet received!" );
845 return 0; 846 return 0;
846 } 847 }
847} 848}
848 849
849 850
850bool OPacketCapturer::open( const QString& name, const QString& filename ) 851bool OPacketCapturer::open( const QString& name, const QString& filename )
851{ 852{
852 if ( _open ) 853 if ( _open )
853 { 854 {
854 if ( name == _name ) // ignore opening an already openend device 855 if ( name == _name ) // ignore opening an already openend device
855 { 856 {
856 return true; 857 return true;
857 } 858 }
858 else // close the last opened device 859 else // close the last opened device
859 { 860 {
860 close(); 861 close();
861 } 862 }
862 } 863 }
863 864
864 _name = name; 865 _name = name;
865 866
866 // open libpcap 867 // open libpcap
867 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 868 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
868 869
869 if ( !handle ) 870 if ( !handle )
870 { 871 {
871 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 872 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
872 return false; 873 return false;
873 } 874 }
874 875
875 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); 876 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name );
876 _pch = handle; 877 _pch = handle;