author | mickeyl <mickeyl> | 2003-05-06 23:01:10 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-05-06 23:01:10 (UTC) |
commit | de62ac94791a969d950fc471b465d4f03267ae01 (patch) (unidiff) | |
tree | a43fa025de468c92d0705657fc950cfcf8151518 | |
parent | 9490e91d3876a8280f3f9a3839fddf95b957b879 (diff) | |
download | opie-de62ac94791a969d950fc471b465d4f03267ae01.zip opie-de62ac94791a969d950fc471b465d4f03267ae01.tar.gz opie-de62ac94791a969d950fc471b465d4f03267ae01.tar.bz2 |
add two minor functions in the pcap interface
-rw-r--r-- | libopie2/opienet/opcap.cpp | 19 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 20 |
2 files changed, 37 insertions, 2 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 523be3e..bef9182 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -674,384 +674,403 @@ OWaveLanManagementCF::~OWaveLanManagementCF() | |||
674 | 674 | ||
675 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) | 675 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) |
676 | :QObject( parent, "802.11 FH" ), _data( data ) | 676 | :QObject( parent, "802.11 FH" ), _data( data ) |
677 | { | 677 | { |
678 | qDebug( "OWaveLanManagementFH()" ); | 678 | qDebug( "OWaveLanManagementFH()" ); |
679 | } | 679 | } |
680 | 680 | ||
681 | 681 | ||
682 | OWaveLanManagementFH::~OWaveLanManagementFH() | 682 | OWaveLanManagementFH::~OWaveLanManagementFH() |
683 | { | 683 | { |
684 | } | 684 | } |
685 | 685 | ||
686 | /*====================================================================================== | 686 | /*====================================================================================== |
687 | * OWaveLanManagementDS | 687 | * OWaveLanManagementDS |
688 | *======================================================================================*/ | 688 | *======================================================================================*/ |
689 | 689 | ||
690 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) | 690 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) |
691 | :QObject( parent, "802.11 DS" ), _data( data ) | 691 | :QObject( parent, "802.11 DS" ), _data( data ) |
692 | { | 692 | { |
693 | qDebug( "OWaveLanManagementDS()" ); | 693 | qDebug( "OWaveLanManagementDS()" ); |
694 | } | 694 | } |
695 | 695 | ||
696 | 696 | ||
697 | OWaveLanManagementDS::~OWaveLanManagementDS() | 697 | OWaveLanManagementDS::~OWaveLanManagementDS() |
698 | { | 698 | { |
699 | } | 699 | } |
700 | 700 | ||
701 | 701 | ||
702 | int OWaveLanManagementDS::channel() const | 702 | int OWaveLanManagementDS::channel() const |
703 | { | 703 | { |
704 | return _data->channel; | 704 | return _data->channel; |
705 | } | 705 | } |
706 | 706 | ||
707 | /*====================================================================================== | 707 | /*====================================================================================== |
708 | * OWaveLanManagementTim | 708 | * OWaveLanManagementTim |
709 | *======================================================================================*/ | 709 | *======================================================================================*/ |
710 | 710 | ||
711 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) | 711 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) |
712 | :QObject( parent, "802.11 Tim" ), _data( data ) | 712 | :QObject( parent, "802.11 Tim" ), _data( data ) |
713 | { | 713 | { |
714 | qDebug( "OWaveLanManagementTim()" ); | 714 | qDebug( "OWaveLanManagementTim()" ); |
715 | } | 715 | } |
716 | 716 | ||
717 | 717 | ||
718 | OWaveLanManagementTim::~OWaveLanManagementTim() | 718 | OWaveLanManagementTim::~OWaveLanManagementTim() |
719 | { | 719 | { |
720 | } | 720 | } |
721 | 721 | ||
722 | /*====================================================================================== | 722 | /*====================================================================================== |
723 | * OWaveLanManagementIBSS | 723 | * OWaveLanManagementIBSS |
724 | *======================================================================================*/ | 724 | *======================================================================================*/ |
725 | 725 | ||
726 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) | 726 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) |
727 | :QObject( parent, "802.11 IBSS" ), _data( data ) | 727 | :QObject( parent, "802.11 IBSS" ), _data( data ) |
728 | { | 728 | { |
729 | qDebug( "OWaveLanManagementIBSS()" ); | 729 | qDebug( "OWaveLanManagementIBSS()" ); |
730 | } | 730 | } |
731 | 731 | ||
732 | 732 | ||
733 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | 733 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() |
734 | { | 734 | { |
735 | } | 735 | } |
736 | 736 | ||
737 | /*====================================================================================== | 737 | /*====================================================================================== |
738 | * OWaveLanManagementChallenge | 738 | * OWaveLanManagementChallenge |
739 | *======================================================================================*/ | 739 | *======================================================================================*/ |
740 | 740 | ||
741 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) | 741 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) |
742 | :QObject( parent, "802.11 Challenge" ), _data( data ) | 742 | :QObject( parent, "802.11 Challenge" ), _data( data ) |
743 | { | 743 | { |
744 | qDebug( "OWaveLanManagementChallenge()" ); | 744 | qDebug( "OWaveLanManagementChallenge()" ); |
745 | } | 745 | } |
746 | 746 | ||
747 | 747 | ||
748 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | 748 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() |
749 | { | 749 | { |
750 | } | 750 | } |
751 | 751 | ||
752 | /*====================================================================================== | 752 | /*====================================================================================== |
753 | * OWaveLanDataPacket | 753 | * OWaveLanDataPacket |
754 | *======================================================================================*/ | 754 | *======================================================================================*/ |
755 | 755 | ||
756 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 756 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) |
757 | :QObject( parent, "802.11 Data" ), _header( data ) | 757 | :QObject( parent, "802.11 Data" ), _header( data ) |
758 | { | 758 | { |
759 | qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); | 759 | qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); |
760 | 760 | ||
761 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); | 761 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); |
762 | 762 | ||
763 | #warning The next line works for most cases, but can not be correct generally! | 763 | #warning The next line works for most cases, but can not be correct generally! |
764 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 764 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address |
765 | 765 | ||
766 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); | 766 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); |
767 | } | 767 | } |
768 | 768 | ||
769 | 769 | ||
770 | OWaveLanDataPacket::~OWaveLanDataPacket() | 770 | OWaveLanDataPacket::~OWaveLanDataPacket() |
771 | { | 771 | { |
772 | } | 772 | } |
773 | 773 | ||
774 | 774 | ||
775 | /*====================================================================================== | 775 | /*====================================================================================== |
776 | * OLLCPacket | 776 | * OLLCPacket |
777 | *======================================================================================*/ | 777 | *======================================================================================*/ |
778 | 778 | ||
779 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) | 779 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
780 | :QObject( parent, "802.11 LLC" ), _header( data ) | 780 | :QObject( parent, "802.11 LLC" ), _header( data ) |
781 | { | 781 | { |
782 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); | 782 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); |
783 | 783 | ||
784 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) | 784 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) |
785 | { | 785 | { |
786 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); | 786 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); |
787 | 787 | ||
788 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h | 788 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h |
789 | { | 789 | { |
790 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 790 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
791 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 791 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
792 | default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) ); | 792 | default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) ); |
793 | } | 793 | } |
794 | 794 | ||
795 | } | 795 | } |
796 | } | 796 | } |
797 | 797 | ||
798 | 798 | ||
799 | OLLCPacket::~OLLCPacket() | 799 | OLLCPacket::~OLLCPacket() |
800 | { | 800 | { |
801 | } | 801 | } |
802 | 802 | ||
803 | 803 | ||
804 | /*====================================================================================== | 804 | /*====================================================================================== |
805 | * OWaveLanControlPacket | 805 | * OWaveLanControlPacket |
806 | *======================================================================================*/ | 806 | *======================================================================================*/ |
807 | 807 | ||
808 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) | 808 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) |
809 | :QObject( parent, "802.11 Control" ), _header( data ) | 809 | :QObject( parent, "802.11 Control" ), _header( data ) |
810 | { | 810 | { |
811 | qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); | 811 | qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); |
812 | //TODO: Implement this | 812 | //TODO: Implement this |
813 | } | 813 | } |
814 | 814 | ||
815 | 815 | ||
816 | OWaveLanControlPacket::~OWaveLanControlPacket() | 816 | OWaveLanControlPacket::~OWaveLanControlPacket() |
817 | { | 817 | { |
818 | } | 818 | } |
819 | 819 | ||
820 | 820 | ||
821 | /*====================================================================================== | 821 | /*====================================================================================== |
822 | * OPacketCapturer | 822 | * OPacketCapturer |
823 | *======================================================================================*/ | 823 | *======================================================================================*/ |
824 | 824 | ||
825 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 825 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) |
826 | :QObject( parent, name ), _name( QString::null ), _open( false ), | 826 | :QObject( parent, name ), _name( QString::null ), _open( false ), |
827 | _pch( 0 ), _pcd( 0 ), _sn( 0 ) | 827 | _pch( 0 ), _pcd( 0 ), _sn( 0 ) |
828 | { | 828 | { |
829 | } | 829 | } |
830 | 830 | ||
831 | 831 | ||
832 | OPacketCapturer::~OPacketCapturer() | 832 | OPacketCapturer::~OPacketCapturer() |
833 | { | 833 | { |
834 | if ( _open ) | 834 | if ( _open ) |
835 | { | 835 | { |
836 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); | 836 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); |
837 | close(); | 837 | close(); |
838 | } | 838 | } |
839 | } | 839 | } |
840 | 840 | ||
841 | 841 | ||
842 | void OPacketCapturer::setBlocking( bool b ) | 842 | void OPacketCapturer::setBlocking( bool b ) |
843 | { | 843 | { |
844 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) | 844 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) |
845 | { | 845 | { |
846 | qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); | 846 | qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); |
847 | } | 847 | } |
848 | else | 848 | else |
849 | { | 849 | { |
850 | qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); | 850 | qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); |
851 | } | 851 | } |
852 | } | 852 | } |
853 | 853 | ||
854 | 854 | ||
855 | bool OPacketCapturer::blocking() const | 855 | bool OPacketCapturer::blocking() const |
856 | { | 856 | { |
857 | int b = pcap_getnonblock( _pch, _errbuf ); | 857 | int b = pcap_getnonblock( _pch, _errbuf ); |
858 | if ( b == -1 ) | 858 | if ( b == -1 ) |
859 | { | 859 | { |
860 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); | 860 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); |
861 | return -1; | 861 | return -1; |
862 | } | 862 | } |
863 | return !b; | 863 | return !b; |
864 | } | 864 | } |
865 | 865 | ||
866 | 866 | ||
867 | void OPacketCapturer::close() | 867 | void OPacketCapturer::close() |
868 | { | 868 | { |
869 | if ( _open ) | 869 | if ( _open ) |
870 | { | 870 | { |
871 | if ( _sn ) | 871 | if ( _sn ) |
872 | { | 872 | { |
873 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 873 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
874 | delete _sn; | 874 | delete _sn; |
875 | } | 875 | } |
876 | if ( _pcd ) | 876 | if ( _pcd ) |
877 | { | 877 | { |
878 | pcap_dump_close( _pcd ); | 878 | pcap_dump_close( _pcd ); |
879 | _pcd = 0; | 879 | _pcd = 0; |
880 | } | 880 | } |
881 | pcap_close( _pch ); | 881 | pcap_close( _pch ); |
882 | _open = false; | 882 | _open = false; |
883 | } | 883 | } |
884 | 884 | ||
885 | qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); | 885 | qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); |
886 | qDebug( "--------------------------------------------------" ); | 886 | qDebug( "--------------------------------------------------" ); |
887 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) | 887 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) |
888 | qDebug( "%s : %d", (const char*) it.key(), it.data() ); | 888 | qDebug( "%s : %d", (const char*) it.key(), it.data() ); |
889 | qDebug( "--------------------------------------------------" ); | 889 | qDebug( "--------------------------------------------------" ); |
890 | 890 | ||
891 | } | 891 | } |
892 | 892 | ||
893 | 893 | ||
894 | int OPacketCapturer::dataLink() const | 894 | int OPacketCapturer::dataLink() const |
895 | { | 895 | { |
896 | return pcap_datalink( _pch ); | 896 | return pcap_datalink( _pch ); |
897 | } | 897 | } |
898 | 898 | ||
899 | 899 | ||
900 | int OPacketCapturer::fileno() const | 900 | int OPacketCapturer::fileno() const |
901 | { | 901 | { |
902 | if ( _open ) | 902 | if ( _open ) |
903 | { | 903 | { |
904 | return pcap_fileno( _pch ); | 904 | return pcap_fileno( _pch ); |
905 | } | 905 | } |
906 | else | 906 | else |
907 | { | 907 | { |
908 | return -1; | 908 | return -1; |
909 | } | 909 | } |
910 | } | 910 | } |
911 | 911 | ||
912 | OPacket* OPacketCapturer::next() | 912 | OPacket* OPacketCapturer::next() |
913 | { | 913 | { |
914 | packetheaderstruct header; | 914 | packetheaderstruct header; |
915 | qDebug( "==> OPacketCapturer::next()" ); | 915 | qDebug( "==> OPacketCapturer::next()" ); |
916 | const unsigned char* pdata = pcap_next( _pch, &header ); | 916 | const unsigned char* pdata = pcap_next( _pch, &header ); |
917 | qDebug( "<== OPacketCapturer::next()" ); | 917 | qDebug( "<== OPacketCapturer::next()" ); |
918 | if ( _pcd ) | 918 | if ( _pcd ) |
919 | pcap_dump( (u_char*) _pcd, &header, pdata ); | 919 | pcap_dump( (u_char*) _pcd, &header, pdata ); |
920 | 920 | ||
921 | if ( pdata && header.len ) | 921 | if ( pdata && header.len ) |
922 | { | 922 | { |
923 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); | 923 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); |
924 | // packets shouldn't be inserted in the QObject child-parent hierarchy, | 924 | // packets shouldn't be inserted in the QObject child-parent hierarchy, |
925 | // because due to memory constraints they will be deleted as soon | 925 | // because due to memory constraints they will be deleted as soon |
926 | // as possible - that is right after they have been processed | 926 | // as possible - that is right after they have been processed |
927 | // by emit() [ see below ] | 927 | // by emit() [ see below ] |
928 | //TODO: make gathering statistics optional, because it takes time | 928 | //TODO: make gathering statistics optional, because it takes time |
929 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); | 929 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); |
930 | 930 | ||
931 | return p; | 931 | return p; |
932 | } | 932 | } |
933 | else | 933 | else |
934 | { | 934 | { |
935 | qWarning( "OPacketCapturer::next() - no packet received!" ); | 935 | qWarning( "OPacketCapturer::next() - no packet received!" ); |
936 | return 0; | 936 | return 0; |
937 | } | 937 | } |
938 | } | 938 | } |
939 | 939 | ||
940 | 940 | ||
941 | bool OPacketCapturer::open( const QString& name, const QString& filename ) | 941 | bool OPacketCapturer::open( const QString& name, const QString& filename ) |
942 | { | 942 | { |
943 | if ( _open ) | 943 | if ( _open ) |
944 | { | 944 | { |
945 | if ( name == _name ) // ignore opening an already openend device | 945 | if ( name == _name ) // ignore opening an already openend device |
946 | { | 946 | { |
947 | return true; | 947 | return true; |
948 | } | 948 | } |
949 | else // close the last opened device | 949 | else // close the last opened device |
950 | { | 950 | { |
951 | close(); | 951 | close(); |
952 | } | 952 | } |
953 | } | 953 | } |
954 | 954 | ||
955 | _name = name; | 955 | _name = name; |
956 | 956 | ||
957 | // open libpcap | 957 | // open libpcap |
958 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); | 958 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); |
959 | 959 | ||
960 | if ( !handle ) | 960 | if ( !handle ) |
961 | { | 961 | { |
962 | qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); | 962 | qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); |
963 | return false; | 963 | return false; |
964 | } | 964 | } |
965 | 965 | ||
966 | qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); | 966 | qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); |
967 | _pch = handle; | 967 | _pch = handle; |
968 | _open = true; | 968 | _open = true; |
969 | _stats.clear(); | 969 | _stats.clear(); |
970 | 970 | ||
971 | // in case we have an application object, create a socket notifier | 971 | // in case we have an application object, create a socket notifier |
972 | if ( qApp ) //TODO: I don't like this here... | 972 | if ( qApp ) //TODO: I don't like this here... |
973 | { | 973 | { |
974 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 974 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
975 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 975 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
976 | } | 976 | } |
977 | 977 | ||
978 | // if requested, open a dump | 978 | // if requested, open a dump |
979 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); | 979 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); |
980 | if ( !dump ) | 980 | if ( !dump ) |
981 | { | 981 | { |
982 | qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); | 982 | qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); |
983 | return false; | 983 | return false; |
984 | } | 984 | } |
985 | qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); | 985 | qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); |
986 | _pcd = dump; | 986 | _pcd = dump; |
987 | 987 | ||
988 | return true; | 988 | return true; |
989 | } | 989 | } |
990 | 990 | ||
991 | 991 | ||
992 | bool OPacketCapturer::open( const QFile& file ) | 992 | bool OPacketCapturer::open( const QFile& file ) |
993 | { | 993 | { |
994 | QString name = file.name(); | 994 | QString name = file.name(); |
995 | 995 | ||
996 | if ( _open ) | 996 | if ( _open ) |
997 | { | 997 | { |
998 | close(); | 998 | close(); |
999 | if ( name == _name ) // ignore opening an already openend device | 999 | if ( name == _name ) // ignore opening an already openend device |
1000 | { | 1000 | { |
1001 | return true; | 1001 | return true; |
1002 | } | 1002 | } |
1003 | else // close the last opened device | 1003 | else // close the last opened device |
1004 | { | 1004 | { |
1005 | close(); | 1005 | close(); |
1006 | } | 1006 | } |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | _name = name; | 1009 | _name = name; |
1010 | 1010 | ||
1011 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); | 1011 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); |
1012 | 1012 | ||
1013 | if ( handle ) | 1013 | if ( handle ) |
1014 | { | 1014 | { |
1015 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); | 1015 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); |
1016 | _pch = handle; | 1016 | _pch = handle; |
1017 | _open = true; | 1017 | _open = true; |
1018 | 1018 | ||
1019 | // in case we have an application object, create a socket notifier | 1019 | // in case we have an application object, create a socket notifier |
1020 | if ( qApp ) | 1020 | if ( qApp ) |
1021 | { | 1021 | { |
1022 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 1022 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
1023 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1023 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1024 | } | 1024 | } |
1025 | 1025 | ||
1026 | return true; | 1026 | return true; |
1027 | } | 1027 | } |
1028 | else | 1028 | else |
1029 | { | 1029 | { |
1030 | qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); | 1030 | qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); |
1031 | return false; | 1031 | return false; |
1032 | } | 1032 | } |
1033 | 1033 | ||
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | 1036 | ||
1037 | bool OPacketCapturer::isOpen() const | 1037 | bool OPacketCapturer::isOpen() const |
1038 | { | 1038 | { |
1039 | return _open; | 1039 | return _open; |
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | 1042 | ||
1043 | void OPacketCapturer::readyToReceive() | 1043 | void OPacketCapturer::readyToReceive() |
1044 | { | 1044 | { |
1045 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); | 1045 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); |
1046 | OPacket* p = next(); | 1046 | OPacket* p = next(); |
1047 | emit receivedPacket( p ); | 1047 | emit receivedPacket( p ); |
1048 | // emit is synchronous - packet has been dealt with, now it's safe to delete | 1048 | // emit is synchronous - packet has been dealt with, now it's safe to delete |
1049 | delete p; | 1049 | delete p; |
1050 | } | 1050 | } |
1051 | 1051 | ||
1052 | 1052 | ||
1053 | const QMap<QString,int>& OPacketCapturer::statistics() const | 1053 | const QMap<QString,int>& OPacketCapturer::statistics() const |
1054 | { | 1054 | { |
1055 | return _stats; | 1055 | return _stats; |
1056 | } | 1056 | } |
1057 | 1057 | ||
1058 | |||
1059 | int OPacketCapturer::snapShot() const | ||
1060 | { | ||
1061 | return pcap_snapshot( _pch ); | ||
1062 | } | ||
1063 | |||
1064 | |||
1065 | bool OPacketCapturer::swapped() const | ||
1066 | { | ||
1067 | return pcap_is_swapped( _pch ); | ||
1068 | } | ||
1069 | |||
1070 | |||
1071 | QString OPacketCapturer::version() const | ||
1072 | { | ||
1073 | return QString().sprintf( "%s.%s", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); | ||
1074 | } | ||
1075 | |||
1076 | |||
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 5a50d9b..ad5b07c 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -161,430 +161,446 @@ class OPrismHeaderPacket : public QObject | |||
161 | { | 161 | { |
162 | Q_OBJECT | 162 | Q_OBJECT |
163 | 163 | ||
164 | public: | 164 | public: |
165 | OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); | 165 | OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); |
166 | virtual ~OPrismHeaderPacket(); | 166 | virtual ~OPrismHeaderPacket(); |
167 | 167 | ||
168 | unsigned int signalStrength() const; | 168 | unsigned int signalStrength() const; |
169 | 169 | ||
170 | private: | 170 | private: |
171 | const struct prism_hdr* _header; | 171 | const struct prism_hdr* _header; |
172 | }; | 172 | }; |
173 | 173 | ||
174 | /*====================================================================================== | 174 | /*====================================================================================== |
175 | * OWaveLanPacket - DLT_IEEE802_11 frame | 175 | * OWaveLanPacket - DLT_IEEE802_11 frame |
176 | *======================================================================================*/ | 176 | *======================================================================================*/ |
177 | 177 | ||
178 | class OWaveLanPacket : public QObject | 178 | class OWaveLanPacket : public QObject |
179 | { | 179 | { |
180 | Q_OBJECT | 180 | Q_OBJECT |
181 | 181 | ||
182 | public: | 182 | public: |
183 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); | 183 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); |
184 | virtual ~OWaveLanPacket(); | 184 | virtual ~OWaveLanPacket(); |
185 | 185 | ||
186 | int duration() const; | 186 | int duration() const; |
187 | bool fromDS() const; | 187 | bool fromDS() const; |
188 | bool toDS() const; | 188 | bool toDS() const; |
189 | virtual OMacAddress macAddress1() const; | 189 | virtual OMacAddress macAddress1() const; |
190 | virtual OMacAddress macAddress2() const; | 190 | virtual OMacAddress macAddress2() const; |
191 | virtual OMacAddress macAddress3() const; | 191 | virtual OMacAddress macAddress3() const; |
192 | virtual OMacAddress macAddress4() const; | 192 | virtual OMacAddress macAddress4() const; |
193 | bool usesPowerManagement() const; | 193 | bool usesPowerManagement() const; |
194 | int type() const; | 194 | int type() const; |
195 | int subType() const; | 195 | int subType() const; |
196 | int version() const; | 196 | int version() const; |
197 | bool usesWep() const; | 197 | bool usesWep() const; |
198 | 198 | ||
199 | private: | 199 | private: |
200 | const struct ieee_802_11_header* _wlanhdr; | 200 | const struct ieee_802_11_header* _wlanhdr; |
201 | }; | 201 | }; |
202 | 202 | ||
203 | 203 | ||
204 | /*====================================================================================== | 204 | /*====================================================================================== |
205 | * OWaveLanManagementPacket - type: management (T_MGMT) | 205 | * OWaveLanManagementPacket - type: management (T_MGMT) |
206 | *======================================================================================*/ | 206 | *======================================================================================*/ |
207 | 207 | ||
208 | class OWaveLanManagementPacket : public QObject | 208 | class OWaveLanManagementPacket : public QObject |
209 | { | 209 | { |
210 | Q_OBJECT | 210 | Q_OBJECT |
211 | 211 | ||
212 | public: | 212 | public: |
213 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); | 213 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); |
214 | virtual ~OWaveLanManagementPacket(); | 214 | virtual ~OWaveLanManagementPacket(); |
215 | 215 | ||
216 | QString managementType() const; | 216 | QString managementType() const; |
217 | 217 | ||
218 | int beaconInterval() const; | 218 | int beaconInterval() const; |
219 | int capabilities() const; // generic | 219 | int capabilities() const; // generic |
220 | 220 | ||
221 | bool canESS() const; | 221 | bool canESS() const; |
222 | bool canIBSS() const; | 222 | bool canIBSS() const; |
223 | bool canCFP() const; | 223 | bool canCFP() const; |
224 | bool canCFP_REQ() const; | 224 | bool canCFP_REQ() const; |
225 | bool canPrivacy() const; | 225 | bool canPrivacy() const; |
226 | 226 | ||
227 | private: | 227 | private: |
228 | const struct ieee_802_11_mgmt_header* _header; | 228 | const struct ieee_802_11_mgmt_header* _header; |
229 | const struct ieee_802_11_mgmt_body* _body; | 229 | const struct ieee_802_11_mgmt_body* _body; |
230 | }; | 230 | }; |
231 | 231 | ||
232 | 232 | ||
233 | /*====================================================================================== | 233 | /*====================================================================================== |
234 | * OWaveLanManagementSSID | 234 | * OWaveLanManagementSSID |
235 | *======================================================================================*/ | 235 | *======================================================================================*/ |
236 | 236 | ||
237 | class OWaveLanManagementSSID : public QObject | 237 | class OWaveLanManagementSSID : public QObject |
238 | { | 238 | { |
239 | Q_OBJECT | 239 | Q_OBJECT |
240 | 240 | ||
241 | public: | 241 | public: |
242 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); | 242 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); |
243 | virtual ~OWaveLanManagementSSID(); | 243 | virtual ~OWaveLanManagementSSID(); |
244 | 244 | ||
245 | QString ID() const; | 245 | QString ID() const; |
246 | 246 | ||
247 | private: | 247 | private: |
248 | const struct ssid_t* _data; | 248 | const struct ssid_t* _data; |
249 | }; | 249 | }; |
250 | 250 | ||
251 | /*====================================================================================== | 251 | /*====================================================================================== |
252 | * OWaveLanManagementRates | 252 | * OWaveLanManagementRates |
253 | *======================================================================================*/ | 253 | *======================================================================================*/ |
254 | 254 | ||
255 | class OWaveLanManagementRates : public QObject | 255 | class OWaveLanManagementRates : public QObject |
256 | { | 256 | { |
257 | Q_OBJECT | 257 | Q_OBJECT |
258 | 258 | ||
259 | public: | 259 | public: |
260 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); | 260 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); |
261 | virtual ~OWaveLanManagementRates(); | 261 | virtual ~OWaveLanManagementRates(); |
262 | 262 | ||
263 | private: | 263 | private: |
264 | const struct rates_t* _data; | 264 | const struct rates_t* _data; |
265 | }; | 265 | }; |
266 | 266 | ||
267 | /*====================================================================================== | 267 | /*====================================================================================== |
268 | * OWaveLanManagementCF | 268 | * OWaveLanManagementCF |
269 | *======================================================================================*/ | 269 | *======================================================================================*/ |
270 | 270 | ||
271 | class OWaveLanManagementCF : public QObject | 271 | class OWaveLanManagementCF : public QObject |
272 | { | 272 | { |
273 | Q_OBJECT | 273 | Q_OBJECT |
274 | 274 | ||
275 | public: | 275 | public: |
276 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); | 276 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); |
277 | virtual ~OWaveLanManagementCF(); | 277 | virtual ~OWaveLanManagementCF(); |
278 | 278 | ||
279 | private: | 279 | private: |
280 | const struct cf_t* _data; | 280 | const struct cf_t* _data; |
281 | }; | 281 | }; |
282 | 282 | ||
283 | /*====================================================================================== | 283 | /*====================================================================================== |
284 | * OWaveLanManagementFH | 284 | * OWaveLanManagementFH |
285 | *======================================================================================*/ | 285 | *======================================================================================*/ |
286 | 286 | ||
287 | class OWaveLanManagementFH : public QObject | 287 | class OWaveLanManagementFH : public QObject |
288 | { | 288 | { |
289 | Q_OBJECT | 289 | Q_OBJECT |
290 | 290 | ||
291 | public: | 291 | public: |
292 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); | 292 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); |
293 | virtual ~OWaveLanManagementFH(); | 293 | virtual ~OWaveLanManagementFH(); |
294 | 294 | ||
295 | private: | 295 | private: |
296 | const struct fh_t* _data; | 296 | const struct fh_t* _data; |
297 | }; | 297 | }; |
298 | 298 | ||
299 | /*====================================================================================== | 299 | /*====================================================================================== |
300 | * OWaveLanManagementDS | 300 | * OWaveLanManagementDS |
301 | *======================================================================================*/ | 301 | *======================================================================================*/ |
302 | 302 | ||
303 | class OWaveLanManagementDS : public QObject | 303 | class OWaveLanManagementDS : public QObject |
304 | { | 304 | { |
305 | Q_OBJECT | 305 | Q_OBJECT |
306 | 306 | ||
307 | public: | 307 | public: |
308 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); | 308 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); |
309 | virtual ~OWaveLanManagementDS(); | 309 | virtual ~OWaveLanManagementDS(); |
310 | 310 | ||
311 | int channel() const; | 311 | int channel() const; |
312 | 312 | ||
313 | private: | 313 | private: |
314 | const struct ds_t* _data; | 314 | const struct ds_t* _data; |
315 | }; | 315 | }; |
316 | 316 | ||
317 | /*====================================================================================== | 317 | /*====================================================================================== |
318 | * OWaveLanManagementTim | 318 | * OWaveLanManagementTim |
319 | *======================================================================================*/ | 319 | *======================================================================================*/ |
320 | 320 | ||
321 | class OWaveLanManagementTim : public QObject | 321 | class OWaveLanManagementTim : public QObject |
322 | { | 322 | { |
323 | Q_OBJECT | 323 | Q_OBJECT |
324 | 324 | ||
325 | public: | 325 | public: |
326 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); | 326 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); |
327 | virtual ~OWaveLanManagementTim(); | 327 | virtual ~OWaveLanManagementTim(); |
328 | 328 | ||
329 | private: | 329 | private: |
330 | const struct tim_t* _data; | 330 | const struct tim_t* _data; |
331 | }; | 331 | }; |
332 | 332 | ||
333 | /*====================================================================================== | 333 | /*====================================================================================== |
334 | * OWaveLanManagementIBSS | 334 | * OWaveLanManagementIBSS |
335 | *======================================================================================*/ | 335 | *======================================================================================*/ |
336 | 336 | ||
337 | class OWaveLanManagementIBSS : public QObject | 337 | class OWaveLanManagementIBSS : public QObject |
338 | { | 338 | { |
339 | Q_OBJECT | 339 | Q_OBJECT |
340 | 340 | ||
341 | public: | 341 | public: |
342 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); | 342 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); |
343 | virtual ~OWaveLanManagementIBSS(); | 343 | virtual ~OWaveLanManagementIBSS(); |
344 | 344 | ||
345 | private: | 345 | private: |
346 | const struct ibss_t* _data; | 346 | const struct ibss_t* _data; |
347 | }; | 347 | }; |
348 | 348 | ||
349 | /*====================================================================================== | 349 | /*====================================================================================== |
350 | * OWaveLanManagementChallenge | 350 | * OWaveLanManagementChallenge |
351 | *======================================================================================*/ | 351 | *======================================================================================*/ |
352 | 352 | ||
353 | class OWaveLanManagementChallenge : public QObject | 353 | class OWaveLanManagementChallenge : public QObject |
354 | { | 354 | { |
355 | Q_OBJECT | 355 | Q_OBJECT |
356 | 356 | ||
357 | public: | 357 | public: |
358 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); | 358 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); |
359 | virtual ~OWaveLanManagementChallenge(); | 359 | virtual ~OWaveLanManagementChallenge(); |
360 | 360 | ||
361 | private: | 361 | private: |
362 | const struct challenge_t* _data; | 362 | const struct challenge_t* _data; |
363 | }; | 363 | }; |
364 | 364 | ||
365 | /*====================================================================================== | 365 | /*====================================================================================== |
366 | * OWaveLanDataPacket - type: data (T_DATA) | 366 | * OWaveLanDataPacket - type: data (T_DATA) |
367 | *======================================================================================*/ | 367 | *======================================================================================*/ |
368 | 368 | ||
369 | class OWaveLanDataPacket : public QObject | 369 | class OWaveLanDataPacket : public QObject |
370 | { | 370 | { |
371 | Q_OBJECT | 371 | Q_OBJECT |
372 | 372 | ||
373 | public: | 373 | public: |
374 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); | 374 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); |
375 | virtual ~OWaveLanDataPacket(); | 375 | virtual ~OWaveLanDataPacket(); |
376 | 376 | ||
377 | private: | 377 | private: |
378 | const struct ieee_802_11_data_header* _header; | 378 | const struct ieee_802_11_data_header* _header; |
379 | }; | 379 | }; |
380 | 380 | ||
381 | /*====================================================================================== | 381 | /*====================================================================================== |
382 | * OWaveLanControlPacket - type: control (T_CTRL) | 382 | * OWaveLanControlPacket - type: control (T_CTRL) |
383 | *======================================================================================*/ | 383 | *======================================================================================*/ |
384 | 384 | ||
385 | class OWaveLanControlPacket : public QObject | 385 | class OWaveLanControlPacket : public QObject |
386 | { | 386 | { |
387 | Q_OBJECT | 387 | Q_OBJECT |
388 | 388 | ||
389 | public: | 389 | public: |
390 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); | 390 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); |
391 | virtual ~OWaveLanControlPacket(); | 391 | virtual ~OWaveLanControlPacket(); |
392 | 392 | ||
393 | private: | 393 | private: |
394 | const struct ieee_802_11_control_header* _header; | 394 | const struct ieee_802_11_control_header* _header; |
395 | }; | 395 | }; |
396 | 396 | ||
397 | /*====================================================================================== | 397 | /*====================================================================================== |
398 | * OLLCPacket - IEEE 802.2 Link Level Control | 398 | * OLLCPacket - IEEE 802.2 Link Level Control |
399 | *======================================================================================*/ | 399 | *======================================================================================*/ |
400 | 400 | ||
401 | class OLLCPacket : public QObject | 401 | class OLLCPacket : public QObject |
402 | { | 402 | { |
403 | Q_OBJECT | 403 | Q_OBJECT |
404 | 404 | ||
405 | public: | 405 | public: |
406 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); | 406 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); |
407 | virtual ~OLLCPacket(); | 407 | virtual ~OLLCPacket(); |
408 | 408 | ||
409 | private: | 409 | private: |
410 | const struct ieee_802_11_802_2_header* _header; | 410 | const struct ieee_802_11_802_2_header* _header; |
411 | }; | 411 | }; |
412 | 412 | ||
413 | /*====================================================================================== | 413 | /*====================================================================================== |
414 | * OIPPacket | 414 | * OIPPacket |
415 | *======================================================================================*/ | 415 | *======================================================================================*/ |
416 | 416 | ||
417 | class OIPPacket : public QObject | 417 | class OIPPacket : public QObject |
418 | { | 418 | { |
419 | Q_OBJECT | 419 | Q_OBJECT |
420 | 420 | ||
421 | public: | 421 | public: |
422 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); | 422 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); |
423 | virtual ~OIPPacket(); | 423 | virtual ~OIPPacket(); |
424 | 424 | ||
425 | QHostAddress fromIPAddress() const; | 425 | QHostAddress fromIPAddress() const; |
426 | QHostAddress toIPAddress() const; | 426 | QHostAddress toIPAddress() const; |
427 | 427 | ||
428 | int tos() const; | 428 | int tos() const; |
429 | int len() const; | 429 | int len() const; |
430 | int id() const; | 430 | int id() const; |
431 | int offset() const; | 431 | int offset() const; |
432 | int ttl() const; | 432 | int ttl() const; |
433 | int protocol() const; | 433 | int protocol() const; |
434 | int checksum() const; | 434 | int checksum() const; |
435 | 435 | ||
436 | private: | 436 | private: |
437 | const struct iphdr* _iphdr; | 437 | const struct iphdr* _iphdr; |
438 | }; | 438 | }; |
439 | 439 | ||
440 | /*====================================================================================== | 440 | /*====================================================================================== |
441 | * OARPPacket | 441 | * OARPPacket |
442 | *======================================================================================*/ | 442 | *======================================================================================*/ |
443 | 443 | ||
444 | class OARPPacket : public QObject | 444 | class OARPPacket : public QObject |
445 | { | 445 | { |
446 | Q_OBJECT | 446 | Q_OBJECT |
447 | 447 | ||
448 | public: | 448 | public: |
449 | OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); | 449 | OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); |
450 | virtual ~OARPPacket(); | 450 | virtual ~OARPPacket(); |
451 | 451 | ||
452 | QHostAddress senderIPV4Address() const; | 452 | QHostAddress senderIPV4Address() const; |
453 | OMacAddress senderMacAddress() const; | 453 | OMacAddress senderMacAddress() const; |
454 | QHostAddress targetIPV4Address() const; | 454 | QHostAddress targetIPV4Address() const; |
455 | OMacAddress targetMacAddress() const; | 455 | OMacAddress targetMacAddress() const; |
456 | 456 | ||
457 | //int type() const; | 457 | //int type() const; |
458 | QString type() const; | 458 | QString type() const; |
459 | 459 | ||
460 | private: | 460 | private: |
461 | const struct myarphdr* _arphdr; | 461 | const struct myarphdr* _arphdr; |
462 | }; | 462 | }; |
463 | 463 | ||
464 | /*====================================================================================== | 464 | /*====================================================================================== |
465 | * OUDPPacket | 465 | * OUDPPacket |
466 | *======================================================================================*/ | 466 | *======================================================================================*/ |
467 | 467 | ||
468 | class OUDPPacket : public QObject | 468 | class OUDPPacket : public QObject |
469 | { | 469 | { |
470 | Q_OBJECT | 470 | Q_OBJECT |
471 | 471 | ||
472 | public: | 472 | public: |
473 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); | 473 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); |
474 | virtual ~OUDPPacket(); | 474 | virtual ~OUDPPacket(); |
475 | 475 | ||
476 | int fromPort() const; | 476 | int fromPort() const; |
477 | int toPort() const; | 477 | int toPort() const; |
478 | 478 | ||
479 | private: | 479 | private: |
480 | const struct udphdr* _udphdr; | 480 | const struct udphdr* _udphdr; |
481 | }; | 481 | }; |
482 | 482 | ||
483 | /*====================================================================================== | 483 | /*====================================================================================== |
484 | * OTCPPacket | 484 | * OTCPPacket |
485 | *======================================================================================*/ | 485 | *======================================================================================*/ |
486 | 486 | ||
487 | class OTCPPacket : public QObject | 487 | class OTCPPacket : public QObject |
488 | { | 488 | { |
489 | Q_OBJECT | 489 | Q_OBJECT |
490 | 490 | ||
491 | public: | 491 | public: |
492 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); | 492 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); |
493 | virtual ~OTCPPacket(); | 493 | virtual ~OTCPPacket(); |
494 | 494 | ||
495 | int fromPort() const; | 495 | int fromPort() const; |
496 | int toPort() const; | 496 | int toPort() const; |
497 | 497 | ||
498 | private: | 498 | private: |
499 | const struct tcphdr* _tcphdr; | 499 | const struct tcphdr* _tcphdr; |
500 | }; | 500 | }; |
501 | 501 | ||
502 | 502 | ||
503 | /*====================================================================================== | 503 | /*====================================================================================== |
504 | * OPacketCapturer | 504 | * OPacketCapturer |
505 | *======================================================================================*/ | 505 | *======================================================================================*/ |
506 | 506 | ||
507 | /** | 507 | /** |
508 | * @brief A class based wrapper for network packet capturing. | 508 | * @brief A class based wrapper for network packet capturing. |
509 | * | 509 | * |
510 | * This class is the base of a high-level interface to the well known packet capturing | 510 | * This class is the base of a high-level interface to the well known packet capturing |
511 | * library libpcap. ... | 511 | * library libpcap. ... |
512 | */ | 512 | */ |
513 | class OPacketCapturer : public QObject | 513 | class OPacketCapturer : public QObject |
514 | { | 514 | { |
515 | Q_OBJECT | 515 | Q_OBJECT |
516 | 516 | ||
517 | public: | 517 | public: |
518 | /** | 518 | /** |
519 | * Constructor. | 519 | * Constructor. |
520 | */ | 520 | */ |
521 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); | 521 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); |
522 | /** | 522 | /** |
523 | * Destructor. | 523 | * Destructor. |
524 | */ | 524 | */ |
525 | ~OPacketCapturer(); | 525 | ~OPacketCapturer(); |
526 | /** | 526 | /** |
527 | * Setting the packet capturer to use blocking IO calls can be useful when | 527 | * Setting the packet capturer to use blocking IO calls can be useful when |
528 | * not using the socket notifier, e.g. without an application object. | 528 | * not using the socket notifier, e.g. without an application object. |
529 | */ | 529 | */ |
530 | void setBlocking( bool ); | 530 | void setBlocking( bool ); |
531 | /** | 531 | /** |
532 | * @returns true if the packet capturer uses blocking IO calls. | 532 | * @returns true if the packet capturer uses blocking IO calls. |
533 | */ | 533 | */ |
534 | bool blocking() const; | 534 | bool blocking() const; |
535 | /** | 535 | /** |
536 | * Closes the packet capturer. This is automatically done in the destructor. | 536 | * Closes the packet capturer. This is automatically done in the destructor. |
537 | */ | 537 | */ |
538 | void close(); | 538 | void close(); |
539 | /** | 539 | /** |
540 | * @returns the data link type. | 540 | * @returns the data link type. |
541 | * @see <pcap.h> for possible values. | 541 | * @see <pcap.h> for possible values. |
542 | */ | 542 | */ |
543 | int dataLink() const; | 543 | int dataLink() const; |
544 | /** | 544 | /** |
545 | * @returns the filedescriptor of the packet capturer. This is only useful, if | 545 | * @returns the file descriptor of the packet capturer. This is only useful, if |
546 | * not using the socket notifier, e.g. without an application object. | 546 | * not using the socket notifier, e.g. without an application object. |
547 | */ | 547 | */ |
548 | int fileno() const; | 548 | int fileno() const; |
549 | /** | 549 | /** |
550 | * @returns the next @ref OPacket from the packet capturer. | 550 | * @returns the next @ref OPacket from the packet capturer. |
551 | * @note If blocking mode is true then this call might block. | 551 | * @note If blocking mode is true then this call might block. |
552 | */ | 552 | */ |
553 | OPacket* next(); | 553 | OPacket* next(); |
554 | /** | 554 | /** |
555 | * Open the packet capturer to capture packets in live-mode from @a interface. | 555 | * Open the packet capturer to capture packets in live-mode from @a interface. |
556 | * If a @a filename is given, all captured packets are output to a tcpdump-compatible capture file. | 556 | * If a @a filename is given, all captured packets are output to a tcpdump-compatible capture file. |
557 | */ | 557 | */ |
558 | bool open( const QString& interface, const QString& filename = QString::null ); | 558 | bool open( const QString& interface, const QString& filename = QString::null ); |
559 | /** | 559 | /** |
560 | * Open the packet capturer to capture packets in offline-mode from @a file. | 560 | * Open the packet capturer to capture packets in offline-mode from @a file. |
561 | */ | 561 | */ |
562 | bool open( const QFile& file ); | 562 | bool open( const QFile& file ); |
563 | /** | 563 | /** |
564 | * @returns true if the packet capturer is open | 564 | * @returns true if the packet capturer is open |
565 | */ | 565 | */ |
566 | bool isOpen() const; | 566 | bool isOpen() const; |
567 | 567 | /** | |
568 | * @returns the snapshot length of this packet capturer | ||
569 | */ | ||
570 | int snapShot() const; | ||
571 | /** | ||
572 | * @returns true if the input capture file has a different byte-order | ||
573 | * than the byte-order of the running system. | ||
574 | */ | ||
575 | bool swapped() const; | ||
576 | /** | ||
577 | * @returns the libpcap version string used to write the input capture file. | ||
578 | */ | ||
579 | QString version() const; | ||
580 | /** | ||
581 | * @returns the packet statistic database. | ||
582 | * @see QMap | ||
583 | */ | ||
568 | const QMap<QString,int>& statistics() const; | 584 | const QMap<QString,int>& statistics() const; |
569 | 585 | ||
570 | signals: | 586 | signals: |
571 | /** | 587 | /** |
572 | * This signal is emitted, when a packet has been received. | 588 | * This signal is emitted, when a packet has been received. |
573 | */ | 589 | */ |
574 | void receivedPacket( OPacket* ); | 590 | void receivedPacket( OPacket* ); |
575 | 591 | ||
576 | protected slots: | 592 | protected slots: |
577 | void readyToReceive(); | 593 | void readyToReceive(); |
578 | 594 | ||
579 | protected: | 595 | protected: |
580 | QString _name; // devicename | 596 | QString _name; // devicename |
581 | bool _open; // check this before doing pcap calls | 597 | bool _open; // check this before doing pcap calls |
582 | pcap_t* _pch; // pcap library handle | 598 | pcap_t* _pch; // pcap library handle |
583 | pcap_dumper_t* _pcd; // pcap dumper handle | 599 | pcap_dumper_t* _pcd; // pcap dumper handle |
584 | QSocketNotifier* _sn; // socket notifier for main loop | 600 | QSocketNotifier* _sn; // socket notifier for main loop |
585 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap | 601 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap |
586 | QMap<QString, int> _stats; // statistics; | 602 | QMap<QString, int> _stats; // statistics; |
587 | }; | 603 | }; |
588 | 604 | ||
589 | #endif // OPCAP_H | 605 | #endif // OPCAP_H |
590 | 606 | ||