summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp47
-rw-r--r--libopie2/opienet/opcap.h4
2 files changed, 34 insertions, 17 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 30f6208..04b1bb1 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -1,951 +1,966 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34/* 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#include <qobjectlist.h> 42#include <qobjectlist.h>
43 43
44/*====================================================================================== 44/*======================================================================================
45 * OPacket 45 * OPacket
46 *======================================================================================*/ 46 *======================================================================================*/
47 47
48OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) 48OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
49 :QObject( parent, "Generic" ), _hdr( header ), _data( data ) 49 :QObject( parent, "Generic" ), _hdr( header ), _data( data )
50{ 50{
51 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); 51 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
52 52
53 _end = (unsigned char*) data + header.len; 53 _end = (unsigned char*) data + header.len;
54 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); 54 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end );
55 55
56 switch ( datalink ) 56 switch ( datalink )
57 { 57 {
58 case DLT_EN10MB: 58 case DLT_EN10MB:
59 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); 59 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" );
60 new OEthernetPacket( _end, (const struct ether_header*) data, this ); 60 new OEthernetPacket( _end, (const struct ether_header*) data, this );
61 break; 61 break;
62 62
63 case DLT_IEEE802_11: 63 case DLT_IEEE802_11:
64 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); 64 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" );
65 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); 65 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this );
66 break; 66 break;
67 67
68 default: 68 default:
69 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink '%s'!", datalink ); 69 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink '%s'!", datalink );
70 } 70 }
71} 71}
72 72
73 73
74OPacket::~OPacket() 74OPacket::~OPacket()
75{ 75{
76} 76}
77 77
78 78
79timevalstruct OPacket::timeval() const 79timevalstruct OPacket::timeval() const
80{ 80{
81 return _hdr.ts; 81 return _hdr.ts;
82} 82}
83 83
84 84
85int OPacket::caplen() const 85int OPacket::caplen() const
86{ 86{
87 return _hdr.caplen; 87 return _hdr.caplen;
88} 88}
89 89
90 90
91void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) 91void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )
92{ 92{
93 if (!l) return; 93 if (!l) return;
94 QObject* o = l->first(); 94 QObject* o = l->first();
95 while ( o ) 95 while ( o )
96 { 96 {
97 stats[o->name()]++; 97 stats[o->name()]++;
98 updateStats( stats, const_cast<QObjectList*>( o->children() ) ); 98 updateStats( stats, const_cast<QObjectList*>( o->children() ) );
99 o = l->next(); 99 o = l->next();
100 } 100 }
101} 101}
102 102
103 103
104QString OPacket::dump( int bpl ) const 104QString OPacket::dump( int bpl ) const
105{ 105{
106 static int index = 0; 106 static int index = 0;
107 index++; 107 index++;
108 int len = _hdr.caplen; 108 int len = _hdr.caplen;
109 QString str; 109 QString str;
110 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); 110 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len );
111 str.append( "0000: " ); 111 str.append( "0000: " );
112 QString tmp; 112 QString tmp;
113 QString bytes; 113 QString bytes;
114 QString chars; 114 QString chars;
115 115
116 for ( int i = 0; i < len; ++i ) 116 for ( int i = 0; i < len; ++i )
117 { 117 {
118 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); 118 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp );
119 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); 119 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] );
120 else chars.append( '.' ); 120 else chars.append( '.' );
121 121
122 if ( !((i+1) % bpl) ) 122 if ( !((i+1) % bpl) )
123 { 123 {
124 str.append( bytes ); 124 str.append( bytes );
125 str.append( ' ' ); 125 str.append( ' ' );
126 str.append( chars ); 126 str.append( chars );
127 str.append( '\n' ); 127 str.append( '\n' );
128 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); 128 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp );
129 bytes = ""; 129 bytes = "";
130 chars = ""; 130 chars = "";
131 } 131 }
132 132
133 } 133 }
134 if ( (len % bpl) ) 134 if ( (len % bpl) )
135 { 135 {
136 str.append( bytes.leftJustify( 1 + 3*bpl ) ); 136 str.append( bytes.leftJustify( 1 + 3*bpl ) );
137 str.append( chars ); 137 str.append( chars );
138 } 138 }
139 str.append( '\n' ); 139 str.append( '\n' );
140 return str; 140 return str;
141} 141}
142 142
143 143
144int OPacket::len() const 144int OPacket::len() const
145{ 145{
146 return _hdr.len; 146 return _hdr.len;
147} 147}
148 148
149 149
150/*====================================================================================== 150/*======================================================================================
151 * OEthernetPacket 151 * OEthernetPacket
152 *======================================================================================*/ 152 *======================================================================================*/
153 153
154OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) 154OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
155 :QObject( parent, "Ethernet" ), _ether( data ) 155 :QObject( parent, "Ethernet" ), _ether( data )
156 156
157{ 157{
158 158
159 qDebug( "Source = %s", (const char*) sourceAddress().toString() ); 159 qDebug( "Source = %s", (const char*) sourceAddress().toString() );
160 qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); 160 qDebug( "Destination = %s", (const char*) destinationAddress().toString() );
161 161
162 if ( sourceAddress() == OMacAddress::broadcast ) 162 if ( sourceAddress() == OMacAddress::broadcast )
163 qDebug( "Source is broadcast address" ); 163 qDebug( "Source is broadcast address" );
164 if ( destinationAddress() == OMacAddress::broadcast ) 164 if ( destinationAddress() == OMacAddress::broadcast )
165 qDebug( "Destination is broadcast address" ); 165 qDebug( "Destination is broadcast address" );
166 166
167 switch ( type() ) 167 switch ( type() )
168 { 168 {
169 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 169 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
170 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } 170 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; }
171 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } 171 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; }
172 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); 172 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" );
173 } 173 }
174 174
175} 175}
176 176
177 177
178OEthernetPacket::~OEthernetPacket() 178OEthernetPacket::~OEthernetPacket()
179{ 179{
180} 180}
181 181
182 182
183OMacAddress OEthernetPacket::sourceAddress() const 183OMacAddress OEthernetPacket::sourceAddress() const
184{ 184{
185 return OMacAddress( _ether->ether_shost ); 185 return OMacAddress( _ether->ether_shost );
186} 186}
187 187
188 188
189OMacAddress OEthernetPacket::destinationAddress() const 189OMacAddress OEthernetPacket::destinationAddress() const
190{ 190{
191 return OMacAddress( _ether->ether_dhost ); 191 return OMacAddress( _ether->ether_dhost );
192} 192}
193 193
194int OEthernetPacket::type() const 194int OEthernetPacket::type() const
195{ 195{
196 return ntohs( _ether->ether_type ); 196 return ntohs( _ether->ether_type );
197} 197}
198 198
199 199
200/*====================================================================================== 200/*======================================================================================
201 * OIPPacket 201 * OIPPacket
202 *======================================================================================*/ 202 *======================================================================================*/
203 203
204 204
205OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) 205OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent )
206 :QObject( parent, "IP" ), _iphdr( data ) 206 :QObject( parent, "IP" ), _iphdr( data )
207 207
208{ 208{
209 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); 209 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." );
210 210
211 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); 211 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) );
212 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); 212 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) );
213 213
214 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); 214 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() );
215 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); 215 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() );
216 216
217 switch ( protocol() ) 217 switch ( protocol() )
218 { 218 {
219 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; 219 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break;
220 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; 220 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break;
221 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); 221 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() );
222 } 222 }
223 223
224} 224}
225 225
226OIPPacket::~OIPPacket() 226OIPPacket::~OIPPacket()
227{ 227{
228} 228}
229 229
230 230
231QHostAddress OIPPacket::fromIPAddress() const 231QHostAddress OIPPacket::fromIPAddress() const
232{ 232{
233 return EXTRACT_32BITS( &_iphdr->saddr ); 233 return EXTRACT_32BITS( &_iphdr->saddr );
234} 234}
235 235
236 236
237QHostAddress OIPPacket::toIPAddress() const 237QHostAddress OIPPacket::toIPAddress() const
238{ 238{
239 return EXTRACT_32BITS( &_iphdr->saddr ); 239 return EXTRACT_32BITS( &_iphdr->saddr );
240} 240}
241 241
242 242
243int OIPPacket::tos() const 243int OIPPacket::tos() const
244{ 244{
245 return _iphdr->tos; 245 return _iphdr->tos;
246} 246}
247 247
248 248
249int OIPPacket::len() const 249int OIPPacket::len() const
250{ 250{
251 return EXTRACT_16BITS( &_iphdr->tot_len ); 251 return EXTRACT_16BITS( &_iphdr->tot_len );
252} 252}
253 253
254 254
255int OIPPacket::id() const 255int OIPPacket::id() const
256{ 256{
257 return EXTRACT_16BITS( &_iphdr->id ); 257 return EXTRACT_16BITS( &_iphdr->id );
258} 258}
259 259
260 260
261int OIPPacket::offset() const 261int OIPPacket::offset() const
262{ 262{
263 return EXTRACT_16BITS( &_iphdr->frag_off ); 263 return EXTRACT_16BITS( &_iphdr->frag_off );
264} 264}
265 265
266 266
267int OIPPacket::ttl() const 267int OIPPacket::ttl() const
268{ 268{
269 return _iphdr->ttl; 269 return _iphdr->ttl;
270} 270}
271 271
272 272
273int OIPPacket::protocol() const 273int OIPPacket::protocol() const
274{ 274{
275 return _iphdr->protocol; 275 return _iphdr->protocol;
276} 276}
277 277
278 278
279int OIPPacket::checksum() const 279int OIPPacket::checksum() const
280{ 280{
281 return EXTRACT_16BITS( &_iphdr->check ); 281 return EXTRACT_16BITS( &_iphdr->check );
282} 282}
283 283
284/*====================================================================================== 284/*======================================================================================
285 * OUDPPacket 285 * OUDPPacket
286 *======================================================================================*/ 286 *======================================================================================*/
287 287
288 288
289OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) 289OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent )
290 :QObject( parent, "UDP" ), _udphdr( data ) 290 :QObject( parent, "UDP" ), _udphdr( data )
291 291
292{ 292{
293 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); 293 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." );
294} 294}
295 295
296OUDPPacket::~OUDPPacket() 296OUDPPacket::~OUDPPacket()
297{ 297{
298} 298}
299 299
300 300
301/*====================================================================================== 301/*======================================================================================
302 * OTCPPacket 302 * OTCPPacket
303 *======================================================================================*/ 303 *======================================================================================*/
304 304
305 305
306OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) 306OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent )
307 :QObject( parent, "TCP" ), _tcphdr( data ) 307 :QObject( parent, "TCP" ), _tcphdr( data )
308 308
309{ 309{
310 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); 310 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." );
311} 311}
312 312
313OTCPPacket::~OTCPPacket() 313OTCPPacket::~OTCPPacket()
314{ 314{
315} 315}
316 316
317 317
318/*====================================================================================== 318/*======================================================================================
319 * OWaveLanPacket 319 * OWaveLanPacket
320 *======================================================================================*/ 320 *======================================================================================*/
321 321
322 322
323OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) 323OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent )
324 :QObject( parent, "802.11" ), _wlanhdr( data ) 324 :QObject( parent, "802.11" ), _wlanhdr( data )
325 325
326{ 326{
327 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); 327 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." );
328 qDebug( "type: %0X", type() ); 328 qDebug( "type: %0X", type() );
329 qDebug( "subType: %0X", subType() ); 329 qDebug( "subType: %0X", subType() );
330 qDebug( "duration: %d", duration() ); 330 qDebug( "duration: %d", duration() );
331 qDebug( "powermanagement: %d", usesPowerManagement() ); 331 qDebug( "powermanagement: %d", usesPowerManagement() );
332 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); 332 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" );
333 qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); 333 qDebug( "MAC1: %s", (const char*) macAddress1().toString() );
334 qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); 334 qDebug( "MAC2: %s", (const char*) macAddress2().toString() );
335 qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); 335 qDebug( "MAC3: %s", (const char*) macAddress3().toString() );
336 qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); 336 qDebug( "MAC4: %s", (const char*) macAddress4().toString() );
337 337
338 switch ( type() ) 338 switch ( type() )
339 { 339 {
340 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; 340 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break;
341 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; 341 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break;
342 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; 342 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break;
343 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); 343 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() );
344 } 344 }
345} 345}
346 346
347OWaveLanPacket::~OWaveLanPacket() 347OWaveLanPacket::~OWaveLanPacket()
348{ 348{
349} 349}
350 350
351 351
352int OWaveLanPacket::duration() const 352int OWaveLanPacket::duration() const
353{ 353{
354 return _wlanhdr->duration; 354 return _wlanhdr->duration;
355} 355}
356 356
357 357
358OMacAddress OWaveLanPacket::macAddress1() const 358OMacAddress OWaveLanPacket::macAddress1() const
359{ 359{
360 return OMacAddress( _wlanhdr->mac1 ); 360 return OMacAddress( _wlanhdr->mac1 );
361} 361}
362 362
363 363
364OMacAddress OWaveLanPacket::macAddress2() const 364OMacAddress OWaveLanPacket::macAddress2() const
365{ 365{
366 return OMacAddress( _wlanhdr->mac2 ); 366 return OMacAddress( _wlanhdr->mac2 );
367} 367}
368 368
369 369
370OMacAddress OWaveLanPacket::macAddress3() const 370OMacAddress OWaveLanPacket::macAddress3() const
371{ 371{
372 return OMacAddress( _wlanhdr->mac3 ); 372 return OMacAddress( _wlanhdr->mac3 );
373} 373}
374 374
375 375
376OMacAddress OWaveLanPacket::macAddress4() const 376OMacAddress OWaveLanPacket::macAddress4() const
377{ 377{
378 return OMacAddress( _wlanhdr->mac4 ); 378 return OMacAddress( _wlanhdr->mac4 );
379} 379}
380 380
381 381
382int OWaveLanPacket::subType() const 382int OWaveLanPacket::subType() const
383{ 383{
384 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 384 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
385} 385}
386 386
387 387
388int OWaveLanPacket::type() const 388int OWaveLanPacket::type() const
389{ 389{
390 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 390 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
391} 391}
392 392
393 393
394int OWaveLanPacket::version() const 394int OWaveLanPacket::version() const
395{ 395{
396 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 396 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
397} 397}
398 398
399 399
400bool OWaveLanPacket::fromDS() const 400bool OWaveLanPacket::fromDS() const
401{ 401{
402 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 402 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
403} 403}
404 404
405 405
406bool OWaveLanPacket::toDS() const 406bool OWaveLanPacket::toDS() const
407{ 407{
408 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 408 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
409} 409}
410 410
411 411
412bool OWaveLanPacket::usesPowerManagement() const 412bool OWaveLanPacket::usesPowerManagement() const
413{ 413{
414 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 414 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
415} 415}
416 416
417 417
418bool OWaveLanPacket::usesWep() const 418bool OWaveLanPacket::usesWep() const
419{ 419{
420 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 420 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
421} 421}
422 422
423 423
424/*====================================================================================== 424/*======================================================================================
425 * OWaveLanManagementPacket 425 * OWaveLanManagementPacket
426 *======================================================================================*/ 426 *======================================================================================*/
427 427
428OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) 428OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent )
429 :QObject( parent, "802.11 Management" ), _header( data ), 429 :QObject( parent, "802.11 Management" ), _header( data ),
430 _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) 430 _body( (const struct ieee_802_11_mgmt_body*) (data+1) )
431{ 431{
432 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); 432 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." );
433 qDebug( "Detected subtype is '%s'", (const char*) managementType() ); 433 qDebug( "Detected subtype is '%s'", (const char*) managementType() );
434 434
435 // grab tagged values 435 // grab tagged values
436 const unsigned char* ptr = (const unsigned char*) (_body+1); 436 const unsigned char* ptr = (const unsigned char*) (_body+1);
437 while (ptr < end) 437 while (ptr < end)
438 { 438 {
439 switch ( *ptr ) 439 switch ( *ptr )
440 { 440 {
441 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; 441 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break;
442 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; 442 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break;
443 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; 443 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break;
444 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; 444 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break;
445 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; 445 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break;
446 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; 446 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break;
447 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; 447 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break;
448 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; 448 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break;
449 } 449 }
450 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value 450 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value
451 ptr+= 2; // skip tag ID and length 451 ptr+= 2; // skip tag ID and length
452 } 452 }
453} 453}
454 454
455 455
456OWaveLanManagementPacket::~OWaveLanManagementPacket() 456OWaveLanManagementPacket::~OWaveLanManagementPacket()
457{ 457{
458} 458}
459 459
460 460
461QString OWaveLanManagementPacket::managementType() const 461QString OWaveLanManagementPacket::managementType() const
462{ 462{
463 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) 463 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) )
464 { 464 {
465 case ST_ASSOC_REQUEST: return "AssociationRequest"; break; 465 case ST_ASSOC_REQUEST: return "AssociationRequest"; break;
466 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; 466 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break;
467 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; 467 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break;
468 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; 468 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break;
469 case ST_PROBE_REQUEST: return "ProbeRequest"; break; 469 case ST_PROBE_REQUEST: return "ProbeRequest"; break;
470 case ST_PROBE_RESPONSE: return "ProbeResponse"; break; 470 case ST_PROBE_RESPONSE: return "ProbeResponse"; break;
471 case ST_BEACON: return "Beacon"; break; 471 case ST_BEACON: return "Beacon"; break;
472 case ST_ATIM: return "Atim"; break; 472 case ST_ATIM: return "Atim"; break;
473 case ST_DISASSOC: return "Disassociation"; break; 473 case ST_DISASSOC: return "Disassociation"; break;
474 case ST_AUTH: return "Authentication"; break; 474 case ST_AUTH: return "Authentication"; break;
475 case ST_DEAUTH: return "Deathentication"; break; 475 case ST_DEAUTH: return "Deathentication"; break;
476 default: 476 default:
477 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); 477 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) );
478 return "Unknown"; 478 return "Unknown";
479 } 479 }
480} 480}
481 481
482 482
483int OWaveLanManagementPacket::beaconInterval() const 483int OWaveLanManagementPacket::beaconInterval() const
484{ 484{
485 return EXTRACT_LE_16BITS( &_body->beacon_interval ); 485 return EXTRACT_LE_16BITS( &_body->beacon_interval );
486} 486}
487 487
488 488
489int OWaveLanManagementPacket::capabilities() const 489int OWaveLanManagementPacket::capabilities() const
490{ 490{
491 return EXTRACT_LE_16BITS( &_body->capability_info ); 491 return EXTRACT_LE_16BITS( &_body->capability_info );
492} 492}
493 493
494 494
495bool OWaveLanManagementPacket::canESS() const 495bool OWaveLanManagementPacket::canESS() const
496{ 496{
497 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 497 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) );
498} 498}
499 499
500 500
501bool OWaveLanManagementPacket::canIBSS() const 501bool OWaveLanManagementPacket::canIBSS() const
502{ 502{
503 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 503 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) );
504} 504}
505 505
506 506
507bool OWaveLanManagementPacket::canCFP() const 507bool OWaveLanManagementPacket::canCFP() const
508{ 508{
509 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); 509 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) );
510} 510}
511 511
512 512
513bool OWaveLanManagementPacket::canCFP_REQ() const 513bool OWaveLanManagementPacket::canCFP_REQ() const
514{ 514{
515 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); 515 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) );
516} 516}
517 517
518 518
519bool OWaveLanManagementPacket::canPrivacy() const 519bool OWaveLanManagementPacket::canPrivacy() const
520{ 520{
521 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); 521 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) );
522} 522}
523 523
524 524
525/*====================================================================================== 525/*======================================================================================
526 * OWaveLanManagementSSID 526 * OWaveLanManagementSSID
527 *======================================================================================*/ 527 *======================================================================================*/
528 528
529OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) 529OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent )
530 :QObject( parent, "802.11 SSID" ), _data( data ) 530 :QObject( parent, "802.11 SSID" ), _data( data )
531{ 531{
532 qDebug( "OWaveLanManagementSSID()" ); 532 qDebug( "OWaveLanManagementSSID()" );
533} 533}
534 534
535 535
536OWaveLanManagementSSID::~OWaveLanManagementSSID() 536OWaveLanManagementSSID::~OWaveLanManagementSSID()
537{ 537{
538} 538}
539 539
540 540
541QString OWaveLanManagementSSID::ID() const 541QString OWaveLanManagementSSID::ID() const
542{ 542{
543 int length = _data->length; 543 int length = _data->length;
544 if ( length > 32 ) length = 32; 544 if ( length > 32 ) length = 32;
545 char essid[length+1]; 545 char essid[length+1];
546 memcpy( &essid, &_data->ssid, length ); 546 memcpy( &essid, &_data->ssid, length );
547 essid[length] = 0x0; 547 essid[length] = 0x0;
548 return essid; 548 return essid;
549} 549}
550 550
551 551
552/*====================================================================================== 552/*======================================================================================
553 * OWaveLanManagementRates 553 * OWaveLanManagementRates
554 *======================================================================================*/ 554 *======================================================================================*/
555 555
556OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) 556OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent )
557 :QObject( parent, "802.11 Rates" ), _data( data ) 557 :QObject( parent, "802.11 Rates" ), _data( data )
558{ 558{
559 qDebug( "OWaveLanManagementRates()" ); 559 qDebug( "OWaveLanManagementRates()" );
560} 560}
561 561
562 562
563OWaveLanManagementRates::~OWaveLanManagementRates() 563OWaveLanManagementRates::~OWaveLanManagementRates()
564{ 564{
565} 565}
566 566
567/*====================================================================================== 567/*======================================================================================
568 * OWaveLanManagementCF 568 * OWaveLanManagementCF
569 *======================================================================================*/ 569 *======================================================================================*/
570 570
571OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) 571OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent )
572 :QObject( parent, "802.11 CF" ), _data( data ) 572 :QObject( parent, "802.11 CF" ), _data( data )
573{ 573{
574 qDebug( "OWaveLanManagementCF()" ); 574 qDebug( "OWaveLanManagementCF()" );
575} 575}
576 576
577 577
578OWaveLanManagementCF::~OWaveLanManagementCF() 578OWaveLanManagementCF::~OWaveLanManagementCF()
579{ 579{
580} 580}
581 581
582/*====================================================================================== 582/*======================================================================================
583 * OWaveLanManagementFH 583 * OWaveLanManagementFH
584 *======================================================================================*/ 584 *======================================================================================*/
585 585
586OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) 586OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent )
587 :QObject( parent, "802.11 FH" ), _data( data ) 587 :QObject( parent, "802.11 FH" ), _data( data )
588{ 588{
589 qDebug( "OWaveLanManagementFH()" ); 589 qDebug( "OWaveLanManagementFH()" );
590} 590}
591 591
592 592
593OWaveLanManagementFH::~OWaveLanManagementFH() 593OWaveLanManagementFH::~OWaveLanManagementFH()
594{ 594{
595} 595}
596 596
597/*====================================================================================== 597/*======================================================================================
598 * OWaveLanManagementDS 598 * OWaveLanManagementDS
599 *======================================================================================*/ 599 *======================================================================================*/
600 600
601OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) 601OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent )
602 :QObject( parent, "802.11 DS" ), _data( data ) 602 :QObject( parent, "802.11 DS" ), _data( data )
603{ 603{
604 qDebug( "OWaveLanManagementDS()" ); 604 qDebug( "OWaveLanManagementDS()" );
605} 605}
606 606
607 607
608OWaveLanManagementDS::~OWaveLanManagementDS() 608OWaveLanManagementDS::~OWaveLanManagementDS()
609{ 609{
610} 610}
611 611
612 612
613int OWaveLanManagementDS::channel() const 613int OWaveLanManagementDS::channel() const
614{ 614{
615 return _data->channel; 615 return _data->channel;
616} 616}
617 617
618/*====================================================================================== 618/*======================================================================================
619 * OWaveLanManagementTim 619 * OWaveLanManagementTim
620 *======================================================================================*/ 620 *======================================================================================*/
621 621
622OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) 622OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent )
623 :QObject( parent, "802.11 Tim" ), _data( data ) 623 :QObject( parent, "802.11 Tim" ), _data( data )
624{ 624{
625 qDebug( "OWaveLanManagementTim()" ); 625 qDebug( "OWaveLanManagementTim()" );
626} 626}
627 627
628 628
629OWaveLanManagementTim::~OWaveLanManagementTim() 629OWaveLanManagementTim::~OWaveLanManagementTim()
630{ 630{
631} 631}
632 632
633/*====================================================================================== 633/*======================================================================================
634 * OWaveLanManagementIBSS 634 * OWaveLanManagementIBSS
635 *======================================================================================*/ 635 *======================================================================================*/
636 636
637OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) 637OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent )
638 :QObject( parent, "802.11 IBSS" ), _data( data ) 638 :QObject( parent, "802.11 IBSS" ), _data( data )
639{ 639{
640 qDebug( "OWaveLanManagementIBSS()" ); 640 qDebug( "OWaveLanManagementIBSS()" );
641} 641}
642 642
643 643
644OWaveLanManagementIBSS::~OWaveLanManagementIBSS() 644OWaveLanManagementIBSS::~OWaveLanManagementIBSS()
645{ 645{
646} 646}
647 647
648/*====================================================================================== 648/*======================================================================================
649 * OWaveLanManagementChallenge 649 * OWaveLanManagementChallenge
650 *======================================================================================*/ 650 *======================================================================================*/
651 651
652OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) 652OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent )
653 :QObject( parent, "802.11 Challenge" ), _data( data ) 653 :QObject( parent, "802.11 Challenge" ), _data( data )
654{ 654{
655 qDebug( "OWaveLanManagementChallenge()" ); 655 qDebug( "OWaveLanManagementChallenge()" );
656} 656}
657 657
658 658
659OWaveLanManagementChallenge::~OWaveLanManagementChallenge() 659OWaveLanManagementChallenge::~OWaveLanManagementChallenge()
660{ 660{
661} 661}
662 662
663/*====================================================================================== 663/*======================================================================================
664 * OWaveLanDataPacket 664 * OWaveLanDataPacket
665 *======================================================================================*/ 665 *======================================================================================*/
666 666
667OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) 667OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent )
668 :QObject( parent, "802.11 Data" ), _header( data ) 668 :QObject( parent, "802.11 Data" ), _header( data )
669{ 669{
670 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); 670 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." );
671 671
672 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); 672 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header );
673 673
674 #warning The next line works for most cases, but can not be correct generally! 674 #warning The next line works for most cases, but can not be correct generally!
675 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address 675 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address
676 676
677 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); 677 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this );
678} 678}
679 679
680 680
681OWaveLanDataPacket::~OWaveLanDataPacket() 681OWaveLanDataPacket::~OWaveLanDataPacket()
682{ 682{
683} 683}
684 684
685 685
686/*====================================================================================== 686/*======================================================================================
687 * OLLCPacket 687 * OLLCPacket
688 *======================================================================================*/ 688 *======================================================================================*/
689 689
690OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) 690OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent )
691 :QObject( parent, "802.11 LLC" ), _header( data ) 691 :QObject( parent, "802.11 LLC" ), _header( data )
692{ 692{
693 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); 693 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." );
694 694
695 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) 695 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) )
696 { 696 {
697 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 697 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) );
698 698
699 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h 699 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h
700 { 700 {
701 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 701 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
702 default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); 702 default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" );
703 } 703 }
704 704
705 } 705 }
706} 706}
707 707
708 708
709OLLCPacket::~OLLCPacket() 709OLLCPacket::~OLLCPacket()
710{ 710{
711} 711}
712 712
713 713
714/*====================================================================================== 714/*======================================================================================
715 * OWaveLanControlPacket 715 * OWaveLanControlPacket
716 *======================================================================================*/ 716 *======================================================================================*/
717 717
718OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) 718OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent )
719 :QObject( parent, "802.11 Data" ), _header( data ) 719 :QObject( parent, "802.11 Data" ), _header( data )
720{ 720{
721 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); 721 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." );
722 //TODO: Implement this 722 //TODO: Implement this
723} 723}
724 724
725 725
726OWaveLanControlPacket::~OWaveLanControlPacket() 726OWaveLanControlPacket::~OWaveLanControlPacket()
727{ 727{
728} 728}
729 729
730 730
731/*====================================================================================== 731/*======================================================================================
732 * OPacketCapturer 732 * OPacketCapturer
733 *======================================================================================*/ 733 *======================================================================================*/
734 734
735OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) 735OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
736 :QObject( parent, name ), _name( QString::null ), _open( false ), 736 :QObject( parent, name ), _name( QString::null ), _open( false ),
737 _pch( 0 ), _sn( 0 ) 737 _pch( 0 ), _pcd( 0 ), _sn( 0 )
738{ 738{
739} 739}
740 740
741 741
742OPacketCapturer::~OPacketCapturer() 742OPacketCapturer::~OPacketCapturer()
743{ 743{
744 if ( _open ) 744 if ( _open )
745 { 745 {
746 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); 746 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." );
747 close(); 747 close();
748 } 748 }
749} 749}
750 750
751 751
752void OPacketCapturer::setBlocking( bool b ) 752void OPacketCapturer::setBlocking( bool b )
753{ 753{
754 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 754 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
755 { 755 {
756 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); 756 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." );
757 } 757 }
758 else 758 else
759 { 759 {
760 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); 760 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf );
761 } 761 }
762} 762}
763 763
764 764
765bool OPacketCapturer::blocking() const 765bool OPacketCapturer::blocking() const
766{ 766{
767 int b = pcap_getnonblock( _pch, _errbuf ); 767 int b = pcap_getnonblock( _pch, _errbuf );
768 if ( b == -1 ) 768 if ( b == -1 )
769 { 769 {
770 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); 770 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf );
771 return -1; 771 return -1;
772 } 772 }
773 return !b; 773 return !b;
774} 774}
775 775
776 776
777void OPacketCapturer::close() 777void OPacketCapturer::close()
778{ 778{
779 if ( _open ) 779 if ( _open )
780 { 780 {
781 if ( _sn ) 781 if ( _sn )
782 { 782 {
783 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 783 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
784 delete _sn; 784 delete _sn;
785 } 785 }
786 if ( _pcd )
787 {
788 pcap_dump_close( _pcd );
789 _pcd = 0;
790 }
786 pcap_close( _pch ); 791 pcap_close( _pch );
787 _open = false; 792 _open = false;
788 } 793 }
789 794
790 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); 795 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." );
791 qDebug( "--------------------------------------------------" ); 796 qDebug( "--------------------------------------------------" );
792 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) 797 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it )
793 qDebug( "%s : %d", (const char*) it.key(), it.data() ); 798 qDebug( "%s : %d", (const char*) it.key(), it.data() );
794 qDebug( "--------------------------------------------------" ); 799 qDebug( "--------------------------------------------------" );
795 800
796} 801}
797 802
798 803
799int OPacketCapturer::dataLink() const 804int OPacketCapturer::dataLink() const
800{ 805{
801 return pcap_datalink( _pch ); 806 return pcap_datalink( _pch );
802} 807}
803 808
804 809
805int OPacketCapturer::fileno() const 810int OPacketCapturer::fileno() const
806{ 811{
807 if ( _open ) 812 if ( _open )
808 { 813 {
809 return pcap_fileno( _pch ); 814 return pcap_fileno( _pch );
810 } 815 }
811 else 816 else
812 { 817 {
813 return -1; 818 return -1;
814 } 819 }
815} 820}
816 821
817OPacket* OPacketCapturer::next() 822OPacket* OPacketCapturer::next()
818{ 823{
819 packetheaderstruct header; 824 packetheaderstruct header;
820 qDebug( "==> OPacketCapturer::next()" ); 825 qDebug( "==> OPacketCapturer::next()" );
821 const unsigned char* pdata = pcap_next( _pch, &header ); 826 const unsigned char* pdata = pcap_next( _pch, &header );
822 qDebug( "<== OPacketCapturer::next()" ); 827 qDebug( "<== OPacketCapturer::next()" );
828 if ( _pcd )
829 pcap_dump( (u_char*) _pcd, &header, pdata );
823 830
824 if ( header.len ) 831 if ( header.len )
825 { 832 {
826 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 833 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
827 // packets shouldn't be inserted in the QObject child-parent hierarchy, 834 // packets shouldn't be inserted in the QObject child-parent hierarchy,
828 // because due to memory constraints they will be deleted as soon 835 // because due to memory constraints they will be deleted as soon
829 // as possible - that is right after they have been processed 836 // as possible - that is right after they have been processed
830 // by emit() [ see below ] 837 // by emit() [ see below ]
831 //TODO: make gathering statistics optional, because it takes time 838 //TODO: make gathering statistics optional, because it takes time
832 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); 839 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
833 840
834 return p; 841 return p;
835 } 842 }
836 else 843 else
837 { 844 {
838 return 0; 845 return 0;
839 } 846 }
840} 847}
841 848
842 849
843bool OPacketCapturer::open( const QString& name ) 850bool OPacketCapturer::open( const QString& name, const QString& filename )
844{ 851{
845 if ( _open ) 852 if ( _open )
846 { 853 {
847 if ( name == _name ) // ignore opening an already openend device 854 if ( name == _name ) // ignore opening an already openend device
848 { 855 {
849 return true; 856 return true;
850 } 857 }
851 else // close the last opened device 858 else // close the last opened device
852 { 859 {
853 close(); 860 close();
854 } 861 }
855 } 862 }
856 863
857 _name = name; 864 _name = name;
858 865
866 // open libpcap
859 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 867 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
860 868
861 if ( handle ) 869 if ( !handle )
862 { 870 {
863 qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); 871 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
864 _pch = handle; 872 return false;
865 _open = true; 873 }
866 _stats.clear();
867 874
868 // in case we have an application object, create a socket notifier 875 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name );
869 if ( qApp ) 876 _pch = handle;
870 { 877 _open = true;
871 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 878 _stats.clear();
872 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
873 }
874 879
875 return true; 880 // in case we have an application object, create a socket notifier
881 if ( qApp ) //TODO: I don't like this here...
882 {
883 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
884 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
876 } 885 }
877 else 886
887 // if requested, open a dump
888 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) );
889 if ( !dump )
878 { 890 {
879 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 891 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf );
880 return false; 892 return false;
881 } 893 }
894 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename );
895 _pcd = dump;
882 896
897 return true;
883} 898}
884 899
885 900
886bool OPacketCapturer::open( const QFile& file ) 901bool OPacketCapturer::open( const QFile& file )
887{ 902{
888 QString name = file.name(); 903 QString name = file.name();
889 904
890 if ( _open ) 905 if ( _open )
891 { 906 {
892 close(); 907 close();
893 if ( name == _name ) // ignore opening an already openend device 908 if ( name == _name ) // ignore opening an already openend device
894 { 909 {
895 return true; 910 return true;
896 } 911 }
897 else // close the last opened device 912 else // close the last opened device
898 { 913 {
899 close(); 914 close();
900 } 915 }
901 } 916 }
902 917
903 _name = name; 918 _name = name;
904 919
905 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); 920 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] );
906 921
907 if ( handle ) 922 if ( handle )
908 { 923 {
909 qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); 924 qDebug( "OPacketCapturer::open(): libpcap opened successfully." );
910 _pch = handle; 925 _pch = handle;
911 _open = true; 926 _open = true;
912 927
913 // in case we have an application object, create a socket notifier 928 // in case we have an application object, create a socket notifier
914 if ( qApp ) 929 if ( qApp )
915 { 930 {
916 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 931 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
917 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 932 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
918 } 933 }
919 934
920 return true; 935 return true;
921 } 936 }
922 else 937 else
923 { 938 {
924 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 939 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
925 return false; 940 return false;
926 } 941 }
927 942
928} 943}
929 944
930 945
931bool OPacketCapturer::isOpen() const 946bool OPacketCapturer::isOpen() const
932{ 947{
933 return _open; 948 return _open;
934} 949}
935 950
936 951
937void OPacketCapturer::readyToReceive() 952void OPacketCapturer::readyToReceive()
938{ 953{
939 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); 954 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" );
940 OPacket* p = next(); 955 OPacket* p = next();
941 emit receivedPacket( p ); 956 emit receivedPacket( p );
942 // emit is synchronous - packet has been dealt with, now it's safe to delete 957 // emit is synchronous - packet has been dealt with, now it's safe to delete
943 delete p; 958 delete p;
944} 959}
945 960
946 961
947const QMap<QString,int>& OPacketCapturer::statistics() const 962const QMap<QString,int>& OPacketCapturer::statistics() const
948{ 963{
949 return _stats; 964 return _stats;
950} 965}
951 966
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h
index 6c3ac6d..99631ba 100644
--- a/libopie2/opienet/opcap.h
+++ b/libopie2/opienet/opcap.h
@@ -1,505 +1,507 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef OPCAP_H 34#ifndef OPCAP_H
35#define OPCAP_H 35#define OPCAP_H
36 36
37/* LINUX */ 37/* LINUX */
38extern "C" // work around a bpf/pcap conflict in recent headers 38extern "C" // work around a bpf/pcap conflict in recent headers
39{ 39{
40 #include <pcap.h> 40 #include <pcap.h>
41} 41}
42#include <netinet/ether.h> 42#include <netinet/ether.h>
43#include <netinet/ip.h> 43#include <netinet/ip.h>
44#include <netinet/udp.h> 44#include <netinet/udp.h>
45#include <netinet/tcp.h> 45#include <netinet/tcp.h>
46#include <time.h> 46#include <time.h>
47 47
48/* QT */ 48/* QT */
49#include <qevent.h> 49#include <qevent.h>
50#include <qfile.h> 50#include <qfile.h>
51#include <qhostaddress.h> 51#include <qhostaddress.h>
52#include <qobject.h> 52#include <qobject.h>
53#include <qstring.h> 53#include <qstring.h>
54#include <qmap.h> 54#include <qmap.h>
55 55
56/* OPIE */ 56/* OPIE */
57#include <opie2/onetutils.h> 57#include <opie2/onetutils.h>
58#include "802_11_user.h" 58#include "802_11_user.h"
59 59
60/* TYPEDEFS */ 60/* TYPEDEFS */
61typedef struct timeval timevalstruct; 61typedef struct timeval timevalstruct;
62typedef struct pcap_pkthdr packetheaderstruct; 62typedef struct pcap_pkthdr packetheaderstruct;
63 63
64/* FORWARDS */ 64/* FORWARDS */
65class OPacketCapturer; 65class OPacketCapturer;
66class QSocketNotifier; 66class QSocketNotifier;
67 67
68/*====================================================================================== 68/*======================================================================================
69 * OPacket - A frame on the wire 69 * OPacket - A frame on the wire
70 *======================================================================================*/ 70 *======================================================================================*/
71 71
72class OPacket : public QObject 72class OPacket : public QObject
73{ 73{
74 Q_OBJECT 74 Q_OBJECT
75 75
76 public: 76 public:
77 OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); 77 OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent );
78 virtual ~OPacket(); 78 virtual ~OPacket();
79 79
80 timevalstruct timeval() const; 80 timevalstruct timeval() const;
81 81
82 int caplen() const; 82 int caplen() const;
83 int len() const; 83 int len() const;
84 QString dump( int = 32 ) const; 84 QString dump( int = 32 ) const;
85 85
86 void updateStats( QMap<QString,int>&, QObjectList* ); 86 void updateStats( QMap<QString,int>&, QObjectList* );
87 87
88 private: 88 private:
89 const packetheaderstruct _hdr; // pcap packet header 89 const packetheaderstruct _hdr; // pcap packet header
90 const unsigned char* _data; // pcap packet data 90 const unsigned char* _data; // pcap packet data
91 const unsigned char* _end; // end of pcap packet data 91 const unsigned char* _end; // end of pcap packet data
92}; 92};
93 93
94/*====================================================================================== 94/*======================================================================================
95 * OEthernetPacket - DLT_EN10MB frame 95 * OEthernetPacket - DLT_EN10MB frame
96 *======================================================================================*/ 96 *======================================================================================*/
97 97
98class OEthernetPacket : public QObject 98class OEthernetPacket : public QObject
99{ 99{
100 Q_OBJECT 100 Q_OBJECT
101 101
102 public: 102 public:
103 OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); 103 OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 );
104 virtual ~OEthernetPacket(); 104 virtual ~OEthernetPacket();
105 105
106 OMacAddress sourceAddress() const; 106 OMacAddress sourceAddress() const;
107 OMacAddress destinationAddress() const; 107 OMacAddress destinationAddress() const;
108 int type() const; 108 int type() const;
109 109
110 private: 110 private:
111 const struct ether_header* _ether; 111 const struct ether_header* _ether;
112}; 112};
113 113
114 114
115/*====================================================================================== 115/*======================================================================================
116 * OWaveLanPacket - DLT_IEEE802_11 frame 116 * OWaveLanPacket - DLT_IEEE802_11 frame
117 *======================================================================================*/ 117 *======================================================================================*/
118 118
119class OWaveLanPacket : public QObject 119class OWaveLanPacket : public QObject
120{ 120{
121 Q_OBJECT 121 Q_OBJECT
122 122
123 public: 123 public:
124 OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); 124 OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 );
125 virtual ~OWaveLanPacket(); 125 virtual ~OWaveLanPacket();
126 126
127 int duration() const; 127 int duration() const;
128 bool fromDS() const; 128 bool fromDS() const;
129 bool toDS() const; 129 bool toDS() const;
130 virtual OMacAddress macAddress1() const; 130 virtual OMacAddress macAddress1() const;
131 virtual OMacAddress macAddress2() const; 131 virtual OMacAddress macAddress2() const;
132 virtual OMacAddress macAddress3() const; 132 virtual OMacAddress macAddress3() const;
133 virtual OMacAddress macAddress4() const; 133 virtual OMacAddress macAddress4() const;
134 bool usesPowerManagement() const; 134 bool usesPowerManagement() const;
135 int type() const; 135 int type() const;
136 int subType() const; 136 int subType() const;
137 int version() const; 137 int version() const;
138 bool usesWep() const; 138 bool usesWep() const;
139 139
140 private: 140 private:
141 const struct ieee_802_11_header* _wlanhdr; 141 const struct ieee_802_11_header* _wlanhdr;
142}; 142};
143 143
144 144
145/*====================================================================================== 145/*======================================================================================
146 * OWaveLanManagementPacket - type: management (T_MGMT) 146 * OWaveLanManagementPacket - type: management (T_MGMT)
147 *======================================================================================*/ 147 *======================================================================================*/
148 148
149class OWaveLanManagementPacket : public QObject 149class OWaveLanManagementPacket : public QObject
150{ 150{
151 Q_OBJECT 151 Q_OBJECT
152 152
153 public: 153 public:
154 OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); 154 OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 );
155 virtual ~OWaveLanManagementPacket(); 155 virtual ~OWaveLanManagementPacket();
156 156
157 QString managementType() const; 157 QString managementType() const;
158 158
159 int beaconInterval() const; 159 int beaconInterval() const;
160 int capabilities() const; // generic 160 int capabilities() const; // generic
161 161
162 bool canESS() const; 162 bool canESS() const;
163 bool canIBSS() const; 163 bool canIBSS() const;
164 bool canCFP() const; 164 bool canCFP() const;
165 bool canCFP_REQ() const; 165 bool canCFP_REQ() const;
166 bool canPrivacy() const; 166 bool canPrivacy() const;
167 167
168 private: 168 private:
169 const struct ieee_802_11_mgmt_header* _header; 169 const struct ieee_802_11_mgmt_header* _header;
170 const struct ieee_802_11_mgmt_body* _body; 170 const struct ieee_802_11_mgmt_body* _body;
171}; 171};
172 172
173 173
174/*====================================================================================== 174/*======================================================================================
175 * OWaveLanManagementSSID 175 * OWaveLanManagementSSID
176 *======================================================================================*/ 176 *======================================================================================*/
177 177
178class OWaveLanManagementSSID : public QObject 178class OWaveLanManagementSSID : public QObject
179{ 179{
180 Q_OBJECT 180 Q_OBJECT
181 181
182 public: 182 public:
183 OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); 183 OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 );
184 virtual ~OWaveLanManagementSSID(); 184 virtual ~OWaveLanManagementSSID();
185 185
186 QString ID() const; 186 QString ID() const;
187 187
188 private: 188 private:
189 const struct ssid_t* _data; 189 const struct ssid_t* _data;
190}; 190};
191 191
192/*====================================================================================== 192/*======================================================================================
193 * OWaveLanManagementRates 193 * OWaveLanManagementRates
194 *======================================================================================*/ 194 *======================================================================================*/
195 195
196class OWaveLanManagementRates : public QObject 196class OWaveLanManagementRates : public QObject
197{ 197{
198 Q_OBJECT 198 Q_OBJECT
199 199
200 public: 200 public:
201 OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); 201 OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 );
202 virtual ~OWaveLanManagementRates(); 202 virtual ~OWaveLanManagementRates();
203 203
204 private: 204 private:
205 const struct rates_t* _data; 205 const struct rates_t* _data;
206}; 206};
207 207
208/*====================================================================================== 208/*======================================================================================
209 * OWaveLanManagementCF 209 * OWaveLanManagementCF
210 *======================================================================================*/ 210 *======================================================================================*/
211 211
212class OWaveLanManagementCF : public QObject 212class OWaveLanManagementCF : public QObject
213{ 213{
214 Q_OBJECT 214 Q_OBJECT
215 215
216 public: 216 public:
217 OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); 217 OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 );
218 virtual ~OWaveLanManagementCF(); 218 virtual ~OWaveLanManagementCF();
219 219
220 private: 220 private:
221 const struct cf_t* _data; 221 const struct cf_t* _data;
222}; 222};
223 223
224/*====================================================================================== 224/*======================================================================================
225 * OWaveLanManagementFH 225 * OWaveLanManagementFH
226 *======================================================================================*/ 226 *======================================================================================*/
227 227
228class OWaveLanManagementFH : public QObject 228class OWaveLanManagementFH : public QObject
229{ 229{
230 Q_OBJECT 230 Q_OBJECT
231 231
232 public: 232 public:
233 OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); 233 OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 );
234 virtual ~OWaveLanManagementFH(); 234 virtual ~OWaveLanManagementFH();
235 235
236 private: 236 private:
237 const struct fh_t* _data; 237 const struct fh_t* _data;
238}; 238};
239 239
240/*====================================================================================== 240/*======================================================================================
241 * OWaveLanManagementDS 241 * OWaveLanManagementDS
242 *======================================================================================*/ 242 *======================================================================================*/
243 243
244class OWaveLanManagementDS : public QObject 244class OWaveLanManagementDS : public QObject
245{ 245{
246 Q_OBJECT 246 Q_OBJECT
247 247
248 public: 248 public:
249 OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); 249 OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 );
250 virtual ~OWaveLanManagementDS(); 250 virtual ~OWaveLanManagementDS();
251 251
252 int channel() const; 252 int channel() const;
253 253
254 private: 254 private:
255 const struct ds_t* _data; 255 const struct ds_t* _data;
256}; 256};
257 257
258/*====================================================================================== 258/*======================================================================================
259 * OWaveLanManagementTim 259 * OWaveLanManagementTim
260 *======================================================================================*/ 260 *======================================================================================*/
261 261
262class OWaveLanManagementTim : public QObject 262class OWaveLanManagementTim : public QObject
263{ 263{
264 Q_OBJECT 264 Q_OBJECT
265 265
266 public: 266 public:
267 OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); 267 OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 );
268 virtual ~OWaveLanManagementTim(); 268 virtual ~OWaveLanManagementTim();
269 269
270 private: 270 private:
271 const struct tim_t* _data; 271 const struct tim_t* _data;
272}; 272};
273 273
274/*====================================================================================== 274/*======================================================================================
275 * OWaveLanManagementIBSS 275 * OWaveLanManagementIBSS
276 *======================================================================================*/ 276 *======================================================================================*/
277 277
278class OWaveLanManagementIBSS : public QObject 278class OWaveLanManagementIBSS : public QObject
279{ 279{
280 Q_OBJECT 280 Q_OBJECT
281 281
282 public: 282 public:
283 OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); 283 OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 );
284 virtual ~OWaveLanManagementIBSS(); 284 virtual ~OWaveLanManagementIBSS();
285 285
286 private: 286 private:
287 const struct ibss_t* _data; 287 const struct ibss_t* _data;
288}; 288};
289 289
290/*====================================================================================== 290/*======================================================================================
291 * OWaveLanManagementChallenge 291 * OWaveLanManagementChallenge
292 *======================================================================================*/ 292 *======================================================================================*/
293 293
294class OWaveLanManagementChallenge : public QObject 294class OWaveLanManagementChallenge : public QObject
295{ 295{
296 Q_OBJECT 296 Q_OBJECT
297 297
298 public: 298 public:
299 OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); 299 OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 );
300 virtual ~OWaveLanManagementChallenge(); 300 virtual ~OWaveLanManagementChallenge();
301 301
302 private: 302 private:
303 const struct challenge_t* _data; 303 const struct challenge_t* _data;
304}; 304};
305 305
306/*====================================================================================== 306/*======================================================================================
307 * OWaveLanDataPacket - type: data (T_DATA) 307 * OWaveLanDataPacket - type: data (T_DATA)
308 *======================================================================================*/ 308 *======================================================================================*/
309 309
310class OWaveLanDataPacket : public QObject 310class OWaveLanDataPacket : public QObject
311{ 311{
312 Q_OBJECT 312 Q_OBJECT
313 313
314 public: 314 public:
315 OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); 315 OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 );
316 virtual ~OWaveLanDataPacket(); 316 virtual ~OWaveLanDataPacket();
317 317
318 private: 318 private:
319 const struct ieee_802_11_data_header* _header; 319 const struct ieee_802_11_data_header* _header;
320}; 320};
321 321
322/*====================================================================================== 322/*======================================================================================
323 * OWaveLanControlPacket - type: control (T_CTRL) 323 * OWaveLanControlPacket - type: control (T_CTRL)
324 *======================================================================================*/ 324 *======================================================================================*/
325 325
326class OWaveLanControlPacket : public QObject 326class OWaveLanControlPacket : public QObject
327{ 327{
328 Q_OBJECT 328 Q_OBJECT
329 329
330 public: 330 public:
331 OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); 331 OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 );
332 virtual ~OWaveLanControlPacket(); 332 virtual ~OWaveLanControlPacket();
333 333
334 private: 334 private:
335 const struct ieee_802_11_control_header* _header; 335 const struct ieee_802_11_control_header* _header;
336}; 336};
337 337
338/*====================================================================================== 338/*======================================================================================
339 * OLLCPacket - IEEE 802.2 Link Level Control 339 * OLLCPacket - IEEE 802.2 Link Level Control
340 *======================================================================================*/ 340 *======================================================================================*/
341 341
342class OLLCPacket : public QObject 342class OLLCPacket : public QObject
343{ 343{
344 Q_OBJECT 344 Q_OBJECT
345 345
346 public: 346 public:
347 OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); 347 OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 );
348 virtual ~OLLCPacket(); 348 virtual ~OLLCPacket();
349 349
350 private: 350 private:
351 const struct ieee_802_11_802_2_header* _header; 351 const struct ieee_802_11_802_2_header* _header;
352}; 352};
353 353
354/*====================================================================================== 354/*======================================================================================
355 * OIPPacket 355 * OIPPacket
356 *======================================================================================*/ 356 *======================================================================================*/
357 357
358class OIPPacket : public QObject 358class OIPPacket : public QObject
359{ 359{
360 Q_OBJECT 360 Q_OBJECT
361 361
362 public: 362 public:
363 OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); 363 OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 );
364 virtual ~OIPPacket(); 364 virtual ~OIPPacket();
365 365
366 QHostAddress fromIPAddress() const; 366 QHostAddress fromIPAddress() const;
367 QHostAddress toIPAddress() const; 367 QHostAddress toIPAddress() const;
368 368
369 int tos() const; 369 int tos() const;
370 int len() const; 370 int len() const;
371 int id() const; 371 int id() const;
372 int offset() const; 372 int offset() const;
373 int ttl() const; 373 int ttl() const;
374 int protocol() const; 374 int protocol() const;
375 int checksum() const; 375 int checksum() const;
376 376
377 private: 377 private:
378 const struct iphdr* _iphdr; 378 const struct iphdr* _iphdr;
379}; 379};
380 380
381/*====================================================================================== 381/*======================================================================================
382 * OUDPPacket 382 * OUDPPacket
383 *======================================================================================*/ 383 *======================================================================================*/
384 384
385class OUDPPacket : public QObject 385class OUDPPacket : public QObject
386{ 386{
387 Q_OBJECT 387 Q_OBJECT
388 388
389 public: 389 public:
390 OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); 390 OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 );
391 virtual ~OUDPPacket(); 391 virtual ~OUDPPacket();
392 392
393 int fromPort() const; 393 int fromPort() const;
394 int toPort() const; 394 int toPort() const;
395 395
396 private: 396 private:
397 const struct udphdr* _udphdr; 397 const struct udphdr* _udphdr;
398}; 398};
399 399
400/*====================================================================================== 400/*======================================================================================
401 * OTCPPacket 401 * OTCPPacket
402 *======================================================================================*/ 402 *======================================================================================*/
403 403
404class OTCPPacket : public QObject 404class OTCPPacket : public QObject
405{ 405{
406 Q_OBJECT 406 Q_OBJECT
407 407
408 public: 408 public:
409 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); 409 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 );
410 virtual ~OTCPPacket(); 410 virtual ~OTCPPacket();
411 411
412 int fromPort() const; 412 int fromPort() const;
413 int toPort() const; 413 int toPort() const;
414 414
415 private: 415 private:
416 const struct tcphdr* _tcphdr; 416 const struct tcphdr* _tcphdr;
417}; 417};
418 418
419 419
420/*====================================================================================== 420/*======================================================================================
421 * OPacketCapturer 421 * OPacketCapturer
422 *======================================================================================*/ 422 *======================================================================================*/
423 423
424/** 424/**
425 * @brief A class based wrapper for network packet capturing. 425 * @brief A class based wrapper for network packet capturing.
426 * 426 *
427 * This class is the base of a high-level interface to the well known packet capturing 427 * This class is the base of a high-level interface to the well known packet capturing
428 * library libpcap. ... 428 * library libpcap. ...
429 */ 429 */
430class OPacketCapturer : public QObject 430class OPacketCapturer : public QObject
431{ 431{
432 Q_OBJECT 432 Q_OBJECT
433 433
434 public: 434 public:
435 /** 435 /**
436 * Constructor. 436 * Constructor.
437 */ 437 */
438 OPacketCapturer( QObject* parent = 0, const char* name = 0 ); 438 OPacketCapturer( QObject* parent = 0, const char* name = 0 );
439 /** 439 /**
440 * Destructor. 440 * Destructor.
441 */ 441 */
442 ~OPacketCapturer(); 442 ~OPacketCapturer();
443 /** 443 /**
444 * Setting the packet capturer to use blocking IO calls can be useful when 444 * Setting the packet capturer to use blocking IO calls can be useful when
445 * not using the socket notifier, e.g. without an application object. 445 * not using the socket notifier, e.g. without an application object.
446 */ 446 */
447 void setBlocking( bool ); 447 void setBlocking( bool );
448 /** 448 /**
449 * @returns true if the packet capturer uses blocking IO calls. 449 * @returns true if the packet capturer uses blocking IO calls.
450 */ 450 */
451 bool blocking() const; 451 bool blocking() const;
452 /** 452 /**
453 * Closes the packet capturer. This is automatically done in the destructor. 453 * Closes the packet capturer. This is automatically done in the destructor.
454 */ 454 */
455 void close(); 455 void close();
456 /** 456 /**
457 * @returns the data link type. 457 * @returns the data link type.
458 * @see <pcap.h> for possible values. 458 * @see <pcap.h> for possible values.
459 */ 459 */
460 int dataLink() const; 460 int dataLink() const;
461 /** 461 /**
462 * @returns the filedescriptor of the packet capturer. This is only useful, if 462 * @returns the filedescriptor of the packet capturer. This is only useful, if
463 * not using the socket notifier, e.g. without an application object. 463 * not using the socket notifier, e.g. without an application object.
464 */ 464 */
465 int fileno() const; 465 int fileno() const;
466 /** 466 /**
467 * @returns the next @ref OPacket from the packet capturer. 467 * @returns the next @ref OPacket from the packet capturer.
468 * @note If blocking mode is true then this call might block. 468 * @note If blocking mode is true then this call might block.
469 */ 469 */
470 OPacket* next(); 470 OPacket* next();
471 /** 471 /**
472 * Open the packet capturer to capture packets in live-mode from @a interface. 472 * Open the packet capturer to capture packets in live-mode from @a interface.
473 * If a @a filename is given, all captured packets are output to a tcpdump-compatible capture file.
473 */ 474 */
474 bool open( const QString& interface ); 475 bool open( const QString& interface, const QString& filename = QString::null );
475 /** 476 /**
476 * Open the packet capturer to capture packets in offline-mode from @a file. 477 * Open the packet capturer to capture packets in offline-mode from @a file.
477 */ 478 */
478 bool open( const QFile& file ); 479 bool open( const QFile& file );
479 /** 480 /**
480 * @returns true if the packet capturer is open 481 * @returns true if the packet capturer is open
481 */ 482 */
482 bool isOpen() const; 483 bool isOpen() const;
483 484
484 const QMap<QString,int>& statistics() const; 485 const QMap<QString,int>& statistics() const;
485 486
486 signals: 487 signals:
487 /** 488 /**
488 * This signal is emitted, when a packet has been received. 489 * This signal is emitted, when a packet has been received.
489 */ 490 */
490 void receivedPacket( OPacket* ); 491 void receivedPacket( OPacket* );
491 492
492 protected slots: 493 protected slots:
493 void readyToReceive(); 494 void readyToReceive();
494 495
495 protected: 496 protected:
496 QString _name; // devicename 497 QString _name; // devicename
497 bool _open; // check this before doing pcap calls 498 bool _open; // check this before doing pcap calls
498 pcap_t* _pch; // pcap library handle 499 pcap_t* _pch; // pcap library handle
500 pcap_dumper_t* _pcd; // pcap dumper handle
499 QSocketNotifier* _sn; // socket notifier for main loop 501 QSocketNotifier* _sn; // socket notifier for main loop
500 mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap 502 mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap
501 QMap<QString, int> _stats; // statistics; 503 QMap<QString, int> _stats; // statistics;
502}; 504};
503 505
504#endif // OPCAP_H 506#endif // OPCAP_H
505 507