author | mickeyl <mickeyl> | 2004-04-23 14:43:53 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-04-23 14:43:53 (UTC) |
commit | d8a8c7bf9559dd1ad6a72c9e5582d72a176c97f6 (patch) (unidiff) | |
tree | 1a069ffb791230709e5be8ce230afb6e8d510af9 | |
parent | 8e32516bbda3fda10314f2afe4ee00eb9a49c013 (diff) | |
download | opie-d8a8c7bf9559dd1ad6a72c9e5582d72a176c97f6.zip opie-d8a8c7bf9559dd1ad6a72c9e5582d72a176c97f6.tar.gz opie-d8a8c7bf9559dd1ad6a72c9e5582d72a176c97f6.tar.bz2 |
disambiguate the API (triggered by gcc 3.4 ;)
-rw-r--r-- | libopie2/opienet/opcap.cpp | 4 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 4 |
2 files changed, 3 insertions, 5 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 067d6b7..f8ebe6b 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -902,470 +902,468 @@ OWaveLanManagementCF::~OWaveLanManagementCF() | |||
902 | * OWaveLanManagementFH | 902 | * OWaveLanManagementFH |
903 | *======================================================================================*/ | 903 | *======================================================================================*/ |
904 | 904 | ||
905 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) | 905 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) |
906 | :QObject( parent, "802.11 FH" ), _data( data ) | 906 | :QObject( parent, "802.11 FH" ), _data( data ) |
907 | { | 907 | { |
908 | odebug << "OWaveLanManagementFH()" << oendl; | 908 | odebug << "OWaveLanManagementFH()" << oendl; |
909 | } | 909 | } |
910 | 910 | ||
911 | 911 | ||
912 | OWaveLanManagementFH::~OWaveLanManagementFH() | 912 | OWaveLanManagementFH::~OWaveLanManagementFH() |
913 | { | 913 | { |
914 | } | 914 | } |
915 | 915 | ||
916 | /*====================================================================================== | 916 | /*====================================================================================== |
917 | * OWaveLanManagementDS | 917 | * OWaveLanManagementDS |
918 | *======================================================================================*/ | 918 | *======================================================================================*/ |
919 | 919 | ||
920 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) | 920 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) |
921 | :QObject( parent, "802.11 DS" ), _data( data ) | 921 | :QObject( parent, "802.11 DS" ), _data( data ) |
922 | { | 922 | { |
923 | odebug << "OWaveLanManagementDS()" << oendl; | 923 | odebug << "OWaveLanManagementDS()" << oendl; |
924 | } | 924 | } |
925 | 925 | ||
926 | 926 | ||
927 | OWaveLanManagementDS::~OWaveLanManagementDS() | 927 | OWaveLanManagementDS::~OWaveLanManagementDS() |
928 | { | 928 | { |
929 | } | 929 | } |
930 | 930 | ||
931 | 931 | ||
932 | int OWaveLanManagementDS::channel() const | 932 | int OWaveLanManagementDS::channel() const |
933 | { | 933 | { |
934 | return _data->channel; | 934 | return _data->channel; |
935 | } | 935 | } |
936 | 936 | ||
937 | /*====================================================================================== | 937 | /*====================================================================================== |
938 | * OWaveLanManagementTim | 938 | * OWaveLanManagementTim |
939 | *======================================================================================*/ | 939 | *======================================================================================*/ |
940 | 940 | ||
941 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) | 941 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) |
942 | :QObject( parent, "802.11 Tim" ), _data( data ) | 942 | :QObject( parent, "802.11 Tim" ), _data( data ) |
943 | { | 943 | { |
944 | odebug << "OWaveLanManagementTim()" << oendl; | 944 | odebug << "OWaveLanManagementTim()" << oendl; |
945 | } | 945 | } |
946 | 946 | ||
947 | 947 | ||
948 | OWaveLanManagementTim::~OWaveLanManagementTim() | 948 | OWaveLanManagementTim::~OWaveLanManagementTim() |
949 | { | 949 | { |
950 | } | 950 | } |
951 | 951 | ||
952 | /*====================================================================================== | 952 | /*====================================================================================== |
953 | * OWaveLanManagementIBSS | 953 | * OWaveLanManagementIBSS |
954 | *======================================================================================*/ | 954 | *======================================================================================*/ |
955 | 955 | ||
956 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) | 956 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) |
957 | :QObject( parent, "802.11 IBSS" ), _data( data ) | 957 | :QObject( parent, "802.11 IBSS" ), _data( data ) |
958 | { | 958 | { |
959 | odebug << "OWaveLanManagementIBSS()" << oendl; | 959 | odebug << "OWaveLanManagementIBSS()" << oendl; |
960 | } | 960 | } |
961 | 961 | ||
962 | 962 | ||
963 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | 963 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() |
964 | { | 964 | { |
965 | } | 965 | } |
966 | 966 | ||
967 | /*====================================================================================== | 967 | /*====================================================================================== |
968 | * OWaveLanManagementChallenge | 968 | * OWaveLanManagementChallenge |
969 | *======================================================================================*/ | 969 | *======================================================================================*/ |
970 | 970 | ||
971 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) | 971 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) |
972 | :QObject( parent, "802.11 Challenge" ), _data( data ) | 972 | :QObject( parent, "802.11 Challenge" ), _data( data ) |
973 | { | 973 | { |
974 | odebug << "OWaveLanManagementChallenge()" << oendl; | 974 | odebug << "OWaveLanManagementChallenge()" << oendl; |
975 | } | 975 | } |
976 | 976 | ||
977 | 977 | ||
978 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | 978 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() |
979 | { | 979 | { |
980 | } | 980 | } |
981 | 981 | ||
982 | /*====================================================================================== | 982 | /*====================================================================================== |
983 | * OWaveLanDataPacket | 983 | * OWaveLanDataPacket |
984 | *======================================================================================*/ | 984 | *======================================================================================*/ |
985 | 985 | ||
986 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 986 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) |
987 | :QObject( parent, "802.11 Data" ), _header( data ) | 987 | :QObject( parent, "802.11 Data" ), _header( data ) |
988 | { | 988 | { |
989 | odebug << "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." << oendl; | 989 | odebug << "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." << oendl; |
990 | 990 | ||
991 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); | 991 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); |
992 | 992 | ||
993 | #warning The next line works for most cases, but can not be correct generally! | 993 | #warning The next line works for most cases, but can not be correct generally! |
994 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 994 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address |
995 | 995 | ||
996 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); | 996 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); |
997 | } | 997 | } |
998 | 998 | ||
999 | 999 | ||
1000 | OWaveLanDataPacket::~OWaveLanDataPacket() | 1000 | OWaveLanDataPacket::~OWaveLanDataPacket() |
1001 | { | 1001 | { |
1002 | } | 1002 | } |
1003 | 1003 | ||
1004 | 1004 | ||
1005 | /*====================================================================================== | 1005 | /*====================================================================================== |
1006 | * OLLCPacket | 1006 | * OLLCPacket |
1007 | *======================================================================================*/ | 1007 | *======================================================================================*/ |
1008 | 1008 | ||
1009 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) | 1009 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
1010 | :QObject( parent, "802.11 LLC" ), _header( data ) | 1010 | :QObject( parent, "802.11 LLC" ), _header( data ) |
1011 | { | 1011 | { |
1012 | odebug << "OLLCPacket::OLLCPacket(): decoding frame..." << oendl; | 1012 | odebug << "OLLCPacket::OLLCPacket(): decoding frame..." << oendl; |
1013 | 1013 | ||
1014 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) | 1014 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) |
1015 | { | 1015 | { |
1016 | owarn << "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type = " << EXTRACT_16BITS( &_header->type ) << ")" << oendl; | 1016 | owarn << "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type = " << EXTRACT_16BITS( &_header->type ) << ")" << oendl; |
1017 | 1017 | ||
1018 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h | 1018 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h |
1019 | { | 1019 | { |
1020 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 1020 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
1021 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 1021 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
1022 | default: owarn << "OLLCPacket::OLLCPacket(): Unknown Encapsulation type = " << EXTRACT_16BITS( &_header->type ) << oendl; | 1022 | default: owarn << "OLLCPacket::OLLCPacket(): Unknown Encapsulation type = " << EXTRACT_16BITS( &_header->type ) << oendl; |
1023 | } | 1023 | } |
1024 | } | 1024 | } |
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | 1027 | ||
1028 | OLLCPacket::~OLLCPacket() | 1028 | OLLCPacket::~OLLCPacket() |
1029 | { | 1029 | { |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | 1032 | ||
1033 | /*====================================================================================== | 1033 | /*====================================================================================== |
1034 | * OWaveLanControlPacket | 1034 | * OWaveLanControlPacket |
1035 | *======================================================================================*/ | 1035 | *======================================================================================*/ |
1036 | 1036 | ||
1037 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) | 1037 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) |
1038 | :QObject( parent, "802.11 Control" ), _header( data ) | 1038 | :QObject( parent, "802.11 Control" ), _header( data ) |
1039 | { | 1039 | { |
1040 | odebug << "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." << oendl; | 1040 | odebug << "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." << oendl; |
1041 | odebug << "Detected subtype is " << controlType() << oendl; | 1041 | odebug << "Detected subtype is " << controlType() << oendl; |
1042 | } | 1042 | } |
1043 | 1043 | ||
1044 | 1044 | ||
1045 | OWaveLanControlPacket::~OWaveLanControlPacket() | 1045 | OWaveLanControlPacket::~OWaveLanControlPacket() |
1046 | { | 1046 | { |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | 1049 | ||
1050 | QString OWaveLanControlPacket::controlType() const | 1050 | QString OWaveLanControlPacket::controlType() const |
1051 | { | 1051 | { |
1052 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | 1052 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
1053 | { | 1053 | { |
1054 | case CTRL_PS_POLL: return "PowerSavePoll"; break; | 1054 | case CTRL_PS_POLL: return "PowerSavePoll"; break; |
1055 | case CTRL_RTS: return "RequestToSend"; break; | 1055 | case CTRL_RTS: return "RequestToSend"; break; |
1056 | case CTRL_CTS: return "ClearToSend"; break; | 1056 | case CTRL_CTS: return "ClearToSend"; break; |
1057 | case CTRL_ACK: return "Acknowledge"; break; | 1057 | case CTRL_ACK: return "Acknowledge"; break; |
1058 | case CTRL_CF_END: return "ContentionFreeEnd"; break; | 1058 | case CTRL_CF_END: return "ContentionFreeEnd"; break; |
1059 | case CTRL_END_ACK: return "AcknowledgeEnd"; break; | 1059 | case CTRL_END_ACK: return "AcknowledgeEnd"; break; |
1060 | default: | 1060 | default: |
1061 | owarn << "OWaveLanControlPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; | 1061 | owarn << "OWaveLanControlPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; |
1062 | return "Unknown"; | 1062 | return "Unknown"; |
1063 | } | 1063 | } |
1064 | } | 1064 | } |
1065 | 1065 | ||
1066 | 1066 | ||
1067 | /*====================================================================================== | 1067 | /*====================================================================================== |
1068 | * OPacketCapturer | 1068 | * OPacketCapturer |
1069 | *======================================================================================*/ | 1069 | *======================================================================================*/ |
1070 | 1070 | ||
1071 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 1071 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) |
1072 | :QObject( parent, name ), _name( QString::null ), _open( false ), _pch( 0 ), _pcd( 0 ), _sn( 0 ), _autodelete( true ) | 1072 | :QObject( parent, name ), _name( QString::null ), _open( false ), _pch( 0 ), _pcd( 0 ), _sn( 0 ), _autodelete( true ) |
1073 | { | 1073 | { |
1074 | } | 1074 | } |
1075 | 1075 | ||
1076 | 1076 | ||
1077 | OPacketCapturer::~OPacketCapturer() | 1077 | OPacketCapturer::~OPacketCapturer() |
1078 | { | 1078 | { |
1079 | if ( _open ) | 1079 | if ( _open ) |
1080 | { | 1080 | { |
1081 | odebug << "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." << oendl; | 1081 | odebug << "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." << oendl; |
1082 | close(); | 1082 | close(); |
1083 | } | 1083 | } |
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | 1086 | ||
1087 | void OPacketCapturer::setAutoDelete( bool b ) | 1087 | void OPacketCapturer::setAutoDelete( bool b ) |
1088 | { | 1088 | { |
1089 | _autodelete = b; | 1089 | _autodelete = b; |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | 1092 | ||
1093 | bool OPacketCapturer::autoDelete() const | 1093 | bool OPacketCapturer::autoDelete() const |
1094 | { | 1094 | { |
1095 | return _autodelete; | 1095 | return _autodelete; |
1096 | } | 1096 | } |
1097 | 1097 | ||
1098 | 1098 | ||
1099 | void OPacketCapturer::setBlocking( bool b ) | 1099 | void OPacketCapturer::setBlocking( bool b ) |
1100 | { | 1100 | { |
1101 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) | 1101 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) |
1102 | { | 1102 | { |
1103 | odebug << "OPacketCapturer::setBlocking(): blocking mode changed successfully." << oendl; | 1103 | odebug << "OPacketCapturer::setBlocking(): blocking mode changed successfully." << oendl; |
1104 | } | 1104 | } |
1105 | else | 1105 | else |
1106 | { | 1106 | { |
1107 | odebug << "OPacketCapturer::setBlocking(): can't change blocking mode: " << _errbuf << oendl; | 1107 | odebug << "OPacketCapturer::setBlocking(): can't change blocking mode: " << _errbuf << oendl; |
1108 | } | 1108 | } |
1109 | } | 1109 | } |
1110 | 1110 | ||
1111 | 1111 | ||
1112 | bool OPacketCapturer::blocking() const | 1112 | bool OPacketCapturer::blocking() const |
1113 | { | 1113 | { |
1114 | int b = pcap_getnonblock( _pch, _errbuf ); | 1114 | int b = pcap_getnonblock( _pch, _errbuf ); |
1115 | if ( b == -1 ) | 1115 | if ( b == -1 ) |
1116 | { | 1116 | { |
1117 | odebug << "OPacketCapturer::blocking(): can't get blocking mode: " << _errbuf << oendl; | 1117 | odebug << "OPacketCapturer::blocking(): can't get blocking mode: " << _errbuf << oendl; |
1118 | return -1; | 1118 | return -1; |
1119 | } | 1119 | } |
1120 | return !b; | 1120 | return !b; |
1121 | } | 1121 | } |
1122 | 1122 | ||
1123 | 1123 | ||
1124 | void OPacketCapturer::closeDumpFile() | 1124 | void OPacketCapturer::closeDumpFile() |
1125 | { | 1125 | { |
1126 | if ( _pcd ) | 1126 | if ( _pcd ) |
1127 | { | 1127 | { |
1128 | pcap_dump_close( _pcd ); | 1128 | pcap_dump_close( _pcd ); |
1129 | _pcd = 0; | 1129 | _pcd = 0; |
1130 | } | 1130 | } |
1131 | pcap_close( _pch ); | 1131 | pcap_close( _pch ); |
1132 | } | 1132 | } |
1133 | 1133 | ||
1134 | 1134 | ||
1135 | void OPacketCapturer::close() | 1135 | void OPacketCapturer::close() |
1136 | { | 1136 | { |
1137 | if ( _open ) | 1137 | if ( _open ) |
1138 | { | 1138 | { |
1139 | if ( _sn ) | 1139 | if ( _sn ) |
1140 | { | 1140 | { |
1141 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1141 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1142 | delete _sn; | 1142 | delete _sn; |
1143 | } | 1143 | } |
1144 | closeDumpFile(); | 1144 | closeDumpFile(); |
1145 | _open = false; | 1145 | _open = false; |
1146 | } | 1146 | } |
1147 | 1147 | ||
1148 | odebug << "OPacketCapturer::close() --- dumping capturing statistics..." << oendl; | 1148 | odebug << "OPacketCapturer::close() --- dumping capturing statistics..." << oendl; |
1149 | odebug << "--------------------------------------------------" << oendl; | 1149 | odebug << "--------------------------------------------------" << oendl; |
1150 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) | 1150 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) |
1151 | odebug << it.key() << " = " << it.data() << oendl; | 1151 | odebug << it.key() << " = " << it.data() << oendl; |
1152 | odebug << "--------------------------------------------------" << oendl; | 1152 | odebug << "--------------------------------------------------" << oendl; |
1153 | 1153 | ||
1154 | } | 1154 | } |
1155 | 1155 | ||
1156 | 1156 | ||
1157 | int OPacketCapturer::dataLink() const | 1157 | int OPacketCapturer::dataLink() const |
1158 | { | 1158 | { |
1159 | return pcap_datalink( _pch ); | 1159 | return pcap_datalink( _pch ); |
1160 | } | 1160 | } |
1161 | 1161 | ||
1162 | 1162 | ||
1163 | void OPacketCapturer::dump( OPacket* p ) | 1163 | void OPacketCapturer::dump( OPacket* p ) |
1164 | { | 1164 | { |
1165 | if ( !_pcd ) | 1165 | if ( !_pcd ) |
1166 | { | 1166 | { |
1167 | owarn << "OPacketCapturer::dump() - cannot dump without open capture file!" << oendl; | 1167 | owarn << "OPacketCapturer::dump() - cannot dump without open capture file!" << oendl; |
1168 | return; | 1168 | return; |
1169 | } | 1169 | } |
1170 | pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); | 1170 | pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); |
1171 | } | 1171 | } |
1172 | 1172 | ||
1173 | 1173 | ||
1174 | int OPacketCapturer::fileno() const | 1174 | int OPacketCapturer::fileno() const |
1175 | { | 1175 | { |
1176 | if ( _open ) | 1176 | if ( _open ) |
1177 | { | 1177 | { |
1178 | return pcap_fileno( _pch ); | 1178 | return pcap_fileno( _pch ); |
1179 | } | 1179 | } |
1180 | else | 1180 | else |
1181 | { | 1181 | { |
1182 | return -1; | 1182 | return -1; |
1183 | } | 1183 | } |
1184 | } | 1184 | } |
1185 | 1185 | ||
1186 | 1186 | ||
1187 | OPacket* OPacketCapturer::next( int time ) | 1187 | OPacket* OPacketCapturer::next( int time ) |
1188 | { | 1188 | { |
1189 | fd_set fds; | 1189 | fd_set fds; |
1190 | struct timeval tv; | 1190 | struct timeval tv; |
1191 | FD_ZERO( &fds ); | 1191 | FD_ZERO( &fds ); |
1192 | FD_SET( pcap_fileno( _pch ), &fds ); | 1192 | FD_SET( pcap_fileno( _pch ), &fds ); |
1193 | tv.tv_sec = time / 1000; | 1193 | tv.tv_sec = time / 1000; |
1194 | tv.tv_usec = time % 1000; | 1194 | tv.tv_usec = time % 1000; |
1195 | int retval = select( pcap_fileno( _pch )+1, &fds, NULL, NULL, &tv); | 1195 | int retval = select( pcap_fileno( _pch )+1, &fds, NULL, NULL, &tv); |
1196 | if ( retval > 0 ) // clear to read! | 1196 | if ( retval > 0 ) // clear to read! |
1197 | return next(); | 1197 | return next(); |
1198 | else | 1198 | else |
1199 | return 0; | 1199 | return 0; |
1200 | } | 1200 | } |
1201 | 1201 | ||
1202 | 1202 | ||
1203 | OPacket* OPacketCapturer::next() | 1203 | OPacket* OPacketCapturer::next() |
1204 | { | 1204 | { |
1205 | packetheaderstruct header; | 1205 | packetheaderstruct header; |
1206 | odebug << "==> OPacketCapturer::next()" << oendl; | 1206 | odebug << "==> OPacketCapturer::next()" << oendl; |
1207 | const unsigned char* pdata = pcap_next( _pch, &header ); | 1207 | const unsigned char* pdata = pcap_next( _pch, &header ); |
1208 | odebug << "<== OPacketCapturer::next()" << oendl; | 1208 | odebug << "<== OPacketCapturer::next()" << oendl; |
1209 | 1209 | ||
1210 | if ( pdata && header.len ) | 1210 | if ( pdata && header.len ) |
1211 | { | 1211 | { |
1212 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); | 1212 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); |
1213 | // packets shouldn't be inserted in the QObject child-parent hierarchy, | 1213 | // packets shouldn't be inserted in the QObject child-parent hierarchy, |
1214 | // because due to memory constraints they will be deleted as soon | 1214 | // because due to memory constraints they will be deleted as soon |
1215 | // as possible - that is right after they have been processed | 1215 | // as possible - that is right after they have been processed |
1216 | // by emit() [ see below ] | 1216 | // by emit() [ see below ] |
1217 | //TODO: make gathering statistics optional, because it takes time | 1217 | //TODO: make gathering statistics optional, because it takes time |
1218 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); | 1218 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); |
1219 | odebug << "OPacket::dumpStructure: " << p->dumpStructure() << oendl; | 1219 | odebug << "OPacket::dumpStructure: " << p->dumpStructure() << oendl; |
1220 | return p; | 1220 | return p; |
1221 | } | 1221 | } |
1222 | else | 1222 | else |
1223 | { | 1223 | { |
1224 | owarn << "OPacketCapturer::next() - no packet received!" << oendl; | 1224 | owarn << "OPacketCapturer::next() - no packet received!" << oendl; |
1225 | return 0; | 1225 | return 0; |
1226 | } | 1226 | } |
1227 | } | 1227 | } |
1228 | 1228 | ||
1229 | 1229 | ||
1230 | bool OPacketCapturer::open( const QString& name ) | 1230 | bool OPacketCapturer::open( const QString& name ) |
1231 | { | 1231 | { |
1232 | if ( _open ) | 1232 | if ( _open ) |
1233 | { | 1233 | { |
1234 | if ( name == _name ) // ignore opening an already openend device | 1234 | if ( name == _name ) // ignore opening an already openend device |
1235 | { | 1235 | { |
1236 | return true; | 1236 | return true; |
1237 | } | 1237 | } |
1238 | else // close the last opened device | 1238 | else // close the last opened device |
1239 | { | 1239 | { |
1240 | close(); | 1240 | close(); |
1241 | } | 1241 | } |
1242 | } | 1242 | } |
1243 | 1243 | ||
1244 | _name = name; | 1244 | _name = name; |
1245 | 1245 | ||
1246 | // open libpcap | 1246 | // open libpcap |
1247 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); | 1247 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); |
1248 | 1248 | ||
1249 | if ( !handle ) | 1249 | if ( !handle ) |
1250 | { | 1250 | { |
1251 | owarn << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; | 1251 | owarn << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; |
1252 | return false; | 1252 | return false; |
1253 | } | 1253 | } |
1254 | 1254 | ||
1255 | odebug << "OPacketCapturer::open(): libpcap [" << name << "] opened successfully." << oendl; | 1255 | odebug << "OPacketCapturer::open(): libpcap [" << name << "] opened successfully." << oendl; |
1256 | _pch = handle; | 1256 | _pch = handle; |
1257 | _open = true; | 1257 | _open = true; |
1258 | _stats.clear(); | 1258 | _stats.clear(); |
1259 | 1259 | ||
1260 | // in case we have an application object, create a socket notifier | 1260 | // in case we have an application object, create a socket notifier |
1261 | if ( qApp ) //TODO: I don't like this here... | 1261 | if ( qApp ) //TODO: I don't like this here... |
1262 | { | 1262 | { |
1263 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 1263 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
1264 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1264 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1265 | } | 1265 | } |
1266 | 1266 | ||
1267 | return true; | 1267 | return true; |
1268 | } | 1268 | } |
1269 | 1269 | ||
1270 | 1270 | ||
1271 | bool OPacketCapturer::openDumpFile( const QString& filename ) | 1271 | bool OPacketCapturer::openDumpFile( const QString& filename ) |
1272 | { | 1272 | { |
1273 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); | 1273 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); |
1274 | if ( !dump ) | 1274 | if ( !dump ) |
1275 | { | 1275 | { |
1276 | owarn << "OPacketCapturer::open(): can't open dump with '" << filename << "': " << _errbuf << oendl; | 1276 | owarn << "OPacketCapturer::open(): can't open dump with '" << filename << "': " << _errbuf << oendl; |
1277 | return false; | 1277 | return false; |
1278 | } | 1278 | } |
1279 | odebug << "OPacketCapturer::open(): dump [" << filename << "] opened successfully." << oendl; | 1279 | odebug << "OPacketCapturer::open(): dump [" << filename << "] opened successfully." << oendl; |
1280 | _pcd = dump; | 1280 | _pcd = dump; |
1281 | 1281 | ||
1282 | return true; | 1282 | return true; |
1283 | } | 1283 | } |
1284 | 1284 | ||
1285 | 1285 | ||
1286 | bool OPacketCapturer::open( const QFile& file ) | 1286 | bool OPacketCapturer::openCaptureFile( const QString& name ) |
1287 | { | 1287 | { |
1288 | QString name = file.name(); | ||
1289 | |||
1290 | if ( _open ) | 1288 | if ( _open ) |
1291 | { | 1289 | { |
1292 | close(); | 1290 | close(); |
1293 | if ( name == _name ) // ignore opening an already openend device | 1291 | if ( name == _name ) // ignore opening an already openend device |
1294 | { | 1292 | { |
1295 | return true; | 1293 | return true; |
1296 | } | 1294 | } |
1297 | else // close the last opened device | 1295 | else // close the last opened device |
1298 | { | 1296 | { |
1299 | close(); | 1297 | close(); |
1300 | } | 1298 | } |
1301 | } | 1299 | } |
1302 | 1300 | ||
1303 | _name = name; | 1301 | _name = name; |
1304 | 1302 | ||
1305 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); | 1303 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); |
1306 | 1304 | ||
1307 | if ( handle ) | 1305 | if ( handle ) |
1308 | { | 1306 | { |
1309 | odebug << "OPacketCapturer::open(): libpcap opened successfully." << oendl; | 1307 | odebug << "OPacketCapturer::open(): libpcap opened successfully." << oendl; |
1310 | _pch = handle; | 1308 | _pch = handle; |
1311 | _open = true; | 1309 | _open = true; |
1312 | 1310 | ||
1313 | // in case we have an application object, create a socket notifier | 1311 | // in case we have an application object, create a socket notifier |
1314 | if ( qApp ) | 1312 | if ( qApp ) |
1315 | { | 1313 | { |
1316 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 1314 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
1317 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1315 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1318 | } | 1316 | } |
1319 | 1317 | ||
1320 | return true; | 1318 | return true; |
1321 | } | 1319 | } |
1322 | else | 1320 | else |
1323 | { | 1321 | { |
1324 | odebug << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; | 1322 | odebug << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; |
1325 | return false; | 1323 | return false; |
1326 | } | 1324 | } |
1327 | 1325 | ||
1328 | } | 1326 | } |
1329 | 1327 | ||
1330 | 1328 | ||
1331 | bool OPacketCapturer::isOpen() const | 1329 | bool OPacketCapturer::isOpen() const |
1332 | { | 1330 | { |
1333 | return _open; | 1331 | return _open; |
1334 | } | 1332 | } |
1335 | 1333 | ||
1336 | 1334 | ||
1337 | void OPacketCapturer::readyToReceive() | 1335 | void OPacketCapturer::readyToReceive() |
1338 | { | 1336 | { |
1339 | odebug << "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" << oendl; | 1337 | odebug << "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" << oendl; |
1340 | OPacket* p = next(); | 1338 | OPacket* p = next(); |
1341 | emit receivedPacket( p ); | 1339 | emit receivedPacket( p ); |
1342 | // emit is synchronous - packet has been dealt with, now it's safe to delete (if enabled) | 1340 | // emit is synchronous - packet has been dealt with, now it's safe to delete (if enabled) |
1343 | if ( _autodelete ) delete p; | 1341 | if ( _autodelete ) delete p; |
1344 | } | 1342 | } |
1345 | 1343 | ||
1346 | 1344 | ||
1347 | const QMap<QString,int>& OPacketCapturer::statistics() const | 1345 | const QMap<QString,int>& OPacketCapturer::statistics() const |
1348 | { | 1346 | { |
1349 | return _stats; | 1347 | return _stats; |
1350 | } | 1348 | } |
1351 | 1349 | ||
1352 | 1350 | ||
1353 | int OPacketCapturer::snapShot() const | 1351 | int OPacketCapturer::snapShot() const |
1354 | { | 1352 | { |
1355 | return pcap_snapshot( _pch ); | 1353 | return pcap_snapshot( _pch ); |
1356 | } | 1354 | } |
1357 | 1355 | ||
1358 | 1356 | ||
1359 | bool OPacketCapturer::swapped() const | 1357 | bool OPacketCapturer::swapped() const |
1360 | { | 1358 | { |
1361 | return pcap_is_swapped( _pch ); | 1359 | return pcap_is_swapped( _pch ); |
1362 | } | 1360 | } |
1363 | 1361 | ||
1364 | 1362 | ||
1365 | QString OPacketCapturer::version() const | 1363 | QString OPacketCapturer::version() const |
1366 | { | 1364 | { |
1367 | return QString().sprintf( "%d.%d", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); | 1365 | return QString().sprintf( "%d.%d", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); |
1368 | } | 1366 | } |
1369 | 1367 | ||
1370 | } | 1368 | } |
1371 | } | 1369 | } |
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 2dbe030..9e718d5 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -282,452 +282,452 @@ class OWaveLanManagementSSID : public QObject | |||
282 | class OWaveLanManagementRates : public QObject | 282 | class OWaveLanManagementRates : public QObject |
283 | { | 283 | { |
284 | Q_OBJECT | 284 | Q_OBJECT |
285 | 285 | ||
286 | public: | 286 | public: |
287 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); | 287 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); |
288 | virtual ~OWaveLanManagementRates(); | 288 | virtual ~OWaveLanManagementRates(); |
289 | 289 | ||
290 | private: | 290 | private: |
291 | const struct rates_t* _data; | 291 | const struct rates_t* _data; |
292 | class Private; | 292 | class Private; |
293 | Private *d; | 293 | Private *d; |
294 | }; | 294 | }; |
295 | 295 | ||
296 | /*====================================================================================== | 296 | /*====================================================================================== |
297 | * OWaveLanManagementCF | 297 | * OWaveLanManagementCF |
298 | *======================================================================================*/ | 298 | *======================================================================================*/ |
299 | 299 | ||
300 | class OWaveLanManagementCF : public QObject | 300 | class OWaveLanManagementCF : public QObject |
301 | { | 301 | { |
302 | Q_OBJECT | 302 | Q_OBJECT |
303 | 303 | ||
304 | public: | 304 | public: |
305 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); | 305 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); |
306 | virtual ~OWaveLanManagementCF(); | 306 | virtual ~OWaveLanManagementCF(); |
307 | 307 | ||
308 | private: | 308 | private: |
309 | const struct cf_t* _data; | 309 | const struct cf_t* _data; |
310 | class Private; | 310 | class Private; |
311 | Private *d; | 311 | Private *d; |
312 | }; | 312 | }; |
313 | 313 | ||
314 | /*====================================================================================== | 314 | /*====================================================================================== |
315 | * OWaveLanManagementFH | 315 | * OWaveLanManagementFH |
316 | *======================================================================================*/ | 316 | *======================================================================================*/ |
317 | 317 | ||
318 | class OWaveLanManagementFH : public QObject | 318 | class OWaveLanManagementFH : public QObject |
319 | { | 319 | { |
320 | Q_OBJECT | 320 | Q_OBJECT |
321 | 321 | ||
322 | public: | 322 | public: |
323 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); | 323 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); |
324 | virtual ~OWaveLanManagementFH(); | 324 | virtual ~OWaveLanManagementFH(); |
325 | 325 | ||
326 | private: | 326 | private: |
327 | const struct fh_t* _data; | 327 | const struct fh_t* _data; |
328 | class Private; | 328 | class Private; |
329 | Private *d; | 329 | Private *d; |
330 | }; | 330 | }; |
331 | 331 | ||
332 | /*====================================================================================== | 332 | /*====================================================================================== |
333 | * OWaveLanManagementDS | 333 | * OWaveLanManagementDS |
334 | *======================================================================================*/ | 334 | *======================================================================================*/ |
335 | 335 | ||
336 | class OWaveLanManagementDS : public QObject | 336 | class OWaveLanManagementDS : public QObject |
337 | { | 337 | { |
338 | Q_OBJECT | 338 | Q_OBJECT |
339 | 339 | ||
340 | public: | 340 | public: |
341 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); | 341 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); |
342 | virtual ~OWaveLanManagementDS(); | 342 | virtual ~OWaveLanManagementDS(); |
343 | 343 | ||
344 | int channel() const; | 344 | int channel() const; |
345 | 345 | ||
346 | private: | 346 | private: |
347 | const struct ds_t* _data; | 347 | const struct ds_t* _data; |
348 | class Private; | 348 | class Private; |
349 | Private *d; | 349 | Private *d; |
350 | }; | 350 | }; |
351 | 351 | ||
352 | /*====================================================================================== | 352 | /*====================================================================================== |
353 | * OWaveLanManagementTim | 353 | * OWaveLanManagementTim |
354 | *======================================================================================*/ | 354 | *======================================================================================*/ |
355 | 355 | ||
356 | class OWaveLanManagementTim : public QObject | 356 | class OWaveLanManagementTim : public QObject |
357 | { | 357 | { |
358 | Q_OBJECT | 358 | Q_OBJECT |
359 | 359 | ||
360 | public: | 360 | public: |
361 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); | 361 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); |
362 | virtual ~OWaveLanManagementTim(); | 362 | virtual ~OWaveLanManagementTim(); |
363 | 363 | ||
364 | private: | 364 | private: |
365 | const struct tim_t* _data; | 365 | const struct tim_t* _data; |
366 | class Private; | 366 | class Private; |
367 | Private *d; | 367 | Private *d; |
368 | }; | 368 | }; |
369 | 369 | ||
370 | /*====================================================================================== | 370 | /*====================================================================================== |
371 | * OWaveLanManagementIBSS | 371 | * OWaveLanManagementIBSS |
372 | *======================================================================================*/ | 372 | *======================================================================================*/ |
373 | 373 | ||
374 | class OWaveLanManagementIBSS : public QObject | 374 | class OWaveLanManagementIBSS : public QObject |
375 | { | 375 | { |
376 | Q_OBJECT | 376 | Q_OBJECT |
377 | 377 | ||
378 | public: | 378 | public: |
379 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); | 379 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); |
380 | virtual ~OWaveLanManagementIBSS(); | 380 | virtual ~OWaveLanManagementIBSS(); |
381 | 381 | ||
382 | private: | 382 | private: |
383 | const struct ibss_t* _data; | 383 | const struct ibss_t* _data; |
384 | class Private; | 384 | class Private; |
385 | Private *d; | 385 | Private *d; |
386 | }; | 386 | }; |
387 | 387 | ||
388 | /*====================================================================================== | 388 | /*====================================================================================== |
389 | * OWaveLanManagementChallenge | 389 | * OWaveLanManagementChallenge |
390 | *======================================================================================*/ | 390 | *======================================================================================*/ |
391 | 391 | ||
392 | class OWaveLanManagementChallenge : public QObject | 392 | class OWaveLanManagementChallenge : public QObject |
393 | { | 393 | { |
394 | Q_OBJECT | 394 | Q_OBJECT |
395 | 395 | ||
396 | public: | 396 | public: |
397 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); | 397 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); |
398 | virtual ~OWaveLanManagementChallenge(); | 398 | virtual ~OWaveLanManagementChallenge(); |
399 | 399 | ||
400 | private: | 400 | private: |
401 | const struct challenge_t* _data; | 401 | const struct challenge_t* _data; |
402 | class Private; | 402 | class Private; |
403 | Private *d; | 403 | Private *d; |
404 | }; | 404 | }; |
405 | 405 | ||
406 | /*====================================================================================== | 406 | /*====================================================================================== |
407 | * OWaveLanDataPacket - type: data (T_DATA) | 407 | * OWaveLanDataPacket - type: data (T_DATA) |
408 | *======================================================================================*/ | 408 | *======================================================================================*/ |
409 | 409 | ||
410 | class OWaveLanDataPacket : public QObject | 410 | class OWaveLanDataPacket : public QObject |
411 | { | 411 | { |
412 | Q_OBJECT | 412 | Q_OBJECT |
413 | 413 | ||
414 | public: | 414 | public: |
415 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); | 415 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); |
416 | virtual ~OWaveLanDataPacket(); | 416 | virtual ~OWaveLanDataPacket(); |
417 | 417 | ||
418 | private: | 418 | private: |
419 | const struct ieee_802_11_data_header* _header; | 419 | const struct ieee_802_11_data_header* _header; |
420 | class Private; | 420 | class Private; |
421 | Private *d; | 421 | Private *d; |
422 | }; | 422 | }; |
423 | 423 | ||
424 | /*====================================================================================== | 424 | /*====================================================================================== |
425 | * OWaveLanControlPacket - type: control (T_CTRL) | 425 | * OWaveLanControlPacket - type: control (T_CTRL) |
426 | *======================================================================================*/ | 426 | *======================================================================================*/ |
427 | 427 | ||
428 | class OWaveLanControlPacket : public QObject | 428 | class OWaveLanControlPacket : public QObject |
429 | { | 429 | { |
430 | Q_OBJECT | 430 | Q_OBJECT |
431 | 431 | ||
432 | public: | 432 | public: |
433 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); | 433 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); |
434 | virtual ~OWaveLanControlPacket(); | 434 | virtual ~OWaveLanControlPacket(); |
435 | 435 | ||
436 | QString controlType() const; | 436 | QString controlType() const; |
437 | 437 | ||
438 | private: | 438 | private: |
439 | const struct ieee_802_11_control_header* _header; | 439 | const struct ieee_802_11_control_header* _header; |
440 | class Private; | 440 | class Private; |
441 | Private *d; | 441 | Private *d; |
442 | }; | 442 | }; |
443 | 443 | ||
444 | /*====================================================================================== | 444 | /*====================================================================================== |
445 | * OLLCPacket - IEEE 802.2 Link Level Control | 445 | * OLLCPacket - IEEE 802.2 Link Level Control |
446 | *======================================================================================*/ | 446 | *======================================================================================*/ |
447 | 447 | ||
448 | class OLLCPacket : public QObject | 448 | class OLLCPacket : public QObject |
449 | { | 449 | { |
450 | Q_OBJECT | 450 | Q_OBJECT |
451 | 451 | ||
452 | public: | 452 | public: |
453 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); | 453 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); |
454 | virtual ~OLLCPacket(); | 454 | virtual ~OLLCPacket(); |
455 | 455 | ||
456 | private: | 456 | private: |
457 | const struct ieee_802_11_802_2_header* _header; | 457 | const struct ieee_802_11_802_2_header* _header; |
458 | class Private; | 458 | class Private; |
459 | Private *d; | 459 | Private *d; |
460 | }; | 460 | }; |
461 | 461 | ||
462 | /*====================================================================================== | 462 | /*====================================================================================== |
463 | * OIPPacket | 463 | * OIPPacket |
464 | *======================================================================================*/ | 464 | *======================================================================================*/ |
465 | 465 | ||
466 | class OIPPacket : public QObject | 466 | class OIPPacket : public QObject |
467 | { | 467 | { |
468 | Q_OBJECT | 468 | Q_OBJECT |
469 | 469 | ||
470 | public: | 470 | public: |
471 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); | 471 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); |
472 | virtual ~OIPPacket(); | 472 | virtual ~OIPPacket(); |
473 | 473 | ||
474 | QHostAddress fromIPAddress() const; | 474 | QHostAddress fromIPAddress() const; |
475 | QHostAddress toIPAddress() const; | 475 | QHostAddress toIPAddress() const; |
476 | 476 | ||
477 | int tos() const; | 477 | int tos() const; |
478 | int len() const; | 478 | int len() const; |
479 | int id() const; | 479 | int id() const; |
480 | int offset() const; | 480 | int offset() const; |
481 | int ttl() const; | 481 | int ttl() const; |
482 | int protocol() const; | 482 | int protocol() const; |
483 | int checksum() const; | 483 | int checksum() const; |
484 | 484 | ||
485 | private: | 485 | private: |
486 | const struct iphdr* _iphdr; | 486 | const struct iphdr* _iphdr; |
487 | class Private; | 487 | class Private; |
488 | Private *d; | 488 | Private *d; |
489 | }; | 489 | }; |
490 | 490 | ||
491 | /*====================================================================================== | 491 | /*====================================================================================== |
492 | * OARPPacket | 492 | * OARPPacket |
493 | *======================================================================================*/ | 493 | *======================================================================================*/ |
494 | 494 | ||
495 | class OARPPacket : public QObject | 495 | class OARPPacket : public QObject |
496 | { | 496 | { |
497 | Q_OBJECT | 497 | Q_OBJECT |
498 | 498 | ||
499 | public: | 499 | public: |
500 | OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); | 500 | OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); |
501 | virtual ~OARPPacket(); | 501 | virtual ~OARPPacket(); |
502 | 502 | ||
503 | QHostAddress senderIPV4Address() const; | 503 | QHostAddress senderIPV4Address() const; |
504 | OMacAddress senderMacAddress() const; | 504 | OMacAddress senderMacAddress() const; |
505 | QHostAddress targetIPV4Address() const; | 505 | QHostAddress targetIPV4Address() const; |
506 | OMacAddress targetMacAddress() const; | 506 | OMacAddress targetMacAddress() const; |
507 | 507 | ||
508 | //int type() const; | 508 | //int type() const; |
509 | QString type() const; | 509 | QString type() const; |
510 | 510 | ||
511 | private: | 511 | private: |
512 | const struct myarphdr* _arphdr; | 512 | const struct myarphdr* _arphdr; |
513 | class Private; | 513 | class Private; |
514 | Private *d; | 514 | Private *d; |
515 | }; | 515 | }; |
516 | 516 | ||
517 | /*====================================================================================== | 517 | /*====================================================================================== |
518 | * OUDPPacket | 518 | * OUDPPacket |
519 | *======================================================================================*/ | 519 | *======================================================================================*/ |
520 | 520 | ||
521 | class OUDPPacket : public QObject | 521 | class OUDPPacket : public QObject |
522 | { | 522 | { |
523 | Q_OBJECT | 523 | Q_OBJECT |
524 | 524 | ||
525 | public: | 525 | public: |
526 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); | 526 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); |
527 | virtual ~OUDPPacket(); | 527 | virtual ~OUDPPacket(); |
528 | 528 | ||
529 | int fromPort() const; | 529 | int fromPort() const; |
530 | int toPort() const; | 530 | int toPort() const; |
531 | int length() const; | 531 | int length() const; |
532 | int checksum() const; | 532 | int checksum() const; |
533 | 533 | ||
534 | private: | 534 | private: |
535 | const struct udphdr* _udphdr; | 535 | const struct udphdr* _udphdr; |
536 | class Private; | 536 | class Private; |
537 | Private *d; | 537 | Private *d; |
538 | }; | 538 | }; |
539 | 539 | ||
540 | /*====================================================================================== | 540 | /*====================================================================================== |
541 | * ODHCPPacket | 541 | * ODHCPPacket |
542 | *======================================================================================*/ | 542 | *======================================================================================*/ |
543 | 543 | ||
544 | class ODHCPPacket : public QObject | 544 | class ODHCPPacket : public QObject |
545 | { | 545 | { |
546 | Q_OBJECT | 546 | Q_OBJECT |
547 | 547 | ||
548 | public: | 548 | public: |
549 | ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); | 549 | ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); |
550 | virtual ~ODHCPPacket(); | 550 | virtual ~ODHCPPacket(); |
551 | 551 | ||
552 | QHostAddress clientAddress() const; | 552 | QHostAddress clientAddress() const; |
553 | QHostAddress yourAddress() const; | 553 | QHostAddress yourAddress() const; |
554 | QHostAddress serverAddress() const; | 554 | QHostAddress serverAddress() const; |
555 | QHostAddress relayAddress() const; | 555 | QHostAddress relayAddress() const; |
556 | 556 | ||
557 | OMacAddress clientMacAddress() const; | 557 | OMacAddress clientMacAddress() const; |
558 | 558 | ||
559 | bool isRequest() const; | 559 | bool isRequest() const; |
560 | bool isReply() const; | 560 | bool isReply() const; |
561 | QString type() const; | 561 | QString type() const; |
562 | 562 | ||
563 | private: | 563 | private: |
564 | const struct dhcp_packet* _dhcphdr; | 564 | const struct dhcp_packet* _dhcphdr; |
565 | unsigned char _type; | 565 | unsigned char _type; |
566 | class Private; | 566 | class Private; |
567 | Private *d; | 567 | Private *d; |
568 | }; | 568 | }; |
569 | 569 | ||
570 | /*====================================================================================== | 570 | /*====================================================================================== |
571 | * OTCPPacket | 571 | * OTCPPacket |
572 | *======================================================================================*/ | 572 | *======================================================================================*/ |
573 | 573 | ||
574 | class OTCPPacket : public QObject | 574 | class OTCPPacket : public QObject |
575 | { | 575 | { |
576 | Q_OBJECT | 576 | Q_OBJECT |
577 | 577 | ||
578 | public: | 578 | public: |
579 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); | 579 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); |
580 | virtual ~OTCPPacket(); | 580 | virtual ~OTCPPacket(); |
581 | 581 | ||
582 | int fromPort() const; | 582 | int fromPort() const; |
583 | int toPort() const; | 583 | int toPort() const; |
584 | int seq() const; | 584 | int seq() const; |
585 | int ack() const; | 585 | int ack() const; |
586 | int window() const; | 586 | int window() const; |
587 | int checksum() const; | 587 | int checksum() const; |
588 | 588 | ||
589 | private: | 589 | private: |
590 | const struct tcphdr* _tcphdr; | 590 | const struct tcphdr* _tcphdr; |
591 | class Private; | 591 | class Private; |
592 | Private *d; | 592 | Private *d; |
593 | }; | 593 | }; |
594 | 594 | ||
595 | 595 | ||
596 | /*====================================================================================== | 596 | /*====================================================================================== |
597 | * OPacketCapturer | 597 | * OPacketCapturer |
598 | *======================================================================================*/ | 598 | *======================================================================================*/ |
599 | 599 | ||
600 | /** | 600 | /** |
601 | * @brief A class based wrapper for network packet capturing. | 601 | * @brief A class based wrapper for network packet capturing. |
602 | * | 602 | * |
603 | * This class is the base of a high-level interface to the well known packet capturing | 603 | * This class is the base of a high-level interface to the well known packet capturing |
604 | * library libpcap. | 604 | * library libpcap. |
605 | * @see http://tcpdump.org | 605 | * @see http://tcpdump.org |
606 | */ | 606 | */ |
607 | class OPacketCapturer : public QObject | 607 | class OPacketCapturer : public QObject |
608 | { | 608 | { |
609 | Q_OBJECT | 609 | Q_OBJECT |
610 | 610 | ||
611 | public: | 611 | public: |
612 | /** | 612 | /** |
613 | * Constructor. | 613 | * Constructor. |
614 | */ | 614 | */ |
615 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); | 615 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); |
616 | /** | 616 | /** |
617 | * Destructor. | 617 | * Destructor. |
618 | */ | 618 | */ |
619 | ~OPacketCapturer(); | 619 | ~OPacketCapturer(); |
620 | /** | 620 | /** |
621 | * Set the packet capturer to use blocking or non-blocking IO. This can be useful when | 621 | * Set the packet capturer to use blocking or non-blocking IO. This can be useful when |
622 | * not using the socket notifier, e.g. without an application object. | 622 | * not using the socket notifier, e.g. without an application object. |
623 | */ | 623 | */ |
624 | void setBlocking( bool ); | 624 | void setBlocking( bool ); |
625 | /** | 625 | /** |
626 | * @returns true if the packet capturer uses blocking IO calls. | 626 | * @returns true if the packet capturer uses blocking IO calls. |
627 | */ | 627 | */ |
628 | bool blocking() const; | 628 | bool blocking() const; |
629 | /** | 629 | /** |
630 | * Close the packet capturer. This is automatically done in the destructor. | 630 | * Close the packet capturer. This is automatically done in the destructor. |
631 | */ | 631 | */ |
632 | void close(); | 632 | void close(); |
633 | /** | 633 | /** |
634 | * Close the output capture file. | 634 | * Close the output capture file. |
635 | */ | 635 | */ |
636 | void closeDumpFile(); | 636 | void closeDumpFile(); |
637 | /** | 637 | /** |
638 | * @returns the data link type. | 638 | * @returns the data link type. |
639 | * @see <pcap.h> for possible values. | 639 | * @see <pcap.h> for possible values. |
640 | */ | 640 | */ |
641 | int dataLink() const; | 641 | int dataLink() const; |
642 | /** | 642 | /** |
643 | * Dump a packet to the output capture file. | 643 | * Dump a packet to the output capture file. |
644 | */ | 644 | */ |
645 | void dump( OPacket* ); | 645 | void dump( OPacket* ); |
646 | /** | 646 | /** |
647 | * @returns the file descriptor of the packet capturer. This is only useful, if | 647 | * @returns the file descriptor of the packet capturer. This is only useful, if |
648 | * not using the socket notifier, e.g. without an application object. | 648 | * not using the socket notifier, e.g. without an application object. |
649 | */ | 649 | */ |
650 | int fileno() const; | 650 | int fileno() const; |
651 | /** | 651 | /** |
652 | * @returns the next @ref OPacket from the packet capturer. | 652 | * @returns the next @ref OPacket from the packet capturer. |
653 | * @note If blocking mode is true then this call might block. | 653 | * @note If blocking mode is true then this call might block. |
654 | */ | 654 | */ |
655 | OPacket* next(); | 655 | OPacket* next(); |
656 | /** | 656 | /** |
657 | * @returns the next @ref OPacket from the packet capturer, if | 657 | * @returns the next @ref OPacket from the packet capturer, if |
658 | * one arrives within @a time milliseconds. | 658 | * one arrives within @a time milliseconds. |
659 | */ | 659 | */ |
660 | OPacket* next( int time ); | 660 | OPacket* next( int time ); |
661 | /** | 661 | /** |
662 | * Open the packet capturer to capture packets in live-mode from @a interface. | 662 | * Open the packet capturer to capture packets in live-mode from @a interface. |
663 | */ | 663 | */ |
664 | bool open( const QString& interface ); | 664 | bool open( const QString& interface ); |
665 | /** | 665 | /** |
666 | * Open the packet capturer to capture packets in offline-mode from @a file. | 666 | * Open the packet capturer to capture packets in offline-mode from @a filename. |
667 | */ | 667 | */ |
668 | bool open( const QFile& file ); | 668 | bool openCaptureFile( const QString& filename ); |
669 | /** | 669 | /** |
670 | * Open a prerecorded tcpdump compatible capture file for use with @ref dump() | 670 | * Open a prerecorded tcpdump compatible capture file for use with @ref dump() |
671 | */ | 671 | */ |
672 | bool openDumpFile( const QString& filename ); | 672 | bool openDumpFile( const QString& filename ); |
673 | /** | 673 | /** |
674 | * @returns true if the packet capturer is open | 674 | * @returns true if the packet capturer is open |
675 | */ | 675 | */ |
676 | bool isOpen() const; | 676 | bool isOpen() const; |
677 | /** | 677 | /** |
678 | * @returns the snapshot length of this packet capturer | 678 | * @returns the snapshot length of this packet capturer |
679 | */ | 679 | */ |
680 | int snapShot() const; | 680 | int snapShot() const; |
681 | /** | 681 | /** |
682 | * @returns true if the input capture file has a different byte-order | 682 | * @returns true if the input capture file has a different byte-order |
683 | * than the byte-order of the running system. | 683 | * than the byte-order of the running system. |
684 | */ | 684 | */ |
685 | bool swapped() const; | 685 | bool swapped() const; |
686 | /** | 686 | /** |
687 | * @returns the libpcap version string used to write the input capture file. | 687 | * @returns the libpcap version string used to write the input capture file. |
688 | */ | 688 | */ |
689 | QString version() const; | 689 | QString version() const; |
690 | /** | 690 | /** |
691 | * @returns the packet statistic database. | 691 | * @returns the packet statistic database. |
692 | * @see QMap | 692 | * @see QMap |
693 | */ | 693 | */ |
694 | const QMap<QString,int>& statistics() const; | 694 | const QMap<QString,int>& statistics() const; |
695 | /** | 695 | /** |
696 | * Enable or disable the auto-delete option. | 696 | * Enable or disable the auto-delete option. |
697 | * If auto-delete is enabled, then the packet capturer will delete a packet right | 697 | * If auto-delete is enabled, then the packet capturer will delete a packet right |
698 | * after it has been emit'ted. This is the default, which is useful if the packet | 698 | * after it has been emit'ted. This is the default, which is useful if the packet |
699 | * capturer has the only reference to the packets. If you pass the packet for adding | 699 | * capturer has the only reference to the packets. If you pass the packet for adding |
700 | * into a collection or do processing after the SLOT, the auto delete must be disabled. | 700 | * into a collection or do processing after the SLOT, the auto delete must be disabled. |
701 | */ | 701 | */ |
702 | void setAutoDelete( bool enable ); | 702 | void setAutoDelete( bool enable ); |
703 | /** | 703 | /** |
704 | * @returns the auto-delete value. | 704 | * @returns the auto-delete value. |
705 | */ | 705 | */ |
706 | bool autoDelete() const; | 706 | bool autoDelete() const; |
707 | 707 | ||
708 | signals: | 708 | signals: |
709 | /** | 709 | /** |
710 | * This signal is emitted, when a packet has been received. | 710 | * This signal is emitted, when a packet has been received. |
711 | */ | 711 | */ |
712 | void receivedPacket( Opie::Net::OPacket* ); | 712 | void receivedPacket( Opie::Net::OPacket* ); |
713 | 713 | ||
714 | protected slots: | 714 | protected slots: |
715 | void readyToReceive(); | 715 | void readyToReceive(); |
716 | 716 | ||
717 | protected: | 717 | protected: |
718 | QString _name; // devicename | 718 | QString _name; // devicename |
719 | bool _open; // check this before doing pcap calls | 719 | bool _open; // check this before doing pcap calls |
720 | pcap_t* _pch; // pcap library handle | 720 | pcap_t* _pch; // pcap library handle |
721 | pcap_dumper_t* _pcd; // pcap dumper handle | 721 | pcap_dumper_t* _pcd; // pcap dumper handle |
722 | QSocketNotifier* _sn; // socket notifier for main loop | 722 | QSocketNotifier* _sn; // socket notifier for main loop |
723 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap | 723 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap |
724 | QMap<QString, int> _stats; // statistics; | 724 | QMap<QString, int> _stats; // statistics; |
725 | bool _autodelete; // if we auto delete packets after emit | 725 | bool _autodelete; // if we auto delete packets after emit |
726 | class Private; // Private Forward declaration | 726 | class Private; // Private Forward declaration |
727 | Private *d; // if we need to add data | 727 | Private *d; // if we need to add data |
728 | }; | 728 | }; |
729 | } | 729 | } |
730 | } | 730 | } |
731 | 731 | ||
732 | #endif // OPCAP_H | 732 | #endif // OPCAP_H |
733 | 733 | ||