-rw-r--r-- | libopie2/opienet/opcap.cpp | 253 |
1 files changed, 225 insertions, 28 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 48f874f..913d42e 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -28,57 +28,60 @@ | |||
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | 35 | ||
36 | #include <opie2/opcap.h> | 36 | #include <opie2/opcap.h> |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | 39 | ||
40 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) | 40 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) |
41 | #include <qsocketnotifier.h> | 41 | #include <qsocketnotifier.h> |
42 | 42 | ||
43 | /*====================================================================================== | 43 | /*====================================================================================== |
44 | * OPacket | 44 | * OPacket |
45 | *======================================================================================*/ | 45 | *======================================================================================*/ |
46 | 46 | ||
47 | OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject* parent ) | 47 | OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject* parent ) |
48 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) | 48 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) |
49 | { | 49 | { |
50 | qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); | 50 | qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); |
51 | 51 | ||
52 | _end = (unsigned char*) data + header.len; | ||
53 | qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); | ||
54 | |||
52 | if ( packetCapturer()->dataLink() == DLT_EN10MB ) | 55 | if ( packetCapturer()->dataLink() == DLT_EN10MB ) |
53 | { | 56 | { |
54 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); | 57 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); |
55 | new OEthernetPacket( (const struct ether_header*) data, this ); | 58 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); |
56 | } | 59 | } |
57 | else | 60 | else |
58 | { | 61 | { |
59 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); | 62 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); |
60 | new OWaveLanPacket( (const struct ieee_802_11_header*) data, this ); | 63 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); |
61 | } | 64 | } |
62 | } | 65 | } |
63 | 66 | ||
64 | 67 | ||
65 | OPacket::~OPacket() | 68 | OPacket::~OPacket() |
66 | { | 69 | { |
67 | } | 70 | } |
68 | 71 | ||
69 | 72 | ||
70 | OPacketCapturer* OPacket::packetCapturer() const | 73 | OPacketCapturer* OPacket::packetCapturer() const |
71 | { | 74 | { |
72 | return parent()->inherits( "OPacketCapturer" ) ? static_cast<OPacketCapturer*>( parent() ) : 0; | 75 | return parent()->inherits( "OPacketCapturer" ) ? static_cast<OPacketCapturer*>( parent() ) : 0; |
73 | } | 76 | } |
74 | 77 | ||
75 | 78 | ||
76 | timevalstruct OPacket::timeval() const | 79 | timevalstruct OPacket::timeval() const |
77 | { | 80 | { |
78 | return _hdr.ts; | 81 | return _hdr.ts; |
79 | } | 82 | } |
80 | 83 | ||
81 | 84 | ||
82 | int OPacket::caplen() const | 85 | int OPacket::caplen() const |
83 | { | 86 | { |
84 | return _hdr.caplen; | 87 | return _hdr.caplen; |
@@ -88,115 +91,115 @@ int OPacket::caplen() const | |||
88 | void OPacket::dump() const | 91 | void OPacket::dump() const |
89 | { | 92 | { |
90 | printf( "OPacket::dump()\n" ); | 93 | printf( "OPacket::dump()\n" ); |
91 | printf( "----------------\n" ); | 94 | printf( "----------------\n" ); |
92 | 95 | ||
93 | for ( int i = 0; i < _hdr.caplen; ++i ) | 96 | for ( int i = 0; i < _hdr.caplen; ++i ) |
94 | { | 97 | { |
95 | printf( "%02x ", _data[i] ); | 98 | printf( "%02x ", _data[i] ); |
96 | if ( !((i+1) % 32) ) printf( "\n" ); | 99 | if ( !((i+1) % 32) ) printf( "\n" ); |
97 | } | 100 | } |
98 | printf( "\n\n" ); | 101 | printf( "\n\n" ); |
99 | } | 102 | } |
100 | 103 | ||
101 | 104 | ||
102 | 105 | ||
103 | int OPacket::len() const | 106 | int OPacket::len() const |
104 | { | 107 | { |
105 | return _hdr.len; | 108 | return _hdr.len; |
106 | } | 109 | } |
107 | 110 | ||
108 | /*====================================================================================== | 111 | /*====================================================================================== |
109 | * OEthernetPacket | 112 | * OEthernetPacket |
110 | *======================================================================================*/ | 113 | *======================================================================================*/ |
111 | 114 | ||
112 | OEthernetPacket::OEthernetPacket( const struct ether_header* data, QObject* parent ) | 115 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
113 | :QObject( parent, "Ethernet" ), _ether( data ) | 116 | :QObject( parent, "Ethernet" ), _ether( data ) |
114 | 117 | ||
115 | { | 118 | { |
116 | 119 | ||
117 | qDebug( "Source = %s", (const char*) sourceAddress().toString() ); | 120 | qDebug( "Source = %s", (const char*) sourceAddress().toString() ); |
118 | qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); | 121 | qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); |
119 | 122 | ||
120 | if ( sourceAddress() == OMacAddress::broadcast ) | 123 | if ( sourceAddress() == OMacAddress::broadcast ) |
121 | qDebug( "Source is broadcast address" ); | 124 | qDebug( "Source is broadcast address" ); |
122 | if ( destinationAddress() == OMacAddress::broadcast ) | 125 | if ( destinationAddress() == OMacAddress::broadcast ) |
123 | qDebug( "Destination is broadcast address" ); | 126 | qDebug( "Destination is broadcast address" ); |
124 | 127 | ||
125 | switch ( type() ) | 128 | switch ( type() ) |
126 | { | 129 | { |
127 | case ETHERTYPE_IP: new OIPPacket( (const struct iphdr*) (data+1), this ); break; | 130 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
128 | case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } | 131 | case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } |
129 | case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } | 132 | case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } |
130 | default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); | 133 | default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); |
131 | } | 134 | } |
132 | 135 | ||
133 | } | 136 | } |
134 | 137 | ||
135 | 138 | ||
136 | OEthernetPacket::~OEthernetPacket() | 139 | OEthernetPacket::~OEthernetPacket() |
137 | { | 140 | { |
138 | } | 141 | } |
139 | 142 | ||
140 | 143 | ||
141 | OMacAddress OEthernetPacket::sourceAddress() const | 144 | OMacAddress OEthernetPacket::sourceAddress() const |
142 | { | 145 | { |
143 | return OMacAddress( _ether->ether_shost ); | 146 | return OMacAddress( _ether->ether_shost ); |
144 | } | 147 | } |
145 | 148 | ||
146 | 149 | ||
147 | OMacAddress OEthernetPacket::destinationAddress() const | 150 | OMacAddress OEthernetPacket::destinationAddress() const |
148 | { | 151 | { |
149 | return OMacAddress( _ether->ether_dhost ); | 152 | return OMacAddress( _ether->ether_dhost ); |
150 | } | 153 | } |
151 | 154 | ||
152 | int OEthernetPacket::type() const | 155 | int OEthernetPacket::type() const |
153 | { | 156 | { |
154 | return ntohs( _ether->ether_type ); | 157 | return ntohs( _ether->ether_type ); |
155 | } | 158 | } |
156 | 159 | ||
157 | 160 | ||
158 | /*====================================================================================== | 161 | /*====================================================================================== |
159 | * OIPPacket | 162 | * OIPPacket |
160 | *======================================================================================*/ | 163 | *======================================================================================*/ |
161 | 164 | ||
162 | 165 | ||
163 | OIPPacket::OIPPacket( const struct iphdr* data, QObject* parent ) | 166 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
164 | :QObject( parent, "IP" ), _iphdr( data ) | 167 | :QObject( parent, "IP" ), _iphdr( data ) |
165 | 168 | ||
166 | { | 169 | { |
167 | qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); | 170 | qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); |
168 | 171 | ||
169 | //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); | 172 | //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); |
170 | //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); | 173 | //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); |
171 | 174 | ||
172 | qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); | 175 | qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); |
173 | qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); | 176 | qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); |
174 | 177 | ||
175 | switch ( protocol() ) | 178 | switch ( protocol() ) |
176 | { | 179 | { |
177 | case IPPROTO_UDP: new OUDPPacket( (const struct udphdr*) (data+1), this ); break; | 180 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
178 | case IPPROTO_TCP: new OTCPPacket( (const struct tcphdr*) (data+1), this ); break; | 181 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
179 | default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); | 182 | default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); |
180 | } | 183 | } |
181 | 184 | ||
182 | } | 185 | } |
183 | 186 | ||
184 | OIPPacket::~OIPPacket() | 187 | OIPPacket::~OIPPacket() |
185 | { | 188 | { |
186 | } | 189 | } |
187 | 190 | ||
188 | 191 | ||
189 | QHostAddress OIPPacket::fromIPAddress() const | 192 | QHostAddress OIPPacket::fromIPAddress() const |
190 | { | 193 | { |
191 | return EXTRACT_32BITS( &_iphdr->saddr ); | 194 | return EXTRACT_32BITS( &_iphdr->saddr ); |
192 | } | 195 | } |
193 | 196 | ||
194 | 197 | ||
195 | QHostAddress OIPPacket::toIPAddress() const | 198 | QHostAddress OIPPacket::toIPAddress() const |
196 | { | 199 | { |
197 | return EXTRACT_32BITS( &_iphdr->saddr ); | 200 | return EXTRACT_32BITS( &_iphdr->saddr ); |
198 | } | 201 | } |
199 | 202 | ||
200 | 203 | ||
201 | int OIPPacket::tos() const | 204 | int OIPPacket::tos() const |
202 | { | 205 | { |
@@ -223,102 +226,102 @@ int OIPPacket::offset() const | |||
223 | 226 | ||
224 | 227 | ||
225 | int OIPPacket::ttl() const | 228 | int OIPPacket::ttl() const |
226 | { | 229 | { |
227 | return _iphdr->ttl; | 230 | return _iphdr->ttl; |
228 | } | 231 | } |
229 | 232 | ||
230 | 233 | ||
231 | int OIPPacket::protocol() const | 234 | int OIPPacket::protocol() const |
232 | { | 235 | { |
233 | return _iphdr->protocol; | 236 | return _iphdr->protocol; |
234 | } | 237 | } |
235 | 238 | ||
236 | 239 | ||
237 | int OIPPacket::checksum() const | 240 | int OIPPacket::checksum() const |
238 | { | 241 | { |
239 | return EXTRACT_16BITS( &_iphdr->check ); | 242 | return EXTRACT_16BITS( &_iphdr->check ); |
240 | } | 243 | } |
241 | 244 | ||
242 | /*====================================================================================== | 245 | /*====================================================================================== |
243 | * OUDPPacket | 246 | * OUDPPacket |
244 | *======================================================================================*/ | 247 | *======================================================================================*/ |
245 | 248 | ||
246 | 249 | ||
247 | OUDPPacket::OUDPPacket( const struct udphdr* data, QObject* parent ) | 250 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) |
248 | :QObject( parent, "UDP" ), _udphdr( data ) | 251 | :QObject( parent, "UDP" ), _udphdr( data ) |
249 | 252 | ||
250 | { | 253 | { |
251 | qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); | 254 | qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); |
252 | } | 255 | } |
253 | 256 | ||
254 | OUDPPacket::~OUDPPacket() | 257 | OUDPPacket::~OUDPPacket() |
255 | { | 258 | { |
256 | } | 259 | } |
257 | 260 | ||
258 | 261 | ||
259 | /*====================================================================================== | 262 | /*====================================================================================== |
260 | * OTCPPacket | 263 | * OTCPPacket |
261 | *======================================================================================*/ | 264 | *======================================================================================*/ |
262 | 265 | ||
263 | 266 | ||
264 | OTCPPacket::OTCPPacket( const struct tcphdr* data, QObject* parent ) | 267 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) |
265 | :QObject( parent, "TCP" ), _tcphdr( data ) | 268 | :QObject( parent, "TCP" ), _tcphdr( data ) |
266 | 269 | ||
267 | { | 270 | { |
268 | qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); | 271 | qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); |
269 | } | 272 | } |
270 | 273 | ||
271 | OTCPPacket::~OTCPPacket() | 274 | OTCPPacket::~OTCPPacket() |
272 | { | 275 | { |
273 | } | 276 | } |
274 | 277 | ||
275 | 278 | ||
276 | /*====================================================================================== | 279 | /*====================================================================================== |
277 | * OWaveLanPacket | 280 | * OWaveLanPacket |
278 | *======================================================================================*/ | 281 | *======================================================================================*/ |
279 | 282 | ||
280 | 283 | ||
281 | OWaveLanPacket::OWaveLanPacket( const struct ieee_802_11_header* data, QObject* parent ) | 284 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) |
282 | :QObject( parent, "802.11" ), _wlanhdr( data ) | 285 | :QObject( parent, "802.11" ), _wlanhdr( data ) |
283 | 286 | ||
284 | { | 287 | { |
285 | qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); | 288 | qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); |
286 | qDebug( "type: %0X", type() ); | 289 | qDebug( "type: %0X", type() ); |
287 | qDebug( "subType: %0X", subType() ); | 290 | qDebug( "subType: %0X", subType() ); |
288 | qDebug( "duration: %d", duration() ); | 291 | qDebug( "duration: %d", duration() ); |
289 | qDebug( "powermanagement: %d", usesPowerManagement() ); | 292 | qDebug( "powermanagement: %d", usesPowerManagement() ); |
290 | qDebug( "wep: %d", usesWep() ); | 293 | qDebug( "wep: %d", usesWep() ); |
291 | qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); | 294 | qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); |
292 | qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); | 295 | qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); |
293 | qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); | 296 | qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); |
294 | qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); | 297 | qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); |
295 | 298 | ||
296 | switch ( type() ) | 299 | switch ( type() ) |
297 | { | 300 | { |
298 | case T_MGMT: new OWaveLanManagementPacket( (const struct ieee_802_11_mgmt_header*) data, this ); break; | 301 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
299 | case T_DATA: new OWaveLanDataPacket( (const struct ieee_802_11_data_header*) data, this ); break; | 302 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
300 | //case T_CTRL: new OWaveLanControlPacket( (const struct ieee_802_11_ctrl_header*) data, this ); break; | 303 | //case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_ctrl_header*) data, this ); break; |
301 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown type!" ); | 304 | default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown type!" ); |
302 | } | 305 | } |
303 | } | 306 | } |
304 | 307 | ||
305 | OWaveLanPacket::~OWaveLanPacket() | 308 | OWaveLanPacket::~OWaveLanPacket() |
306 | { | 309 | { |
307 | } | 310 | } |
308 | 311 | ||
309 | 312 | ||
310 | int OWaveLanPacket::duration() const | 313 | int OWaveLanPacket::duration() const |
311 | { | 314 | { |
312 | return _wlanhdr->duration; | 315 | return _wlanhdr->duration; |
313 | } | 316 | } |
314 | 317 | ||
315 | 318 | ||
316 | OMacAddress OWaveLanPacket::macAddress1() const | 319 | OMacAddress OWaveLanPacket::macAddress1() const |
317 | { | 320 | { |
318 | return OMacAddress( _wlanhdr->mac1 ); | 321 | return OMacAddress( _wlanhdr->mac1 ); |
319 | } | 322 | } |
320 | 323 | ||
321 | 324 | ||
322 | OMacAddress OWaveLanPacket::macAddress2() const | 325 | OMacAddress OWaveLanPacket::macAddress2() const |
323 | { | 326 | { |
324 | return OMacAddress( _wlanhdr->mac2 ); | 327 | return OMacAddress( _wlanhdr->mac2 ); |
@@ -362,247 +365,441 @@ bool OWaveLanPacket::fromDS() const | |||
362 | 365 | ||
363 | 366 | ||
364 | bool OWaveLanPacket::toDS() const | 367 | bool OWaveLanPacket::toDS() const |
365 | { | 368 | { |
366 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 369 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
367 | } | 370 | } |
368 | 371 | ||
369 | 372 | ||
370 | bool OWaveLanPacket::usesPowerManagement() const | 373 | bool OWaveLanPacket::usesPowerManagement() const |
371 | { | 374 | { |
372 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 375 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
373 | } | 376 | } |
374 | 377 | ||
375 | 378 | ||
376 | bool OWaveLanPacket::usesWep() const | 379 | bool OWaveLanPacket::usesWep() const |
377 | { | 380 | { |
378 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 381 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
379 | } | 382 | } |
380 | 383 | ||
381 | 384 | ||
382 | /*====================================================================================== | 385 | /*====================================================================================== |
383 | * OWaveLanManagementPacket | 386 | * OWaveLanManagementPacket |
384 | *======================================================================================*/ | 387 | *======================================================================================*/ |
385 | 388 | ||
386 | OWaveLanManagementPacket::OWaveLanManagementPacket( const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 389 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
387 | :QObject( parent, "802.11 Management" ), _header( data ), | 390 | :QObject( parent, "802.11 Management" ), _header( data ), |
388 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 391 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
389 | { | 392 | { |
390 | qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); | 393 | qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); |
391 | 394 | ||
392 | switch ( ((OWaveLanPacket*) this->parent() )->subType() ) | 395 | switch ( ((OWaveLanPacket*) this->parent() )->subType() ) |
393 | { | 396 | { |
394 | case ST_BEACON: | 397 | case ST_BEACON: |
395 | { | 398 | { |
396 | qDebug( "TYPE: BEACON FRAME" ); | 399 | // nice, received a beacon... |
397 | qDebug( "ESSID: %s", (const char*) SSID() ); | 400 | } |
398 | break; | 401 | } |
402 | |||
403 | // grab tagged values | ||
404 | const unsigned char* ptr = (const unsigned char*) (_body+1); | ||
405 | while (ptr < end) | ||
406 | { | ||
407 | switch ( *ptr ) | ||
408 | { | ||
409 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; | ||
410 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; | ||
411 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; | ||
412 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; | ||
413 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; | ||
414 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; | ||
415 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; | ||
416 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; | ||
399 | } | 417 | } |
418 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value | ||
419 | ptr+= 2; // skip tag ID and length | ||
400 | } | 420 | } |
401 | } | 421 | } |
402 | 422 | ||
403 | 423 | ||
404 | OWaveLanManagementPacket::~OWaveLanManagementPacket() | 424 | OWaveLanManagementPacket::~OWaveLanManagementPacket() |
405 | { | 425 | { |
406 | } | 426 | } |
407 | 427 | ||
408 | 428 | ||
409 | QString OWaveLanManagementPacket::SSID() const | 429 | int OWaveLanManagementPacket::beaconInterval() const |
430 | { | ||
431 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); | ||
432 | } | ||
433 | |||
434 | |||
435 | int OWaveLanManagementPacket::capabilities() const | ||
436 | { | ||
437 | return EXTRACT_LE_16BITS( &_body->capability_info ); | ||
438 | } | ||
439 | |||
440 | |||
441 | bool OWaveLanManagementPacket::canESS() const | ||
410 | { | 442 | { |
411 | int length = _body->ssid.length; | 443 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
444 | } | ||
445 | |||
446 | |||
447 | bool OWaveLanManagementPacket::canIBSS() const | ||
448 | { | ||
449 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | ||
450 | } | ||
451 | |||
452 | |||
453 | bool OWaveLanManagementPacket::canCFP() const | ||
454 | { | ||
455 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); | ||
456 | } | ||
457 | |||
458 | |||
459 | bool OWaveLanManagementPacket::canCFP_REQ() const | ||
460 | { | ||
461 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); | ||
462 | } | ||
463 | |||
464 | |||
465 | bool OWaveLanManagementPacket::canPrivacy() const | ||
466 | { | ||
467 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); | ||
468 | } | ||
469 | |||
470 | |||
471 | /*====================================================================================== | ||
472 | * OWaveLanManagementSSID | ||
473 | *======================================================================================*/ | ||
474 | |||
475 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) | ||
476 | :QObject( parent, "802.11 SSID" ), _data( data ) | ||
477 | { | ||
478 | qDebug( "OWaveLanManagementSSID()" ); | ||
479 | } | ||
480 | |||
481 | |||
482 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | ||
483 | { | ||
484 | } | ||
485 | |||
486 | |||
487 | QString OWaveLanManagementSSID::ID() const | ||
488 | { | ||
489 | int length = _data->length; | ||
412 | if ( length > 32 ) length = 32; | 490 | if ( length > 32 ) length = 32; |
413 | char essid[length+1]; | 491 | char essid[length+1]; |
414 | memcpy( &essid, _body->ssid.ssid, length ); | 492 | memcpy( &essid, &_data->ssid, length ); |
415 | essid[length] = 0x0; | 493 | essid[length] = 0x0; |
416 | return essid; | 494 | return essid; |
417 | } | 495 | } |
418 | 496 | ||
419 | 497 | ||
420 | /*====================================================================================== | 498 | /*====================================================================================== |
499 | * OWaveLanManagementRates | ||
500 | *======================================================================================*/ | ||
501 | |||
502 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) | ||
503 | :QObject( parent, "802.11 Rates" ), _data( data ) | ||
504 | { | ||
505 | qDebug( "OWaveLanManagementRates()" ); | ||
506 | } | ||
507 | |||
508 | |||
509 | OWaveLanManagementRates::~OWaveLanManagementRates() | ||
510 | { | ||
511 | } | ||
512 | |||
513 | /*====================================================================================== | ||
514 | * OWaveLanManagementCF | ||
515 | *======================================================================================*/ | ||
516 | |||
517 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) | ||
518 | :QObject( parent, "802.11 CF" ), _data( data ) | ||
519 | { | ||
520 | qDebug( "OWaveLanManagementCF()" ); | ||
521 | } | ||
522 | |||
523 | |||
524 | OWaveLanManagementCF::~OWaveLanManagementCF() | ||
525 | { | ||
526 | } | ||
527 | |||
528 | /*====================================================================================== | ||
529 | * OWaveLanManagementFH | ||
530 | *======================================================================================*/ | ||
531 | |||
532 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) | ||
533 | :QObject( parent, "802.11 FH" ), _data( data ) | ||
534 | { | ||
535 | qDebug( "OWaveLanManagementFH()" ); | ||
536 | } | ||
537 | |||
538 | |||
539 | OWaveLanManagementFH::~OWaveLanManagementFH() | ||
540 | { | ||
541 | } | ||
542 | |||
543 | /*====================================================================================== | ||
544 | * OWaveLanManagementDS | ||
545 | *======================================================================================*/ | ||
546 | |||
547 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) | ||
548 | :QObject( parent, "802.11 DS" ), _data( data ) | ||
549 | { | ||
550 | qDebug( "OWaveLanManagementDS()" ); | ||
551 | } | ||
552 | |||
553 | |||
554 | OWaveLanManagementDS::~OWaveLanManagementDS() | ||
555 | { | ||
556 | } | ||
557 | |||
558 | |||
559 | int OWaveLanManagementDS::channel() const | ||
560 | { | ||
561 | return _data->channel; | ||
562 | } | ||
563 | |||
564 | /*====================================================================================== | ||
565 | * OWaveLanManagementTim | ||
566 | *======================================================================================*/ | ||
567 | |||
568 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) | ||
569 | :QObject( parent, "802.11 Tim" ), _data( data ) | ||
570 | { | ||
571 | qDebug( "OWaveLanManagementTim()" ); | ||
572 | } | ||
573 | |||
574 | |||
575 | OWaveLanManagementTim::~OWaveLanManagementTim() | ||
576 | { | ||
577 | } | ||
578 | |||
579 | /*====================================================================================== | ||
580 | * OWaveLanManagementIBSS | ||
581 | *======================================================================================*/ | ||
582 | |||
583 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) | ||
584 | :QObject( parent, "802.11 IBSS" ), _data( data ) | ||
585 | { | ||
586 | qDebug( "OWaveLanManagementIBSS()" ); | ||
587 | } | ||
588 | |||
589 | |||
590 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | ||
591 | { | ||
592 | } | ||
593 | |||
594 | /*====================================================================================== | ||
595 | * OWaveLanManagementChallenge | ||
596 | *======================================================================================*/ | ||
597 | |||
598 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) | ||
599 | :QObject( parent, "802.11 Challenge" ), _data( data ) | ||
600 | { | ||
601 | qDebug( "OWaveLanManagementChallenge()" ); | ||
602 | } | ||
603 | |||
604 | |||
605 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | ||
606 | { | ||
607 | } | ||
608 | |||
609 | /*====================================================================================== | ||
421 | * OWaveLanDataPacket | 610 | * OWaveLanDataPacket |
422 | *======================================================================================*/ | 611 | *======================================================================================*/ |
423 | 612 | ||
424 | OWaveLanDataPacket::OWaveLanDataPacket( const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 613 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) |
425 | :QObject( parent, "802.11 Data" ), _header( data ) | 614 | :QObject( parent, "802.11 Data" ), _header( data ) |
426 | { | 615 | { |
427 | //qDebug( "size of header = %d", sizeof( struct ieee_802_11_data_header ) ); | 616 | //qDebug( "size of header = %d", sizeof( struct ieee_802_11_data_header ) ); |
428 | //qDebug( "header: %0x", data ); | 617 | //qDebug( "header: %0x", data ); |
429 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); | 618 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); |
430 | //qDebug( "payload: %0x", payload ); | 619 | //qDebug( "payload: %0x", payload ); |
431 | 620 | ||
432 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 621 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address |
433 | 622 | ||
434 | new OLLCPacket( (const struct ieee_802_11_802_2_header*) payload, this ); | 623 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); |
435 | } | 624 | } |
436 | 625 | ||
437 | 626 | ||
438 | OWaveLanDataPacket::~OWaveLanDataPacket() | 627 | OWaveLanDataPacket::~OWaveLanDataPacket() |
439 | { | 628 | { |
440 | } | 629 | } |
441 | 630 | ||
442 | 631 | ||
443 | /*====================================================================================== | 632 | /*====================================================================================== |
444 | * OLLCPacket | 633 | * OLLCPacket |
445 | *======================================================================================*/ | 634 | *======================================================================================*/ |
446 | 635 | ||
447 | OLLCPacket::OLLCPacket( const struct ieee_802_11_802_2_header* data, QObject* parent ) | 636 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
448 | :QObject( parent, "802.11 802_2" ), _header( data ) | 637 | :QObject( parent, "802.11 802_2" ), _header( data ) |
449 | { | 638 | { |
450 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); | 639 | qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); |
451 | 640 | ||
452 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) | 641 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) |
453 | { | 642 | { |
454 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); | 643 | qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); |
455 | 644 | ||
456 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h | 645 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h |
457 | { | 646 | { |
458 | case ETH_P_IP: new OIPPacket( (const struct iphdr*) (data+1), this ); break; | 647 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
459 | default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); | 648 | default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); |
460 | } | 649 | } |
461 | 650 | ||
462 | } | 651 | } |
463 | } | 652 | } |
464 | 653 | ||
465 | 654 | ||
466 | OLLCPacket::~OLLCPacket() | 655 | OLLCPacket::~OLLCPacket() |
467 | { | 656 | { |
468 | } | 657 | } |
469 | 658 | ||
470 | /*====================================================================================== | 659 | /*====================================================================================== |
471 | * OPacketCapturer | 660 | * OPacketCapturer |
472 | *======================================================================================*/ | 661 | *======================================================================================*/ |
473 | 662 | ||
474 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 663 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) |
475 | :QObject( parent, name ), _name( QString::null ), _open( false ), | 664 | :QObject( parent, name ), _name( QString::null ), _open( false ), |
476 | _pch( 0 ) | 665 | _pch( 0 ), _sn( 0 ) |
477 | { | 666 | { |
478 | } | 667 | } |
479 | 668 | ||
480 | 669 | ||
481 | OPacketCapturer::~OPacketCapturer() | 670 | OPacketCapturer::~OPacketCapturer() |
482 | { | 671 | { |
483 | if ( _open ) | 672 | if ( _open ) |
484 | { | 673 | { |
485 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); | 674 | qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); |
486 | close(); | 675 | close(); |
487 | } | 676 | } |
488 | } | 677 | } |
489 | 678 | ||
490 | 679 | ||
491 | void OPacketCapturer::setBlocking( bool b ) | 680 | void OPacketCapturer::setBlocking( bool b ) |
492 | { | 681 | { |
493 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) | 682 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) |
494 | { | 683 | { |
495 | qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); | 684 | qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); |
496 | } | 685 | } |
497 | else | 686 | else |
498 | { | 687 | { |
499 | qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); | 688 | qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); |
500 | } | 689 | } |
501 | } | 690 | } |
502 | 691 | ||
503 | 692 | ||
504 | bool OPacketCapturer::blocking() const | 693 | bool OPacketCapturer::blocking() const |
505 | { | 694 | { |
506 | int b = pcap_getnonblock( _pch, _errbuf ); | 695 | int b = pcap_getnonblock( _pch, _errbuf ); |
507 | if ( b == -1 ) | 696 | if ( b == -1 ) |
508 | { | 697 | { |
509 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); | 698 | qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); |
510 | return -1; | 699 | return -1; |
511 | } | 700 | } |
512 | return !b; | 701 | return !b; |
513 | } | 702 | } |
514 | 703 | ||
515 | 704 | ||
516 | void OPacketCapturer::close() | 705 | void OPacketCapturer::close() |
517 | { | 706 | { |
518 | if ( _open ) | 707 | if ( _open ) |
519 | { | 708 | { |
709 | if ( _sn ) | ||
710 | { | ||
711 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | ||
712 | delete _sn; | ||
713 | } | ||
520 | pcap_close( _pch ); | 714 | pcap_close( _pch ); |
521 | _open = false; | 715 | _open = false; |
522 | } | 716 | } |
523 | } | 717 | } |
524 | 718 | ||
525 | 719 | ||
526 | int OPacketCapturer::dataLink() const | 720 | int OPacketCapturer::dataLink() const |
527 | { | 721 | { |
528 | return pcap_datalink( _pch ); | 722 | return pcap_datalink( _pch ); |
529 | } | 723 | } |
530 | 724 | ||
531 | 725 | ||
532 | int OPacketCapturer::fileno() const | 726 | int OPacketCapturer::fileno() const |
533 | { | 727 | { |
534 | if ( _open ) | 728 | if ( _open ) |
535 | { | 729 | { |
536 | return pcap_fileno( _pch ); | 730 | return pcap_fileno( _pch ); |
537 | } | 731 | } |
538 | else | 732 | else |
539 | { | 733 | { |
540 | return -1; | 734 | return -1; |
541 | } | 735 | } |
542 | } | 736 | } |
543 | 737 | ||
544 | 738 | ||
545 | OPacket* OPacketCapturer::next() | 739 | OPacket* OPacketCapturer::next() |
546 | { | 740 | { |
547 | packetheaderstruct header; | 741 | packetheaderstruct header; |
742 | qDebug( "==> OPacketCapturer::next()" ); | ||
548 | const unsigned char* pdata = pcap_next( _pch, &header ); | 743 | const unsigned char* pdata = pcap_next( _pch, &header ); |
744 | qDebug( "<== OPacketCapturer::next()" ); | ||
745 | |||
549 | if ( header.len ) | 746 | if ( header.len ) |
550 | return new OPacket( header, pdata, this ); | 747 | return new OPacket( header, pdata, this ); |
551 | else | 748 | else |
552 | return 0; | 749 | return 0; |
553 | } | 750 | } |
554 | 751 | ||
555 | 752 | ||
556 | bool OPacketCapturer::open( const QString& name ) | 753 | bool OPacketCapturer::open( const QString& name ) |
557 | { | 754 | { |
558 | if ( _open ) | 755 | if ( _open ) |
559 | { | 756 | { |
560 | if ( name == _name ) // ignore opening an already openend device | 757 | if ( name == _name ) // ignore opening an already openend device |
561 | { | 758 | { |
562 | return true; | 759 | return true; |
563 | } | 760 | } |
564 | else // close the last opened device | 761 | else // close the last opened device |
565 | { | 762 | { |
566 | close(); | 763 | close(); |
567 | } | 764 | } |
568 | } | 765 | } |
569 | 766 | ||
570 | _name = name; | 767 | _name = name; |
571 | 768 | ||
572 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); | 769 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); |
573 | 770 | ||
574 | if ( handle ) | 771 | if ( handle ) |
575 | { | 772 | { |
576 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); | 773 | qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); |
577 | _pch = handle; | 774 | _pch = handle; |
578 | _open = true; | 775 | _open = true; |
579 | 776 | ||
580 | // in case we have a qapp, create a socket notifier | 777 | // in case we have an application object, create a socket notifier |
581 | if ( qApp ) | 778 | if ( qApp ) |
582 | { | 779 | { |
583 | QSocketNotifier* sn = new QSocketNotifier( fileno(), QSocketNotifier::Read, this ); | 780 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
584 | connect( sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 781 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
585 | } | 782 | } |
586 | 783 | ||
587 | return true; | 784 | return true; |
588 | } | 785 | } |
589 | else | 786 | else |
590 | { | 787 | { |
591 | qDebug( "OPacketCapturer::open(): can't open libpcap: %s", _errbuf ); | 788 | qDebug( "OPacketCapturer::open(): can't open libpcap: %s", _errbuf ); |
592 | return false; | 789 | return false; |
593 | } | 790 | } |
594 | 791 | ||
595 | } | 792 | } |
596 | 793 | ||
597 | 794 | ||
598 | bool OPacketCapturer::isOpen() const | 795 | bool OPacketCapturer::isOpen() const |
599 | { | 796 | { |
600 | return _open; | 797 | return _open; |
601 | } | 798 | } |
602 | 799 | ||
603 | 800 | ||
604 | void OPacketCapturer::readyToReceive() | 801 | void OPacketCapturer::readyToReceive() |
605 | { | 802 | { |
606 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(...)'" ); | 803 | qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(...)'" ); |
607 | emit receivedPacket( next() ); | 804 | emit receivedPacket( next() ); |
608 | } | 805 | } |