author | mickeyl <mickeyl> | 2004-05-02 18:14:46 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-05-02 18:14:46 (UTC) |
commit | 3e8fab5fddb3a38d93eaca1a8d69d8f668c7cd99 (patch) (unidiff) | |
tree | 4ea10a8f334f5af1133c9e762462701fb38b4f76 | |
parent | 1ddcf3566b3339bb649b07b64bd5802b735f37ba (diff) | |
download | opie-3e8fab5fddb3a38d93eaca1a8d69d8f668c7cd99.zip opie-3e8fab5fddb3a38d93eaca1a8d69d8f668c7cd99.tar.gz opie-3e8fab5fddb3a38d93eaca1a8d69d8f668c7cd99.tar.bz2 |
fix one odebug warning
-rw-r--r-- | libopie2/opienet/opcap.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index a9dc577..8ec4f47 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -1,1231 +1,1231 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "udp_ports.h" | 31 | #include "udp_ports.h" |
32 | #include "opcap.h" | 32 | #include "opcap.h" |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <opie2/odebug.h> | 35 | #include <opie2/odebug.h> |
36 | using namespace Opie::Core; | 36 | using namespace Opie::Core; |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) | 39 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) |
40 | #include <qsocketnotifier.h> | 40 | #include <qsocketnotifier.h> |
41 | #include <qobjectlist.h> | 41 | #include <qobjectlist.h> |
42 | 42 | ||
43 | /* STD */ | 43 | /* STD */ |
44 | #include <sys/time.h> | 44 | #include <sys/time.h> |
45 | #include <sys/types.h> | 45 | #include <sys/types.h> |
46 | #include <assert.h> | 46 | #include <assert.h> |
47 | #include <unistd.h> | 47 | #include <unistd.h> |
48 | #include <string.h> | 48 | #include <string.h> |
49 | 49 | ||
50 | namespace Opie { | 50 | namespace Opie { |
51 | namespace Net { | 51 | namespace Net { |
52 | 52 | ||
53 | /*====================================================================================== | 53 | /*====================================================================================== |
54 | * OPacket | 54 | * OPacket |
55 | *======================================================================================*/ | 55 | *======================================================================================*/ |
56 | 56 | ||
57 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) | 57 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) |
58 | :QObject( parent, "Generic" ), _hdr( header ), _data( 0 ) | 58 | :QObject( parent, "Generic" ), _hdr( header ), _data( 0 ) |
59 | { | 59 | { |
60 | 60 | ||
61 | _data = new unsigned char[ header.len ]; | 61 | _data = new unsigned char[ header.len ]; |
62 | assert( _data ); | 62 | assert( _data ); |
63 | memcpy( const_cast<unsigned char*>(_data), data, header.len ); | 63 | memcpy( const_cast<unsigned char*>(_data), data, header.len ); |
64 | // We have to copy the data structure here, because the 'data' pointer handed by libpcap | 64 | // We have to copy the data structure here, because the 'data' pointer handed by libpcap |
65 | // points to an internal region which is reused by lipcap. | 65 | // points to an internal region which is reused by lipcap. |
66 | odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl; | 66 | odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl; |
67 | _end = (unsigned char*) _data + header.len; | 67 | _end = (unsigned char*) _data + header.len; |
68 | 68 | ||
69 | switch ( datalink ) | 69 | switch ( datalink ) |
70 | { | 70 | { |
71 | case DLT_EN10MB: | 71 | case DLT_EN10MB: |
72 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; | 72 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; |
73 | new OEthernetPacket( _end, (const struct ether_header*) _data, this ); | 73 | new OEthernetPacket( _end, (const struct ether_header*) _data, this ); |
74 | break; | 74 | break; |
75 | 75 | ||
76 | case DLT_IEEE802_11: | 76 | case DLT_IEEE802_11: |
77 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; | 77 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; |
78 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this ); | 78 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this ); |
79 | break; | 79 | break; |
80 | 80 | ||
81 | case DLT_PRISM_HEADER: | 81 | case DLT_PRISM_HEADER: |
82 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; | 82 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; |
83 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this ); | 83 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this ); |
84 | break; | 84 | break; |
85 | 85 | ||
86 | default: | 86 | default: |
87 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; | 87 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
92 | OPacket::~OPacket() | 92 | OPacket::~OPacket() |
93 | { | 93 | { |
94 | odebug << "~OPacket( " << name() << " )" << oendl; | 94 | odebug << "~OPacket( " << name() << " )" << oendl; |
95 | delete _data; | 95 | delete _data; |
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
99 | timevalstruct OPacket::timeval() const | 99 | timevalstruct OPacket::timeval() const |
100 | { | 100 | { |
101 | return _hdr.ts; | 101 | return _hdr.ts; |
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
105 | int OPacket::caplen() const | 105 | int OPacket::caplen() const |
106 | { | 106 | { |
107 | return _hdr.caplen; | 107 | return _hdr.caplen; |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) | 111 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) |
112 | { | 112 | { |
113 | if (!l) return; | 113 | if (!l) return; |
114 | QObject* o = l->first(); | 114 | QObject* o = l->first(); |
115 | while ( o ) | 115 | while ( o ) |
116 | { | 116 | { |
117 | stats[o->name()]++; | 117 | stats[o->name()]++; |
118 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); | 118 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); |
119 | o = l->next(); | 119 | o = l->next(); |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
124 | QString OPacket::dumpStructure() const | 124 | QString OPacket::dumpStructure() const |
125 | { | 125 | { |
126 | return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; | 126 | return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | QString OPacket::_dumpStructure( QObjectList* l ) const | 130 | QString OPacket::_dumpStructure( QObjectList* l ) const |
131 | { | 131 | { |
132 | if (!l) return QString::null; | 132 | if (!l) return QString::null; |
133 | QObject* o = l->first(); | 133 | QObject* o = l->first(); |
134 | QString str(" "); | 134 | QString str(" "); |
135 | 135 | ||
136 | while ( o ) | 136 | while ( o ) |
137 | { | 137 | { |
138 | str.append( o->name() ); | 138 | str.append( o->name() ); |
139 | str.append( " |" ); | 139 | str.append( " |" ); |
140 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); | 140 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); |
141 | o = l->next(); | 141 | o = l->next(); |
142 | } | 142 | } |
143 | return str; | 143 | return str; |
144 | } | 144 | } |
145 | 145 | ||
146 | QString OPacket::dump( int bpl ) const | 146 | QString OPacket::dump( int bpl ) const |
147 | { | 147 | { |
148 | static int index = 0; | 148 | static int index = 0; |
149 | index++; | 149 | index++; |
150 | int len = _hdr.caplen; | 150 | int len = _hdr.caplen; |
151 | QString str; | 151 | QString str; |
152 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); | 152 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); |
153 | str.append( "0000: " ); | 153 | str.append( "0000: " ); |
154 | QString tmp; | 154 | QString tmp; |
155 | QString bytes; | 155 | QString bytes; |
156 | QString chars; | 156 | QString chars; |
157 | 157 | ||
158 | for ( int i = 0; i < len; ++i ) | 158 | for ( int i = 0; i < len; ++i ) |
159 | { | 159 | { |
160 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); | 160 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); |
161 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); | 161 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); |
162 | else chars.append( '.' ); | 162 | else chars.append( '.' ); |
163 | 163 | ||
164 | if ( !((i+1) % bpl) ) | 164 | if ( !((i+1) % bpl) ) |
165 | { | 165 | { |
166 | str.append( bytes ); | 166 | str.append( bytes ); |
167 | str.append( ' ' ); | 167 | str.append( ' ' ); |
168 | str.append( chars ); | 168 | str.append( chars ); |
169 | str.append( '\n' ); | 169 | str.append( '\n' ); |
170 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); | 170 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); |
171 | bytes = ""; | 171 | bytes = ""; |
172 | chars = ""; | 172 | chars = ""; |
173 | } | 173 | } |
174 | 174 | ||
175 | } | 175 | } |
176 | if ( (len % bpl) ) | 176 | if ( (len % bpl) ) |
177 | { | 177 | { |
178 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); | 178 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); |
179 | str.append( chars ); | 179 | str.append( chars ); |
180 | } | 180 | } |
181 | str.append( '\n' ); | 181 | str.append( '\n' ); |
182 | return str; | 182 | return str; |
183 | } | 183 | } |
184 | 184 | ||
185 | 185 | ||
186 | int OPacket::len() const | 186 | int OPacket::len() const |
187 | { | 187 | { |
188 | return _hdr.len; | 188 | return _hdr.len; |
189 | } | 189 | } |
190 | 190 | ||
191 | 191 | ||
192 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) | 192 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) |
193 | { | 193 | { |
194 | s << p.dumpStructure(); | 194 | s << p.dumpStructure(); |
195 | } | 195 | } |
196 | 196 | ||
197 | 197 | ||
198 | /*====================================================================================== | 198 | /*====================================================================================== |
199 | * OEthernetPacket | 199 | * OEthernetPacket |
200 | *======================================================================================*/ | 200 | *======================================================================================*/ |
201 | 201 | ||
202 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) | 202 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
203 | :QObject( parent, "Ethernet" ), _ether( data ) | 203 | :QObject( parent, "Ethernet" ), _ether( data ) |
204 | { | 204 | { |
205 | 205 | ||
206 | odebug << "Source = " << sourceAddress().toString(); | 206 | odebug << "Source = " << sourceAddress().toString() << oendl; |
207 | odebug << "Destination = " << destinationAddress().toString(); | 207 | odebug << "Destination = " << destinationAddress().toString() << oendl; |
208 | 208 | ||
209 | if ( sourceAddress() == OMacAddress::broadcast ) | 209 | if ( sourceAddress() == OMacAddress::broadcast ) |
210 | odebug << "Source is broadcast address" << oendl; | 210 | odebug << "Source is broadcast address" << oendl; |
211 | if ( destinationAddress() == OMacAddress::broadcast ) | 211 | if ( destinationAddress() == OMacAddress::broadcast ) |
212 | odebug << "Destination is broadcast address" << oendl; | 212 | odebug << "Destination is broadcast address" << oendl; |
213 | 213 | ||
214 | switch ( type() ) | 214 | switch ( type() ) |
215 | { | 215 | { |
216 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 216 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
217 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 217 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
218 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } | 218 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } |
219 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; | 219 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; |
220 | } | 220 | } |
221 | 221 | ||
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | OEthernetPacket::~OEthernetPacket() | 225 | OEthernetPacket::~OEthernetPacket() |
226 | { | 226 | { |
227 | } | 227 | } |
228 | 228 | ||
229 | 229 | ||
230 | OMacAddress OEthernetPacket::sourceAddress() const | 230 | OMacAddress OEthernetPacket::sourceAddress() const |
231 | { | 231 | { |
232 | return OMacAddress( _ether->ether_shost ); | 232 | return OMacAddress( _ether->ether_shost ); |
233 | } | 233 | } |
234 | 234 | ||
235 | 235 | ||
236 | OMacAddress OEthernetPacket::destinationAddress() const | 236 | OMacAddress OEthernetPacket::destinationAddress() const |
237 | { | 237 | { |
238 | return OMacAddress( _ether->ether_dhost ); | 238 | return OMacAddress( _ether->ether_dhost ); |
239 | } | 239 | } |
240 | 240 | ||
241 | int OEthernetPacket::type() const | 241 | int OEthernetPacket::type() const |
242 | { | 242 | { |
243 | return ntohs( _ether->ether_type ); | 243 | return ntohs( _ether->ether_type ); |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
247 | /*====================================================================================== | 247 | /*====================================================================================== |
248 | * OIPPacket | 248 | * OIPPacket |
249 | *======================================================================================*/ | 249 | *======================================================================================*/ |
250 | 250 | ||
251 | 251 | ||
252 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) | 252 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
253 | :QObject( parent, "IP" ), _iphdr( data ) | 253 | :QObject( parent, "IP" ), _iphdr( data ) |
254 | { | 254 | { |
255 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; | 255 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; |
256 | 256 | ||
257 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; | 257 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; |
258 | odebug << " toAddress = " << toIPAddress().toString() << oendl; | 258 | odebug << " toAddress = " << toIPAddress().toString() << oendl; |
259 | 259 | ||
260 | switch ( protocol() ) | 260 | switch ( protocol() ) |
261 | { | 261 | { |
262 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; | 262 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
263 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; | 263 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
264 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; | 264 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; |
265 | } | 265 | } |
266 | 266 | ||
267 | } | 267 | } |
268 | 268 | ||
269 | OIPPacket::~OIPPacket() | 269 | OIPPacket::~OIPPacket() |
270 | { | 270 | { |
271 | } | 271 | } |
272 | 272 | ||
273 | 273 | ||
274 | QHostAddress OIPPacket::fromIPAddress() const | 274 | QHostAddress OIPPacket::fromIPAddress() const |
275 | { | 275 | { |
276 | return EXTRACT_32BITS( &_iphdr->saddr ); | 276 | return EXTRACT_32BITS( &_iphdr->saddr ); |
277 | } | 277 | } |
278 | 278 | ||
279 | 279 | ||
280 | QHostAddress OIPPacket::toIPAddress() const | 280 | QHostAddress OIPPacket::toIPAddress() const |
281 | { | 281 | { |
282 | return EXTRACT_32BITS( &_iphdr->saddr ); | 282 | return EXTRACT_32BITS( &_iphdr->saddr ); |
283 | } | 283 | } |
284 | 284 | ||
285 | 285 | ||
286 | int OIPPacket::tos() const | 286 | int OIPPacket::tos() const |
287 | { | 287 | { |
288 | return _iphdr->tos; | 288 | return _iphdr->tos; |
289 | } | 289 | } |
290 | 290 | ||
291 | 291 | ||
292 | int OIPPacket::len() const | 292 | int OIPPacket::len() const |
293 | { | 293 | { |
294 | return EXTRACT_16BITS( &_iphdr->tot_len ); | 294 | return EXTRACT_16BITS( &_iphdr->tot_len ); |
295 | } | 295 | } |
296 | 296 | ||
297 | 297 | ||
298 | int OIPPacket::id() const | 298 | int OIPPacket::id() const |
299 | { | 299 | { |
300 | return EXTRACT_16BITS( &_iphdr->id ); | 300 | return EXTRACT_16BITS( &_iphdr->id ); |
301 | } | 301 | } |
302 | 302 | ||
303 | 303 | ||
304 | int OIPPacket::offset() const | 304 | int OIPPacket::offset() const |
305 | { | 305 | { |
306 | return EXTRACT_16BITS( &_iphdr->frag_off ); | 306 | return EXTRACT_16BITS( &_iphdr->frag_off ); |
307 | } | 307 | } |
308 | 308 | ||
309 | 309 | ||
310 | int OIPPacket::ttl() const | 310 | int OIPPacket::ttl() const |
311 | { | 311 | { |
312 | return _iphdr->ttl; | 312 | return _iphdr->ttl; |
313 | } | 313 | } |
314 | 314 | ||
315 | 315 | ||
316 | int OIPPacket::protocol() const | 316 | int OIPPacket::protocol() const |
317 | { | 317 | { |
318 | return _iphdr->protocol; | 318 | return _iphdr->protocol; |
319 | } | 319 | } |
320 | 320 | ||
321 | 321 | ||
322 | int OIPPacket::checksum() const | 322 | int OIPPacket::checksum() const |
323 | { | 323 | { |
324 | return EXTRACT_16BITS( &_iphdr->check ); | 324 | return EXTRACT_16BITS( &_iphdr->check ); |
325 | } | 325 | } |
326 | 326 | ||
327 | /*====================================================================================== | 327 | /*====================================================================================== |
328 | * OARPPacket | 328 | * OARPPacket |
329 | *======================================================================================*/ | 329 | *======================================================================================*/ |
330 | 330 | ||
331 | 331 | ||
332 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) | 332 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) |
333 | :QObject( parent, "ARP" ), _arphdr( data ) | 333 | :QObject( parent, "ARP" ), _arphdr( data ) |
334 | { | 334 | { |
335 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; | 335 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; |
336 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; | 336 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; |
337 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; | 337 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; |
338 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; | 338 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; |
339 | } | 339 | } |
340 | 340 | ||
341 | 341 | ||
342 | OARPPacket::~OARPPacket() | 342 | OARPPacket::~OARPPacket() |
343 | { | 343 | { |
344 | } | 344 | } |
345 | 345 | ||
346 | 346 | ||
347 | QString OARPPacket::type() const | 347 | QString OARPPacket::type() const |
348 | { | 348 | { |
349 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) | 349 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) |
350 | { | 350 | { |
351 | case 1: return "REQUEST"; | 351 | case 1: return "REQUEST"; |
352 | case 2: return "REPLY"; | 352 | case 2: return "REPLY"; |
353 | case 3: return "RREQUEST"; | 353 | case 3: return "RREQUEST"; |
354 | case 4: return "RREPLY"; | 354 | case 4: return "RREPLY"; |
355 | case 8: return "InREQUEST"; | 355 | case 8: return "InREQUEST"; |
356 | case 9: return "InREPLY"; | 356 | case 9: return "InREPLY"; |
357 | case 10: return "NAK"; | 357 | case 10: return "NAK"; |
358 | default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; | 358 | default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; |
359 | } | 359 | } |
360 | } | 360 | } |
361 | 361 | ||
362 | 362 | ||
363 | QHostAddress OARPPacket::senderIPV4Address() const | 363 | QHostAddress OARPPacket::senderIPV4Address() const |
364 | { | 364 | { |
365 | return EXTRACT_32BITS( &_arphdr->ar_sip ); | 365 | return EXTRACT_32BITS( &_arphdr->ar_sip ); |
366 | } | 366 | } |
367 | 367 | ||
368 | 368 | ||
369 | QHostAddress OARPPacket::targetIPV4Address() const | 369 | QHostAddress OARPPacket::targetIPV4Address() const |
370 | { | 370 | { |
371 | return EXTRACT_32BITS( &_arphdr->ar_tip ); | 371 | return EXTRACT_32BITS( &_arphdr->ar_tip ); |
372 | } | 372 | } |
373 | 373 | ||
374 | 374 | ||
375 | OMacAddress OARPPacket::senderMacAddress() const | 375 | OMacAddress OARPPacket::senderMacAddress() const |
376 | { | 376 | { |
377 | return OMacAddress( _arphdr->ar_sha ); | 377 | return OMacAddress( _arphdr->ar_sha ); |
378 | } | 378 | } |
379 | 379 | ||
380 | 380 | ||
381 | OMacAddress OARPPacket::targetMacAddress() const | 381 | OMacAddress OARPPacket::targetMacAddress() const |
382 | { | 382 | { |
383 | return OMacAddress( _arphdr->ar_tha ); | 383 | return OMacAddress( _arphdr->ar_tha ); |
384 | } | 384 | } |
385 | 385 | ||
386 | 386 | ||
387 | /*====================================================================================== | 387 | /*====================================================================================== |
388 | * OUDPPacket | 388 | * OUDPPacket |
389 | *======================================================================================*/ | 389 | *======================================================================================*/ |
390 | 390 | ||
391 | 391 | ||
392 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) | 392 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) |
393 | :QObject( parent, "UDP" ), _udphdr( data ) | 393 | :QObject( parent, "UDP" ), _udphdr( data ) |
394 | 394 | ||
395 | { | 395 | { |
396 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; | 396 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; |
397 | odebug << "fromPort = " << fromPort() << oendl; | 397 | odebug << "fromPort = " << fromPort() << oendl; |
398 | odebug << " toPort = " << toPort() << oendl; | 398 | odebug << " toPort = " << toPort() << oendl; |
399 | 399 | ||
400 | // TODO: Make this a case or a hash if we know more udp protocols | 400 | // TODO: Make this a case or a hash if we know more udp protocols |
401 | 401 | ||
402 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || | 402 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || |
403 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) | 403 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) |
404 | { | 404 | { |
405 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; | 405 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; |
406 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); | 406 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); |
407 | } | 407 | } |
408 | } | 408 | } |
409 | 409 | ||
410 | 410 | ||
411 | OUDPPacket::~OUDPPacket() | 411 | OUDPPacket::~OUDPPacket() |
412 | { | 412 | { |
413 | } | 413 | } |
414 | 414 | ||
415 | 415 | ||
416 | int OUDPPacket::fromPort() const | 416 | int OUDPPacket::fromPort() const |
417 | { | 417 | { |
418 | return EXTRACT_16BITS( &_udphdr->source ); | 418 | return EXTRACT_16BITS( &_udphdr->source ); |
419 | } | 419 | } |
420 | 420 | ||
421 | 421 | ||
422 | int OUDPPacket::toPort() const | 422 | int OUDPPacket::toPort() const |
423 | { | 423 | { |
424 | return EXTRACT_16BITS( &_udphdr->dest ); | 424 | return EXTRACT_16BITS( &_udphdr->dest ); |
425 | } | 425 | } |
426 | 426 | ||
427 | 427 | ||
428 | int OUDPPacket::length() const | 428 | int OUDPPacket::length() const |
429 | { | 429 | { |
430 | return EXTRACT_16BITS( &_udphdr->len ); | 430 | return EXTRACT_16BITS( &_udphdr->len ); |
431 | } | 431 | } |
432 | 432 | ||
433 | 433 | ||
434 | int OUDPPacket::checksum() const | 434 | int OUDPPacket::checksum() const |
435 | { | 435 | { |
436 | return EXTRACT_16BITS( &_udphdr->check ); | 436 | return EXTRACT_16BITS( &_udphdr->check ); |
437 | } | 437 | } |
438 | 438 | ||
439 | 439 | ||
440 | /*====================================================================================== | 440 | /*====================================================================================== |
441 | * ODHCPPacket | 441 | * ODHCPPacket |
442 | *======================================================================================*/ | 442 | *======================================================================================*/ |
443 | 443 | ||
444 | 444 | ||
445 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) | 445 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) |
446 | :QObject( parent, "DHCP" ), _dhcphdr( data ) | 446 | :QObject( parent, "DHCP" ), _dhcphdr( data ) |
447 | 447 | ||
448 | { | 448 | { |
449 | odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; | 449 | odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; |
450 | odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; | 450 | odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; |
451 | odebug << "clientAddress = " << clientAddress().toString() << oendl; | 451 | odebug << "clientAddress = " << clientAddress().toString() << oendl; |
452 | odebug << " yourAddress = " << yourAddress().toString() << oendl; | 452 | odebug << " yourAddress = " << yourAddress().toString() << oendl; |
453 | odebug << "serverAddress = " << serverAddress().toString() << oendl; | 453 | odebug << "serverAddress = " << serverAddress().toString() << oendl; |
454 | odebug << " relayAddress = " << relayAddress().toString() << oendl; | 454 | odebug << " relayAddress = " << relayAddress().toString() << oendl; |
455 | odebug << "parsing DHCP options..." << oendl; | 455 | odebug << "parsing DHCP options..." << oendl; |
456 | 456 | ||
457 | _type = 0; | 457 | _type = 0; |
458 | 458 | ||
459 | const unsigned char* option = &_dhcphdr->options[4]; | 459 | const unsigned char* option = &_dhcphdr->options[4]; |
460 | char tag = -1; | 460 | char tag = -1; |
461 | char len = -1; | 461 | char len = -1; |
462 | 462 | ||
463 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) | 463 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) |
464 | { | 464 | { |
465 | len = *option++; | 465 | len = *option++; |
466 | odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; | 466 | odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; |
467 | 467 | ||
468 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) | 468 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) |
469 | _type = *option; | 469 | _type = *option; |
470 | 470 | ||
471 | option += len; | 471 | option += len; |
472 | if ( option >= end ) | 472 | if ( option >= end ) |
473 | { | 473 | { |
474 | owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; | 474 | owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; |
475 | break; | 475 | break; |
476 | } | 476 | } |
477 | } | 477 | } |
478 | 478 | ||
479 | odebug << "DHCP type seems to be << " << type() << oendl; | 479 | odebug << "DHCP type seems to be << " << type() << oendl; |
480 | } | 480 | } |
481 | 481 | ||
482 | 482 | ||
483 | ODHCPPacket::~ODHCPPacket() | 483 | ODHCPPacket::~ODHCPPacket() |
484 | { | 484 | { |
485 | } | 485 | } |
486 | 486 | ||
487 | 487 | ||
488 | bool ODHCPPacket::isRequest() const | 488 | bool ODHCPPacket::isRequest() const |
489 | { | 489 | { |
490 | return ( _dhcphdr->op == 01 ); | 490 | return ( _dhcphdr->op == 01 ); |
491 | } | 491 | } |
492 | 492 | ||
493 | 493 | ||
494 | bool ODHCPPacket::isReply() const | 494 | bool ODHCPPacket::isReply() const |
495 | { | 495 | { |
496 | return ( _dhcphdr->op == 02 ); | 496 | return ( _dhcphdr->op == 02 ); |
497 | } | 497 | } |
498 | 498 | ||
499 | 499 | ||
500 | QString ODHCPPacket::type() const | 500 | QString ODHCPPacket::type() const |
501 | { | 501 | { |
502 | switch ( _type ) | 502 | switch ( _type ) |
503 | { | 503 | { |
504 | case 1: return "DISCOVER"; | 504 | case 1: return "DISCOVER"; |
505 | case 2: return "OFFER"; | 505 | case 2: return "OFFER"; |
506 | case 3: return "REQUEST"; | 506 | case 3: return "REQUEST"; |
507 | case 4: return "DECLINE"; | 507 | case 4: return "DECLINE"; |
508 | case 5: return "ACK"; | 508 | case 5: return "ACK"; |
509 | case 6: return "NAK"; | 509 | case 6: return "NAK"; |
510 | case 7: return "RELEASE"; | 510 | case 7: return "RELEASE"; |
511 | case 8: return "INFORM"; | 511 | case 8: return "INFORM"; |
512 | default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>"; | 512 | default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>"; |
513 | } | 513 | } |
514 | } | 514 | } |
515 | 515 | ||
516 | 516 | ||
517 | QHostAddress ODHCPPacket::clientAddress() const | 517 | QHostAddress ODHCPPacket::clientAddress() const |
518 | { | 518 | { |
519 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); | 519 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); |
520 | } | 520 | } |
521 | 521 | ||
522 | 522 | ||
523 | QHostAddress ODHCPPacket::yourAddress() const | 523 | QHostAddress ODHCPPacket::yourAddress() const |
524 | { | 524 | { |
525 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); | 525 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); |
526 | } | 526 | } |
527 | 527 | ||
528 | 528 | ||
529 | QHostAddress ODHCPPacket::serverAddress() const | 529 | QHostAddress ODHCPPacket::serverAddress() const |
530 | { | 530 | { |
531 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); | 531 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); |
532 | } | 532 | } |
533 | 533 | ||
534 | 534 | ||
535 | QHostAddress ODHCPPacket::relayAddress() const | 535 | QHostAddress ODHCPPacket::relayAddress() const |
536 | { | 536 | { |
537 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); | 537 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); |
538 | } | 538 | } |
539 | 539 | ||
540 | 540 | ||
541 | OMacAddress ODHCPPacket::clientMacAddress() const | 541 | OMacAddress ODHCPPacket::clientMacAddress() const |
542 | { | 542 | { |
543 | return OMacAddress( _dhcphdr->chaddr ); | 543 | return OMacAddress( _dhcphdr->chaddr ); |
544 | } | 544 | } |
545 | 545 | ||
546 | 546 | ||
547 | /*====================================================================================== | 547 | /*====================================================================================== |
548 | * OTCPPacket | 548 | * OTCPPacket |
549 | *======================================================================================*/ | 549 | *======================================================================================*/ |
550 | 550 | ||
551 | 551 | ||
552 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) | 552 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) |
553 | :QObject( parent, "TCP" ), _tcphdr( data ) | 553 | :QObject( parent, "TCP" ), _tcphdr( data ) |
554 | 554 | ||
555 | { | 555 | { |
556 | odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; | 556 | odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; |
557 | } | 557 | } |
558 | 558 | ||
559 | 559 | ||
560 | OTCPPacket::~OTCPPacket() | 560 | OTCPPacket::~OTCPPacket() |
561 | { | 561 | { |
562 | } | 562 | } |
563 | 563 | ||
564 | 564 | ||
565 | int OTCPPacket::fromPort() const | 565 | int OTCPPacket::fromPort() const |
566 | { | 566 | { |
567 | return EXTRACT_16BITS( &_tcphdr->source ); | 567 | return EXTRACT_16BITS( &_tcphdr->source ); |
568 | } | 568 | } |
569 | 569 | ||
570 | 570 | ||
571 | int OTCPPacket::toPort() const | 571 | int OTCPPacket::toPort() const |
572 | { | 572 | { |
573 | return EXTRACT_16BITS( &_tcphdr->dest ); | 573 | return EXTRACT_16BITS( &_tcphdr->dest ); |
574 | } | 574 | } |
575 | 575 | ||
576 | 576 | ||
577 | int OTCPPacket::seq() const | 577 | int OTCPPacket::seq() const |
578 | { | 578 | { |
579 | return EXTRACT_16BITS( &_tcphdr->seq ); | 579 | return EXTRACT_16BITS( &_tcphdr->seq ); |
580 | } | 580 | } |
581 | 581 | ||
582 | 582 | ||
583 | int OTCPPacket::ack() const | 583 | int OTCPPacket::ack() const |
584 | { | 584 | { |
585 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); | 585 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); |
586 | } | 586 | } |
587 | 587 | ||
588 | 588 | ||
589 | int OTCPPacket::window() const | 589 | int OTCPPacket::window() const |
590 | { | 590 | { |
591 | return EXTRACT_16BITS( &_tcphdr->window ); | 591 | return EXTRACT_16BITS( &_tcphdr->window ); |
592 | } | 592 | } |
593 | 593 | ||
594 | 594 | ||
595 | int OTCPPacket::checksum() const | 595 | int OTCPPacket::checksum() const |
596 | { | 596 | { |
597 | return EXTRACT_16BITS( &_tcphdr->check ); | 597 | return EXTRACT_16BITS( &_tcphdr->check ); |
598 | } | 598 | } |
599 | 599 | ||
600 | /*====================================================================================== | 600 | /*====================================================================================== |
601 | * OPrismHeaderPacket | 601 | * OPrismHeaderPacket |
602 | *======================================================================================*/ | 602 | *======================================================================================*/ |
603 | 603 | ||
604 | 604 | ||
605 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) | 605 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) |
606 | :QObject( parent, "Prism" ), _header( data ) | 606 | :QObject( parent, "Prism" ), _header( data ) |
607 | 607 | ||
608 | { | 608 | { |
609 | odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; | 609 | odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; |
610 | 610 | ||
611 | odebug << "Signal Strength = " << data->signal.data << oendl; | 611 | odebug << "Signal Strength = " << data->signal.data << oendl; |
612 | 612 | ||
613 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); | 613 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); |
614 | } | 614 | } |
615 | 615 | ||
616 | OPrismHeaderPacket::~OPrismHeaderPacket() | 616 | OPrismHeaderPacket::~OPrismHeaderPacket() |
617 | { | 617 | { |
618 | } | 618 | } |
619 | 619 | ||
620 | 620 | ||
621 | unsigned int OPrismHeaderPacket::signalStrength() const | 621 | unsigned int OPrismHeaderPacket::signalStrength() const |
622 | { | 622 | { |
623 | return _header->signal.data; | 623 | return _header->signal.data; |
624 | } | 624 | } |
625 | 625 | ||
626 | /*====================================================================================== | 626 | /*====================================================================================== |
627 | * OWaveLanPacket | 627 | * OWaveLanPacket |
628 | *======================================================================================*/ | 628 | *======================================================================================*/ |
629 | 629 | ||
630 | 630 | ||
631 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) | 631 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) |
632 | :QObject( parent, "802.11" ), _wlanhdr( data ) | 632 | :QObject( parent, "802.11" ), _wlanhdr( data ) |
633 | 633 | ||
634 | { | 634 | { |
635 | odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl; | 635 | odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl; |
636 | odebug << "type = " << type() << oendl; | 636 | odebug << "type = " << type() << oendl; |
637 | odebug << "subType = " << subType() << oendl; | 637 | odebug << "subType = " << subType() << oendl; |
638 | odebug << "duration = " << duration() << oendl; | 638 | odebug << "duration = " << duration() << oendl; |
639 | odebug << "powermanagement = " << usesPowerManagement() << oendl; | 639 | odebug << "powermanagement = " << usesPowerManagement() << oendl; |
640 | odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl; | 640 | odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl; |
641 | odebug << "MAC1 = " << macAddress1().toString() << oendl; | 641 | odebug << "MAC1 = " << macAddress1().toString() << oendl; |
642 | odebug << "MAC2 = " << macAddress2().toString() << oendl; | 642 | odebug << "MAC2 = " << macAddress2().toString() << oendl; |
643 | odebug << "MAC3 = " << macAddress3().toString() << oendl; | 643 | odebug << "MAC3 = " << macAddress3().toString() << oendl; |
644 | odebug << "MAC4 = " << macAddress4().toString() << oendl; | 644 | odebug << "MAC4 = " << macAddress4().toString() << oendl; |
645 | 645 | ||
646 | switch ( type() ) | 646 | switch ( type() ) |
647 | { | 647 | { |
648 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; | 648 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
649 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; | 649 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
650 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; | 650 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; |
651 | default: odebug << "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type = " << type() << oendl; | 651 | default: odebug << "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type = " << type() << oendl; |
652 | } | 652 | } |
653 | } | 653 | } |
654 | 654 | ||
655 | OWaveLanPacket::~OWaveLanPacket() | 655 | OWaveLanPacket::~OWaveLanPacket() |
656 | { | 656 | { |
657 | } | 657 | } |
658 | 658 | ||
659 | 659 | ||
660 | int OWaveLanPacket::duration() const | 660 | int OWaveLanPacket::duration() const |
661 | { | 661 | { |
662 | return _wlanhdr->duration; | 662 | return _wlanhdr->duration; |
663 | } | 663 | } |
664 | 664 | ||
665 | 665 | ||
666 | OMacAddress OWaveLanPacket::macAddress1() const | 666 | OMacAddress OWaveLanPacket::macAddress1() const |
667 | { | 667 | { |
668 | return OMacAddress( _wlanhdr->mac1 ); | 668 | return OMacAddress( _wlanhdr->mac1 ); |
669 | } | 669 | } |
670 | 670 | ||
671 | 671 | ||
672 | OMacAddress OWaveLanPacket::macAddress2() const | 672 | OMacAddress OWaveLanPacket::macAddress2() const |
673 | { | 673 | { |
674 | return OMacAddress( _wlanhdr->mac2 ); | 674 | return OMacAddress( _wlanhdr->mac2 ); |
675 | } | 675 | } |
676 | 676 | ||
677 | 677 | ||
678 | OMacAddress OWaveLanPacket::macAddress3() const | 678 | OMacAddress OWaveLanPacket::macAddress3() const |
679 | { | 679 | { |
680 | return OMacAddress( _wlanhdr->mac3 ); | 680 | return OMacAddress( _wlanhdr->mac3 ); |
681 | } | 681 | } |
682 | 682 | ||
683 | 683 | ||
684 | OMacAddress OWaveLanPacket::macAddress4() const | 684 | OMacAddress OWaveLanPacket::macAddress4() const |
685 | { | 685 | { |
686 | return OMacAddress( _wlanhdr->mac4 ); | 686 | return OMacAddress( _wlanhdr->mac4 ); |
687 | } | 687 | } |
688 | 688 | ||
689 | 689 | ||
690 | int OWaveLanPacket::subType() const | 690 | int OWaveLanPacket::subType() const |
691 | { | 691 | { |
692 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 692 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
693 | } | 693 | } |
694 | 694 | ||
695 | 695 | ||
696 | int OWaveLanPacket::type() const | 696 | int OWaveLanPacket::type() const |
697 | { | 697 | { |
698 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 698 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
699 | } | 699 | } |
700 | 700 | ||
701 | 701 | ||
702 | int OWaveLanPacket::version() const | 702 | int OWaveLanPacket::version() const |
703 | { | 703 | { |
704 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 704 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
705 | } | 705 | } |
706 | 706 | ||
707 | 707 | ||
708 | bool OWaveLanPacket::fromDS() const | 708 | bool OWaveLanPacket::fromDS() const |
709 | { | 709 | { |
710 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 710 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
711 | } | 711 | } |
712 | 712 | ||
713 | 713 | ||
714 | bool OWaveLanPacket::toDS() const | 714 | bool OWaveLanPacket::toDS() const |
715 | { | 715 | { |
716 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 716 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
717 | } | 717 | } |
718 | 718 | ||
719 | 719 | ||
720 | bool OWaveLanPacket::usesPowerManagement() const | 720 | bool OWaveLanPacket::usesPowerManagement() const |
721 | { | 721 | { |
722 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 722 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
723 | } | 723 | } |
724 | 724 | ||
725 | 725 | ||
726 | bool OWaveLanPacket::usesWep() const | 726 | bool OWaveLanPacket::usesWep() const |
727 | { | 727 | { |
728 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 728 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
729 | } | 729 | } |
730 | 730 | ||
731 | 731 | ||
732 | /*====================================================================================== | 732 | /*====================================================================================== |
733 | * OWaveLanManagementPacket | 733 | * OWaveLanManagementPacket |
734 | *======================================================================================*/ | 734 | *======================================================================================*/ |
735 | 735 | ||
736 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 736 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
737 | :QObject( parent, "802.11 Management" ), _header( data ), | 737 | :QObject( parent, "802.11 Management" ), _header( data ), |
738 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 738 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
739 | { | 739 | { |
740 | odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; | 740 | odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; |
741 | odebug << "Detected subtype is " << managementType() << oendl; | 741 | odebug << "Detected subtype is " << managementType() << oendl; |
742 | 742 | ||
743 | // Grab tagged values. | 743 | // Grab tagged values. |
744 | // Beacons contain a 12 byte long fixed parameters set before the tagged parameters come, | 744 | // Beacons contain a 12 byte long fixed parameters set before the tagged parameters come, |
745 | // Other management frames don't - which is why we have to inspect the subtype here. | 745 | // Other management frames don't - which is why we have to inspect the subtype here. |
746 | 746 | ||
747 | const unsigned char* ptr = managementType() == "Beacon" ? (const unsigned char*) (_body+1) : (const unsigned char*) (_header+1); | 747 | const unsigned char* ptr = managementType() == "Beacon" ? (const unsigned char*) (_body+1) : (const unsigned char*) (_header+1); |
748 | 748 | ||
749 | while (ptr < end) | 749 | while (ptr < end) |
750 | { | 750 | { |
751 | switch ( *ptr ) | 751 | switch ( *ptr ) |
752 | { | 752 | { |
753 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; | 753 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; |
754 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; | 754 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; |
755 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; | 755 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; |
756 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; | 756 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; |
757 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; | 757 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; |
758 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; | 758 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; |
759 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; | 759 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; |
760 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; | 760 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; |
761 | } | 761 | } |
762 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value | 762 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value |
763 | ptr+= 2; // skip tag ID and length | 763 | ptr+= 2; // skip tag ID and length |
764 | } | 764 | } |
765 | } | 765 | } |
766 | 766 | ||
767 | 767 | ||
768 | OWaveLanManagementPacket::~OWaveLanManagementPacket() | 768 | OWaveLanManagementPacket::~OWaveLanManagementPacket() |
769 | { | 769 | { |
770 | } | 770 | } |
771 | 771 | ||
772 | 772 | ||
773 | QString OWaveLanManagementPacket::managementType() const | 773 | QString OWaveLanManagementPacket::managementType() const |
774 | { | 774 | { |
775 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | 775 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
776 | { | 776 | { |
777 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; | 777 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; |
778 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; | 778 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; |
779 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; | 779 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; |
780 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; | 780 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; |
781 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; | 781 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; |
782 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; | 782 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; |
783 | case ST_BEACON: return "Beacon"; break; | 783 | case ST_BEACON: return "Beacon"; break; |
784 | case ST_ATIM: return "Atim"; break; | 784 | case ST_ATIM: return "Atim"; break; |
785 | case ST_DISASSOC: return "Disassociation"; break; | 785 | case ST_DISASSOC: return "Disassociation"; break; |
786 | case ST_AUTH: return "Authentication"; break; | 786 | case ST_AUTH: return "Authentication"; break; |
787 | case ST_DEAUTH: return "Deathentication"; break; | 787 | case ST_DEAUTH: return "Deathentication"; break; |
788 | default: owarn << "OWaveLanManagementPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; return "Unknown"; | 788 | default: owarn << "OWaveLanManagementPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; return "Unknown"; |
789 | } | 789 | } |
790 | } | 790 | } |
791 | 791 | ||
792 | 792 | ||
793 | int OWaveLanManagementPacket::beaconInterval() const | 793 | int OWaveLanManagementPacket::beaconInterval() const |
794 | { | 794 | { |
795 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); | 795 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); |
796 | } | 796 | } |
797 | 797 | ||
798 | 798 | ||
799 | int OWaveLanManagementPacket::capabilities() const | 799 | int OWaveLanManagementPacket::capabilities() const |
800 | { | 800 | { |
801 | return EXTRACT_LE_16BITS( &_body->capability_info ); | 801 | return EXTRACT_LE_16BITS( &_body->capability_info ); |
802 | } | 802 | } |
803 | 803 | ||
804 | 804 | ||
805 | bool OWaveLanManagementPacket::canESS() const | 805 | bool OWaveLanManagementPacket::canESS() const |
806 | { | 806 | { |
807 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 807 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
808 | } | 808 | } |
809 | 809 | ||
810 | 810 | ||
811 | bool OWaveLanManagementPacket::canIBSS() const | 811 | bool OWaveLanManagementPacket::canIBSS() const |
812 | { | 812 | { |
813 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 813 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
814 | } | 814 | } |
815 | 815 | ||
816 | 816 | ||
817 | bool OWaveLanManagementPacket::canCFP() const | 817 | bool OWaveLanManagementPacket::canCFP() const |
818 | { | 818 | { |
819 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 819 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
820 | } | 820 | } |
821 | 821 | ||
822 | 822 | ||
823 | bool OWaveLanManagementPacket::canCFP_REQ() const | 823 | bool OWaveLanManagementPacket::canCFP_REQ() const |
824 | { | 824 | { |
825 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 825 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
826 | } | 826 | } |
827 | 827 | ||
828 | 828 | ||
829 | bool OWaveLanManagementPacket::canPrivacy() const | 829 | bool OWaveLanManagementPacket::canPrivacy() const |
830 | { | 830 | { |
831 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 831 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
832 | } | 832 | } |
833 | 833 | ||
834 | 834 | ||
835 | /*====================================================================================== | 835 | /*====================================================================================== |
836 | * OWaveLanManagementSSID | 836 | * OWaveLanManagementSSID |
837 | *======================================================================================*/ | 837 | *======================================================================================*/ |
838 | 838 | ||
839 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) | 839 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) |
840 | :QObject( parent, "802.11 SSID" ), _data( data ) | 840 | :QObject( parent, "802.11 SSID" ), _data( data ) |
841 | { | 841 | { |
842 | odebug << "OWaveLanManagementSSID()" << oendl; | 842 | odebug << "OWaveLanManagementSSID()" << oendl; |
843 | } | 843 | } |
844 | 844 | ||
845 | 845 | ||
846 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | 846 | OWaveLanManagementSSID::~OWaveLanManagementSSID() |
847 | { | 847 | { |
848 | } | 848 | } |
849 | 849 | ||
850 | 850 | ||
851 | QString OWaveLanManagementSSID::ID( bool decloak ) const | 851 | QString OWaveLanManagementSSID::ID( bool decloak ) const |
852 | { | 852 | { |
853 | int length = _data->length; | 853 | int length = _data->length; |
854 | if ( length > 32 ) length = 32; | 854 | if ( length > 32 ) length = 32; |
855 | char essid[length+1]; | 855 | char essid[length+1]; |
856 | memcpy( &essid, &_data->ssid, length ); | 856 | memcpy( &essid, &_data->ssid, length ); |
857 | essid[length] = 0x0; | 857 | essid[length] = 0x0; |
858 | if ( !decloak || length < 2 || essid[0] != '\0' ) return essid; | 858 | if ( !decloak || length < 2 || essid[0] != '\0' ) return essid; |
859 | odebug << "OWaveLanManagementSSID:ID(): SSID is cloaked - decloaking..." << oendl; | 859 | odebug << "OWaveLanManagementSSID:ID(): SSID is cloaked - decloaking..." << oendl; |
860 | 860 | ||
861 | QString decloakedID; | 861 | QString decloakedID; |
862 | for ( int i = 1; i < length; ++i ) | 862 | for ( int i = 1; i < length; ++i ) |
863 | { | 863 | { |
864 | if ( essid[i] >= 32 && essid[i] <= 126 ) decloakedID.append( essid[i] ); | 864 | if ( essid[i] >= 32 && essid[i] <= 126 ) decloakedID.append( essid[i] ); |
865 | else decloakedID.append( '.' ); | 865 | else decloakedID.append( '.' ); |
866 | } | 866 | } |
867 | return decloakedID; | 867 | return decloakedID; |
868 | } | 868 | } |
869 | 869 | ||
870 | 870 | ||
871 | /*====================================================================================== | 871 | /*====================================================================================== |
872 | * OWaveLanManagementRates | 872 | * OWaveLanManagementRates |
873 | *======================================================================================*/ | 873 | *======================================================================================*/ |
874 | 874 | ||
875 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) | 875 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) |
876 | :QObject( parent, "802.11 Rates" ), _data( data ) | 876 | :QObject( parent, "802.11 Rates" ), _data( data ) |
877 | { | 877 | { |
878 | odebug << "OWaveLanManagementRates()" << oendl; | 878 | odebug << "OWaveLanManagementRates()" << oendl; |
879 | } | 879 | } |
880 | 880 | ||
881 | 881 | ||
882 | OWaveLanManagementRates::~OWaveLanManagementRates() | 882 | OWaveLanManagementRates::~OWaveLanManagementRates() |
883 | { | 883 | { |
884 | } | 884 | } |
885 | 885 | ||
886 | /*====================================================================================== | 886 | /*====================================================================================== |
887 | * OWaveLanManagementCF | 887 | * OWaveLanManagementCF |
888 | *======================================================================================*/ | 888 | *======================================================================================*/ |
889 | 889 | ||
890 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) | 890 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) |
891 | :QObject( parent, "802.11 CF" ), _data( data ) | 891 | :QObject( parent, "802.11 CF" ), _data( data ) |
892 | { | 892 | { |
893 | odebug << "OWaveLanManagementCF()" << oendl; | 893 | odebug << "OWaveLanManagementCF()" << oendl; |
894 | } | 894 | } |
895 | 895 | ||
896 | 896 | ||
897 | OWaveLanManagementCF::~OWaveLanManagementCF() | 897 | OWaveLanManagementCF::~OWaveLanManagementCF() |
898 | { | 898 | { |
899 | } | 899 | } |
900 | 900 | ||
901 | /*====================================================================================== | 901 | /*====================================================================================== |
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 | { |