-rw-r--r-- | libopie2/opienet/opcap.cpp | 48 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 64 |
2 files changed, 101 insertions, 11 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 | |||
@@ -639,269 +639,313 @@ OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const | |||
639 | { | 639 | { |
640 | qDebug( "OWaveLanManagementIBSS()" ); | 640 | qDebug( "OWaveLanManagementIBSS()" ); |
641 | } | 641 | } |
642 | 642 | ||
643 | 643 | ||
644 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | 644 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() |
645 | { | 645 | { |
646 | } | 646 | } |
647 | 647 | ||
648 | /*====================================================================================== | 648 | /*====================================================================================== |
649 | * OWaveLanManagementChallenge | 649 | * OWaveLanManagementChallenge |
650 | *======================================================================================*/ | 650 | *======================================================================================*/ |
651 | 651 | ||
652 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) | 652 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) |
653 | :QObject( parent, "802.11 Challenge" ), _data( data ) | 653 | :QObject( parent, "802.11 Challenge" ), _data( data ) |
654 | { | 654 | { |
655 | qDebug( "OWaveLanManagementChallenge()" ); | 655 | qDebug( "OWaveLanManagementChallenge()" ); |
656 | } | 656 | } |
657 | 657 | ||
658 | 658 | ||
659 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | 659 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() |
660 | { | 660 | { |
661 | } | 661 | } |
662 | 662 | ||
663 | /*====================================================================================== | 663 | /*====================================================================================== |
664 | * OWaveLanDataPacket | 664 | * OWaveLanDataPacket |
665 | *======================================================================================*/ | 665 | *======================================================================================*/ |
666 | 666 | ||
667 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 667 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) |
668 | :QObject( parent, "802.11 Data" ), _header( data ) | 668 | :QObject( parent, "802.11 Data" ), _header( data ) |
669 | { | 669 | { |
670 | qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); | 670 | qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); |
671 | 671 | ||
672 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); | 672 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); |
673 | 673 | ||
674 | #warning The next line works for most cases, but can not be correct generally! | 674 | #warning The next line works for most cases, but can not be correct generally! |
675 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 675 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address |
676 | 676 | ||
677 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); | 677 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); |
678 | } | 678 | } |
679 | 679 | ||
680 | 680 | ||
681 | OWaveLanDataPacket::~OWaveLanDataPacket() | 681 | OWaveLanDataPacket::~OWaveLanDataPacket() |
682 | { | 682 | { |
683 | } | 683 | } |
684 | 684 | ||
685 | 685 | ||
686 | /*====================================================================================== | 686 | /*====================================================================================== |
687 | * OLLCPacket | 687 | * OLLCPacket |
688 | *======================================================================================*/ | 688 | *======================================================================================*/ |
689 | 689 | ||
690 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) | 690 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
691 | :QObject( parent, "802.11 LLC" ), _header( data ) | 691 | :QObject( parent, "802.11 LLC" ), _header( data ) |
692 | { | 692 | { |
693 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); | 693 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); |
694 | 694 | ||
695 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) | 695 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) |
696 | { | 696 | { |
697 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); | 697 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); |
698 | 698 | ||
699 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h | 699 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h |
700 | { | 700 | { |
701 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 701 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
702 | default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); | 702 | default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); |
703 | } | 703 | } |
704 | 704 | ||
705 | } | 705 | } |
706 | } | 706 | } |
707 | 707 | ||
708 | 708 | ||
709 | OLLCPacket::~OLLCPacket() | 709 | OLLCPacket::~OLLCPacket() |
710 | { | 710 | { |
711 | } | 711 | } |
712 | 712 | ||
713 | 713 | ||
714 | /*====================================================================================== | 714 | /*====================================================================================== |
715 | * OWaveLanControlPacket | 715 | * OWaveLanControlPacket |
716 | *======================================================================================*/ | 716 | *======================================================================================*/ |
717 | 717 | ||
718 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) | 718 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) |
719 | :QObject( parent, "802.11 Data" ), _header( data ) | 719 | :QObject( parent, "802.11 Data" ), _header( data ) |
720 | { | 720 | { |
721 | qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); | 721 | qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); |
722 | //TODO: Implement this | 722 | //TODO: Implement this |
723 | } | 723 | } |
724 | 724 | ||
725 | 725 | ||
726 | OWaveLanControlPacket::~OWaveLanControlPacket() | 726 | OWaveLanControlPacket::~OWaveLanControlPacket() |
727 | { | 727 | { |
728 | } | 728 | } |
729 | 729 | ||
730 | 730 | ||
731 | /*====================================================================================== | 731 | /*====================================================================================== |
732 | * OPacketCapturer | 732 | * OPacketCapturer |
733 | *======================================================================================*/ | 733 | *======================================================================================*/ |
734 | 734 | ||
735 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 735 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) |
736 | :QObject( parent, name ), _name( QString::null ), _open( false ), | 736 | :QObject( parent, name ), _name( QString::null ), _open( false ), |
737 | _pch( 0 ), _sn( 0 ) | 737 | _pch( 0 ), _sn( 0 ) |
738 | { | 738 | { |
739 | } | 739 | } |
740 | 740 | ||
741 | 741 | ||
742 | OPacketCapturer::~OPacketCapturer() | 742 | OPacketCapturer::~OPacketCapturer() |
743 | { | 743 | { |
744 | if ( _open ) | 744 | if ( _open ) |
745 | { | 745 | { |
746 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); | 746 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); |
747 | close(); | 747 | close(); |
748 | } | 748 | } |
749 | } | 749 | } |
750 | 750 | ||
751 | 751 | ||
752 | void OPacketCapturer::setBlocking( bool b ) | 752 | void OPacketCapturer::setBlocking( bool b ) |
753 | { | 753 | { |
754 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) | 754 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) |
755 | { | 755 | { |
756 | qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); | 756 | qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); |
757 | } | 757 | } |
758 | else | 758 | else |
759 | { | 759 | { |
760 | qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); | 760 | qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); |
761 | } | 761 | } |
762 | } | 762 | } |
763 | 763 | ||
764 | 764 | ||
765 | bool OPacketCapturer::blocking() const | 765 | bool OPacketCapturer::blocking() const |
766 | { | 766 | { |
767 | int b = pcap_getnonblock( _pch, _errbuf ); | 767 | int b = pcap_getnonblock( _pch, _errbuf ); |
768 | if ( b == -1 ) | 768 | if ( b == -1 ) |
769 | { | 769 | { |
770 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); | 770 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); |
771 | return -1; | 771 | return -1; |
772 | } | 772 | } |
773 | return !b; | 773 | return !b; |
774 | } | 774 | } |
775 | 775 | ||
776 | 776 | ||
777 | void OPacketCapturer::close() | 777 | void OPacketCapturer::close() |
778 | { | 778 | { |
779 | if ( _open ) | 779 | if ( _open ) |
780 | { | 780 | { |
781 | if ( _sn ) | 781 | if ( _sn ) |
782 | { | 782 | { |
783 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 783 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
784 | delete _sn; | 784 | delete _sn; |
785 | } | 785 | } |
786 | pcap_close( _pch ); | 786 | pcap_close( _pch ); |
787 | _open = false; | 787 | _open = false; |
788 | } | 788 | } |
789 | 789 | ||
790 | qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); | 790 | qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); |
791 | qDebug( "--------------------------------------------------" ); | 791 | qDebug( "--------------------------------------------------" ); |
792 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) | 792 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) |
793 | qDebug( "%s : %d", (const char*) it.key(), it.data() ); | 793 | qDebug( "%s : %d", (const char*) it.key(), it.data() ); |
794 | qDebug( "--------------------------------------------------" ); | 794 | qDebug( "--------------------------------------------------" ); |
795 | 795 | ||
796 | } | 796 | } |
797 | 797 | ||
798 | 798 | ||
799 | int OPacketCapturer::dataLink() const | 799 | int OPacketCapturer::dataLink() const |
800 | { | 800 | { |
801 | return pcap_datalink( _pch ); | 801 | return pcap_datalink( _pch ); |
802 | } | 802 | } |
803 | 803 | ||
804 | 804 | ||
805 | int OPacketCapturer::fileno() const | 805 | int OPacketCapturer::fileno() const |
806 | { | 806 | { |
807 | if ( _open ) | 807 | if ( _open ) |
808 | { | 808 | { |
809 | return pcap_fileno( _pch ); | 809 | return pcap_fileno( _pch ); |
810 | } | 810 | } |
811 | else | 811 | else |
812 | { | 812 | { |
813 | return -1; | 813 | return -1; |
814 | } | 814 | } |
815 | } | 815 | } |
816 | 816 | ||
817 | OPacket* OPacketCapturer::next() | 817 | OPacket* OPacketCapturer::next() |
818 | { | 818 | { |
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 | ||
844 | bool OPacketCapturer::open( const QString& name ) | 843 | bool OPacketCapturer::open( const QString& name ) |
845 | { | 844 | { |
846 | if ( _open ) | 845 | if ( _open ) |
847 | { | 846 | { |
848 | if ( name == _name ) // ignore opening an already openend device | 847 | if ( name == _name ) // ignore opening an already openend device |
849 | { | 848 | { |
850 | return true; | 849 | return true; |
851 | } | 850 | } |
852 | else // close the last opened device | 851 | else // close the last opened device |
853 | { | 852 | { |
854 | close(); | 853 | close(); |
855 | } | 854 | } |
856 | } | 855 | } |
857 | 856 | ||
858 | _name = name; | 857 | _name = name; |
859 | 858 | ||
860 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); | 859 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); |
861 | 860 | ||
862 | if ( handle ) | 861 | if ( handle ) |
863 | { | 862 | { |
864 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); | 863 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); |
865 | _pch = handle; | 864 | _pch = handle; |
866 | _open = true; | 865 | _open = true; |
867 | _stats.clear(); | 866 | _stats.clear(); |
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 | |||
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 | ||
887 | bool OPacketCapturer::isOpen() const | 931 | bool OPacketCapturer::isOpen() const |
888 | { | 932 | { |
889 | return _open; | 933 | return _open; |
890 | } | 934 | } |
891 | 935 | ||
892 | 936 | ||
893 | void OPacketCapturer::readyToReceive() | 937 | void OPacketCapturer::readyToReceive() |
894 | { | 938 | { |
895 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); | 939 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); |
896 | OPacket* p = next(); | 940 | OPacket* p = next(); |
897 | emit receivedPacket( p ); | 941 | emit receivedPacket( p ); |
898 | // emit is synchronous - packet has been dealt with, now it's safe to delete | 942 | // emit is synchronous - packet has been dealt with, now it's safe to delete |
899 | delete p; | 943 | delete p; |
900 | } | 944 | } |
901 | 945 | ||
902 | 946 | ||
903 | const QMap<QString,int>& OPacketCapturer::statistics() const | 947 | const QMap<QString,int>& OPacketCapturer::statistics() const |
904 | { | 948 | { |
905 | return _stats; | 949 | return _stats; |
906 | } | 950 | } |
907 | 951 | ||
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index c9b0624..6c3ac6d 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -1,459 +1,505 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 by the Wellenreiter team: | 3 | Copyright (C) 2003 by the Wellenreiter team: |
4 | Martin J. Muench <mjm@remote-exploit.org> | 4 | Martin J. Muench <mjm@remote-exploit.org> |
5 | Max Moser <mmo@remote-exploit.org | 5 | Max Moser <mmo@remote-exploit.org |
6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #ifndef OPCAP_H | 34 | #ifndef OPCAP_H |
35 | #define OPCAP_H | 35 | #define OPCAP_H |
36 | 36 | ||
37 | /* LINUX */ | 37 | /* LINUX */ |
38 | extern "C" // work around a bpf/pcap conflict in recent headers | 38 | extern "C" // work around a bpf/pcap conflict in recent headers |
39 | { | 39 | { |
40 | #include <pcap.h> | 40 | #include <pcap.h> |
41 | } | 41 | } |
42 | #include <netinet/ether.h> | 42 | #include <netinet/ether.h> |
43 | #include <netinet/ip.h> | 43 | #include <netinet/ip.h> |
44 | #include <netinet/udp.h> | 44 | #include <netinet/udp.h> |
45 | #include <netinet/tcp.h> | 45 | #include <netinet/tcp.h> |
46 | #include <time.h> | 46 | #include <time.h> |
47 | 47 | ||
48 | /* QT */ | 48 | /* QT */ |
49 | #include <qevent.h> | 49 | #include <qevent.h> |
50 | #include <qfile.h> | ||
50 | #include <qhostaddress.h> | 51 | #include <qhostaddress.h> |
51 | #include <qobject.h> | 52 | #include <qobject.h> |
52 | #include <qstring.h> | 53 | #include <qstring.h> |
53 | #include <qmap.h> | 54 | #include <qmap.h> |
54 | 55 | ||
55 | /* OPIE */ | 56 | /* OPIE */ |
56 | #include <opie2/onetutils.h> | 57 | #include <opie2/onetutils.h> |
57 | #include "802_11_user.h" | 58 | #include "802_11_user.h" |
58 | 59 | ||
59 | /* TYPEDEFS */ | 60 | /* TYPEDEFS */ |
60 | typedef struct timeval timevalstruct; | 61 | typedef struct timeval timevalstruct; |
61 | typedef struct pcap_pkthdr packetheaderstruct; | 62 | typedef struct pcap_pkthdr packetheaderstruct; |
62 | 63 | ||
63 | /* FORWARDS */ | 64 | /* FORWARDS */ |
64 | class OPacketCapturer; | 65 | class OPacketCapturer; |
65 | class QSocketNotifier; | 66 | class QSocketNotifier; |
66 | 67 | ||
67 | /*====================================================================================== | 68 | /*====================================================================================== |
68 | * OPacket - A frame on the wire | 69 | * OPacket - A frame on the wire |
69 | *======================================================================================*/ | 70 | *======================================================================================*/ |
70 | 71 | ||
71 | class OPacket : public QObject | 72 | class OPacket : public QObject |
72 | { | 73 | { |
73 | Q_OBJECT | 74 | Q_OBJECT |
74 | 75 | ||
75 | public: | 76 | public: |
76 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); | 77 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); |
77 | virtual ~OPacket(); | 78 | virtual ~OPacket(); |
78 | 79 | ||
79 | timevalstruct timeval() const; | 80 | timevalstruct timeval() const; |
80 | 81 | ||
81 | int caplen() const; | 82 | int caplen() const; |
82 | int len() const; | 83 | int len() const; |
83 | QString dump( int = 32 ) const; | 84 | QString dump( int = 32 ) const; |
84 | 85 | ||
85 | void updateStats( QMap<QString,int>&, QObjectList* ); | 86 | void updateStats( QMap<QString,int>&, QObjectList* ); |
86 | 87 | ||
87 | private: | 88 | private: |
88 | const packetheaderstruct _hdr; // pcap packet header | 89 | const packetheaderstruct _hdr; // pcap packet header |
89 | const unsigned char* _data; // pcap packet data | 90 | const unsigned char* _data; // pcap packet data |
90 | const unsigned char* _end; // end of pcap packet data | 91 | const unsigned char* _end; // end of pcap packet data |
91 | }; | 92 | }; |
92 | 93 | ||
93 | /*====================================================================================== | 94 | /*====================================================================================== |
94 | * OEthernetPacket - DLT_EN10MB frame | 95 | * OEthernetPacket - DLT_EN10MB frame |
95 | *======================================================================================*/ | 96 | *======================================================================================*/ |
96 | 97 | ||
97 | class OEthernetPacket : public QObject | 98 | class OEthernetPacket : public QObject |
98 | { | 99 | { |
99 | Q_OBJECT | 100 | Q_OBJECT |
100 | 101 | ||
101 | public: | 102 | public: |
102 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); | 103 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); |
103 | virtual ~OEthernetPacket(); | 104 | virtual ~OEthernetPacket(); |
104 | 105 | ||
105 | OMacAddress sourceAddress() const; | 106 | OMacAddress sourceAddress() const; |
106 | OMacAddress destinationAddress() const; | 107 | OMacAddress destinationAddress() const; |
107 | int type() const; | 108 | int type() const; |
108 | 109 | ||
109 | private: | 110 | private: |
110 | const struct ether_header* _ether; | 111 | const struct ether_header* _ether; |
111 | }; | 112 | }; |
112 | 113 | ||
113 | 114 | ||
114 | /*====================================================================================== | 115 | /*====================================================================================== |
115 | * OWaveLanPacket - DLT_IEEE802_11 frame | 116 | * OWaveLanPacket - DLT_IEEE802_11 frame |
116 | *======================================================================================*/ | 117 | *======================================================================================*/ |
117 | 118 | ||
118 | class OWaveLanPacket : public QObject | 119 | class OWaveLanPacket : public QObject |
119 | { | 120 | { |
120 | Q_OBJECT | 121 | Q_OBJECT |
121 | 122 | ||
122 | public: | 123 | public: |
123 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); | 124 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); |
124 | virtual ~OWaveLanPacket(); | 125 | virtual ~OWaveLanPacket(); |
125 | 126 | ||
126 | int duration() const; | 127 | int duration() const; |
127 | bool fromDS() const; | 128 | bool fromDS() const; |
128 | bool toDS() const; | 129 | bool toDS() const; |
129 | virtual OMacAddress macAddress1() const; | 130 | virtual OMacAddress macAddress1() const; |
130 | virtual OMacAddress macAddress2() const; | 131 | virtual OMacAddress macAddress2() const; |
131 | virtual OMacAddress macAddress3() const; | 132 | virtual OMacAddress macAddress3() const; |
132 | virtual OMacAddress macAddress4() const; | 133 | virtual OMacAddress macAddress4() const; |
133 | bool usesPowerManagement() const; | 134 | bool usesPowerManagement() const; |
134 | int type() const; | 135 | int type() const; |
135 | int subType() const; | 136 | int subType() const; |
136 | int version() const; | 137 | int version() const; |
137 | bool usesWep() const; | 138 | bool usesWep() const; |
138 | 139 | ||
139 | private: | 140 | private: |
140 | const struct ieee_802_11_header* _wlanhdr; | 141 | const struct ieee_802_11_header* _wlanhdr; |
141 | }; | 142 | }; |
142 | 143 | ||
143 | 144 | ||
144 | /*====================================================================================== | 145 | /*====================================================================================== |
145 | * OWaveLanManagementPacket - type: management (T_MGMT) | 146 | * OWaveLanManagementPacket - type: management (T_MGMT) |
146 | *======================================================================================*/ | 147 | *======================================================================================*/ |
147 | 148 | ||
148 | class OWaveLanManagementPacket : public QObject | 149 | class OWaveLanManagementPacket : public QObject |
149 | { | 150 | { |
150 | Q_OBJECT | 151 | Q_OBJECT |
151 | 152 | ||
152 | public: | 153 | public: |
153 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); | 154 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); |
154 | virtual ~OWaveLanManagementPacket(); | 155 | virtual ~OWaveLanManagementPacket(); |
155 | 156 | ||
156 | QString managementType() const; | 157 | QString managementType() const; |
157 | 158 | ||
158 | int beaconInterval() const; | 159 | int beaconInterval() const; |
159 | int capabilities() const; // generic | 160 | int capabilities() const; // generic |
160 | 161 | ||
161 | bool canESS() const; | 162 | bool canESS() const; |
162 | bool canIBSS() const; | 163 | bool canIBSS() const; |
163 | bool canCFP() const; | 164 | bool canCFP() const; |
164 | bool canCFP_REQ() const; | 165 | bool canCFP_REQ() const; |
165 | bool canPrivacy() const; | 166 | bool canPrivacy() const; |
166 | 167 | ||
167 | private: | 168 | private: |
168 | const struct ieee_802_11_mgmt_header* _header; | 169 | const struct ieee_802_11_mgmt_header* _header; |
169 | const struct ieee_802_11_mgmt_body* _body; | 170 | const struct ieee_802_11_mgmt_body* _body; |
170 | }; | 171 | }; |
171 | 172 | ||
172 | 173 | ||
173 | /*====================================================================================== | 174 | /*====================================================================================== |
174 | * OWaveLanManagementSSID | 175 | * OWaveLanManagementSSID |
175 | *======================================================================================*/ | 176 | *======================================================================================*/ |
176 | 177 | ||
177 | class OWaveLanManagementSSID : public QObject | 178 | class OWaveLanManagementSSID : public QObject |
178 | { | 179 | { |
179 | Q_OBJECT | 180 | Q_OBJECT |
180 | 181 | ||
181 | public: | 182 | public: |
182 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); | 183 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); |
183 | virtual ~OWaveLanManagementSSID(); | 184 | virtual ~OWaveLanManagementSSID(); |
184 | 185 | ||
185 | QString ID() const; | 186 | QString ID() const; |
186 | 187 | ||
187 | private: | 188 | private: |
188 | const struct ssid_t* _data; | 189 | const struct ssid_t* _data; |
189 | }; | 190 | }; |
190 | 191 | ||
191 | /*====================================================================================== | 192 | /*====================================================================================== |
192 | * OWaveLanManagementRates | 193 | * OWaveLanManagementRates |
193 | *======================================================================================*/ | 194 | *======================================================================================*/ |
194 | 195 | ||
195 | class OWaveLanManagementRates : public QObject | 196 | class OWaveLanManagementRates : public QObject |
196 | { | 197 | { |
197 | Q_OBJECT | 198 | Q_OBJECT |
198 | 199 | ||
199 | public: | 200 | public: |
200 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); | 201 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); |
201 | virtual ~OWaveLanManagementRates(); | 202 | virtual ~OWaveLanManagementRates(); |
202 | 203 | ||
203 | private: | 204 | private: |
204 | const struct rates_t* _data; | 205 | const struct rates_t* _data; |
205 | }; | 206 | }; |
206 | 207 | ||
207 | /*====================================================================================== | 208 | /*====================================================================================== |
208 | * OWaveLanManagementCF | 209 | * OWaveLanManagementCF |
209 | *======================================================================================*/ | 210 | *======================================================================================*/ |
210 | 211 | ||
211 | class OWaveLanManagementCF : public QObject | 212 | class OWaveLanManagementCF : public QObject |
212 | { | 213 | { |
213 | Q_OBJECT | 214 | Q_OBJECT |
214 | 215 | ||
215 | public: | 216 | public: |
216 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); | 217 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); |
217 | virtual ~OWaveLanManagementCF(); | 218 | virtual ~OWaveLanManagementCF(); |
218 | 219 | ||
219 | private: | 220 | private: |
220 | const struct cf_t* _data; | 221 | const struct cf_t* _data; |
221 | }; | 222 | }; |
222 | 223 | ||
223 | /*====================================================================================== | 224 | /*====================================================================================== |
224 | * OWaveLanManagementFH | 225 | * OWaveLanManagementFH |
225 | *======================================================================================*/ | 226 | *======================================================================================*/ |
226 | 227 | ||
227 | class OWaveLanManagementFH : public QObject | 228 | class OWaveLanManagementFH : public QObject |
228 | { | 229 | { |
229 | Q_OBJECT | 230 | Q_OBJECT |
230 | 231 | ||
231 | public: | 232 | public: |
232 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); | 233 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); |
233 | virtual ~OWaveLanManagementFH(); | 234 | virtual ~OWaveLanManagementFH(); |
234 | 235 | ||
235 | private: | 236 | private: |
236 | const struct fh_t* _data; | 237 | const struct fh_t* _data; |
237 | }; | 238 | }; |
238 | 239 | ||
239 | /*====================================================================================== | 240 | /*====================================================================================== |
240 | * OWaveLanManagementDS | 241 | * OWaveLanManagementDS |
241 | *======================================================================================*/ | 242 | *======================================================================================*/ |
242 | 243 | ||
243 | class OWaveLanManagementDS : public QObject | 244 | class OWaveLanManagementDS : public QObject |
244 | { | 245 | { |
245 | Q_OBJECT | 246 | Q_OBJECT |
246 | 247 | ||
247 | public: | 248 | public: |
248 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); | 249 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); |
249 | virtual ~OWaveLanManagementDS(); | 250 | virtual ~OWaveLanManagementDS(); |
250 | 251 | ||
251 | int channel() const; | 252 | int channel() const; |
252 | 253 | ||
253 | private: | 254 | private: |
254 | const struct ds_t* _data; | 255 | const struct ds_t* _data; |
255 | }; | 256 | }; |
256 | 257 | ||
257 | /*====================================================================================== | 258 | /*====================================================================================== |
258 | * OWaveLanManagementTim | 259 | * OWaveLanManagementTim |
259 | *======================================================================================*/ | 260 | *======================================================================================*/ |
260 | 261 | ||
261 | class OWaveLanManagementTim : public QObject | 262 | class OWaveLanManagementTim : public QObject |
262 | { | 263 | { |
263 | Q_OBJECT | 264 | Q_OBJECT |
264 | 265 | ||
265 | public: | 266 | public: |
266 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); | 267 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); |
267 | virtual ~OWaveLanManagementTim(); | 268 | virtual ~OWaveLanManagementTim(); |
268 | 269 | ||
269 | private: | 270 | private: |
270 | const struct tim_t* _data; | 271 | const struct tim_t* _data; |
271 | }; | 272 | }; |
272 | 273 | ||
273 | /*====================================================================================== | 274 | /*====================================================================================== |
274 | * OWaveLanManagementIBSS | 275 | * OWaveLanManagementIBSS |
275 | *======================================================================================*/ | 276 | *======================================================================================*/ |
276 | 277 | ||
277 | class OWaveLanManagementIBSS : public QObject | 278 | class OWaveLanManagementIBSS : public QObject |
278 | { | 279 | { |
279 | Q_OBJECT | 280 | Q_OBJECT |
280 | 281 | ||
281 | public: | 282 | public: |
282 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); | 283 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); |
283 | virtual ~OWaveLanManagementIBSS(); | 284 | virtual ~OWaveLanManagementIBSS(); |
284 | 285 | ||
285 | private: | 286 | private: |
286 | const struct ibss_t* _data; | 287 | const struct ibss_t* _data; |
287 | }; | 288 | }; |
288 | 289 | ||
289 | /*====================================================================================== | 290 | /*====================================================================================== |
290 | * OWaveLanManagementChallenge | 291 | * OWaveLanManagementChallenge |
291 | *======================================================================================*/ | 292 | *======================================================================================*/ |
292 | 293 | ||
293 | class OWaveLanManagementChallenge : public QObject | 294 | class OWaveLanManagementChallenge : public QObject |
294 | { | 295 | { |
295 | Q_OBJECT | 296 | Q_OBJECT |
296 | 297 | ||
297 | public: | 298 | public: |
298 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); | 299 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); |
299 | virtual ~OWaveLanManagementChallenge(); | 300 | virtual ~OWaveLanManagementChallenge(); |
300 | 301 | ||
301 | private: | 302 | private: |
302 | const struct challenge_t* _data; | 303 | const struct challenge_t* _data; |
303 | }; | 304 | }; |
304 | 305 | ||
305 | /*====================================================================================== | 306 | /*====================================================================================== |
306 | * OWaveLanDataPacket - type: data (T_DATA) | 307 | * OWaveLanDataPacket - type: data (T_DATA) |
307 | *======================================================================================*/ | 308 | *======================================================================================*/ |
308 | 309 | ||
309 | class OWaveLanDataPacket : public QObject | 310 | class OWaveLanDataPacket : public QObject |
310 | { | 311 | { |
311 | Q_OBJECT | 312 | Q_OBJECT |
312 | 313 | ||
313 | public: | 314 | public: |
314 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); | 315 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); |
315 | virtual ~OWaveLanDataPacket(); | 316 | virtual ~OWaveLanDataPacket(); |
316 | 317 | ||
317 | private: | 318 | private: |
318 | const struct ieee_802_11_data_header* _header; | 319 | const struct ieee_802_11_data_header* _header; |
319 | }; | 320 | }; |
320 | 321 | ||
321 | /*====================================================================================== | 322 | /*====================================================================================== |
322 | * OWaveLanControlPacket - type: control (T_CTRL) | 323 | * OWaveLanControlPacket - type: control (T_CTRL) |
323 | *======================================================================================*/ | 324 | *======================================================================================*/ |
324 | 325 | ||
325 | class OWaveLanControlPacket : public QObject | 326 | class OWaveLanControlPacket : public QObject |
326 | { | 327 | { |
327 | Q_OBJECT | 328 | Q_OBJECT |
328 | 329 | ||
329 | public: | 330 | public: |
330 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); | 331 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); |
331 | virtual ~OWaveLanControlPacket(); | 332 | virtual ~OWaveLanControlPacket(); |
332 | 333 | ||
333 | private: | 334 | private: |
334 | const struct ieee_802_11_control_header* _header; | 335 | const struct ieee_802_11_control_header* _header; |
335 | }; | 336 | }; |
336 | 337 | ||
337 | /*====================================================================================== | 338 | /*====================================================================================== |
338 | * OLLCPacket - IEEE 802.2 Link Level Control | 339 | * OLLCPacket - IEEE 802.2 Link Level Control |
339 | *======================================================================================*/ | 340 | *======================================================================================*/ |
340 | 341 | ||
341 | class OLLCPacket : public QObject | 342 | class OLLCPacket : public QObject |
342 | { | 343 | { |
343 | Q_OBJECT | 344 | Q_OBJECT |
344 | 345 | ||
345 | public: | 346 | public: |
346 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); | 347 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); |
347 | virtual ~OLLCPacket(); | 348 | virtual ~OLLCPacket(); |
348 | 349 | ||
349 | private: | 350 | private: |
350 | const struct ieee_802_11_802_2_header* _header; | 351 | const struct ieee_802_11_802_2_header* _header; |
351 | }; | 352 | }; |
352 | 353 | ||
353 | /*====================================================================================== | 354 | /*====================================================================================== |
354 | * OIPPacket | 355 | * OIPPacket |
355 | *======================================================================================*/ | 356 | *======================================================================================*/ |
356 | 357 | ||
357 | class OIPPacket : public QObject | 358 | class OIPPacket : public QObject |
358 | { | 359 | { |
359 | Q_OBJECT | 360 | Q_OBJECT |
360 | 361 | ||
361 | public: | 362 | public: |
362 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); | 363 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); |
363 | virtual ~OIPPacket(); | 364 | virtual ~OIPPacket(); |
364 | 365 | ||
365 | QHostAddress fromIPAddress() const; | 366 | QHostAddress fromIPAddress() const; |
366 | QHostAddress toIPAddress() const; | 367 | QHostAddress toIPAddress() const; |
367 | 368 | ||
368 | int tos() const; | 369 | int tos() const; |
369 | int len() const; | 370 | int len() const; |
370 | int id() const; | 371 | int id() const; |
371 | int offset() const; | 372 | int offset() const; |
372 | int ttl() const; | 373 | int ttl() const; |
373 | int protocol() const; | 374 | int protocol() const; |
374 | int checksum() const; | 375 | int checksum() const; |
375 | 376 | ||
376 | private: | 377 | private: |
377 | const struct iphdr* _iphdr; | 378 | const struct iphdr* _iphdr; |
378 | }; | 379 | }; |
379 | 380 | ||
380 | /*====================================================================================== | 381 | /*====================================================================================== |
381 | * OUDPPacket | 382 | * OUDPPacket |
382 | *======================================================================================*/ | 383 | *======================================================================================*/ |
383 | 384 | ||
384 | class OUDPPacket : public QObject | 385 | class OUDPPacket : public QObject |
385 | { | 386 | { |
386 | Q_OBJECT | 387 | Q_OBJECT |
387 | 388 | ||
388 | public: | 389 | public: |
389 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); | 390 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); |
390 | virtual ~OUDPPacket(); | 391 | virtual ~OUDPPacket(); |
391 | 392 | ||
392 | int fromPort() const; | 393 | int fromPort() const; |
393 | int toPort() const; | 394 | int toPort() const; |
394 | 395 | ||
395 | private: | 396 | private: |
396 | const struct udphdr* _udphdr; | 397 | const struct udphdr* _udphdr; |
397 | }; | 398 | }; |
398 | 399 | ||
399 | /*====================================================================================== | 400 | /*====================================================================================== |
400 | * OTCPPacket | 401 | * OTCPPacket |
401 | *======================================================================================*/ | 402 | *======================================================================================*/ |
402 | 403 | ||
403 | class OTCPPacket : public QObject | 404 | class OTCPPacket : public QObject |
404 | { | 405 | { |
405 | Q_OBJECT | 406 | Q_OBJECT |
406 | 407 | ||
407 | public: | 408 | public: |
408 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); | 409 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); |
409 | virtual ~OTCPPacket(); | 410 | virtual ~OTCPPacket(); |
410 | 411 | ||
411 | int fromPort() const; | 412 | int fromPort() const; |
412 | int toPort() const; | 413 | int toPort() const; |
413 | 414 | ||
414 | private: | 415 | private: |
415 | const struct tcphdr* _tcphdr; | 416 | const struct tcphdr* _tcphdr; |
416 | }; | 417 | }; |
417 | 418 | ||
418 | 419 | ||
419 | /*====================================================================================== | 420 | /*====================================================================================== |
420 | * OPacketCapturer | 421 | * OPacketCapturer |
421 | *======================================================================================*/ | 422 | *======================================================================================*/ |
422 | 423 | ||
424 | /** | ||
425 | * @brief A class based wrapper for network packet capturing. | ||
426 | * | ||
427 | * This class is the base of a high-level interface to the well known packet capturing | ||
428 | * library libpcap. ... | ||
429 | */ | ||
423 | class OPacketCapturer : public QObject | 430 | class OPacketCapturer : public QObject |
424 | { | 431 | { |
425 | Q_OBJECT | 432 | Q_OBJECT |
426 | 433 | ||
427 | public: | 434 | public: |
435 | /** | ||
436 | * Constructor. | ||
437 | */ | ||
428 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); | 438 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); |
439 | /** | ||
440 | * Destructor. | ||
441 | */ | ||
429 | ~OPacketCapturer(); | 442 | ~OPacketCapturer(); |
430 | 443 | /** | |
444 | * Setting the packet capturer to use blocking IO calls can be useful when | ||
445 | * not using the socket notifier, e.g. without an application object. | ||
446 | */ | ||
431 | void setBlocking( bool ); | 447 | void setBlocking( bool ); |
448 | /** | ||
449 | * @returns true if the packet capturer uses blocking IO calls. | ||
450 | */ | ||
432 | bool blocking() const; | 451 | bool blocking() const; |
433 | 452 | /** | |
453 | * Closes the packet capturer. This is automatically done in the destructor. | ||
454 | */ | ||
434 | void close(); | 455 | void close(); |
456 | /** | ||
457 | * @returns the data link type. | ||
458 | * @see <pcap.h> for possible values. | ||
459 | */ | ||
435 | int dataLink() const; | 460 | int dataLink() const; |
461 | /** | ||
462 | * @returns the filedescriptor of the packet capturer. This is only useful, if | ||
463 | * not using the socket notifier, e.g. without an application object. | ||
464 | */ | ||
436 | int fileno() const; | 465 | int fileno() const; |
466 | /** | ||
467 | * @returns the next @ref OPacket from the packet capturer. | ||
468 | * @note If blocking mode is true then this call might block. | ||
469 | */ | ||
437 | OPacket* next(); | 470 | OPacket* next(); |
438 | bool open( const QString& name ); | 471 | /** |
472 | * Open the packet capturer to capture packets in live-mode from @a interface. | ||
473 | */ | ||
474 | bool open( const QString& interface ); | ||
475 | /** | ||
476 | * Open the packet capturer to capture packets in offline-mode from @a file. | ||
477 | */ | ||
478 | bool open( const QFile& file ); | ||
479 | /** | ||
480 | * @returns true if the packet capturer is open | ||
481 | */ | ||
439 | bool isOpen() const; | 482 | bool isOpen() const; |
440 | 483 | ||
441 | const QMap<QString,int>& statistics() const; | 484 | const QMap<QString,int>& statistics() const; |
442 | 485 | ||
443 | signals: | 486 | signals: |
487 | /** | ||
488 | * This signal is emitted, when a packet has been received. | ||
489 | */ | ||
444 | void receivedPacket( OPacket* ); | 490 | void receivedPacket( OPacket* ); |
445 | 491 | ||
446 | protected slots: | 492 | protected slots: |
447 | void readyToReceive(); | 493 | void readyToReceive(); |
448 | 494 | ||
449 | protected: | 495 | protected: |
450 | QString _name; // devicename | 496 | QString _name; // devicename |
451 | bool _open; // check this before doing pcap calls | 497 | bool _open; // check this before doing pcap calls |
452 | pcap_t* _pch; // pcap library handle | 498 | pcap_t* _pch; // pcap library handle |
453 | QSocketNotifier* _sn; // socket notifier for main loop | 499 | QSocketNotifier* _sn; // socket notifier for main loop |
454 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; | 500 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap |
455 | QMap<QString, int> _stats; // statistics; | 501 | QMap<QString, int> _stats; // statistics; |
456 | }; | 502 | }; |
457 | 503 | ||
458 | #endif // OPCAP_H | 504 | #endif // OPCAP_H |
459 | 505 | ||