author | zecke <zecke> | 2004-05-07 16:45:46 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-05-07 16:45:46 (UTC) |
commit | de674154922b40fd2c01e008c7a7871520a86209 (patch) (unidiff) | |
tree | 29155a26d71fa6c6f59bd01ad3dece7f15193905 | |
parent | a8c2ce4c6bc83223a32e6e803b1277a0db5ebd7f (diff) | |
download | opie-de674154922b40fd2c01e008c7a7871520a86209.zip opie-de674154922b40fd2c01e008c7a7871520a86209.tar.gz opie-de674154922b40fd2c01e008c7a7871520a86209.tar.bz2 |
If you create an array, delete it as an array
-rw-r--r-- | libopie2/opienet/opcap.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 8184f21..03e4502 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -1,1119 +1,1119 @@ | |||
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( "000:" ); | 151 | QString str( "000:" ); |
152 | QString tmp; | 152 | QString tmp; |
153 | QString bytes; | 153 | QString bytes; |
154 | QString chars; | 154 | QString chars; |
155 | 155 | ||
156 | for ( int i = 0; i < len; ++i ) | 156 | for ( int i = 0; i < len; ++i ) |
157 | { | 157 | { |
158 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); | 158 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); |
159 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); | 159 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); |
160 | else chars.append( '.' ); | 160 | else chars.append( '.' ); |
161 | 161 | ||
162 | if ( !((i+1) % bpl) ) | 162 | if ( !((i+1) % bpl) ) |
163 | { | 163 | { |
164 | str.append( bytes ); | 164 | str.append( bytes ); |
165 | str.append( ' ' ); | 165 | str.append( ' ' ); |
166 | str.append( chars ); | 166 | str.append( chars ); |
167 | str.append( '\n' ); | 167 | str.append( '\n' ); |
168 | tmp.sprintf( "%03X:", i+1 ); str.append( tmp ); | 168 | tmp.sprintf( "%03X:", i+1 ); str.append( tmp ); |
169 | bytes = ""; | 169 | bytes = ""; |
170 | chars = ""; | 170 | chars = ""; |
171 | } | 171 | } |
172 | 172 | ||
173 | } | 173 | } |
174 | if ( (len % bpl) ) | 174 | if ( (len % bpl) ) |
175 | { | 175 | { |
176 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); | 176 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); |
177 | str.append( chars ); | 177 | str.append( chars ); |
178 | } | 178 | } |
179 | str.append( '\n' ); | 179 | str.append( '\n' ); |
180 | return str; | 180 | return str; |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
184 | int OPacket::len() const | 184 | int OPacket::len() const |
185 | { | 185 | { |
186 | return _hdr.len; | 186 | return _hdr.len; |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
190 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) | 190 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) |
191 | { | 191 | { |
192 | s << p.dumpStructure(); | 192 | s << p.dumpStructure(); |
193 | } | 193 | } |
194 | 194 | ||
195 | 195 | ||
196 | /*====================================================================================== | 196 | /*====================================================================================== |
197 | * OEthernetPacket | 197 | * OEthernetPacket |
198 | *======================================================================================*/ | 198 | *======================================================================================*/ |
199 | 199 | ||
200 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) | 200 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
201 | :QObject( parent, "Ethernet" ), _ether( data ) | 201 | :QObject( parent, "Ethernet" ), _ether( data ) |
202 | { | 202 | { |
203 | 203 | ||
204 | odebug << "Source = " << sourceAddress().toString() << oendl; | 204 | odebug << "Source = " << sourceAddress().toString() << oendl; |
205 | odebug << "Destination = " << destinationAddress().toString() << oendl; | 205 | odebug << "Destination = " << destinationAddress().toString() << oendl; |
206 | 206 | ||
207 | if ( sourceAddress() == OMacAddress::broadcast ) | 207 | if ( sourceAddress() == OMacAddress::broadcast ) |
208 | odebug << "Source is broadcast address" << oendl; | 208 | odebug << "Source is broadcast address" << oendl; |
209 | if ( destinationAddress() == OMacAddress::broadcast ) | 209 | if ( destinationAddress() == OMacAddress::broadcast ) |
210 | odebug << "Destination is broadcast address" << oendl; | 210 | odebug << "Destination is broadcast address" << oendl; |
211 | 211 | ||
212 | switch ( type() ) | 212 | switch ( type() ) |
213 | { | 213 | { |
214 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 214 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
215 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 215 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
216 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } | 216 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } |
217 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; | 217 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; |
218 | } | 218 | } |
219 | 219 | ||
220 | } | 220 | } |
221 | 221 | ||
222 | 222 | ||
223 | OEthernetPacket::~OEthernetPacket() | 223 | OEthernetPacket::~OEthernetPacket() |
224 | { | 224 | { |
225 | } | 225 | } |
226 | 226 | ||
227 | 227 | ||
228 | OMacAddress OEthernetPacket::sourceAddress() const | 228 | OMacAddress OEthernetPacket::sourceAddress() const |
229 | { | 229 | { |
230 | return OMacAddress( _ether->ether_shost ); | 230 | return OMacAddress( _ether->ether_shost ); |
231 | } | 231 | } |
232 | 232 | ||
233 | 233 | ||
234 | OMacAddress OEthernetPacket::destinationAddress() const | 234 | OMacAddress OEthernetPacket::destinationAddress() const |
235 | { | 235 | { |
236 | return OMacAddress( _ether->ether_dhost ); | 236 | return OMacAddress( _ether->ether_dhost ); |
237 | } | 237 | } |
238 | 238 | ||
239 | int OEthernetPacket::type() const | 239 | int OEthernetPacket::type() const |
240 | { | 240 | { |
241 | return ntohs( _ether->ether_type ); | 241 | return ntohs( _ether->ether_type ); |
242 | } | 242 | } |
243 | 243 | ||
244 | 244 | ||
245 | /*====================================================================================== | 245 | /*====================================================================================== |
246 | * OIPPacket | 246 | * OIPPacket |
247 | *======================================================================================*/ | 247 | *======================================================================================*/ |
248 | 248 | ||
249 | 249 | ||
250 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) | 250 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
251 | :QObject( parent, "IP" ), _iphdr( data ) | 251 | :QObject( parent, "IP" ), _iphdr( data ) |
252 | { | 252 | { |
253 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; | 253 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; |
254 | 254 | ||
255 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; | 255 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; |
256 | odebug << " toAddress = " << toIPAddress().toString() << oendl; | 256 | odebug << " toAddress = " << toIPAddress().toString() << oendl; |
257 | 257 | ||
258 | switch ( protocol() ) | 258 | switch ( protocol() ) |
259 | { | 259 | { |
260 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; | 260 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
261 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; | 261 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
262 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; | 262 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; |
263 | } | 263 | } |
264 | 264 | ||
265 | } | 265 | } |
266 | 266 | ||
267 | OIPPacket::~OIPPacket() | 267 | OIPPacket::~OIPPacket() |
268 | { | 268 | { |
269 | } | 269 | } |
270 | 270 | ||
271 | 271 | ||
272 | QHostAddress OIPPacket::fromIPAddress() const | 272 | QHostAddress OIPPacket::fromIPAddress() const |
273 | { | 273 | { |
274 | return EXTRACT_32BITS( &_iphdr->saddr ); | 274 | return EXTRACT_32BITS( &_iphdr->saddr ); |
275 | } | 275 | } |
276 | 276 | ||
277 | 277 | ||
278 | QHostAddress OIPPacket::toIPAddress() const | 278 | QHostAddress OIPPacket::toIPAddress() const |
279 | { | 279 | { |
280 | return EXTRACT_32BITS( &_iphdr->saddr ); | 280 | return EXTRACT_32BITS( &_iphdr->saddr ); |
281 | } | 281 | } |
282 | 282 | ||
283 | 283 | ||
284 | int OIPPacket::tos() const | 284 | int OIPPacket::tos() const |
285 | { | 285 | { |
286 | return _iphdr->tos; | 286 | return _iphdr->tos; |
287 | } | 287 | } |
288 | 288 | ||
289 | 289 | ||
290 | int OIPPacket::len() const | 290 | int OIPPacket::len() const |
291 | { | 291 | { |
292 | return EXTRACT_16BITS( &_iphdr->tot_len ); | 292 | return EXTRACT_16BITS( &_iphdr->tot_len ); |
293 | } | 293 | } |
294 | 294 | ||
295 | 295 | ||
296 | int OIPPacket::id() const | 296 | int OIPPacket::id() const |
297 | { | 297 | { |
298 | return EXTRACT_16BITS( &_iphdr->id ); | 298 | return EXTRACT_16BITS( &_iphdr->id ); |
299 | } | 299 | } |
300 | 300 | ||
301 | 301 | ||
302 | int OIPPacket::offset() const | 302 | int OIPPacket::offset() const |
303 | { | 303 | { |
304 | return EXTRACT_16BITS( &_iphdr->frag_off ); | 304 | return EXTRACT_16BITS( &_iphdr->frag_off ); |
305 | } | 305 | } |
306 | 306 | ||
307 | 307 | ||
308 | int OIPPacket::ttl() const | 308 | int OIPPacket::ttl() const |
309 | { | 309 | { |
310 | return _iphdr->ttl; | 310 | return _iphdr->ttl; |
311 | } | 311 | } |
312 | 312 | ||
313 | 313 | ||
314 | int OIPPacket::protocol() const | 314 | int OIPPacket::protocol() const |
315 | { | 315 | { |
316 | return _iphdr->protocol; | 316 | return _iphdr->protocol; |
317 | } | 317 | } |
318 | 318 | ||
319 | 319 | ||
320 | int OIPPacket::checksum() const | 320 | int OIPPacket::checksum() const |
321 | { | 321 | { |
322 | return EXTRACT_16BITS( &_iphdr->check ); | 322 | return EXTRACT_16BITS( &_iphdr->check ); |
323 | } | 323 | } |
324 | 324 | ||
325 | /*====================================================================================== | 325 | /*====================================================================================== |
326 | * OARPPacket | 326 | * OARPPacket |
327 | *======================================================================================*/ | 327 | *======================================================================================*/ |
328 | 328 | ||
329 | 329 | ||
330 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) | 330 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) |
331 | :QObject( parent, "ARP" ), _arphdr( data ) | 331 | :QObject( parent, "ARP" ), _arphdr( data ) |
332 | { | 332 | { |
333 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; | 333 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; |
334 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; | 334 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; |
335 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; | 335 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; |
336 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; | 336 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; |
337 | } | 337 | } |
338 | 338 | ||
339 | 339 | ||
340 | OARPPacket::~OARPPacket() | 340 | OARPPacket::~OARPPacket() |
341 | { | 341 | { |
342 | } | 342 | } |
343 | 343 | ||
344 | 344 | ||
345 | QString OARPPacket::type() const | 345 | QString OARPPacket::type() const |
346 | { | 346 | { |
347 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) | 347 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) |
348 | { | 348 | { |
349 | case 1: return "REQUEST"; | 349 | case 1: return "REQUEST"; |
350 | case 2: return "REPLY"; | 350 | case 2: return "REPLY"; |
351 | case 3: return "RREQUEST"; | 351 | case 3: return "RREQUEST"; |
352 | case 4: return "RREPLY"; | 352 | case 4: return "RREPLY"; |
353 | case 8: return "InREQUEST"; | 353 | case 8: return "InREQUEST"; |
354 | case 9: return "InREPLY"; | 354 | case 9: return "InREPLY"; |
355 | case 10: return "NAK"; | 355 | case 10: return "NAK"; |
356 | default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; | 356 | default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; |
357 | } | 357 | } |
358 | } | 358 | } |
359 | 359 | ||
360 | 360 | ||
361 | QHostAddress OARPPacket::senderIPV4Address() const | 361 | QHostAddress OARPPacket::senderIPV4Address() const |
362 | { | 362 | { |
363 | return EXTRACT_32BITS( &_arphdr->ar_sip ); | 363 | return EXTRACT_32BITS( &_arphdr->ar_sip ); |
364 | } | 364 | } |
365 | 365 | ||
366 | 366 | ||
367 | QHostAddress OARPPacket::targetIPV4Address() const | 367 | QHostAddress OARPPacket::targetIPV4Address() const |
368 | { | 368 | { |
369 | return EXTRACT_32BITS( &_arphdr->ar_tip ); | 369 | return EXTRACT_32BITS( &_arphdr->ar_tip ); |
370 | } | 370 | } |
371 | 371 | ||
372 | 372 | ||
373 | OMacAddress OARPPacket::senderMacAddress() const | 373 | OMacAddress OARPPacket::senderMacAddress() const |
374 | { | 374 | { |
375 | return OMacAddress( _arphdr->ar_sha ); | 375 | return OMacAddress( _arphdr->ar_sha ); |
376 | } | 376 | } |
377 | 377 | ||
378 | 378 | ||
379 | OMacAddress OARPPacket::targetMacAddress() const | 379 | OMacAddress OARPPacket::targetMacAddress() const |
380 | { | 380 | { |
381 | return OMacAddress( _arphdr->ar_tha ); | 381 | return OMacAddress( _arphdr->ar_tha ); |
382 | } | 382 | } |
383 | 383 | ||
384 | 384 | ||
385 | /*====================================================================================== | 385 | /*====================================================================================== |
386 | * OUDPPacket | 386 | * OUDPPacket |
387 | *======================================================================================*/ | 387 | *======================================================================================*/ |
388 | 388 | ||
389 | 389 | ||
390 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) | 390 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) |
391 | :QObject( parent, "UDP" ), _udphdr( data ) | 391 | :QObject( parent, "UDP" ), _udphdr( data ) |
392 | 392 | ||
393 | { | 393 | { |
394 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; | 394 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; |
395 | odebug << "fromPort = " << fromPort() << oendl; | 395 | odebug << "fromPort = " << fromPort() << oendl; |
396 | odebug << " toPort = " << toPort() << oendl; | 396 | odebug << " toPort = " << toPort() << oendl; |
397 | 397 | ||
398 | // TODO: Make this a case or a hash if we know more udp protocols | 398 | // TODO: Make this a case or a hash if we know more udp protocols |
399 | 399 | ||
400 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || | 400 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || |
401 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) | 401 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) |
402 | { | 402 | { |
403 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; | 403 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; |
404 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); | 404 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); |
405 | } | 405 | } |
406 | } | 406 | } |
407 | 407 | ||
408 | 408 | ||
409 | OUDPPacket::~OUDPPacket() | 409 | OUDPPacket::~OUDPPacket() |
410 | { | 410 | { |
411 | } | 411 | } |
412 | 412 | ||
413 | 413 | ||
414 | int OUDPPacket::fromPort() const | 414 | int OUDPPacket::fromPort() const |
415 | { | 415 | { |
416 | return EXTRACT_16BITS( &_udphdr->source ); | 416 | return EXTRACT_16BITS( &_udphdr->source ); |
417 | } | 417 | } |
418 | 418 | ||
419 | 419 | ||
420 | int OUDPPacket::toPort() const | 420 | int OUDPPacket::toPort() const |
421 | { | 421 | { |
422 | return EXTRACT_16BITS( &_udphdr->dest ); | 422 | return EXTRACT_16BITS( &_udphdr->dest ); |
423 | } | 423 | } |
424 | 424 | ||
425 | 425 | ||
426 | int OUDPPacket::length() const | 426 | int OUDPPacket::length() const |
427 | { | 427 | { |
428 | return EXTRACT_16BITS( &_udphdr->len ); | 428 | return EXTRACT_16BITS( &_udphdr->len ); |
429 | } | 429 | } |
430 | 430 | ||
431 | 431 | ||
432 | int OUDPPacket::checksum() const | 432 | int OUDPPacket::checksum() const |
433 | { | 433 | { |
434 | return EXTRACT_16BITS( &_udphdr->check ); | 434 | return EXTRACT_16BITS( &_udphdr->check ); |
435 | } | 435 | } |
436 | 436 | ||
437 | 437 | ||
438 | /*====================================================================================== | 438 | /*====================================================================================== |
439 | * ODHCPPacket | 439 | * ODHCPPacket |
440 | *======================================================================================*/ | 440 | *======================================================================================*/ |
441 | 441 | ||
442 | 442 | ||
443 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) | 443 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) |
444 | :QObject( parent, "DHCP" ), _dhcphdr( data ) | 444 | :QObject( parent, "DHCP" ), _dhcphdr( data ) |
445 | 445 | ||
446 | { | 446 | { |
447 | odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; | 447 | odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; |
448 | odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; | 448 | odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; |
449 | odebug << "clientAddress = " << clientAddress().toString() << oendl; | 449 | odebug << "clientAddress = " << clientAddress().toString() << oendl; |
450 | odebug << " yourAddress = " << yourAddress().toString() << oendl; | 450 | odebug << " yourAddress = " << yourAddress().toString() << oendl; |
451 | odebug << "serverAddress = " << serverAddress().toString() << oendl; | 451 | odebug << "serverAddress = " << serverAddress().toString() << oendl; |
452 | odebug << " relayAddress = " << relayAddress().toString() << oendl; | 452 | odebug << " relayAddress = " << relayAddress().toString() << oendl; |
453 | odebug << "parsing DHCP options..." << oendl; | 453 | odebug << "parsing DHCP options..." << oendl; |
454 | 454 | ||
455 | _type = 0; | 455 | _type = 0; |
456 | 456 | ||
457 | const unsigned char* option = &_dhcphdr->options[4]; | 457 | const unsigned char* option = &_dhcphdr->options[4]; |
458 | char tag = -1; | 458 | char tag = -1; |
459 | char len = -1; | 459 | char len = -1; |
460 | 460 | ||
461 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) | 461 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) |
462 | { | 462 | { |
463 | len = *option++; | 463 | len = *option++; |
464 | odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; | 464 | odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; |
465 | 465 | ||
466 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) | 466 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) |
467 | _type = *option; | 467 | _type = *option; |
468 | 468 | ||
469 | option += len; | 469 | option += len; |
470 | if ( option >= end ) | 470 | if ( option >= end ) |
471 | { | 471 | { |
472 | owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; | 472 | owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; |
473 | break; | 473 | break; |
474 | } | 474 | } |
475 | } | 475 | } |
476 | 476 | ||
477 | odebug << "DHCP type seems to be << " << type() << oendl; | 477 | odebug << "DHCP type seems to be << " << type() << oendl; |
478 | } | 478 | } |
479 | 479 | ||
480 | 480 | ||
481 | ODHCPPacket::~ODHCPPacket() | 481 | ODHCPPacket::~ODHCPPacket() |
482 | { | 482 | { |
483 | } | 483 | } |
484 | 484 | ||
485 | 485 | ||
486 | bool ODHCPPacket::isRequest() const | 486 | bool ODHCPPacket::isRequest() const |
487 | { | 487 | { |
488 | return ( _dhcphdr->op == 01 ); | 488 | return ( _dhcphdr->op == 01 ); |
489 | } | 489 | } |
490 | 490 | ||
491 | 491 | ||
492 | bool ODHCPPacket::isReply() const | 492 | bool ODHCPPacket::isReply() const |
493 | { | 493 | { |
494 | return ( _dhcphdr->op == 02 ); | 494 | return ( _dhcphdr->op == 02 ); |
495 | } | 495 | } |
496 | 496 | ||
497 | 497 | ||
498 | QString ODHCPPacket::type() const | 498 | QString ODHCPPacket::type() const |
499 | { | 499 | { |
500 | switch ( _type ) | 500 | switch ( _type ) |
501 | { | 501 | { |
502 | case 1: return "DISCOVER"; | 502 | case 1: return "DISCOVER"; |
503 | case 2: return "OFFER"; | 503 | case 2: return "OFFER"; |
504 | case 3: return "REQUEST"; | 504 | case 3: return "REQUEST"; |
505 | case 4: return "DECLINE"; | 505 | case 4: return "DECLINE"; |
506 | case 5: return "ACK"; | 506 | case 5: return "ACK"; |
507 | case 6: return "NAK"; | 507 | case 6: return "NAK"; |
508 | case 7: return "RELEASE"; | 508 | case 7: return "RELEASE"; |
509 | case 8: return "INFORM"; | 509 | case 8: return "INFORM"; |
510 | default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>"; | 510 | default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>"; |
511 | } | 511 | } |
512 | } | 512 | } |
513 | 513 | ||
514 | 514 | ||
515 | QHostAddress ODHCPPacket::clientAddress() const | 515 | QHostAddress ODHCPPacket::clientAddress() const |
516 | { | 516 | { |
517 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); | 517 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); |
518 | } | 518 | } |
519 | 519 | ||
520 | 520 | ||
521 | QHostAddress ODHCPPacket::yourAddress() const | 521 | QHostAddress ODHCPPacket::yourAddress() const |
522 | { | 522 | { |
523 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); | 523 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); |
524 | } | 524 | } |
525 | 525 | ||
526 | 526 | ||
527 | QHostAddress ODHCPPacket::serverAddress() const | 527 | QHostAddress ODHCPPacket::serverAddress() const |
528 | { | 528 | { |
529 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); | 529 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); |
530 | } | 530 | } |
531 | 531 | ||
532 | 532 | ||
533 | QHostAddress ODHCPPacket::relayAddress() const | 533 | QHostAddress ODHCPPacket::relayAddress() const |
534 | { | 534 | { |
535 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); | 535 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); |
536 | } | 536 | } |
537 | 537 | ||
538 | 538 | ||
539 | OMacAddress ODHCPPacket::clientMacAddress() const | 539 | OMacAddress ODHCPPacket::clientMacAddress() const |
540 | { | 540 | { |
541 | return OMacAddress( _dhcphdr->chaddr ); | 541 | return OMacAddress( _dhcphdr->chaddr ); |
542 | } | 542 | } |
543 | 543 | ||
544 | 544 | ||
545 | /*====================================================================================== | 545 | /*====================================================================================== |
546 | * OTCPPacket | 546 | * OTCPPacket |
547 | *======================================================================================*/ | 547 | *======================================================================================*/ |
548 | 548 | ||
549 | 549 | ||
550 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) | 550 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) |
551 | :QObject( parent, "TCP" ), _tcphdr( data ) | 551 | :QObject( parent, "TCP" ), _tcphdr( data ) |
552 | 552 | ||
553 | { | 553 | { |
554 | odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; | 554 | odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; |
555 | } | 555 | } |
556 | 556 | ||
557 | 557 | ||
558 | OTCPPacket::~OTCPPacket() | 558 | OTCPPacket::~OTCPPacket() |
559 | { | 559 | { |
560 | } | 560 | } |
561 | 561 | ||
562 | 562 | ||
563 | int OTCPPacket::fromPort() const | 563 | int OTCPPacket::fromPort() const |
564 | { | 564 | { |
565 | return EXTRACT_16BITS( &_tcphdr->source ); | 565 | return EXTRACT_16BITS( &_tcphdr->source ); |
566 | } | 566 | } |
567 | 567 | ||
568 | 568 | ||
569 | int OTCPPacket::toPort() const | 569 | int OTCPPacket::toPort() const |
570 | { | 570 | { |
571 | return EXTRACT_16BITS( &_tcphdr->dest ); | 571 | return EXTRACT_16BITS( &_tcphdr->dest ); |
572 | } | 572 | } |
573 | 573 | ||
574 | 574 | ||
575 | int OTCPPacket::seq() const | 575 | int OTCPPacket::seq() const |
576 | { | 576 | { |
577 | return EXTRACT_16BITS( &_tcphdr->seq ); | 577 | return EXTRACT_16BITS( &_tcphdr->seq ); |
578 | } | 578 | } |
579 | 579 | ||
580 | 580 | ||
581 | int OTCPPacket::ack() const | 581 | int OTCPPacket::ack() const |
582 | { | 582 | { |
583 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); | 583 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); |
584 | } | 584 | } |
585 | 585 | ||
586 | 586 | ||
587 | int OTCPPacket::window() const | 587 | int OTCPPacket::window() const |
588 | { | 588 | { |
589 | return EXTRACT_16BITS( &_tcphdr->window ); | 589 | return EXTRACT_16BITS( &_tcphdr->window ); |
590 | } | 590 | } |
591 | 591 | ||
592 | 592 | ||
593 | int OTCPPacket::checksum() const | 593 | int OTCPPacket::checksum() const |
594 | { | 594 | { |
595 | return EXTRACT_16BITS( &_tcphdr->check ); | 595 | return EXTRACT_16BITS( &_tcphdr->check ); |
596 | } | 596 | } |
597 | 597 | ||
598 | /*====================================================================================== | 598 | /*====================================================================================== |
599 | * OPrismHeaderPacket | 599 | * OPrismHeaderPacket |
600 | *======================================================================================*/ | 600 | *======================================================================================*/ |
601 | 601 | ||
602 | 602 | ||
603 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) | 603 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) |
604 | :QObject( parent, "Prism" ), _header( data ) | 604 | :QObject( parent, "Prism" ), _header( data ) |
605 | 605 | ||
606 | { | 606 | { |
607 | odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; | 607 | odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; |
608 | 608 | ||
609 | odebug << "Signal Strength = " << data->signal.data << oendl; | 609 | odebug << "Signal Strength = " << data->signal.data << oendl; |
610 | 610 | ||
611 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); | 611 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); |
612 | } | 612 | } |
613 | 613 | ||
614 | OPrismHeaderPacket::~OPrismHeaderPacket() | 614 | OPrismHeaderPacket::~OPrismHeaderPacket() |
615 | { | 615 | { |
616 | } | 616 | } |
617 | 617 | ||
618 | 618 | ||
619 | unsigned int OPrismHeaderPacket::signalStrength() const | 619 | unsigned int OPrismHeaderPacket::signalStrength() const |
620 | { | 620 | { |
621 | return _header->signal.data; | 621 | return _header->signal.data; |
622 | } | 622 | } |
623 | 623 | ||
624 | /*====================================================================================== | 624 | /*====================================================================================== |
625 | * OWaveLanPacket | 625 | * OWaveLanPacket |
626 | *======================================================================================*/ | 626 | *======================================================================================*/ |
627 | 627 | ||
628 | 628 | ||
629 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) | 629 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) |
630 | :QObject( parent, "802.11" ), _wlanhdr( data ) | 630 | :QObject( parent, "802.11" ), _wlanhdr( data ) |
631 | 631 | ||
632 | { | 632 | { |
633 | odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl; | 633 | odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl; |
634 | odebug << "type = " << type() << oendl; | 634 | odebug << "type = " << type() << oendl; |
635 | odebug << "subType = " << subType() << oendl; | 635 | odebug << "subType = " << subType() << oendl; |
636 | odebug << "duration = " << duration() << oendl; | 636 | odebug << "duration = " << duration() << oendl; |
637 | odebug << "powermanagement = " << usesPowerManagement() << oendl; | 637 | odebug << "powermanagement = " << usesPowerManagement() << oendl; |
638 | odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl; | 638 | odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl; |
639 | odebug << "MAC1 = " << macAddress1().toString() << oendl; | 639 | odebug << "MAC1 = " << macAddress1().toString() << oendl; |
640 | odebug << "MAC2 = " << macAddress2().toString() << oendl; | 640 | odebug << "MAC2 = " << macAddress2().toString() << oendl; |
641 | odebug << "MAC3 = " << macAddress3().toString() << oendl; | 641 | odebug << "MAC3 = " << macAddress3().toString() << oendl; |
642 | odebug << "MAC4 = " << macAddress4().toString() << oendl; | 642 | odebug << "MAC4 = " << macAddress4().toString() << oendl; |
643 | 643 | ||
644 | switch ( type() ) | 644 | switch ( type() ) |
645 | { | 645 | { |
646 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; | 646 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
647 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; | 647 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
648 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; | 648 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; |
649 | default: odebug << "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type = " << type() << oendl; | 649 | default: odebug << "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type = " << type() << oendl; |
650 | } | 650 | } |
651 | } | 651 | } |
652 | 652 | ||
653 | OWaveLanPacket::~OWaveLanPacket() | 653 | OWaveLanPacket::~OWaveLanPacket() |
654 | { | 654 | { |
655 | } | 655 | } |
656 | 656 | ||
657 | 657 | ||
658 | int OWaveLanPacket::duration() const | 658 | int OWaveLanPacket::duration() const |
659 | { | 659 | { |
660 | return _wlanhdr->duration; | 660 | return _wlanhdr->duration; |
661 | } | 661 | } |
662 | 662 | ||
663 | 663 | ||
664 | OMacAddress OWaveLanPacket::macAddress1() const | 664 | OMacAddress OWaveLanPacket::macAddress1() const |
665 | { | 665 | { |
666 | return OMacAddress( _wlanhdr->mac1 ); | 666 | return OMacAddress( _wlanhdr->mac1 ); |
667 | } | 667 | } |
668 | 668 | ||
669 | 669 | ||
670 | OMacAddress OWaveLanPacket::macAddress2() const | 670 | OMacAddress OWaveLanPacket::macAddress2() const |
671 | { | 671 | { |
672 | return OMacAddress( _wlanhdr->mac2 ); | 672 | return OMacAddress( _wlanhdr->mac2 ); |
673 | } | 673 | } |
674 | 674 | ||
675 | 675 | ||
676 | OMacAddress OWaveLanPacket::macAddress3() const | 676 | OMacAddress OWaveLanPacket::macAddress3() const |
677 | { | 677 | { |
678 | return OMacAddress( _wlanhdr->mac3 ); | 678 | return OMacAddress( _wlanhdr->mac3 ); |
679 | } | 679 | } |
680 | 680 | ||
681 | 681 | ||
682 | OMacAddress OWaveLanPacket::macAddress4() const | 682 | OMacAddress OWaveLanPacket::macAddress4() const |
683 | { | 683 | { |
684 | return OMacAddress( _wlanhdr->mac4 ); | 684 | return OMacAddress( _wlanhdr->mac4 ); |
685 | } | 685 | } |
686 | 686 | ||
687 | 687 | ||
688 | int OWaveLanPacket::subType() const | 688 | int OWaveLanPacket::subType() const |
689 | { | 689 | { |
690 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 690 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
691 | } | 691 | } |
692 | 692 | ||
693 | 693 | ||
694 | int OWaveLanPacket::type() const | 694 | int OWaveLanPacket::type() const |
695 | { | 695 | { |
696 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 696 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
697 | } | 697 | } |
698 | 698 | ||
699 | 699 | ||
700 | int OWaveLanPacket::version() const | 700 | int OWaveLanPacket::version() const |
701 | { | 701 | { |
702 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 702 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
703 | } | 703 | } |
704 | 704 | ||
705 | 705 | ||
706 | bool OWaveLanPacket::fromDS() const | 706 | bool OWaveLanPacket::fromDS() const |
707 | { | 707 | { |
708 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 708 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
709 | } | 709 | } |
710 | 710 | ||
711 | 711 | ||
712 | bool OWaveLanPacket::toDS() const | 712 | bool OWaveLanPacket::toDS() const |
713 | { | 713 | { |
714 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 714 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
715 | } | 715 | } |
716 | 716 | ||
717 | 717 | ||
718 | bool OWaveLanPacket::usesPowerManagement() const | 718 | bool OWaveLanPacket::usesPowerManagement() const |
719 | { | 719 | { |
720 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 720 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
721 | } | 721 | } |
722 | 722 | ||
723 | 723 | ||
724 | bool OWaveLanPacket::usesWep() const | 724 | bool OWaveLanPacket::usesWep() const |
725 | { | 725 | { |
726 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 726 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
727 | } | 727 | } |
728 | 728 | ||
729 | 729 | ||
730 | /*====================================================================================== | 730 | /*====================================================================================== |
731 | * OWaveLanManagementPacket | 731 | * OWaveLanManagementPacket |
732 | *======================================================================================*/ | 732 | *======================================================================================*/ |
733 | 733 | ||
734 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 734 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
735 | :QObject( parent, "802.11 Management" ), _header( data ), | 735 | :QObject( parent, "802.11 Management" ), _header( data ), |
736 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 736 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
737 | { | 737 | { |
738 | odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; | 738 | odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; |
739 | odebug << "Detected subtype is " << managementType() << oendl; | 739 | odebug << "Detected subtype is " << managementType() << oendl; |
740 | 740 | ||
741 | // Grab tagged values. | 741 | // Grab tagged values. |
742 | // Beacons contain a 12 byte long fixed parameters set before the tagged parameters come, | 742 | // Beacons contain a 12 byte long fixed parameters set before the tagged parameters come, |
743 | // Other management frames don't - which is why we have to inspect the subtype here. | 743 | // Other management frames don't - which is why we have to inspect the subtype here. |
744 | 744 | ||
745 | const unsigned char* ptr = managementType() == "Beacon" ? (const unsigned char*) (_body+1) : (const unsigned char*) (_header+1); | 745 | const unsigned char* ptr = managementType() == "Beacon" ? (const unsigned char*) (_body+1) : (const unsigned char*) (_header+1); |
746 | 746 | ||
747 | while (ptr < end) | 747 | while (ptr < end) |
748 | { | 748 | { |
749 | switch ( *ptr ) | 749 | switch ( *ptr ) |
750 | { | 750 | { |
751 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; | 751 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; |
752 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; | 752 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; |
753 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; | 753 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; |
754 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; | 754 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; |
755 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; | 755 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; |
756 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; | 756 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; |
757 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; | 757 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; |
758 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; | 758 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; |
759 | } | 759 | } |
760 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value | 760 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value |
761 | ptr+= 2; // skip tag ID and length | 761 | ptr+= 2; // skip tag ID and length |
762 | } | 762 | } |
763 | } | 763 | } |
764 | 764 | ||
765 | 765 | ||
766 | OWaveLanManagementPacket::~OWaveLanManagementPacket() | 766 | OWaveLanManagementPacket::~OWaveLanManagementPacket() |
767 | { | 767 | { |
768 | } | 768 | } |
769 | 769 | ||
770 | 770 | ||
771 | QString OWaveLanManagementPacket::managementType() const | 771 | QString OWaveLanManagementPacket::managementType() const |
772 | { | 772 | { |
773 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | 773 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
774 | { | 774 | { |
775 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; | 775 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; |
776 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; | 776 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; |
777 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; | 777 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; |
778 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; | 778 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; |
779 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; | 779 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; |
780 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; | 780 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; |
781 | case ST_BEACON: return "Beacon"; break; | 781 | case ST_BEACON: return "Beacon"; break; |
782 | case ST_ATIM: return "Atim"; break; | 782 | case ST_ATIM: return "Atim"; break; |
783 | case ST_DISASSOC: return "Disassociation"; break; | 783 | case ST_DISASSOC: return "Disassociation"; break; |
784 | case ST_AUTH: return "Authentication"; break; | 784 | case ST_AUTH: return "Authentication"; break; |
785 | case ST_DEAUTH: return "Deathentication"; break; | 785 | case ST_DEAUTH: return "Deathentication"; break; |
786 | default: owarn << "OWaveLanManagementPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; return "Unknown"; | 786 | default: owarn << "OWaveLanManagementPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; return "Unknown"; |
787 | } | 787 | } |
788 | } | 788 | } |
789 | 789 | ||
790 | 790 | ||
791 | int OWaveLanManagementPacket::beaconInterval() const | 791 | int OWaveLanManagementPacket::beaconInterval() const |
792 | { | 792 | { |
793 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); | 793 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); |
794 | } | 794 | } |
795 | 795 | ||
796 | 796 | ||
797 | int OWaveLanManagementPacket::capabilities() const | 797 | int OWaveLanManagementPacket::capabilities() const |
798 | { | 798 | { |
799 | return EXTRACT_LE_16BITS( &_body->capability_info ); | 799 | return EXTRACT_LE_16BITS( &_body->capability_info ); |
800 | } | 800 | } |
801 | 801 | ||
802 | 802 | ||
803 | bool OWaveLanManagementPacket::canESS() const | 803 | bool OWaveLanManagementPacket::canESS() const |
804 | { | 804 | { |
805 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 805 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
806 | } | 806 | } |
807 | 807 | ||
808 | 808 | ||
809 | bool OWaveLanManagementPacket::canIBSS() const | 809 | bool OWaveLanManagementPacket::canIBSS() const |
810 | { | 810 | { |
811 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 811 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
812 | } | 812 | } |
813 | 813 | ||
814 | 814 | ||
815 | bool OWaveLanManagementPacket::canCFP() const | 815 | bool OWaveLanManagementPacket::canCFP() const |
816 | { | 816 | { |
817 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 817 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
818 | } | 818 | } |
819 | 819 | ||
820 | 820 | ||
821 | bool OWaveLanManagementPacket::canCFP_REQ() const | 821 | bool OWaveLanManagementPacket::canCFP_REQ() const |
822 | { | 822 | { |
823 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 823 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
824 | } | 824 | } |
825 | 825 | ||
826 | 826 | ||
827 | bool OWaveLanManagementPacket::canPrivacy() const | 827 | bool OWaveLanManagementPacket::canPrivacy() const |
828 | { | 828 | { |
829 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 829 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
830 | } | 830 | } |
831 | 831 | ||
832 | 832 | ||
833 | /*====================================================================================== | 833 | /*====================================================================================== |
834 | * OWaveLanManagementSSID | 834 | * OWaveLanManagementSSID |
835 | *======================================================================================*/ | 835 | *======================================================================================*/ |
836 | 836 | ||
837 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) | 837 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) |
838 | :QObject( parent, "802.11 SSID" ), _data( data ) | 838 | :QObject( parent, "802.11 SSID" ), _data( data ) |
839 | { | 839 | { |
840 | odebug << "OWaveLanManagementSSID()" << oendl; | 840 | odebug << "OWaveLanManagementSSID()" << oendl; |
841 | } | 841 | } |
842 | 842 | ||
843 | 843 | ||
844 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | 844 | OWaveLanManagementSSID::~OWaveLanManagementSSID() |
845 | { | 845 | { |
846 | } | 846 | } |
847 | 847 | ||
848 | 848 | ||
849 | QString OWaveLanManagementSSID::ID( bool decloak ) const | 849 | QString OWaveLanManagementSSID::ID( bool decloak ) const |
850 | { | 850 | { |
851 | int length = _data->length; | 851 | int length = _data->length; |
852 | if ( length > 32 ) length = 32; | 852 | if ( length > 32 ) length = 32; |
853 | char essid[length+1]; | 853 | char essid[length+1]; |
854 | memcpy( &essid, &_data->ssid, length ); | 854 | memcpy( &essid, &_data->ssid, length ); |
855 | essid[length] = 0x0; | 855 | essid[length] = 0x0; |
856 | if ( !decloak || length < 2 || essid[0] != '\0' ) return essid; | 856 | if ( !decloak || length < 2 || essid[0] != '\0' ) return essid; |
857 | odebug << "OWaveLanManagementSSID:ID(): SSID is cloaked - decloaking..." << oendl; | 857 | odebug << "OWaveLanManagementSSID:ID(): SSID is cloaked - decloaking..." << oendl; |
858 | 858 | ||
859 | QString decloakedID; | 859 | QString decloakedID; |
860 | for ( int i = 1; i < length; ++i ) | 860 | for ( int i = 1; i < length; ++i ) |
861 | { | 861 | { |
862 | if ( essid[i] >= 32 && essid[i] <= 126 ) decloakedID.append( essid[i] ); | 862 | if ( essid[i] >= 32 && essid[i] <= 126 ) decloakedID.append( essid[i] ); |
863 | else decloakedID.append( '.' ); | 863 | else decloakedID.append( '.' ); |
864 | } | 864 | } |
865 | return decloakedID; | 865 | return decloakedID; |
866 | } | 866 | } |
867 | 867 | ||
868 | 868 | ||
869 | /*====================================================================================== | 869 | /*====================================================================================== |
870 | * OWaveLanManagementRates | 870 | * OWaveLanManagementRates |
871 | *======================================================================================*/ | 871 | *======================================================================================*/ |
872 | 872 | ||
873 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) | 873 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) |
874 | :QObject( parent, "802.11 Rates" ), _data( data ) | 874 | :QObject( parent, "802.11 Rates" ), _data( data ) |
875 | { | 875 | { |
876 | odebug << "OWaveLanManagementRates()" << oendl; | 876 | odebug << "OWaveLanManagementRates()" << oendl; |
877 | } | 877 | } |
878 | 878 | ||
879 | 879 | ||
880 | OWaveLanManagementRates::~OWaveLanManagementRates() | 880 | OWaveLanManagementRates::~OWaveLanManagementRates() |
881 | { | 881 | { |
882 | } | 882 | } |
883 | 883 | ||
884 | /*====================================================================================== | 884 | /*====================================================================================== |
885 | * OWaveLanManagementCF | 885 | * OWaveLanManagementCF |
886 | *======================================================================================*/ | 886 | *======================================================================================*/ |
887 | 887 | ||
888 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) | 888 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) |
889 | :QObject( parent, "802.11 CF" ), _data( data ) | 889 | :QObject( parent, "802.11 CF" ), _data( data ) |
890 | { | 890 | { |
891 | odebug << "OWaveLanManagementCF()" << oendl; | 891 | odebug << "OWaveLanManagementCF()" << oendl; |
892 | } | 892 | } |
893 | 893 | ||
894 | 894 | ||
895 | OWaveLanManagementCF::~OWaveLanManagementCF() | 895 | OWaveLanManagementCF::~OWaveLanManagementCF() |
896 | { | 896 | { |
897 | } | 897 | } |
898 | 898 | ||
899 | /*====================================================================================== | 899 | /*====================================================================================== |
900 | * OWaveLanManagementFH | 900 | * OWaveLanManagementFH |
901 | *======================================================================================*/ | 901 | *======================================================================================*/ |
902 | 902 | ||
903 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) | 903 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) |
904 | :QObject( parent, "802.11 FH" ), _data( data ) | 904 | :QObject( parent, "802.11 FH" ), _data( data ) |
905 | { | 905 | { |
906 | odebug << "OWaveLanManagementFH()" << oendl; | 906 | odebug << "OWaveLanManagementFH()" << oendl; |
907 | } | 907 | } |
908 | 908 | ||
909 | 909 | ||
910 | OWaveLanManagementFH::~OWaveLanManagementFH() | 910 | OWaveLanManagementFH::~OWaveLanManagementFH() |
911 | { | 911 | { |
912 | } | 912 | } |
913 | 913 | ||
914 | /*====================================================================================== | 914 | /*====================================================================================== |
915 | * OWaveLanManagementDS | 915 | * OWaveLanManagementDS |
916 | *======================================================================================*/ | 916 | *======================================================================================*/ |
917 | 917 | ||
918 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) | 918 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) |
919 | :QObject( parent, "802.11 DS" ), _data( data ) | 919 | :QObject( parent, "802.11 DS" ), _data( data ) |
920 | { | 920 | { |
921 | odebug << "OWaveLanManagementDS()" << oendl; | 921 | odebug << "OWaveLanManagementDS()" << oendl; |
922 | } | 922 | } |
923 | 923 | ||
924 | 924 | ||
925 | OWaveLanManagementDS::~OWaveLanManagementDS() | 925 | OWaveLanManagementDS::~OWaveLanManagementDS() |
926 | { | 926 | { |
927 | } | 927 | } |
928 | 928 | ||
929 | 929 | ||
930 | int OWaveLanManagementDS::channel() const | 930 | int OWaveLanManagementDS::channel() const |
931 | { | 931 | { |
932 | return _data->channel; | 932 | return _data->channel; |
933 | } | 933 | } |
934 | 934 | ||
935 | /*====================================================================================== | 935 | /*====================================================================================== |
936 | * OWaveLanManagementTim | 936 | * OWaveLanManagementTim |
937 | *======================================================================================*/ | 937 | *======================================================================================*/ |
938 | 938 | ||
939 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) | 939 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) |
940 | :QObject( parent, "802.11 Tim" ), _data( data ) | 940 | :QObject( parent, "802.11 Tim" ), _data( data ) |
941 | { | 941 | { |
942 | odebug << "OWaveLanManagementTim()" << oendl; | 942 | odebug << "OWaveLanManagementTim()" << oendl; |
943 | } | 943 | } |
944 | 944 | ||
945 | 945 | ||
946 | OWaveLanManagementTim::~OWaveLanManagementTim() | 946 | OWaveLanManagementTim::~OWaveLanManagementTim() |
947 | { | 947 | { |
948 | } | 948 | } |
949 | 949 | ||
950 | /*====================================================================================== | 950 | /*====================================================================================== |
951 | * OWaveLanManagementIBSS | 951 | * OWaveLanManagementIBSS |
952 | *======================================================================================*/ | 952 | *======================================================================================*/ |
953 | 953 | ||
954 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) | 954 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) |
955 | :QObject( parent, "802.11 IBSS" ), _data( data ) | 955 | :QObject( parent, "802.11 IBSS" ), _data( data ) |
956 | { | 956 | { |
957 | odebug << "OWaveLanManagementIBSS()" << oendl; | 957 | odebug << "OWaveLanManagementIBSS()" << oendl; |
958 | } | 958 | } |
959 | 959 | ||
960 | 960 | ||
961 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | 961 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() |
962 | { | 962 | { |
963 | } | 963 | } |
964 | 964 | ||
965 | /*====================================================================================== | 965 | /*====================================================================================== |
966 | * OWaveLanManagementChallenge | 966 | * OWaveLanManagementChallenge |
967 | *======================================================================================*/ | 967 | *======================================================================================*/ |
968 | 968 | ||
969 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) | 969 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) |
970 | :QObject( parent, "802.11 Challenge" ), _data( data ) | 970 | :QObject( parent, "802.11 Challenge" ), _data( data ) |
971 | { | 971 | { |
972 | odebug << "OWaveLanManagementChallenge()" << oendl; | 972 | odebug << "OWaveLanManagementChallenge()" << oendl; |
973 | } | 973 | } |
974 | 974 | ||
975 | 975 | ||
976 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | 976 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() |
977 | { | 977 | { |
978 | } | 978 | } |
979 | 979 | ||
980 | /*====================================================================================== | 980 | /*====================================================================================== |
981 | * OWaveLanDataPacket | 981 | * OWaveLanDataPacket |
982 | *======================================================================================*/ | 982 | *======================================================================================*/ |
983 | 983 | ||
984 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 984 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) |
985 | :QObject( parent, "802.11 Data" ), _header( data ) | 985 | :QObject( parent, "802.11 Data" ), _header( data ) |
986 | { | 986 | { |
987 | odebug << "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." << oendl; | 987 | odebug << "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." << oendl; |
988 | 988 | ||
989 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); | 989 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); |
990 | 990 | ||
991 | #warning The next line works for most cases, but can not be correct generally! | 991 | #warning The next line works for most cases, but can not be correct generally! |
992 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 992 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address |
993 | 993 | ||
994 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); | 994 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); |
995 | } | 995 | } |
996 | 996 | ||
997 | 997 | ||
998 | OWaveLanDataPacket::~OWaveLanDataPacket() | 998 | OWaveLanDataPacket::~OWaveLanDataPacket() |
999 | { | 999 | { |
1000 | } | 1000 | } |
1001 | 1001 | ||
1002 | 1002 | ||
1003 | /*====================================================================================== | 1003 | /*====================================================================================== |
1004 | * OLLCPacket | 1004 | * OLLCPacket |
1005 | *======================================================================================*/ | 1005 | *======================================================================================*/ |
1006 | 1006 | ||
1007 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) | 1007 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
1008 | :QObject( parent, "802.11 LLC" ), _header( data ) | 1008 | :QObject( parent, "802.11 LLC" ), _header( data ) |
1009 | { | 1009 | { |
1010 | odebug << "OLLCPacket::OLLCPacket(): decoding frame..." << oendl; | 1010 | odebug << "OLLCPacket::OLLCPacket(): decoding frame..." << oendl; |
1011 | 1011 | ||
1012 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) | 1012 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) |
1013 | { | 1013 | { |
1014 | owarn << "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type = " << EXTRACT_16BITS( &_header->type ) << ")" << oendl; | 1014 | owarn << "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type = " << EXTRACT_16BITS( &_header->type ) << ")" << oendl; |
1015 | 1015 | ||
1016 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h | 1016 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h |
1017 | { | 1017 | { |
1018 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 1018 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
1019 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 1019 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
1020 | default: owarn << "OLLCPacket::OLLCPacket(): Unknown Encapsulation type = " << EXTRACT_16BITS( &_header->type ) << oendl; | 1020 | default: owarn << "OLLCPacket::OLLCPacket(): Unknown Encapsulation type = " << EXTRACT_16BITS( &_header->type ) << oendl; |
1021 | } | 1021 | } |
1022 | } | 1022 | } |
1023 | } | 1023 | } |
1024 | 1024 | ||
1025 | 1025 | ||
1026 | OLLCPacket::~OLLCPacket() | 1026 | OLLCPacket::~OLLCPacket() |
1027 | { | 1027 | { |
1028 | } | 1028 | } |
1029 | 1029 | ||
1030 | 1030 | ||
1031 | /*====================================================================================== | 1031 | /*====================================================================================== |
1032 | * OWaveLanControlPacket | 1032 | * OWaveLanControlPacket |
1033 | *======================================================================================*/ | 1033 | *======================================================================================*/ |
1034 | 1034 | ||
1035 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) | 1035 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) |
1036 | :QObject( parent, "802.11 Control" ), _header( data ) | 1036 | :QObject( parent, "802.11 Control" ), _header( data ) |
1037 | { | 1037 | { |
1038 | odebug << "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." << oendl; | 1038 | odebug << "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." << oendl; |
1039 | odebug << "Detected subtype is " << controlType() << oendl; | 1039 | odebug << "Detected subtype is " << controlType() << oendl; |
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | 1042 | ||
1043 | OWaveLanControlPacket::~OWaveLanControlPacket() | 1043 | OWaveLanControlPacket::~OWaveLanControlPacket() |
1044 | { | 1044 | { |
1045 | } | 1045 | } |
1046 | 1046 | ||
1047 | 1047 | ||
1048 | QString OWaveLanControlPacket::controlType() const | 1048 | QString OWaveLanControlPacket::controlType() const |
1049 | { | 1049 | { |
1050 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | 1050 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
1051 | { | 1051 | { |
1052 | case CTRL_PS_POLL: return "PowerSavePoll"; break; | 1052 | case CTRL_PS_POLL: return "PowerSavePoll"; break; |
1053 | case CTRL_RTS: return "RequestToSend"; break; | 1053 | case CTRL_RTS: return "RequestToSend"; break; |
1054 | case CTRL_CTS: return "ClearToSend"; break; | 1054 | case CTRL_CTS: return "ClearToSend"; break; |
1055 | case CTRL_ACK: return "Acknowledge"; break; | 1055 | case CTRL_ACK: return "Acknowledge"; break; |
1056 | case CTRL_CF_END: return "ContentionFreeEnd"; break; | 1056 | case CTRL_CF_END: return "ContentionFreeEnd"; break; |
1057 | case CTRL_END_ACK: return "AcknowledgeEnd"; break; | 1057 | case CTRL_END_ACK: return "AcknowledgeEnd"; break; |
1058 | default: | 1058 | default: |
1059 | owarn << "OWaveLanControlPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; | 1059 | owarn << "OWaveLanControlPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; |
1060 | return "Unknown"; | 1060 | return "Unknown"; |
1061 | } | 1061 | } |
1062 | } | 1062 | } |
1063 | 1063 | ||
1064 | 1064 | ||
1065 | /*====================================================================================== | 1065 | /*====================================================================================== |
1066 | * OPacketCapturer | 1066 | * OPacketCapturer |
1067 | *======================================================================================*/ | 1067 | *======================================================================================*/ |
1068 | 1068 | ||
1069 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 1069 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) |
1070 | :QObject( parent, name ), _name( QString::null ), _open( false ), _pch( 0 ), _pcd( 0 ), _sn( 0 ), _autodelete( true ) | 1070 | :QObject( parent, name ), _name( QString::null ), _open( false ), _pch( 0 ), _pcd( 0 ), _sn( 0 ), _autodelete( true ) |
1071 | { | 1071 | { |
1072 | } | 1072 | } |
1073 | 1073 | ||
1074 | 1074 | ||
1075 | OPacketCapturer::~OPacketCapturer() | 1075 | OPacketCapturer::~OPacketCapturer() |
1076 | { | 1076 | { |
1077 | if ( _open ) | 1077 | if ( _open ) |
1078 | { | 1078 | { |
1079 | odebug << "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." << oendl; | 1079 | odebug << "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." << oendl; |
1080 | close(); | 1080 | close(); |
1081 | } | 1081 | } |
1082 | } | 1082 | } |
1083 | 1083 | ||
1084 | 1084 | ||
1085 | void OPacketCapturer::setAutoDelete( bool b ) | 1085 | void OPacketCapturer::setAutoDelete( bool b ) |
1086 | { | 1086 | { |
1087 | _autodelete = b; | 1087 | _autodelete = b; |
1088 | } | 1088 | } |
1089 | 1089 | ||
1090 | 1090 | ||
1091 | bool OPacketCapturer::autoDelete() const | 1091 | bool OPacketCapturer::autoDelete() const |
1092 | { | 1092 | { |
1093 | return _autodelete; | 1093 | return _autodelete; |
1094 | } | 1094 | } |
1095 | 1095 | ||
1096 | 1096 | ||
1097 | void OPacketCapturer::setBlocking( bool b ) | 1097 | void OPacketCapturer::setBlocking( bool b ) |
1098 | { | 1098 | { |
1099 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) | 1099 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) |
1100 | { | 1100 | { |
1101 | odebug << "OPacketCapturer::setBlocking(): blocking mode changed successfully." << oendl; | 1101 | odebug << "OPacketCapturer::setBlocking(): blocking mode changed successfully." << oendl; |
1102 | } | 1102 | } |
1103 | else | 1103 | else |
1104 | { | 1104 | { |
1105 | odebug << "OPacketCapturer::setBlocking(): can't change blocking mode: " << _errbuf << oendl; | 1105 | odebug << "OPacketCapturer::setBlocking(): can't change blocking mode: " << _errbuf << oendl; |
1106 | } | 1106 | } |
1107 | } | 1107 | } |
1108 | 1108 | ||
1109 | 1109 | ||
1110 | bool OPacketCapturer::blocking() const | 1110 | bool OPacketCapturer::blocking() const |
1111 | { | 1111 | { |
1112 | int b = pcap_getnonblock( _pch, _errbuf ); | 1112 | int b = pcap_getnonblock( _pch, _errbuf ); |
1113 | if ( b == -1 ) | 1113 | if ( b == -1 ) |
1114 | { | 1114 | { |
1115 | odebug << "OPacketCapturer::blocking(): can't get blocking mode: " << _errbuf << oendl; | 1115 | odebug << "OPacketCapturer::blocking(): can't get blocking mode: " << _errbuf << oendl; |
1116 | return -1; | 1116 | return -1; |
1117 | } | 1117 | } |
1118 | return !b; | 1118 | return !b; |
1119 | } | 1119 | } |