summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp12
-rw-r--r--libopie2/opienet/opcap.cpp27
-rw-r--r--libopie2/opienet/opcap.h5
3 files changed, 38 insertions, 6 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 1f529d2..45ee4c0 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -166,869 +166,875 @@ ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
166 166
167struct ifreq& ONetworkInterface::ifr() const 167struct ifreq& ONetworkInterface::ifr() const
168{ 168{
169 return _ifr; 169 return _ifr;
170} 170}
171 171
172 172
173void ONetworkInterface::init() 173void ONetworkInterface::init()
174{ 174{
175 qDebug( "ONetworkInterface::init()" ); 175 qDebug( "ONetworkInterface::init()" );
176 176
177 memset( &_ifr, 0, sizeof( struct ifreq ) ); 177 memset( &_ifr, 0, sizeof( struct ifreq ) );
178 178
179 if ( _sfd == -1 ) 179 if ( _sfd == -1 )
180 { 180 {
181 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); 181 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() );
182 return; 182 return;
183 } 183 }
184} 184}
185 185
186 186
187bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const 187bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
188{ 188{
189 int result = ::ioctl( _sfd, call, &ifreq ); 189 int result = ::ioctl( _sfd, call, &ifreq );
190 if ( result == -1 ) 190 if ( result == -1 )
191 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 191 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
192 else 192 else
193 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); 193 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call );
194 return ( result != -1 ); 194 return ( result != -1 );
195} 195}
196 196
197 197
198bool ONetworkInterface::ioctl( int call ) const 198bool ONetworkInterface::ioctl( int call ) const
199{ 199{
200 strcpy( _ifr.ifr_name, name() ); 200 strcpy( _ifr.ifr_name, name() );
201 return ioctl( call, _ifr ); 201 return ioctl( call, _ifr );
202} 202}
203 203
204 204
205bool ONetworkInterface::isLoopback() const 205bool ONetworkInterface::isLoopback() const
206{ 206{
207 ioctl( SIOCGIFFLAGS ); 207 ioctl( SIOCGIFFLAGS );
208 return _ifr.ifr_flags & IFF_LOOPBACK; 208 return _ifr.ifr_flags & IFF_LOOPBACK;
209} 209}
210 210
211 211
212bool ONetworkInterface::setUp( bool b ) 212bool ONetworkInterface::setUp( bool b )
213{ 213{
214 ioctl( SIOCGIFFLAGS ); 214 ioctl( SIOCGIFFLAGS );
215 if ( b ) _ifr.ifr_flags |= IFF_UP; 215 if ( b ) _ifr.ifr_flags |= IFF_UP;
216 else _ifr.ifr_flags &= (~IFF_UP); 216 else _ifr.ifr_flags &= (~IFF_UP);
217 return ioctl( SIOCSIFFLAGS ); 217 return ioctl( SIOCSIFFLAGS );
218} 218}
219 219
220 220
221bool ONetworkInterface::isUp() const 221bool ONetworkInterface::isUp() const
222{ 222{
223 ioctl( SIOCGIFFLAGS ); 223 ioctl( SIOCGIFFLAGS );
224 return _ifr.ifr_flags & IFF_UP; 224 return _ifr.ifr_flags & IFF_UP;
225} 225}
226 226
227 227
228void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) 228void ONetworkInterface::setIPV4Address( const QHostAddress& addr )
229{ 229{
230 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 230 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
231 sa->sin_family = AF_INET; 231 sa->sin_family = AF_INET;
232 sa->sin_port = 0; 232 sa->sin_port = 0;
233 sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); 233 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
234 ioctl( SIOCSIFADDR ); 234 ioctl( SIOCSIFADDR );
235} 235}
236 236
237 237
238QString ONetworkInterface::ipV4Address() const 238QString ONetworkInterface::ipV4Address() const
239{ 239{
240 if ( ioctl( SIOCGIFADDR ) ) 240 if ( ioctl( SIOCGIFADDR ) )
241 { 241 {
242 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; 242 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
243 //FIXME: Use QHostAddress here 243 //FIXME: Use QHostAddress here
244 return QString( inet_ntoa( sa->sin_addr ) ); 244 return QString( inet_ntoa( sa->sin_addr ) );
245 } 245 }
246 else 246 else
247 return "<unknown>"; 247 return "<unknown>";
248} 248}
249 249
250 250
251void ONetworkInterface::setMacAddress( const OMacAddress& addr ) 251void ONetworkInterface::setMacAddress( const OMacAddress& addr )
252{ 252{
253 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 253 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
254 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); 254 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 );
255 ioctl( SIOCSIFHWADDR ); 255 ioctl( SIOCSIFHWADDR );
256} 256}
257 257
258 258
259OMacAddress ONetworkInterface::macAddress() const 259OMacAddress ONetworkInterface::macAddress() const
260{ 260{
261 if ( ioctl( SIOCGIFHWADDR ) ) 261 if ( ioctl( SIOCGIFHWADDR ) )
262 { 262 {
263 return OMacAddress( _ifr ); 263 return OMacAddress( _ifr );
264 } 264 }
265 else 265 else
266 { 266 {
267 return OMacAddress::unknown; 267 return OMacAddress::unknown;
268 } 268 }
269} 269}
270 270
271 271
272void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) 272void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr )
273{ 273{
274 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 274 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
275 sa->sin_family = AF_INET; 275 sa->sin_family = AF_INET;
276 sa->sin_port = 0; 276 sa->sin_port = 0;
277 sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); 277 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
278 ioctl( SIOCSIFNETMASK ); 278 ioctl( SIOCSIFNETMASK );
279} 279}
280 280
281 281
282QString ONetworkInterface::ipV4Netmask() const 282QString ONetworkInterface::ipV4Netmask() const
283{ 283{
284 if ( ioctl( SIOCGIFNETMASK ) ) 284 if ( ioctl( SIOCGIFNETMASK ) )
285 { 285 {
286 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; 286 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
287 //FIXME: Use QHostAddress here 287 //FIXME: Use QHostAddress here
288 return QString( inet_ntoa( sa->sin_addr ) ); 288 return QString( inet_ntoa( sa->sin_addr ) );
289 } 289 }
290 else 290 else
291 return "<unknown>"; 291 return "<unknown>";
292} 292}
293 293
294 294
295int ONetworkInterface::dataLinkType() const 295int ONetworkInterface::dataLinkType() const
296{ 296{
297 if ( ioctl( SIOCGIFHWADDR ) ) 297 if ( ioctl( SIOCGIFHWADDR ) )
298 { 298 {
299 return _ifr.ifr_hwaddr.sa_family; 299 return _ifr.ifr_hwaddr.sa_family;
300 } 300 }
301 else 301 else
302 { 302 {
303 return -1; 303 return -1;
304 } 304 }
305} 305}
306 306
307 307
308void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) 308void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
309{ 309{
310 _mon = m; 310 _mon = m;
311 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); 311 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() );
312} 312}
313 313
314 314
315OMonitoringInterface* ONetworkInterface::monitoring() const 315OMonitoringInterface* ONetworkInterface::monitoring() const
316{ 316{
317 return _mon; 317 return _mon;
318} 318}
319 319
320 320
321ONetworkInterface::~ONetworkInterface() 321ONetworkInterface::~ONetworkInterface()
322{ 322{
323 qDebug( "ONetworkInterface::~ONetworkInterface()" ); 323 qDebug( "ONetworkInterface::~ONetworkInterface()" );
324 if ( _sfd != -1 ) ::close( _sfd ); 324 if ( _sfd != -1 ) ::close( _sfd );
325} 325}
326 326
327 327
328bool ONetworkInterface::setPromiscuousMode( bool b ) 328bool ONetworkInterface::setPromiscuousMode( bool b )
329{ 329{
330 ioctl( SIOCGIFFLAGS ); 330 ioctl( SIOCGIFFLAGS );
331 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 331 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
332 else _ifr.ifr_flags &= (~IFF_PROMISC); 332 else _ifr.ifr_flags &= (~IFF_PROMISC);
333 return ioctl( SIOCSIFFLAGS ); 333 return ioctl( SIOCSIFFLAGS );
334} 334}
335 335
336 336
337bool ONetworkInterface::promiscuousMode() const 337bool ONetworkInterface::promiscuousMode() const
338{ 338{
339 ioctl( SIOCGIFFLAGS ); 339 ioctl( SIOCGIFFLAGS );
340 return _ifr.ifr_flags & IFF_PROMISC; 340 return _ifr.ifr_flags & IFF_PROMISC;
341} 341}
342 342
343 343
344bool ONetworkInterface::isWireless() const 344bool ONetworkInterface::isWireless() const
345{ 345{
346 return ioctl( SIOCGIWNAME ); 346 return ioctl( SIOCGIWNAME );
347} 347}
348 348
349 349
350/*====================================================================================== 350/*======================================================================================
351 * OChannelHopper 351 * OChannelHopper
352 *======================================================================================*/ 352 *======================================================================================*/
353 353
354OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) 354OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
355 :QObject( 0, "Mickey's funky hopper" ), 355 :QObject( 0, "Mickey's funky hopper" ),
356 _iface( iface ), _interval( 0 ), _tid( 0 ) 356 _iface( iface ), _interval( 0 ), _tid( 0 )
357{ 357{
358 int _maxChannel = iface->channels()+1; 358 int _maxChannel = iface->channels()+1;
359 // generate fancy hopping sequence honoring the device capabilities 359 // generate fancy hopping sequence honoring the device capabilities
360 if ( _maxChannel >= 1 ) _channels.append( 1 ); 360 if ( _maxChannel >= 1 ) _channels.append( 1 );
361 if ( _maxChannel >= 7 ) _channels.append( 7 ); 361 if ( _maxChannel >= 7 ) _channels.append( 7 );
362 if ( _maxChannel >= 13 ) _channels.append( 13 ); 362 if ( _maxChannel >= 13 ) _channels.append( 13 );
363 if ( _maxChannel >= 2 ) _channels.append( 2 ); 363 if ( _maxChannel >= 2 ) _channels.append( 2 );
364 if ( _maxChannel >= 8 ) _channels.append( 8 ); 364 if ( _maxChannel >= 8 ) _channels.append( 8 );
365 if ( _maxChannel >= 3 ) _channels.append( 3 ); 365 if ( _maxChannel >= 3 ) _channels.append( 3 );
366 if ( _maxChannel >= 14 ) _channels.append( 14 ); 366 if ( _maxChannel >= 14 ) _channels.append( 14 );
367 if ( _maxChannel >= 9 ) _channels.append( 9 ); 367 if ( _maxChannel >= 9 ) _channels.append( 9 );
368 if ( _maxChannel >= 4 ) _channels.append( 4 ); 368 if ( _maxChannel >= 4 ) _channels.append( 4 );
369 if ( _maxChannel >= 10 ) _channels.append( 10 ); 369 if ( _maxChannel >= 10 ) _channels.append( 10 );
370 if ( _maxChannel >= 5 ) _channels.append( 5 ); 370 if ( _maxChannel >= 5 ) _channels.append( 5 );
371 if ( _maxChannel >= 11 ) _channels.append( 11 ); 371 if ( _maxChannel >= 11 ) _channels.append( 11 );
372 if ( _maxChannel >= 6 ) _channels.append( 6 ); 372 if ( _maxChannel >= 6 ) _channels.append( 6 );
373 if ( _maxChannel >= 12 ) _channels.append( 12 ); 373 if ( _maxChannel >= 12 ) _channels.append( 12 );
374 _channel = _channels.begin(); 374 _channel = _channels.begin();
375 375
376} 376}
377 377
378 378
379OChannelHopper::~OChannelHopper() 379OChannelHopper::~OChannelHopper()
380{ 380{
381} 381}
382 382
383 383
384bool OChannelHopper::isActive() const 384bool OChannelHopper::isActive() const
385{ 385{
386 return _tid; 386 return _tid;
387} 387}
388 388
389 389
390int OChannelHopper::channel() const 390int OChannelHopper::channel() const
391{ 391{
392 return *_channel; 392 return *_channel;
393} 393}
394 394
395 395
396void OChannelHopper::timerEvent( QTimerEvent* ) 396void OChannelHopper::timerEvent( QTimerEvent* )
397{ 397{
398 _iface->setChannel( *_channel ); 398 _iface->setChannel( *_channel );
399 emit( hopped( *_channel ) ); 399 emit( hopped( *_channel ) );
400 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", 400 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'",
401 *_channel, (const char*) _iface->name() ); 401 *_channel, (const char*) _iface->name() );
402 if ( ++_channel == _channels.end() ) _channel = _channels.begin(); 402 if ( ++_channel == _channels.end() ) _channel = _channels.begin();
403} 403}
404 404
405 405
406void OChannelHopper::setInterval( int interval ) 406void OChannelHopper::setInterval( int interval )
407{ 407{
408 if ( interval == _interval ) 408 if ( interval == _interval )
409 return; 409 return;
410 410
411 if ( _interval ) 411 if ( _interval )
412 killTimer( _tid ); 412 killTimer( _tid );
413 413
414 _tid = 0; 414 _tid = 0;
415 _interval = interval; 415 _interval = interval;
416 416
417 if ( _interval ) 417 if ( _interval )
418 { 418 {
419 _tid = startTimer( interval ); 419 _tid = startTimer( interval );
420 } 420 }
421} 421}
422 422
423 423
424int OChannelHopper::interval() const 424int OChannelHopper::interval() const
425{ 425{
426 return _interval; 426 return _interval;
427} 427}
428 428
429 429
430/*====================================================================================== 430/*======================================================================================
431 * OWirelessNetworkInterface 431 * OWirelessNetworkInterface
432 *======================================================================================*/ 432 *======================================================================================*/
433 433
434OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) 434OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name )
435 :ONetworkInterface( parent, name ), _hopper( 0 ) 435 :ONetworkInterface( parent, name ), _hopper( 0 )
436{ 436{
437 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); 437 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" );
438 init(); 438 init();
439} 439}
440 440
441 441
442OWirelessNetworkInterface::~OWirelessNetworkInterface() 442OWirelessNetworkInterface::~OWirelessNetworkInterface()
443{ 443{
444} 444}
445 445
446 446
447struct iwreq& OWirelessNetworkInterface::iwr() const 447struct iwreq& OWirelessNetworkInterface::iwr() const
448{ 448{
449 return _iwr; 449 return _iwr;
450} 450}
451 451
452 452
453void OWirelessNetworkInterface::init() 453void OWirelessNetworkInterface::init()
454{ 454{
455 qDebug( "OWirelessNetworkInterface::init()" ); 455 qDebug( "OWirelessNetworkInterface::init()" );
456 memset( &_iwr, 0, sizeof( struct iwreq ) ); 456 memset( &_iwr, 0, sizeof( struct iwreq ) );
457 buildChannelList(); 457 buildChannelList();
458 buildPrivateList(); 458 buildPrivateList();
459} 459}
460 460
461 461
462QString OWirelessNetworkInterface::associatedAP() const 462QString OWirelessNetworkInterface::associatedAP() const
463{ 463{
464 //FIXME: use OMacAddress 464 //FIXME: use OMacAddress
465 QString mac; 465 QString mac;
466 466
467 if ( ioctl( SIOCGIWAP ) ) 467 if ( ioctl( SIOCGIWAP ) )
468 { 468 {
469 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 469 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
470 _ifr.ifr_hwaddr.sa_data[0]&0xff, 470 _ifr.ifr_hwaddr.sa_data[0]&0xff,
471 _ifr.ifr_hwaddr.sa_data[1]&0xff, 471 _ifr.ifr_hwaddr.sa_data[1]&0xff,
472 _ifr.ifr_hwaddr.sa_data[2]&0xff, 472 _ifr.ifr_hwaddr.sa_data[2]&0xff,
473 _ifr.ifr_hwaddr.sa_data[3]&0xff, 473 _ifr.ifr_hwaddr.sa_data[3]&0xff,
474 _ifr.ifr_hwaddr.sa_data[4]&0xff, 474 _ifr.ifr_hwaddr.sa_data[4]&0xff,
475 _ifr.ifr_hwaddr.sa_data[5]&0xff ); 475 _ifr.ifr_hwaddr.sa_data[5]&0xff );
476 } 476 }
477 else 477 else
478 { 478 {
479 mac = "<Unknown>"; 479 mac = "<Unknown>";
480 } 480 }
481 return mac; 481 return mac;
482} 482}
483 483
484 484
485void OWirelessNetworkInterface::buildChannelList() 485void OWirelessNetworkInterface::buildChannelList()
486{ 486{
487 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck 487 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
488 //ML: The HostAP drivers need more than sizeof struct_iw range to complete 488 //ML: The HostAP drivers need more than sizeof struct_iw range to complete
489 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". 489 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
490 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate 490 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
491 //ML: _too much_ space. This is damn shitty crap *sigh* 491 //ML: _too much_ space. This is damn shitty crap *sigh*
492 //ML: We allocate a large memory region in RAM and check whether the 492 //ML: We allocate a large memory region in RAM and check whether the
493 //ML: driver pollutes this extra space. The complaint will be made on stdout, 493 //ML: driver pollutes this extra space. The complaint will be made on stdout,
494 //ML: so please forward this... 494 //ML: so please forward this...
495 495
496 struct iwreq wrq; 496 struct iwreq wrq;
497 int len = sizeof( struct iw_range )*2; 497 int len = sizeof( struct iw_range )*2;
498 char *buffer = (char*) malloc( len ); 498 char *buffer = (char*) malloc( len );
499 //FIXME: Validate if we actually got the memory block 499 //FIXME: Validate if we actually got the memory block
500 memset( buffer, 0, len ); 500 memset( buffer, 0, len );
501 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 501 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
502 wrq.u.data.pointer = (caddr_t) buffer; 502 wrq.u.data.pointer = (caddr_t) buffer;
503 wrq.u.data.length = sizeof( struct iw_range ); 503 wrq.u.data.length = sizeof( struct iw_range );
504 wrq.u.data.flags = 0; 504 wrq.u.data.flags = 0;
505 505
506 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) 506 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
507 { 507 {
508 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); 508 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) );
509 _channels.insert( 2412, 1 ); // 2.412 GHz 509 _channels.insert( 2412, 1 ); // 2.412 GHz
510 _channels.insert( 2417, 2 ); // 2.417 GHz 510 _channels.insert( 2417, 2 ); // 2.417 GHz
511 _channels.insert( 2422, 3 ); // 2.422 GHz 511 _channels.insert( 2422, 3 ); // 2.422 GHz
512 _channels.insert( 2427, 4 ); // 2.427 GHz 512 _channels.insert( 2427, 4 ); // 2.427 GHz
513 _channels.insert( 2432, 5 ); // 2.432 GHz 513 _channels.insert( 2432, 5 ); // 2.432 GHz
514 _channels.insert( 2437, 6 ); // 2.437 GHz 514 _channels.insert( 2437, 6 ); // 2.437 GHz
515 _channels.insert( 2442, 7 ); // 2.442 GHz 515 _channels.insert( 2442, 7 ); // 2.442 GHz
516 _channels.insert( 2447, 8 ); // 2.447 GHz 516 _channels.insert( 2447, 8 ); // 2.447 GHz
517 _channels.insert( 2452, 9 ); // 2.452 GHz 517 _channels.insert( 2452, 9 ); // 2.452 GHz
518 _channels.insert( 2457, 10 ); // 2.457 GHz 518 _channels.insert( 2457, 10 ); // 2.457 GHz
519 _channels.insert( 2462, 11 ); // 2.462 GHz 519 _channels.insert( 2462, 11 ); // 2.462 GHz
520 } 520 }
521 else 521 else
522 { 522 {
523 // <check if the driver overwrites stuff> 523 // <check if the driver overwrites stuff>
524 int max = 0; 524 int max = 0;
525 for ( int r = sizeof( struct iw_range ); r < len; r++ ) 525 for ( int r = sizeof( struct iw_range ); r < len; r++ )
526 if (buffer[r] != 0) 526 if (buffer[r] != 0)
527 max = r; 527 max = r;
528 if (max > 0) 528 if (max > 0)
529 { 529 {
530 qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" 530 qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'"
531 "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); 531 "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) );
532 } 532 }
533 // </check if the driver overwrites stuff> 533 // </check if the driver overwrites stuff>
534 534
535 struct iw_range range; 535 struct iw_range range;
536 memcpy( &range, buffer, sizeof range ); 536 memcpy( &range, buffer, sizeof range );
537 537
538 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); 538 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency );
539 for ( int i = 0; i < range.num_frequency; ++i ) 539 for ( int i = 0; i < range.num_frequency; ++i )
540 { 540 {
541 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 541 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
542 _channels.insert( freq, i+1 ); 542 _channels.insert( freq, i+1 );
543 } 543 }
544 } 544 }
545 545
546 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); 546 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." );
547 free(buffer); 547 free(buffer);
548} 548}
549 549
550 550
551void OWirelessNetworkInterface::buildPrivateList() 551void OWirelessNetworkInterface::buildPrivateList()
552{ 552{
553 qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); 553 qDebug( "OWirelessNetworkInterface::buildPrivateList()" );
554 554
555 struct iw_priv_args priv[IW_MAX_PRIV_DEF]; 555 struct iw_priv_args priv[IW_MAX_PRIV_DEF];
556 556
557 _iwr.u.data.pointer = (char*) &priv; 557 _iwr.u.data.pointer = (char*) &priv;
558 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself 558 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
559 _iwr.u.data.flags = 0; 559 _iwr.u.data.flags = 0;
560 560
561 if ( !wioctl( SIOCGIWPRIV ) ) 561 if ( !wioctl( SIOCGIWPRIV ) )
562 { 562 {
563 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); 563 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) );
564 return; 564 return;
565 } 565 }
566 566
567 for ( int i = 0; i < _iwr.u.data.length; ++i ) 567 for ( int i = 0; i < _iwr.u.data.length; ++i )
568 { 568 {
569 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 569 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
570 } 570 }
571 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); 571 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." );
572} 572}
573 573
574 574
575int OWirelessNetworkInterface::channel() const 575int OWirelessNetworkInterface::channel() const
576{ 576{
577 //FIXME: When monitoring enabled, then use it 577 //FIXME: When monitoring enabled, then use it
578 //FIXME: to gather the current RF channel 578 //FIXME: to gather the current RF channel
579 //FIXME: Until then, get active channel from hopper. 579 //FIXME: Until then, get active channel from hopper.
580 if ( _hopper && _hopper->isActive() ) 580 if ( _hopper && _hopper->isActive() )
581 return _hopper->channel(); 581 return _hopper->channel();
582 582
583 if ( !wioctl( SIOCGIWFREQ ) ) 583 if ( !wioctl( SIOCGIWFREQ ) )
584 { 584 {
585 return -1; 585 return -1;
586 } 586 }
587 else 587 else
588 { 588 {
589 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 589 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
590 } 590 }
591} 591}
592 592
593 593
594void OWirelessNetworkInterface::setChannel( int c ) const 594void OWirelessNetworkInterface::setChannel( int c ) const
595{ 595{
596 if ( !_mon ) 596 if ( !_mon )
597 { 597 {
598 memset( &_iwr, 0, sizeof( struct iwreq ) ); 598 memset( &_iwr, 0, sizeof( struct iwreq ) );
599 _iwr.u.freq.m = c; 599 _iwr.u.freq.m = c;
600 _iwr.u.freq.e = 0; 600 _iwr.u.freq.e = 0;
601 wioctl( SIOCSIWFREQ ); 601 wioctl( SIOCSIWFREQ );
602 } 602 }
603 else 603 else
604 { 604 {
605 _mon->setChannel( c ); 605 _mon->setChannel( c );
606 } 606 }
607} 607}
608 608
609 609
610double OWirelessNetworkInterface::frequency() const 610double OWirelessNetworkInterface::frequency() const
611{ 611{
612 if ( !wioctl( SIOCGIWFREQ ) ) 612 if ( !wioctl( SIOCGIWFREQ ) )
613 { 613 {
614 return -1.0; 614 return -1.0;
615 } 615 }
616 else 616 else
617 { 617 {
618 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 618 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
619 } 619 }
620} 620}
621 621
622 622
623int OWirelessNetworkInterface::channels() const 623int OWirelessNetworkInterface::channels() const
624{ 624{
625 return _channels.count(); 625 return _channels.count();
626} 626}
627 627
628 628
629void OWirelessNetworkInterface::setChannelHopping( int interval ) 629void OWirelessNetworkInterface::setChannelHopping( int interval )
630{ 630{
631 if ( !_hopper ) _hopper = new OChannelHopper( this ); 631 if ( !_hopper ) _hopper = new OChannelHopper( this );
632 _hopper->setInterval( interval ); 632 _hopper->setInterval( interval );
633 //FIXME: When and by whom will the channel hopper be deleted? 633 //FIXME: When and by whom will the channel hopper be deleted?
634 //TODO: rely on QObject hierarchy 634 //TODO: rely on QObject hierarchy
635} 635}
636 636
637 637
638int OWirelessNetworkInterface::channelHopping() const 638int OWirelessNetworkInterface::channelHopping() const
639{ 639{
640 return _hopper->interval(); 640 return _hopper->interval();
641} 641}
642 642
643 643
644OChannelHopper* OWirelessNetworkInterface::channelHopper() const 644OChannelHopper* OWirelessNetworkInterface::channelHopper() const
645{ 645{
646 return _hopper; 646 return _hopper;
647} 647}
648 648
649 649
650void OWirelessNetworkInterface::setMode( const QString& mode ) 650void OWirelessNetworkInterface::setMode( const QString& mode )
651{ 651{
652 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; 652 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO;
653 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; 653 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC;
654 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; 654 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA;
655 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; 655 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER;
656 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; 656 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT;
657 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; 657 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND;
658 #if WIRELESS_EXT > 14 658 #if WIRELESS_EXT > 14
659 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; 659 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR;
660 #endif 660 #endif
661 else 661 else
662 { 662 {
663 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); 663 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode );
664 return; 664 return;
665 } 665 }
666 wioctl( SIOCSIWMODE ); 666 wioctl( SIOCSIWMODE );
667} 667}
668 668
669 669
670QString OWirelessNetworkInterface::mode() const 670QString OWirelessNetworkInterface::mode() const
671{ 671{
672 if ( !wioctl( SIOCGIWMODE ) ) 672 if ( !wioctl( SIOCGIWMODE ) )
673 { 673 {
674 return "<unknown>"; 674 return "<unknown>";
675 } 675 }
676 switch ( _iwr.u.mode ) 676 switch ( _iwr.u.mode )
677 { 677 {
678 case IW_MODE_AUTO: return "auto"; 678 case IW_MODE_AUTO: return "auto";
679 case IW_MODE_ADHOC: return "adhoc"; 679 case IW_MODE_ADHOC: return "adhoc";
680 case IW_MODE_INFRA: return "managed"; 680 case IW_MODE_INFRA: return "managed";
681 case IW_MODE_MASTER: return "master"; 681 case IW_MODE_MASTER: return "master";
682 case IW_MODE_REPEAT: return "repeater"; 682 case IW_MODE_REPEAT: return "repeater";
683 case IW_MODE_SECOND: return "secondary"; 683 case IW_MODE_SECOND: return "secondary";
684 #if WIRELESS_EXT > 14 684 #if WIRELESS_EXT > 14
685 case IW_MODE_MONITOR: return "monitor"; 685 case IW_MODE_MONITOR: return "monitor";
686 #endif 686 #endif
687 default: assert( 0 ); // shouldn't happen 687 default: assert( 0 ); // shouldn't happen
688 } 688 }
689} 689}
690 690
691 691
692void OWirelessNetworkInterface::setMonitorMode( bool b ) 692void OWirelessNetworkInterface::setMonitorMode( bool b )
693{ 693{
694 if ( _mon ) 694 if ( _mon )
695 _mon->setEnabled( b ); 695 _mon->setEnabled( b );
696 else 696 else
697 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 697 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
698} 698}
699 699
700 700
701bool OWirelessNetworkInterface::monitorMode() const 701bool OWirelessNetworkInterface::monitorMode() const
702{ 702{
703 qDebug( "dataLinkType = %d", dataLinkType() ); 703 qDebug( "dataLinkType = %d", dataLinkType() );
704 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); 704 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 );
705 // 802 is the header type for PRISM - Linux support for this is pending... 705 // 802 is the header type for PRISM - Linux support for this is pending...
706} 706}
707 707
708 708
709void OWirelessNetworkInterface::setNickName( const QString& nickname ) 709void OWirelessNetworkInterface::setNickName( const QString& nickname )
710{ 710{
711 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); 711 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
712 _iwr.u.essid.length = nickname.length(); 712 _iwr.u.essid.length = nickname.length();
713 wioctl( SIOCSIWNICKN ); 713 wioctl( SIOCSIWNICKN );
714} 714}
715 715
716 716
717QString OWirelessNetworkInterface::nickName() const 717QString OWirelessNetworkInterface::nickName() const
718{ 718{
719 char str[IW_ESSID_MAX_SIZE]; 719 char str[IW_ESSID_MAX_SIZE];
720 _iwr.u.data.pointer = &str[0]; 720 _iwr.u.data.pointer = &str[0];
721 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 721 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
722 if ( !wioctl( SIOCGIWNICKN ) ) 722 if ( !wioctl( SIOCGIWNICKN ) )
723 { 723 {
724 return "<unknown>"; 724 return "<unknown>";
725 } 725 }
726 else 726 else
727 { 727 {
728 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 728 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
729 return str; 729 return str;
730 } 730 }
731} 731}
732 732
733 733
734void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 734void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
735{ 735{
736 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 736 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
737 if ( !priv ) 737 if ( !priv )
738 { 738 {
739 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); 739 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call );
740 return; 740 return;
741 } 741 }
742 if ( priv->numberSetArgs() != numargs ) 742 if ( priv->numberSetArgs() != numargs )
743 { 743 {
744 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); 744 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs );
745 return; 745 return;
746 } 746 }
747 747
748 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); 748 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() );
749 memset( &_iwr, 0, sizeof _iwr ); 749 memset( &_iwr, 0, sizeof _iwr );
750 va_list argp; 750 va_list argp;
751 va_start( argp, numargs ); 751 va_start( argp, numargs );
752 for ( int i = 0; i < numargs; ++i ) 752 for ( int i = 0; i < numargs; ++i )
753 { 753 {
754 priv->setParameter( i, va_arg( argp, int ) ); 754 priv->setParameter( i, va_arg( argp, int ) );
755 } 755 }
756 va_end( argp ); 756 va_end( argp );
757 priv->invoke(); 757 priv->invoke();
758} 758}
759 759
760 760
761void OWirelessNetworkInterface::getPrivate( const QString& call ) 761void OWirelessNetworkInterface::getPrivate( const QString& call )
762{ 762{
763 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); 763 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." );
764} 764}
765 765
766 766
767bool OWirelessNetworkInterface::hasPrivate( const QString& call ) 767bool OWirelessNetworkInterface::hasPrivate( const QString& call )
768{ 768{
769 return child( (const char*) call ); 769 return child( (const char*) call );
770} 770}
771 771
772 772
773QString OWirelessNetworkInterface::SSID() const 773QString OWirelessNetworkInterface::SSID() const
774{ 774{
775 char str[IW_ESSID_MAX_SIZE]; 775 char str[IW_ESSID_MAX_SIZE];
776 _iwr.u.essid.pointer = &str[0]; 776 _iwr.u.essid.pointer = &str[0];
777 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 777 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
778 if ( !wioctl( SIOCGIWESSID ) ) 778 if ( !wioctl( SIOCGIWESSID ) )
779 { 779 {
780 return "<unknown>"; 780 return "<unknown>";
781 } 781 }
782 else 782 else
783 { 783 {
784 return str; 784 return str;
785 } 785 }
786} 786}
787 787
788 788
789void OWirelessNetworkInterface::setSSID( const QString& ssid ) 789void OWirelessNetworkInterface::setSSID( const QString& ssid )
790{ 790{
791 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 791 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
792 _iwr.u.essid.length = ssid.length(); 792 _iwr.u.essid.length = ssid.length();
793 wioctl( SIOCSIWESSID ); 793 wioctl( SIOCSIWESSID );
794} 794}
795 795
796 796
797bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 797bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
798{ 798{
799 int result = ::ioctl( _sfd, call, &iwreq ); 799 int result = ::ioctl( _sfd, call, &iwreq );
800 if ( result == -1 ) 800 if ( result == -1 )
801 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 801 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
802 else 802 else
803 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); 803 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call );
804 return ( result != -1 ); 804 return ( result != -1 );
805} 805}
806 806
807 807
808bool OWirelessNetworkInterface::wioctl( int call ) const 808bool OWirelessNetworkInterface::wioctl( int call ) const
809{ 809{
810 strcpy( _iwr.ifr_name, name() ); 810 strcpy( _iwr.ifr_name, name() );
811 return wioctl( call, _iwr ); 811 return wioctl( call, _iwr );
812} 812}
813 813
814 814
815/*====================================================================================== 815/*======================================================================================
816 * OMonitoringInterface 816 * OMonitoringInterface
817 *======================================================================================*/ 817 *======================================================================================*/
818 818
819OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 819OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
820 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) 820 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader )
821{ 821{
822} 822}
823 823
824 824
825OMonitoringInterface::~OMonitoringInterface() 825OMonitoringInterface::~OMonitoringInterface()
826{ 826{
827} 827}
828 828
829 829
830void OMonitoringInterface::setChannel( int c ) 830void OMonitoringInterface::setChannel( int c )
831{ 831{
832 // use standard WE channel switching protocol 832 // use standard WE channel switching protocol
833 memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); 833 memset( &_if->_iwr, 0, sizeof( struct iwreq ) );
834 _if->_iwr.u.freq.m = c; 834 _if->_iwr.u.freq.m = c;
835 _if->_iwr.u.freq.e = 0; 835 _if->_iwr.u.freq.e = 0;
836 _if->wioctl( SIOCSIWFREQ ); 836 _if->wioctl( SIOCSIWFREQ );
837} 837}
838 838
839 839
840bool OMonitoringInterface::enabled() const 840bool OMonitoringInterface::enabled() const
841{ 841{
842 return _if->monitorMode(); 842 return _if->monitorMode();
843} 843}
844 844
845 845
846void OMonitoringInterface::setEnabled( bool b ) 846void OMonitoringInterface::setEnabled( bool b )
847{ 847{
848} 848}
849 849
850 850
851/*====================================================================================== 851/*======================================================================================
852 * OCiscoMonitoringInterface 852 * OCiscoMonitoringInterface
853 *======================================================================================*/ 853 *======================================================================================*/
854 854
855OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 855OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
856 :OMonitoringInterface( iface, prismHeader ) 856 :OMonitoringInterface( iface, prismHeader )
857{ 857{
858 iface->setMonitoring( this ); 858 iface->setMonitoring( this );
859} 859}
860 860
861 861
862OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 862OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
863{ 863{
864} 864}
865 865
866 866
867void OCiscoMonitoringInterface::setEnabled( bool b ) 867void OCiscoMonitoringInterface::setEnabled( bool b )
868{ 868{
869 QString fname; 869 QString fname;
870 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); 870 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
871 QFile f( fname ); 871 QFile f( fname );
872 if ( !f.exists() ) return; 872 if ( !f.exists() ) return;
873 873
874 if ( f.open( IO_WriteOnly ) ) 874 if ( f.open( IO_WriteOnly ) )
875 { 875 {
876 QTextStream s( &f ); 876 QTextStream s( &f );
877 s << "Mode: r"; 877 s << "Mode: r";
878 s << "Mode: y"; 878 s << "Mode: y";
879 s << "XmitPower: 1"; 879 s << "XmitPower: 1";
880 } 880 }
881 881
882 // flushing and closing will be done automatically when f goes out of scope 882 // flushing and closing will be done automatically when f goes out of scope
883} 883}
884 884
885 885
886QString OCiscoMonitoringInterface::name() const 886QString OCiscoMonitoringInterface::name() const
887{ 887{
888 return "cisco"; 888 return "cisco";
889} 889}
890 890
891 891
892void OCiscoMonitoringInterface::setChannel( int ) 892void OCiscoMonitoringInterface::setChannel( int )
893{ 893{
894 // cisco devices automatically switch channels when in monitor mode 894 // cisco devices automatically switch channels when in monitor mode
895} 895}
896 896
897 897
898/*====================================================================================== 898/*======================================================================================
899 * OWlanNGMonitoringInterface 899 * OWlanNGMonitoringInterface
900 *======================================================================================*/ 900 *======================================================================================*/
901 901
902 902
903OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 903OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
904 :OMonitoringInterface( iface, prismHeader ) 904 :OMonitoringInterface( iface, prismHeader )
905{ 905{
906 iface->setMonitoring( this ); 906 iface->setMonitoring( this );
907} 907}
908 908
909 909
910OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 910OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
911{ 911{
912} 912}
913 913
914 914
915void OWlanNGMonitoringInterface::setEnabled( bool b ) 915void OWlanNGMonitoringInterface::setEnabled( bool b )
916{ 916{
917 //FIXME: do nothing if its already in the same mode 917 //FIXME: do nothing if its already in the same mode
918 918
919 QString enable = b ? "true" : "false"; 919 QString enable = b ? "true" : "false";
920 QString prism = _prismHeader ? "true" : "false"; 920 QString prism = _prismHeader ? "true" : "false";
921 QString cmd; 921 QString cmd;
922 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", 922 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
923 (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); 923 (const char*) _if->name(), 1, (const char*) enable, (const char*) prism );
924 system( cmd ); 924 system( cmd );
925} 925}
926 926
927 927
928QString OWlanNGMonitoringInterface::name() const 928QString OWlanNGMonitoringInterface::name() const
929{ 929{
930 return "wlan-ng"; 930 return "wlan-ng";
931} 931}
932 932
933 933
934void OWlanNGMonitoringInterface::setChannel( int ) 934void OWlanNGMonitoringInterface::setChannel( int c )
935{ 935{
936 // wlan-ng devices automatically switch channels when in monitor mode 936 //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't.
937 // NOTE: The above note no longer seems to be true for recent driver versions! 937
938 QString enable = "true"; //_if->monitorMode() ? "true" : "false";
939 QString prism = _prismHeader ? "true" : "false";
940 QString cmd;
941 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
942 (const char*) _if->name(), c+1, (const char*) enable, (const char*) prism );
943 system( cmd );
938} 944}
939 945
940 946
941/*====================================================================================== 947/*======================================================================================
942 * OHostAPMonitoringInterface 948 * OHostAPMonitoringInterface
943 *======================================================================================*/ 949 *======================================================================================*/
944 950
945OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 951OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
946 :OMonitoringInterface( iface, prismHeader ) 952 :OMonitoringInterface( iface, prismHeader )
947{ 953{
948 iface->setMonitoring( this ); 954 iface->setMonitoring( this );
949} 955}
950 956
951OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 957OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
952{ 958{
953} 959}
954 960
955void OHostAPMonitoringInterface::setEnabled( bool b ) 961void OHostAPMonitoringInterface::setEnabled( bool b )
956{ 962{
957 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 963 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
958 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 964 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
959 965
960 #if WIRELESS_EXT > 14 966 #if WIRELESS_EXT > 14
961 if ( b ) 967 if ( b )
962 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header 968 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header
963 else 969 else
964 _if->setMode( "managed" ); 970 _if->setMode( "managed" );
965 #else 971 #else
966 int monitorCode = _prismHeader ? 1 : 2; 972 int monitorCode = _prismHeader ? 1 : 2;
967 if ( b ) 973 if ( b )
968 { 974 {
969 _if->setPrivate( "monitor", 1, monitorCode ); 975 _if->setPrivate( "monitor", 1, monitorCode );
970 } 976 }
971 else 977 else
972 { 978 {
973 _if->setPrivate( "monitor", 1, 0 ); 979 _if->setPrivate( "monitor", 1, 0 );
974 } 980 }
975 #endif 981 #endif
976} 982}
977 983
978 984
979QString OHostAPMonitoringInterface::name() const 985QString OHostAPMonitoringInterface::name() const
980{ 986{
981 return "hostap"; 987 return "hostap";
982} 988}
983 989
984 990
985/*====================================================================================== 991/*======================================================================================
986 * OOrinocoNetworkInterface 992 * OOrinocoNetworkInterface
987 *======================================================================================*/ 993 *======================================================================================*/
988 994
989OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 995OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
990 :OMonitoringInterface( iface, prismHeader ) 996 :OMonitoringInterface( iface, prismHeader )
991{ 997{
992 iface->setMonitoring( this ); 998 iface->setMonitoring( this );
993} 999}
994 1000
995 1001
996OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 1002OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
997{ 1003{
998} 1004}
999 1005
1000 1006
1001void OOrinocoMonitoringInterface::setChannel( int c ) 1007void OOrinocoMonitoringInterface::setChannel( int c )
1002{ 1008{
1003 int monitorCode = _prismHeader ? 1 : 2; 1009 int monitorCode = _prismHeader ? 1 : 2;
1004 _if->setPrivate( "monitor", 2, monitorCode, c ); 1010 _if->setPrivate( "monitor", 2, monitorCode, c );
1005} 1011}
1006 1012
1007 1013
1008void OOrinocoMonitoringInterface::setEnabled( bool b ) 1014void OOrinocoMonitoringInterface::setEnabled( bool b )
1009{ 1015{
1010 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 1016 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
1011 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 1017 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
1012 1018
1013 #if WIRELESS_EXT > 14 1019 #if WIRELESS_EXT > 14
1014 if ( b ) 1020 if ( b )
1015 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header 1021 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header
1016 else 1022 else
1017 _if->setMode( "managed" ); 1023 _if->setMode( "managed" );
1018 #else 1024 #else
1019 if ( b ) 1025 if ( b )
1020 { 1026 {
1021 setChannel( 1 ); 1027 setChannel( 1 );
1022 } 1028 }
1023 else 1029 else
1024 { 1030 {
1025 _if->setPrivate( "monitor", 2, 0, 0 ); 1031 _if->setPrivate( "monitor", 2, 0, 0 );
1026 } 1032 }
1027 #endif 1033 #endif
1028} 1034}
1029 1035
1030 1036
1031QString OOrinocoMonitoringInterface::name() const 1037QString OOrinocoMonitoringInterface::name() const
1032{ 1038{
1033 return "orinoco"; 1039 return "orinoco";
1034} 1040}
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 9ed2b83..38ca1a1 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -1,1302 +1,1323 @@
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
36#include <opie2/opcap.h> 35#include <opie2/opcap.h>
37 36
38/* QT */ 37/* QT */
39
40#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) 38#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects)
41#include <qsocketnotifier.h> 39#include <qsocketnotifier.h>
42#include <qobjectlist.h> 40#include <qobjectlist.h>
43 41
42/* SYSTEM */
43#include <sys/time.h>
44#include <sys/types.h>
45#include <unistd.h>
46
47/* LOCAL */
44#include "udp_ports.h" 48#include "udp_ports.h"
45 49
46/*====================================================================================== 50/*======================================================================================
47 * OPacket 51 * OPacket
48 *======================================================================================*/ 52 *======================================================================================*/
49 53
50OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) 54OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
51 :QObject( parent, "Generic" ), _hdr( header ), _data( data ) 55 :QObject( parent, "Generic" ), _hdr( header ), _data( data )
52{ 56{
53 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); 57 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
54 58
55 _end = (unsigned char*) data + header.len; 59 _end = (unsigned char*) data + header.len;
56 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); 60 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end );
57 61
58 switch ( datalink ) 62 switch ( datalink )
59 { 63 {
60 case DLT_EN10MB: 64 case DLT_EN10MB:
61 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); 65 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" );
62 new OEthernetPacket( _end, (const struct ether_header*) data, this ); 66 new OEthernetPacket( _end, (const struct ether_header*) data, this );
63 break; 67 break;
64 68
65 case DLT_IEEE802_11: 69 case DLT_IEEE802_11:
66 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); 70 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" );
67 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); 71 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this );
68 break; 72 break;
69 73
70 case DLT_PRISM_HEADER: 74 case DLT_PRISM_HEADER:
71 qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" ); 75 qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" );
72 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); 76 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this );
73 break; 77 break;
74 78
75 default: 79 default:
76 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink (type %d)!", datalink ); 80 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink (type %d)!", datalink );
77 } 81 }
78} 82}
79 83
80 84
81OPacket::~OPacket() 85OPacket::~OPacket()
82{ 86{
83} 87}
84 88
85 89
86timevalstruct OPacket::timeval() const 90timevalstruct OPacket::timeval() const
87{ 91{
88 return _hdr.ts; 92 return _hdr.ts;
89} 93}
90 94
91 95
92int OPacket::caplen() const 96int OPacket::caplen() const
93{ 97{
94 return _hdr.caplen; 98 return _hdr.caplen;
95} 99}
96 100
97 101
98void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) 102void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )
99{ 103{
100 if (!l) return; 104 if (!l) return;
101 QObject* o = l->first(); 105 QObject* o = l->first();
102 while ( o ) 106 while ( o )
103 { 107 {
104 stats[o->name()]++; 108 stats[o->name()]++;
105 updateStats( stats, const_cast<QObjectList*>( o->children() ) ); 109 updateStats( stats, const_cast<QObjectList*>( o->children() ) );
106 o = l->next(); 110 o = l->next();
107 } 111 }
108} 112}
109 113
110 114
111void OPacket::dumpStructure( QObjectList* l ) 115void OPacket::dumpStructure( QObjectList* l )
112{ 116{
113 QString packetString( "[ |" + _dumpStructure( l ) + " ]" ); 117 QString packetString( "[ |" + _dumpStructure( l ) + " ]" );
114 qDebug( "OPacket::dumpStructure: %s", (const char*) packetString ); 118 qDebug( "OPacket::dumpStructure: %s", (const char*) packetString );
115} 119}
116 120
117 121
118QString OPacket::_dumpStructure( QObjectList* l ) 122QString OPacket::_dumpStructure( QObjectList* l )
119{ 123{
120 if (!l) return QString::null; 124 if (!l) return QString::null;
121 QObject* o = l->first(); 125 QObject* o = l->first();
122 QString str(" "); 126 QString str(" ");
123 127
124 while ( o ) 128 while ( o )
125 { 129 {
126 str.append( o->name() ); 130 str.append( o->name() );
127 str.append( " |" ); 131 str.append( " |" );
128 str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); 132 str += _dumpStructure( const_cast<QObjectList*>( o->children() ) );
129 o = l->next(); 133 o = l->next();
130 } 134 }
131 return str; 135 return str;
132} 136}
133 137
134QString OPacket::dump( int bpl ) const 138QString OPacket::dump( int bpl ) const
135{ 139{
136 static int index = 0; 140 static int index = 0;
137 index++; 141 index++;
138 int len = _hdr.caplen; 142 int len = _hdr.caplen;
139 QString str; 143 QString str;
140 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); 144 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len );
141 str.append( "0000: " ); 145 str.append( "0000: " );
142 QString tmp; 146 QString tmp;
143 QString bytes; 147 QString bytes;
144 QString chars; 148 QString chars;
145 149
146 for ( int i = 0; i < len; ++i ) 150 for ( int i = 0; i < len; ++i )
147 { 151 {
148 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); 152 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp );
149 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); 153 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] );
150 else chars.append( '.' ); 154 else chars.append( '.' );
151 155
152 if ( !((i+1) % bpl) ) 156 if ( !((i+1) % bpl) )
153 { 157 {
154 str.append( bytes ); 158 str.append( bytes );
155 str.append( ' ' ); 159 str.append( ' ' );
156 str.append( chars ); 160 str.append( chars );
157 str.append( '\n' ); 161 str.append( '\n' );
158 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); 162 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp );
159 bytes = ""; 163 bytes = "";
160 chars = ""; 164 chars = "";
161 } 165 }
162 166
163 } 167 }
164 if ( (len % bpl) ) 168 if ( (len % bpl) )
165 { 169 {
166 str.append( bytes.leftJustify( 1 + 3*bpl ) ); 170 str.append( bytes.leftJustify( 1 + 3*bpl ) );
167 str.append( chars ); 171 str.append( chars );
168 } 172 }
169 str.append( '\n' ); 173 str.append( '\n' );
170 return str; 174 return str;
171} 175}
172 176
173 177
174int OPacket::len() const 178int OPacket::len() const
175{ 179{
176 return _hdr.len; 180 return _hdr.len;
177} 181}
178 182
179 183
180/*====================================================================================== 184/*======================================================================================
181 * OEthernetPacket 185 * OEthernetPacket
182 *======================================================================================*/ 186 *======================================================================================*/
183 187
184OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) 188OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
185 :QObject( parent, "Ethernet" ), _ether( data ) 189 :QObject( parent, "Ethernet" ), _ether( data )
186{ 190{
187 191
188 qDebug( "Source = %s", (const char*) sourceAddress().toString() ); 192 qDebug( "Source = %s", (const char*) sourceAddress().toString() );
189 qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); 193 qDebug( "Destination = %s", (const char*) destinationAddress().toString() );
190 194
191 if ( sourceAddress() == OMacAddress::broadcast ) 195 if ( sourceAddress() == OMacAddress::broadcast )
192 qDebug( "Source is broadcast address" ); 196 qDebug( "Source is broadcast address" );
193 if ( destinationAddress() == OMacAddress::broadcast ) 197 if ( destinationAddress() == OMacAddress::broadcast )
194 qDebug( "Destination is broadcast address" ); 198 qDebug( "Destination is broadcast address" );
195 199
196 switch ( type() ) 200 switch ( type() )
197 { 201 {
198 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 202 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
199 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } 203 case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break;
200 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } 204 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; }
201 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); 205 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" );
202 } 206 }
203 207
204} 208}
205 209
206 210
207OEthernetPacket::~OEthernetPacket() 211OEthernetPacket::~OEthernetPacket()
208{ 212{
209} 213}
210 214
211 215
212OMacAddress OEthernetPacket::sourceAddress() const 216OMacAddress OEthernetPacket::sourceAddress() const
213{ 217{
214 return OMacAddress( _ether->ether_shost ); 218 return OMacAddress( _ether->ether_shost );
215} 219}
216 220
217 221
218OMacAddress OEthernetPacket::destinationAddress() const 222OMacAddress OEthernetPacket::destinationAddress() const
219{ 223{
220 return OMacAddress( _ether->ether_dhost ); 224 return OMacAddress( _ether->ether_dhost );
221} 225}
222 226
223int OEthernetPacket::type() const 227int OEthernetPacket::type() const
224{ 228{
225 return ntohs( _ether->ether_type ); 229 return ntohs( _ether->ether_type );
226} 230}
227 231
228 232
229/*====================================================================================== 233/*======================================================================================
230 * OIPPacket 234 * OIPPacket
231 *======================================================================================*/ 235 *======================================================================================*/
232 236
233 237
234OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) 238OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent )
235 :QObject( parent, "IP" ), _iphdr( data ) 239 :QObject( parent, "IP" ), _iphdr( data )
236{ 240{
237 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); 241 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." );
238 242
239 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); 243 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) );
240 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); 244 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) );
241 245
242 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); 246 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() );
243 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); 247 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() );
244 248
245 switch ( protocol() ) 249 switch ( protocol() )
246 { 250 {
247 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; 251 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break;
248 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; 252 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break;
249 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); 253 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() );
250 } 254 }
251 255
252} 256}
253 257
254OIPPacket::~OIPPacket() 258OIPPacket::~OIPPacket()
255{ 259{
256} 260}
257 261
258 262
259QHostAddress OIPPacket::fromIPAddress() const 263QHostAddress OIPPacket::fromIPAddress() const
260{ 264{
261 return EXTRACT_32BITS( &_iphdr->saddr ); 265 return EXTRACT_32BITS( &_iphdr->saddr );
262} 266}
263 267
264 268
265QHostAddress OIPPacket::toIPAddress() const 269QHostAddress OIPPacket::toIPAddress() const
266{ 270{
267 return EXTRACT_32BITS( &_iphdr->saddr ); 271 return EXTRACT_32BITS( &_iphdr->saddr );
268} 272}
269 273
270 274
271int OIPPacket::tos() const 275int OIPPacket::tos() const
272{ 276{
273 return _iphdr->tos; 277 return _iphdr->tos;
274} 278}
275 279
276 280
277int OIPPacket::len() const 281int OIPPacket::len() const
278{ 282{
279 return EXTRACT_16BITS( &_iphdr->tot_len ); 283 return EXTRACT_16BITS( &_iphdr->tot_len );
280} 284}
281 285
282 286
283int OIPPacket::id() const 287int OIPPacket::id() const
284{ 288{
285 return EXTRACT_16BITS( &_iphdr->id ); 289 return EXTRACT_16BITS( &_iphdr->id );
286} 290}
287 291
288 292
289int OIPPacket::offset() const 293int OIPPacket::offset() const
290{ 294{
291 return EXTRACT_16BITS( &_iphdr->frag_off ); 295 return EXTRACT_16BITS( &_iphdr->frag_off );
292} 296}
293 297
294 298
295int OIPPacket::ttl() const 299int OIPPacket::ttl() const
296{ 300{
297 return _iphdr->ttl; 301 return _iphdr->ttl;
298} 302}
299 303
300 304
301int OIPPacket::protocol() const 305int OIPPacket::protocol() const
302{ 306{
303 return _iphdr->protocol; 307 return _iphdr->protocol;
304} 308}
305 309
306 310
307int OIPPacket::checksum() const 311int OIPPacket::checksum() const
308{ 312{
309 return EXTRACT_16BITS( &_iphdr->check ); 313 return EXTRACT_16BITS( &_iphdr->check );
310} 314}
311 315
312/*====================================================================================== 316/*======================================================================================
313 * OARPPacket 317 * OARPPacket
314 *======================================================================================*/ 318 *======================================================================================*/
315 319
316 320
317OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) 321OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent )
318 :QObject( parent, "ARP" ), _arphdr( data ) 322 :QObject( parent, "ARP" ), _arphdr( data )
319{ 323{
320 qDebug( "OARPPacket::OARPPacket(): decoding ARP header..." ); 324 qDebug( "OARPPacket::OARPPacket(): decoding ARP header..." );
321 qDebug( "ARP type seems to be %02d - '%s'", EXTRACT_16BITS( &_arphdr->ar_op ), (const char*) type() ); 325 qDebug( "ARP type seems to be %02d - '%s'", EXTRACT_16BITS( &_arphdr->ar_op ), (const char*) type() );
322 qDebug( "Sender: MAC %s = IP %s", (const char*) senderMacAddress().toString(), (const char*) senderIPV4Address().toString() ); 326 qDebug( "Sender: MAC %s = IP %s", (const char*) senderMacAddress().toString(), (const char*) senderIPV4Address().toString() );
323 qDebug( "Target: MAC %s = IP %s", (const char*) targetMacAddress().toString(), (const char*) targetIPV4Address().toString() ); 327 qDebug( "Target: MAC %s = IP %s", (const char*) targetMacAddress().toString(), (const char*) targetIPV4Address().toString() );
324} 328}
325 329
326 330
327OARPPacket::~OARPPacket() 331OARPPacket::~OARPPacket()
328{ 332{
329} 333}
330 334
331 335
332QString OARPPacket::type() const 336QString OARPPacket::type() const
333{ 337{
334 switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) 338 switch ( EXTRACT_16BITS( &_arphdr->ar_op ) )
335 { 339 {
336 case 1: return "REQUEST"; 340 case 1: return "REQUEST";
337 case 2: return "REPLY"; 341 case 2: return "REPLY";
338 case 3: return "RREQUEST"; 342 case 3: return "RREQUEST";
339 case 4: return "RREPLY"; 343 case 4: return "RREPLY";
340 case 8: return "InREQUEST"; 344 case 8: return "InREQUEST";
341 case 9: return "InREPLY"; 345 case 9: return "InREPLY";
342 case 10: return "NAK"; 346 case 10: return "NAK";
343 default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>"; 347 default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>";
344 } 348 }
345} 349}
346 350
347 351
348QHostAddress OARPPacket::senderIPV4Address() const 352QHostAddress OARPPacket::senderIPV4Address() const
349{ 353{
350 return EXTRACT_32BITS( &_arphdr->ar_sip ); 354 return EXTRACT_32BITS( &_arphdr->ar_sip );
351} 355}
352 356
353 357
354QHostAddress OARPPacket::targetIPV4Address() const 358QHostAddress OARPPacket::targetIPV4Address() const
355{ 359{
356 return EXTRACT_32BITS( &_arphdr->ar_tip ); 360 return EXTRACT_32BITS( &_arphdr->ar_tip );
357} 361}
358 362
359 363
360OMacAddress OARPPacket::senderMacAddress() const 364OMacAddress OARPPacket::senderMacAddress() const
361{ 365{
362 return OMacAddress( _arphdr->ar_sha ); 366 return OMacAddress( _arphdr->ar_sha );
363} 367}
364 368
365 369
366OMacAddress OARPPacket::targetMacAddress() const 370OMacAddress OARPPacket::targetMacAddress() const
367{ 371{
368 return OMacAddress( _arphdr->ar_tha ); 372 return OMacAddress( _arphdr->ar_tha );
369} 373}
370 374
371 375
372/*====================================================================================== 376/*======================================================================================
373 * OUDPPacket 377 * OUDPPacket
374 *======================================================================================*/ 378 *======================================================================================*/
375 379
376 380
377OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) 381OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent )
378 :QObject( parent, "UDP" ), _udphdr( data ) 382 :QObject( parent, "UDP" ), _udphdr( data )
379 383
380{ 384{
381 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); 385 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." );
382 qDebug( "fromPort = %d", fromPort() ); 386 qDebug( "fromPort = %d", fromPort() );
383 qDebug( " toPort = %d", toPort() ); 387 qDebug( " toPort = %d", toPort() );
384 388
385 // TODO: Make this a case or a hash if we know more udp protocols 389 // TODO: Make this a case or a hash if we know more udp protocols
386 390
387 if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || 391 if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC ||
388 toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) 392 toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC )
389 { 393 {
390 qDebug( "seems to be part of a DHCP conversation => creating DHCP packet." ); 394 qDebug( "seems to be part of a DHCP conversation => creating DHCP packet." );
391 new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); 395 new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this );
392 } 396 }
393} 397}
394 398
395 399
396OUDPPacket::~OUDPPacket() 400OUDPPacket::~OUDPPacket()
397{ 401{
398} 402}
399 403
400 404
401int OUDPPacket::fromPort() const 405int OUDPPacket::fromPort() const
402{ 406{
403 return EXTRACT_16BITS( &_udphdr->source ); 407 return EXTRACT_16BITS( &_udphdr->source );
404} 408}
405 409
406 410
407int OUDPPacket::toPort() const 411int OUDPPacket::toPort() const
408{ 412{
409 return EXTRACT_16BITS( &_udphdr->dest ); 413 return EXTRACT_16BITS( &_udphdr->dest );
410} 414}
411 415
412 416
413int OUDPPacket::length() const 417int OUDPPacket::length() const
414{ 418{
415 return EXTRACT_16BITS( &_udphdr->len ); 419 return EXTRACT_16BITS( &_udphdr->len );
416} 420}
417 421
418 422
419int OUDPPacket::checksum() const 423int OUDPPacket::checksum() const
420{ 424{
421 return EXTRACT_16BITS( &_udphdr->check ); 425 return EXTRACT_16BITS( &_udphdr->check );
422} 426}
423 427
424 428
425/*====================================================================================== 429/*======================================================================================
426 * ODHCPPacket 430 * ODHCPPacket
427 *======================================================================================*/ 431 *======================================================================================*/
428 432
429 433
430ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) 434ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent )
431 :QObject( parent, "DHCP" ), _dhcphdr( data ) 435 :QObject( parent, "DHCP" ), _dhcphdr( data )
432 436
433{ 437{
434 qDebug( "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." ); 438 qDebug( "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." );
435 qDebug( "DHCP opcode seems to be %02d - '%s'", _dhcphdr->op, isRequest() ? "REQUEST" : "REPLY" ); 439 qDebug( "DHCP opcode seems to be %02d - '%s'", _dhcphdr->op, isRequest() ? "REQUEST" : "REPLY" );
436 qDebug( "clientAddress: %s", (const char*) clientAddress().toString() ); 440 qDebug( "clientAddress: %s", (const char*) clientAddress().toString() );
437 qDebug( " yourAddress: %s", (const char*) yourAddress().toString() ); 441 qDebug( " yourAddress: %s", (const char*) yourAddress().toString() );
438 qDebug( "serverAddress: %s", (const char*) serverAddress().toString() ); 442 qDebug( "serverAddress: %s", (const char*) serverAddress().toString() );
439 qDebug( " relayAddress: %s", (const char*) relayAddress().toString() ); 443 qDebug( " relayAddress: %s", (const char*) relayAddress().toString() );
440 qDebug( "parsing DHCP options..." ); 444 qDebug( "parsing DHCP options..." );
441 445
442 _type = 0; 446 _type = 0;
443 447
444 const unsigned char* option = &_dhcphdr->options[4]; 448 const unsigned char* option = &_dhcphdr->options[4];
445 char tag = -1; 449 char tag = -1;
446 char len = -1; 450 char len = -1;
447 451
448 while ( ( tag = *option++ ) != -1 /* end of option field */ ) 452 while ( ( tag = *option++ ) != -1 /* end of option field */ )
449 { 453 {
450 len = *option++; 454 len = *option++;
451 qDebug( "recognized DHCP option #%d, length %d", tag, len ); 455 qDebug( "recognized DHCP option #%d, length %d", tag, len );
452 456
453 if ( tag == DHO_DHCP_MESSAGE_TYPE ) 457 if ( tag == DHO_DHCP_MESSAGE_TYPE )
454 _type = *option; 458 _type = *option;
455 459
456 option += len; 460 option += len;
457 if ( option >= end ) 461 if ( option >= end )
458 { 462 {
459 qWarning( "DHCP parsing ERROR: sanity check says the packet is at its end!" ); 463 qWarning( "DHCP parsing ERROR: sanity check says the packet is at its end!" );
460 break; 464 break;
461 } 465 }
462 } 466 }
463 467
464 qDebug( "DHCP type seems to be '%s'", (const char*) type() ); 468 qDebug( "DHCP type seems to be '%s'", (const char*) type() );
465} 469}
466 470
467 471
468ODHCPPacket::~ODHCPPacket() 472ODHCPPacket::~ODHCPPacket()
469{ 473{
470} 474}
471 475
472 476
473bool ODHCPPacket::isRequest() const 477bool ODHCPPacket::isRequest() const
474{ 478{
475 return ( _dhcphdr->op == 01 ); 479 return ( _dhcphdr->op == 01 );
476} 480}
477 481
478 482
479bool ODHCPPacket::isReply() const 483bool ODHCPPacket::isReply() const
480{ 484{
481 return ( _dhcphdr->op == 02 ); 485 return ( _dhcphdr->op == 02 );
482} 486}
483 487
484 488
485QString ODHCPPacket::type() const 489QString ODHCPPacket::type() const
486{ 490{
487 switch ( _type ) 491 switch ( _type )
488 { 492 {
489 case 1: return "DISCOVER"; 493 case 1: return "DISCOVER";
490 case 2: return "OFFER"; 494 case 2: return "OFFER";
491 case 3: return "REQUEST"; 495 case 3: return "REQUEST";
492 case 4: return "DECLINE"; 496 case 4: return "DECLINE";
493 case 5: return "ACK"; 497 case 5: return "ACK";
494 case 6: return "NAK"; 498 case 6: return "NAK";
495 case 7: return "RELEASE"; 499 case 7: return "RELEASE";
496 case 8: return "INFORM"; 500 case 8: return "INFORM";
497 default: qWarning( "ODHCPPacket::type(): invalid DHCP type (%d) !", _dhcphdr->op ); return "<unknown>"; 501 default: qWarning( "ODHCPPacket::type(): invalid DHCP type (%d) !", _dhcphdr->op ); return "<unknown>";
498 } 502 }
499} 503}
500 504
501 505
502QHostAddress ODHCPPacket::clientAddress() const 506QHostAddress ODHCPPacket::clientAddress() const
503{ 507{
504 return EXTRACT_32BITS( &_dhcphdr->ciaddr ); 508 return EXTRACT_32BITS( &_dhcphdr->ciaddr );
505} 509}
506 510
507 511
508QHostAddress ODHCPPacket::yourAddress() const 512QHostAddress ODHCPPacket::yourAddress() const
509{ 513{
510 return EXTRACT_32BITS( &_dhcphdr->yiaddr ); 514 return EXTRACT_32BITS( &_dhcphdr->yiaddr );
511} 515}
512 516
513 517
514QHostAddress ODHCPPacket::serverAddress() const 518QHostAddress ODHCPPacket::serverAddress() const
515{ 519{
516 return EXTRACT_32BITS( &_dhcphdr->siaddr ); 520 return EXTRACT_32BITS( &_dhcphdr->siaddr );
517} 521}
518 522
519 523
520QHostAddress ODHCPPacket::relayAddress() const 524QHostAddress ODHCPPacket::relayAddress() const
521{ 525{
522 return EXTRACT_32BITS( &_dhcphdr->giaddr ); 526 return EXTRACT_32BITS( &_dhcphdr->giaddr );
523} 527}
524 528
525 529
526OMacAddress ODHCPPacket::clientMacAddress() const 530OMacAddress ODHCPPacket::clientMacAddress() const
527{ 531{
528 return OMacAddress( _dhcphdr->chaddr ); 532 return OMacAddress( _dhcphdr->chaddr );
529} 533}
530 534
531 535
532/*====================================================================================== 536/*======================================================================================
533 * OTCPPacket 537 * OTCPPacket
534 *======================================================================================*/ 538 *======================================================================================*/
535 539
536 540
537OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) 541OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent )
538 :QObject( parent, "TCP" ), _tcphdr( data ) 542 :QObject( parent, "TCP" ), _tcphdr( data )
539 543
540{ 544{
541 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); 545 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." );
542} 546}
543 547
544 548
545OTCPPacket::~OTCPPacket() 549OTCPPacket::~OTCPPacket()
546{ 550{
547} 551}
548 552
549 553
550int OTCPPacket::fromPort() const 554int OTCPPacket::fromPort() const
551{ 555{
552 return EXTRACT_16BITS( &_tcphdr->source ); 556 return EXTRACT_16BITS( &_tcphdr->source );
553} 557}
554 558
555 559
556int OTCPPacket::toPort() const 560int OTCPPacket::toPort() const
557{ 561{
558 return EXTRACT_16BITS( &_tcphdr->dest ); 562 return EXTRACT_16BITS( &_tcphdr->dest );
559} 563}
560 564
561 565
562int OTCPPacket::seq() const 566int OTCPPacket::seq() const
563{ 567{
564 return EXTRACT_16BITS( &_tcphdr->seq ); 568 return EXTRACT_16BITS( &_tcphdr->seq );
565} 569}
566 570
567 571
568int OTCPPacket::ack() const 572int OTCPPacket::ack() const
569{ 573{
570 return EXTRACT_16BITS( &_tcphdr->ack_seq ); 574 return EXTRACT_16BITS( &_tcphdr->ack_seq );
571} 575}
572 576
573 577
574int OTCPPacket::window() const 578int OTCPPacket::window() const
575{ 579{
576 return EXTRACT_16BITS( &_tcphdr->window ); 580 return EXTRACT_16BITS( &_tcphdr->window );
577} 581}
578 582
579 583
580int OTCPPacket::checksum() const 584int OTCPPacket::checksum() const
581{ 585{
582 return EXTRACT_16BITS( &_tcphdr->check ); 586 return EXTRACT_16BITS( &_tcphdr->check );
583} 587}
584 588
585/*====================================================================================== 589/*======================================================================================
586 * OPrismHeaderPacket 590 * OPrismHeaderPacket
587 *======================================================================================*/ 591 *======================================================================================*/
588 592
589 593
590OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) 594OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent )
591 :QObject( parent, "Prism" ), _header( data ) 595 :QObject( parent, "Prism" ), _header( data )
592 596
593{ 597{
594 qDebug( "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." ); 598 qDebug( "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." );
595 599
596 qDebug( "Signal Strength = %d", data->signal.data ); 600 qDebug( "Signal Strength = %d", data->signal.data );
597 601
598 new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); 602 new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this );
599} 603}
600 604
601OPrismHeaderPacket::~OPrismHeaderPacket() 605OPrismHeaderPacket::~OPrismHeaderPacket()
602{ 606{
603} 607}
604 608
605 609
606unsigned int OPrismHeaderPacket::signalStrength() const 610unsigned int OPrismHeaderPacket::signalStrength() const
607{ 611{
608 return _header->signal.data; 612 return _header->signal.data;
609} 613}
610 614
611/*====================================================================================== 615/*======================================================================================
612 * OWaveLanPacket 616 * OWaveLanPacket
613 *======================================================================================*/ 617 *======================================================================================*/
614 618
615 619
616OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) 620OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent )
617 :QObject( parent, "802.11" ), _wlanhdr( data ) 621 :QObject( parent, "802.11" ), _wlanhdr( data )
618 622
619{ 623{
620 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); 624 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." );
621 qDebug( "type: %0X", type() ); 625 qDebug( "type: %0X", type() );
622 qDebug( "subType: %0X", subType() ); 626 qDebug( "subType: %0X", subType() );
623 qDebug( "duration: %d", duration() ); 627 qDebug( "duration: %d", duration() );
624 qDebug( "powermanagement: %d", usesPowerManagement() ); 628 qDebug( "powermanagement: %d", usesPowerManagement() );
625 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); 629 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" );
626 qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); 630 qDebug( "MAC1: %s", (const char*) macAddress1().toString() );
627 qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); 631 qDebug( "MAC2: %s", (const char*) macAddress2().toString() );
628 qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); 632 qDebug( "MAC3: %s", (const char*) macAddress3().toString() );
629 qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); 633 qDebug( "MAC4: %s", (const char*) macAddress4().toString() );
630 634
631 switch ( type() ) 635 switch ( type() )
632 { 636 {
633 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; 637 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break;
634 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; 638 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break;
635 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; 639 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break;
636 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); 640 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() );
637 } 641 }
638} 642}
639 643
640OWaveLanPacket::~OWaveLanPacket() 644OWaveLanPacket::~OWaveLanPacket()
641{ 645{
642} 646}
643 647
644 648
645int OWaveLanPacket::duration() const 649int OWaveLanPacket::duration() const
646{ 650{
647 return _wlanhdr->duration; 651 return _wlanhdr->duration;
648} 652}
649 653
650 654
651OMacAddress OWaveLanPacket::macAddress1() const 655OMacAddress OWaveLanPacket::macAddress1() const
652{ 656{
653 return OMacAddress( _wlanhdr->mac1 ); 657 return OMacAddress( _wlanhdr->mac1 );
654} 658}
655 659
656 660
657OMacAddress OWaveLanPacket::macAddress2() const 661OMacAddress OWaveLanPacket::macAddress2() const
658{ 662{
659 return OMacAddress( _wlanhdr->mac2 ); 663 return OMacAddress( _wlanhdr->mac2 );
660} 664}
661 665
662 666
663OMacAddress OWaveLanPacket::macAddress3() const 667OMacAddress OWaveLanPacket::macAddress3() const
664{ 668{
665 return OMacAddress( _wlanhdr->mac3 ); 669 return OMacAddress( _wlanhdr->mac3 );
666} 670}
667 671
668 672
669OMacAddress OWaveLanPacket::macAddress4() const 673OMacAddress OWaveLanPacket::macAddress4() const
670{ 674{
671 return OMacAddress( _wlanhdr->mac4 ); 675 return OMacAddress( _wlanhdr->mac4 );
672} 676}
673 677
674 678
675int OWaveLanPacket::subType() const 679int OWaveLanPacket::subType() const
676{ 680{
677 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 681 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
678} 682}
679 683
680 684
681int OWaveLanPacket::type() const 685int OWaveLanPacket::type() const
682{ 686{
683 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 687 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
684} 688}
685 689
686 690
687int OWaveLanPacket::version() const 691int OWaveLanPacket::version() const
688{ 692{
689 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 693 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
690} 694}
691 695
692 696
693bool OWaveLanPacket::fromDS() const 697bool OWaveLanPacket::fromDS() const
694{ 698{
695 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 699 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
696} 700}
697 701
698 702
699bool OWaveLanPacket::toDS() const 703bool OWaveLanPacket::toDS() const
700{ 704{
701 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 705 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
702} 706}
703 707
704 708
705bool OWaveLanPacket::usesPowerManagement() const 709bool OWaveLanPacket::usesPowerManagement() const
706{ 710{
707 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 711 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
708} 712}
709 713
710 714
711bool OWaveLanPacket::usesWep() const 715bool OWaveLanPacket::usesWep() const
712{ 716{
713 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 717 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
714} 718}
715 719
716 720
717/*====================================================================================== 721/*======================================================================================
718 * OWaveLanManagementPacket 722 * OWaveLanManagementPacket
719 *======================================================================================*/ 723 *======================================================================================*/
720 724
721OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) 725OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent )
722 :QObject( parent, "802.11 Management" ), _header( data ), 726 :QObject( parent, "802.11 Management" ), _header( data ),
723 _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) 727 _body( (const struct ieee_802_11_mgmt_body*) (data+1) )
724{ 728{
725 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); 729 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." );
726 qDebug( "Detected subtype is '%s'", (const char*) managementType() ); 730 qDebug( "Detected subtype is '%s'", (const char*) managementType() );
727 731
728 // grab tagged values 732 // grab tagged values
729 const unsigned char* ptr = (const unsigned char*) (_body+1); 733 const unsigned char* ptr = (const unsigned char*) (_body+1);
730 while (ptr < end) 734 while (ptr < end)
731 { 735 {
732 switch ( *ptr ) 736 switch ( *ptr )
733 { 737 {
734 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; 738 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break;
735 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; 739 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break;
736 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; 740 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break;
737 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; 741 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break;
738 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; 742 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break;
739 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; 743 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break;
740 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; 744 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break;
741 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; 745 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break;
742 } 746 }
743 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value 747 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value
744 ptr+= 2; // skip tag ID and length 748 ptr+= 2; // skip tag ID and length
745 } 749 }
746} 750}
747 751
748 752
749OWaveLanManagementPacket::~OWaveLanManagementPacket() 753OWaveLanManagementPacket::~OWaveLanManagementPacket()
750{ 754{
751} 755}
752 756
753 757
754QString OWaveLanManagementPacket::managementType() const 758QString OWaveLanManagementPacket::managementType() const
755{ 759{
756 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) 760 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) )
757 { 761 {
758 case ST_ASSOC_REQUEST: return "AssociationRequest"; break; 762 case ST_ASSOC_REQUEST: return "AssociationRequest"; break;
759 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; 763 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break;
760 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; 764 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break;
761 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; 765 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break;
762 case ST_PROBE_REQUEST: return "ProbeRequest"; break; 766 case ST_PROBE_REQUEST: return "ProbeRequest"; break;
763 case ST_PROBE_RESPONSE: return "ProbeResponse"; break; 767 case ST_PROBE_RESPONSE: return "ProbeResponse"; break;
764 case ST_BEACON: return "Beacon"; break; 768 case ST_BEACON: return "Beacon"; break;
765 case ST_ATIM: return "Atim"; break; 769 case ST_ATIM: return "Atim"; break;
766 case ST_DISASSOC: return "Disassociation"; break; 770 case ST_DISASSOC: return "Disassociation"; break;
767 case ST_AUTH: return "Authentication"; break; 771 case ST_AUTH: return "Authentication"; break;
768 case ST_DEAUTH: return "Deathentication"; break; 772 case ST_DEAUTH: return "Deathentication"; break;
769 default: 773 default:
770 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); 774 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) );
771 return "Unknown"; 775 return "Unknown";
772 } 776 }
773} 777}
774 778
775 779
776int OWaveLanManagementPacket::beaconInterval() const 780int OWaveLanManagementPacket::beaconInterval() const
777{ 781{
778 return EXTRACT_LE_16BITS( &_body->beacon_interval ); 782 return EXTRACT_LE_16BITS( &_body->beacon_interval );
779} 783}
780 784
781 785
782int OWaveLanManagementPacket::capabilities() const 786int OWaveLanManagementPacket::capabilities() const
783{ 787{
784 return EXTRACT_LE_16BITS( &_body->capability_info ); 788 return EXTRACT_LE_16BITS( &_body->capability_info );
785} 789}
786 790
787 791
788bool OWaveLanManagementPacket::canESS() const 792bool OWaveLanManagementPacket::canESS() const
789{ 793{
790 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 794 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) );
791} 795}
792 796
793 797
794bool OWaveLanManagementPacket::canIBSS() const 798bool OWaveLanManagementPacket::canIBSS() const
795{ 799{
796 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 800 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) );
797} 801}
798 802
799 803
800bool OWaveLanManagementPacket::canCFP() const 804bool OWaveLanManagementPacket::canCFP() const
801{ 805{
802 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); 806 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) );
803} 807}
804 808
805 809
806bool OWaveLanManagementPacket::canCFP_REQ() const 810bool OWaveLanManagementPacket::canCFP_REQ() const
807{ 811{
808 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); 812 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) );
809} 813}
810 814
811 815
812bool OWaveLanManagementPacket::canPrivacy() const 816bool OWaveLanManagementPacket::canPrivacy() const
813{ 817{
814 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); 818 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) );
815} 819}
816 820
817 821
818/*====================================================================================== 822/*======================================================================================
819 * OWaveLanManagementSSID 823 * OWaveLanManagementSSID
820 *======================================================================================*/ 824 *======================================================================================*/
821 825
822OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) 826OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent )
823 :QObject( parent, "802.11 SSID" ), _data( data ) 827 :QObject( parent, "802.11 SSID" ), _data( data )
824{ 828{
825 qDebug( "OWaveLanManagementSSID()" ); 829 qDebug( "OWaveLanManagementSSID()" );
826} 830}
827 831
828 832
829OWaveLanManagementSSID::~OWaveLanManagementSSID() 833OWaveLanManagementSSID::~OWaveLanManagementSSID()
830{ 834{
831} 835}
832 836
833 837
834QString OWaveLanManagementSSID::ID() const 838QString OWaveLanManagementSSID::ID() const
835{ 839{
836 int length = _data->length; 840 int length = _data->length;
837 if ( length > 32 ) length = 32; 841 if ( length > 32 ) length = 32;
838 char essid[length+1]; 842 char essid[length+1];
839 memcpy( &essid, &_data->ssid, length ); 843 memcpy( &essid, &_data->ssid, length );
840 essid[length] = 0x0; 844 essid[length] = 0x0;
841 return essid; 845 return essid;
842} 846}
843 847
844 848
845/*====================================================================================== 849/*======================================================================================
846 * OWaveLanManagementRates 850 * OWaveLanManagementRates
847 *======================================================================================*/ 851 *======================================================================================*/
848 852
849OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) 853OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent )
850 :QObject( parent, "802.11 Rates" ), _data( data ) 854 :QObject( parent, "802.11 Rates" ), _data( data )
851{ 855{
852 qDebug( "OWaveLanManagementRates()" ); 856 qDebug( "OWaveLanManagementRates()" );
853} 857}
854 858
855 859
856OWaveLanManagementRates::~OWaveLanManagementRates() 860OWaveLanManagementRates::~OWaveLanManagementRates()
857{ 861{
858} 862}
859 863
860/*====================================================================================== 864/*======================================================================================
861 * OWaveLanManagementCF 865 * OWaveLanManagementCF
862 *======================================================================================*/ 866 *======================================================================================*/
863 867
864OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) 868OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent )
865 :QObject( parent, "802.11 CF" ), _data( data ) 869 :QObject( parent, "802.11 CF" ), _data( data )
866{ 870{
867 qDebug( "OWaveLanManagementCF()" ); 871 qDebug( "OWaveLanManagementCF()" );
868} 872}
869 873
870 874
871OWaveLanManagementCF::~OWaveLanManagementCF() 875OWaveLanManagementCF::~OWaveLanManagementCF()
872{ 876{
873} 877}
874 878
875/*====================================================================================== 879/*======================================================================================
876 * OWaveLanManagementFH 880 * OWaveLanManagementFH
877 *======================================================================================*/ 881 *======================================================================================*/
878 882
879OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) 883OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent )
880 :QObject( parent, "802.11 FH" ), _data( data ) 884 :QObject( parent, "802.11 FH" ), _data( data )
881{ 885{
882 qDebug( "OWaveLanManagementFH()" ); 886 qDebug( "OWaveLanManagementFH()" );
883} 887}
884 888
885 889
886OWaveLanManagementFH::~OWaveLanManagementFH() 890OWaveLanManagementFH::~OWaveLanManagementFH()
887{ 891{
888} 892}
889 893
890/*====================================================================================== 894/*======================================================================================
891 * OWaveLanManagementDS 895 * OWaveLanManagementDS
892 *======================================================================================*/ 896 *======================================================================================*/
893 897
894OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) 898OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent )
895 :QObject( parent, "802.11 DS" ), _data( data ) 899 :QObject( parent, "802.11 DS" ), _data( data )
896{ 900{
897 qDebug( "OWaveLanManagementDS()" ); 901 qDebug( "OWaveLanManagementDS()" );
898} 902}
899 903
900 904
901OWaveLanManagementDS::~OWaveLanManagementDS() 905OWaveLanManagementDS::~OWaveLanManagementDS()
902{ 906{
903} 907}
904 908
905 909
906int OWaveLanManagementDS::channel() const 910int OWaveLanManagementDS::channel() const
907{ 911{
908 return _data->channel; 912 return _data->channel;
909} 913}
910 914
911/*====================================================================================== 915/*======================================================================================
912 * OWaveLanManagementTim 916 * OWaveLanManagementTim
913 *======================================================================================*/ 917 *======================================================================================*/
914 918
915OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) 919OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent )
916 :QObject( parent, "802.11 Tim" ), _data( data ) 920 :QObject( parent, "802.11 Tim" ), _data( data )
917{ 921{
918 qDebug( "OWaveLanManagementTim()" ); 922 qDebug( "OWaveLanManagementTim()" );
919} 923}
920 924
921 925
922OWaveLanManagementTim::~OWaveLanManagementTim() 926OWaveLanManagementTim::~OWaveLanManagementTim()
923{ 927{
924} 928}
925 929
926/*====================================================================================== 930/*======================================================================================
927 * OWaveLanManagementIBSS 931 * OWaveLanManagementIBSS
928 *======================================================================================*/ 932 *======================================================================================*/
929 933
930OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) 934OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent )
931 :QObject( parent, "802.11 IBSS" ), _data( data ) 935 :QObject( parent, "802.11 IBSS" ), _data( data )
932{ 936{
933 qDebug( "OWaveLanManagementIBSS()" ); 937 qDebug( "OWaveLanManagementIBSS()" );
934} 938}
935 939
936 940
937OWaveLanManagementIBSS::~OWaveLanManagementIBSS() 941OWaveLanManagementIBSS::~OWaveLanManagementIBSS()
938{ 942{
939} 943}
940 944
941/*====================================================================================== 945/*======================================================================================
942 * OWaveLanManagementChallenge 946 * OWaveLanManagementChallenge
943 *======================================================================================*/ 947 *======================================================================================*/
944 948
945OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) 949OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent )
946 :QObject( parent, "802.11 Challenge" ), _data( data ) 950 :QObject( parent, "802.11 Challenge" ), _data( data )
947{ 951{
948 qDebug( "OWaveLanManagementChallenge()" ); 952 qDebug( "OWaveLanManagementChallenge()" );
949} 953}
950 954
951 955
952OWaveLanManagementChallenge::~OWaveLanManagementChallenge() 956OWaveLanManagementChallenge::~OWaveLanManagementChallenge()
953{ 957{
954} 958}
955 959
956/*====================================================================================== 960/*======================================================================================
957 * OWaveLanDataPacket 961 * OWaveLanDataPacket
958 *======================================================================================*/ 962 *======================================================================================*/
959 963
960OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) 964OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent )
961 :QObject( parent, "802.11 Data" ), _header( data ) 965 :QObject( parent, "802.11 Data" ), _header( data )
962{ 966{
963 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); 967 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." );
964 968
965 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); 969 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header );
966 970
967 #warning The next line works for most cases, but can not be correct generally! 971 #warning The next line works for most cases, but can not be correct generally!
968 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address 972 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address
969 973
970 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); 974 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this );
971} 975}
972 976
973 977
974OWaveLanDataPacket::~OWaveLanDataPacket() 978OWaveLanDataPacket::~OWaveLanDataPacket()
975{ 979{
976} 980}
977 981
978 982
979/*====================================================================================== 983/*======================================================================================
980 * OLLCPacket 984 * OLLCPacket
981 *======================================================================================*/ 985 *======================================================================================*/
982 986
983OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) 987OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent )
984 :QObject( parent, "802.11 LLC" ), _header( data ) 988 :QObject( parent, "802.11 LLC" ), _header( data )
985{ 989{
986 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); 990 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." );
987 991
988 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) 992 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) )
989 { 993 {
990 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 994 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) );
991 995
992 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h 996 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h
993 { 997 {
994 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 998 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
995 case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; 999 case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break;
996 default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 1000 default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) );
997 } 1001 }
998 1002
999 } 1003 }
1000} 1004}
1001 1005
1002 1006
1003OLLCPacket::~OLLCPacket() 1007OLLCPacket::~OLLCPacket()
1004{ 1008{
1005} 1009}
1006 1010
1007 1011
1008/*====================================================================================== 1012/*======================================================================================
1009 * OWaveLanControlPacket 1013 * OWaveLanControlPacket
1010 *======================================================================================*/ 1014 *======================================================================================*/
1011 1015
1012OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) 1016OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent )
1013 :QObject( parent, "802.11 Control" ), _header( data ) 1017 :QObject( parent, "802.11 Control" ), _header( data )
1014{ 1018{
1015 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); 1019 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." );
1016 //TODO: Implement this 1020 //TODO: Implement this
1017} 1021}
1018 1022
1019 1023
1020OWaveLanControlPacket::~OWaveLanControlPacket() 1024OWaveLanControlPacket::~OWaveLanControlPacket()
1021{ 1025{
1022} 1026}
1023 1027
1024 1028
1025/*====================================================================================== 1029/*======================================================================================
1026 * OPacketCapturer 1030 * OPacketCapturer
1027 *======================================================================================*/ 1031 *======================================================================================*/
1028 1032
1029OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) 1033OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
1030 :QObject( parent, name ), _name( QString::null ), _open( false ), 1034 :QObject( parent, name ), _name( QString::null ), _open( false ),
1031 _pch( 0 ), _pcd( 0 ), _sn( 0 ) 1035 _pch( 0 ), _pcd( 0 ), _sn( 0 )
1032{ 1036{
1033} 1037}
1034 1038
1035 1039
1036OPacketCapturer::~OPacketCapturer() 1040OPacketCapturer::~OPacketCapturer()
1037{ 1041{
1038 if ( _open ) 1042 if ( _open )
1039 { 1043 {
1040 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); 1044 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." );
1041 close(); 1045 close();
1042 } 1046 }
1043} 1047}
1044 1048
1045 1049
1046void OPacketCapturer::setBlocking( bool b ) 1050void OPacketCapturer::setBlocking( bool b )
1047{ 1051{
1048 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 1052 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
1049 { 1053 {
1050 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); 1054 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." );
1051 } 1055 }
1052 else 1056 else
1053 { 1057 {
1054 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); 1058 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf );
1055 } 1059 }
1056} 1060}
1057 1061
1058 1062
1059bool OPacketCapturer::blocking() const 1063bool OPacketCapturer::blocking() const
1060{ 1064{
1061 int b = pcap_getnonblock( _pch, _errbuf ); 1065 int b = pcap_getnonblock( _pch, _errbuf );
1062 if ( b == -1 ) 1066 if ( b == -1 )
1063 { 1067 {
1064 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); 1068 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf );
1065 return -1; 1069 return -1;
1066 } 1070 }
1067 return !b; 1071 return !b;
1068} 1072}
1069 1073
1070 1074
1071void OPacketCapturer::closeDumpFile() 1075void OPacketCapturer::closeDumpFile()
1072{ 1076{
1073 if ( _pcd ) 1077 if ( _pcd )
1074 { 1078 {
1075 pcap_dump_close( _pcd ); 1079 pcap_dump_close( _pcd );
1076 _pcd = 0; 1080 _pcd = 0;
1077 } 1081 }
1078 pcap_close( _pch ); 1082 pcap_close( _pch );
1079} 1083}
1080 1084
1081 1085
1082void OPacketCapturer::close() 1086void OPacketCapturer::close()
1083{ 1087{
1084 if ( _open ) 1088 if ( _open )
1085 { 1089 {
1086 if ( _sn ) 1090 if ( _sn )
1087 { 1091 {
1088 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1092 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1089 delete _sn; 1093 delete _sn;
1090 } 1094 }
1091 closeDumpFile(); 1095 closeDumpFile();
1092 _open = false; 1096 _open = false;
1093 } 1097 }
1094 1098
1095 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); 1099 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." );
1096 qDebug( "--------------------------------------------------" ); 1100 qDebug( "--------------------------------------------------" );
1097 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) 1101 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it )
1098 qDebug( "%s : %d", (const char*) it.key(), it.data() ); 1102 qDebug( "%s : %d", (const char*) it.key(), it.data() );
1099 qDebug( "--------------------------------------------------" ); 1103 qDebug( "--------------------------------------------------" );
1100 1104
1101} 1105}
1102 1106
1103 1107
1104int OPacketCapturer::dataLink() const 1108int OPacketCapturer::dataLink() const
1105{ 1109{
1106 return pcap_datalink( _pch ); 1110 return pcap_datalink( _pch );
1107} 1111}
1108 1112
1109 1113
1110void OPacketCapturer::dump( OPacket* p ) 1114void OPacketCapturer::dump( OPacket* p )
1111{ 1115{
1112 if ( !_pcd ) 1116 if ( !_pcd )
1113 { 1117 {
1114 qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" ); 1118 qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" );
1115 return; 1119 return;
1116 } 1120 }
1117 pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); 1121 pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data );
1118} 1122}
1119 1123
1120 1124
1121int OPacketCapturer::fileno() const 1125int OPacketCapturer::fileno() const
1122{ 1126{
1123 if ( _open ) 1127 if ( _open )
1124 { 1128 {
1125 return pcap_fileno( _pch ); 1129 return pcap_fileno( _pch );
1126 } 1130 }
1127 else 1131 else
1128 { 1132 {
1129 return -1; 1133 return -1;
1130 } 1134 }
1131} 1135}
1132 1136
1137
1138OPacket* OPacketCapturer::next( int time )
1139{
1140 fd_set fds;
1141 struct timeval tv;
1142 FD_ZERO( &fds );
1143 FD_SET( pcap_fileno( _pch ), &fds );
1144 tv.tv_sec = time / 1000;
1145 tv.tv_usec = time % 1000;
1146 int retval = select( 1, &fds, NULL, NULL, &tv);
1147 if ( retval > 0 ) // clear to read!
1148 return next();
1149 else
1150 return 0;
1151}
1152
1153
1133OPacket* OPacketCapturer::next() 1154OPacket* OPacketCapturer::next()
1134{ 1155{
1135 packetheaderstruct header; 1156 packetheaderstruct header;
1136 qDebug( "==> OPacketCapturer::next()" ); 1157 qDebug( "==> OPacketCapturer::next()" );
1137 const unsigned char* pdata = pcap_next( _pch, &header ); 1158 const unsigned char* pdata = pcap_next( _pch, &header );
1138 qDebug( "<== OPacketCapturer::next()" ); 1159 qDebug( "<== OPacketCapturer::next()" );
1139 1160
1140 if ( pdata && header.len ) 1161 if ( pdata && header.len )
1141 { 1162 {
1142 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 1163 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
1143 // packets shouldn't be inserted in the QObject child-parent hierarchy, 1164 // packets shouldn't be inserted in the QObject child-parent hierarchy,
1144 // because due to memory constraints they will be deleted as soon 1165 // because due to memory constraints they will be deleted as soon
1145 // as possible - that is right after they have been processed 1166 // as possible - that is right after they have been processed
1146 // by emit() [ see below ] 1167 // by emit() [ see below ]
1147 //TODO: make gathering statistics optional, because it takes time 1168 //TODO: make gathering statistics optional, because it takes time
1148 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); 1169 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
1149 #ifndef NODEBUG 1170 #ifndef NODEBUG
1150 p->dumpStructure( const_cast<QObjectList*>( p->children() ) ); 1171 p->dumpStructure( const_cast<QObjectList*>( p->children() ) );
1151 #endif 1172 #endif
1152 return p; 1173 return p;
1153 } 1174 }
1154 else 1175 else
1155 { 1176 {
1156 qWarning( "OPacketCapturer::next() - no packet received!" ); 1177 qWarning( "OPacketCapturer::next() - no packet received!" );
1157 return 0; 1178 return 0;
1158 } 1179 }
1159} 1180}
1160 1181
1161 1182
1162bool OPacketCapturer::open( const QString& name ) 1183bool OPacketCapturer::open( const QString& name )
1163{ 1184{
1164 if ( _open ) 1185 if ( _open )
1165 { 1186 {
1166 if ( name == _name ) // ignore opening an already openend device 1187 if ( name == _name ) // ignore opening an already openend device
1167 { 1188 {
1168 return true; 1189 return true;
1169 } 1190 }
1170 else // close the last opened device 1191 else // close the last opened device
1171 { 1192 {
1172 close(); 1193 close();
1173 } 1194 }
1174 } 1195 }
1175 1196
1176 _name = name; 1197 _name = name;
1177 1198
1178 // open libpcap 1199 // open libpcap
1179 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 1200 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
1180 1201
1181 if ( !handle ) 1202 if ( !handle )
1182 { 1203 {
1183 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 1204 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
1184 return false; 1205 return false;
1185 } 1206 }
1186 1207
1187 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); 1208 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name );
1188 _pch = handle; 1209 _pch = handle;
1189 _open = true; 1210 _open = true;
1190 _stats.clear(); 1211 _stats.clear();
1191 1212
1192 // in case we have an application object, create a socket notifier 1213 // in case we have an application object, create a socket notifier
1193 if ( qApp ) //TODO: I don't like this here... 1214 if ( qApp ) //TODO: I don't like this here...
1194 { 1215 {
1195 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 1216 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
1196 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1217 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1197 } 1218 }
1198 1219
1199 return true; 1220 return true;
1200} 1221}
1201 1222
1202 1223
1203bool OPacketCapturer::openDumpFile( const QString& filename ) 1224bool OPacketCapturer::openDumpFile( const QString& filename )
1204{ 1225{
1205 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); 1226 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) );
1206 if ( !dump ) 1227 if ( !dump )
1207 { 1228 {
1208 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); 1229 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf );
1209 return false; 1230 return false;
1210 } 1231 }
1211 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); 1232 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename );
1212 _pcd = dump; 1233 _pcd = dump;
1213 1234
1214 return true; 1235 return true;
1215} 1236}
1216 1237
1217 1238
1218bool OPacketCapturer::open( const QFile& file ) 1239bool OPacketCapturer::open( const QFile& file )
1219{ 1240{
1220 QString name = file.name(); 1241 QString name = file.name();
1221 1242
1222 if ( _open ) 1243 if ( _open )
1223 { 1244 {
1224 close(); 1245 close();
1225 if ( name == _name ) // ignore opening an already openend device 1246 if ( name == _name ) // ignore opening an already openend device
1226 { 1247 {
1227 return true; 1248 return true;
1228 } 1249 }
1229 else // close the last opened device 1250 else // close the last opened device
1230 { 1251 {
1231 close(); 1252 close();
1232 } 1253 }
1233 } 1254 }
1234 1255
1235 _name = name; 1256 _name = name;
1236 1257
1237 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); 1258 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] );
1238 1259
1239 if ( handle ) 1260 if ( handle )
1240 { 1261 {
1241 qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); 1262 qDebug( "OPacketCapturer::open(): libpcap opened successfully." );
1242 _pch = handle; 1263 _pch = handle;
1243 _open = true; 1264 _open = true;
1244 1265
1245 // in case we have an application object, create a socket notifier 1266 // in case we have an application object, create a socket notifier
1246 if ( qApp ) 1267 if ( qApp )
1247 { 1268 {
1248 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 1269 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
1249 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1270 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1250 } 1271 }
1251 1272
1252 return true; 1273 return true;
1253 } 1274 }
1254 else 1275 else
1255 { 1276 {
1256 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 1277 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
1257 return false; 1278 return false;
1258 } 1279 }
1259 1280
1260} 1281}
1261 1282
1262 1283
1263bool OPacketCapturer::isOpen() const 1284bool OPacketCapturer::isOpen() const
1264{ 1285{
1265 return _open; 1286 return _open;
1266} 1287}
1267 1288
1268 1289
1269void OPacketCapturer::readyToReceive() 1290void OPacketCapturer::readyToReceive()
1270{ 1291{
1271 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); 1292 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" );
1272 OPacket* p = next(); 1293 OPacket* p = next();
1273 emit receivedPacket( p ); 1294 emit receivedPacket( p );
1274 // emit is synchronous - packet has been dealt with, now it's safe to delete 1295 // emit is synchronous - packet has been dealt with, now it's safe to delete
1275 delete p; 1296 delete p;
1276} 1297}
1277 1298
1278 1299
1279const QMap<QString,int>& OPacketCapturer::statistics() const 1300const QMap<QString,int>& OPacketCapturer::statistics() const
1280{ 1301{
1281 return _stats; 1302 return _stats;
1282} 1303}
1283 1304
1284 1305
1285int OPacketCapturer::snapShot() const 1306int OPacketCapturer::snapShot() const
1286{ 1307{
1287 return pcap_snapshot( _pch ); 1308 return pcap_snapshot( _pch );
1288} 1309}
1289 1310
1290 1311
1291bool OPacketCapturer::swapped() const 1312bool OPacketCapturer::swapped() const
1292{ 1313{
1293 return pcap_is_swapped( _pch ); 1314 return pcap_is_swapped( _pch );
1294} 1315}
1295 1316
1296 1317
1297QString OPacketCapturer::version() const 1318QString OPacketCapturer::version() const
1298{ 1319{
1299 return QString().sprintf( "%s.%s", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); 1320 return QString().sprintf( "%s.%s", pcap_major_version( _pch ), pcap_minor_version( _pch ) );
1300} 1321}
1301 1322
1302 1323
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h
index 51f067a..54b256b 100644
--- a/libopie2/opienet/opcap.h
+++ b/libopie2/opienet/opcap.h
@@ -1,662 +1,667 @@
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 58
59/* Custom Network Includes */ 59/* Custom Network Includes */
60#include "802_11_user.h" 60#include "802_11_user.h"
61#include "dhcp.h" 61#include "dhcp.h"
62 62
63/* TYPEDEFS */ 63/* TYPEDEFS */
64typedef struct timeval timevalstruct; 64typedef struct timeval timevalstruct;
65typedef struct pcap_pkthdr packetheaderstruct; 65typedef struct pcap_pkthdr packetheaderstruct;
66 66
67/* FORWARDS */ 67/* FORWARDS */
68class OPacketCapturer; 68class OPacketCapturer;
69class QSocketNotifier; 69class QSocketNotifier;
70 70
71/*====================================================================================== 71/*======================================================================================
72 * OPacket - A frame on the wire 72 * OPacket - A frame on the wire
73 *======================================================================================*/ 73 *======================================================================================*/
74 74
75/** @brief A class representing a data frame on the wire. 75/** @brief A class representing a data frame on the wire.
76 * 76 *
77 * The whole family of the packet classes are used when capturing frames from a network. 77 * The whole family of the packet classes are used when capturing frames from a network.
78 * Most standard network protocols in use share a common architecture, which mostly is 78 * Most standard network protocols in use share a common architecture, which mostly is
79 * a packet header and then the packet payload. In layered architectures, each lower layer 79 * a packet header and then the packet payload. In layered architectures, each lower layer
80 * encapsulates data from its upper layer - that is it 80 * encapsulates data from its upper layer - that is it
81 * treats the data from its upper layer as payload and prepends an own header to the packet, 81 * treats the data from its upper layer as payload and prepends an own header to the packet,
82 * which - again - is treated as the payload for the layer below. The figure below is an 82 * which - again - is treated as the payload for the layer below. The figure below is an
83 * example for how such a data frame is composed out of packets, e.g. when sending a mail. 83 * example for how such a data frame is composed out of packets, e.g. when sending a mail.
84 * 84 *
85 * <pre> 85 * <pre>
86 * | User Data | == Mail Data 86 * | User Data | == Mail Data
87 * | SMTP Header | User Data | == SMTP 87 * | SMTP Header | User Data | == SMTP
88 * | TCP Header | SMTP Header | User Data | == TCP 88 * | TCP Header | SMTP Header | User Data | == TCP
89 * | IP Header | TCP Header | SMTP Header | User Data | == IP 89 * | IP Header | TCP Header | SMTP Header | User Data | == IP
90 * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC 90 * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC
91 * 91 *
92 * </pre> 92 * </pre>
93 * 93 *
94 * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer 94 * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer
95 * also contains a few more levels of encapsulation. 95 * also contains a few more levels of encapsulation.
96 * Since the type of the payload is more or less independent from the encapsulating protocol, 96 * Since the type of the payload is more or less independent from the encapsulating protocol,
97 * the header must be inspected before attempting to decode the payload. Hence, the 97 * the header must be inspected before attempting to decode the payload. Hence, the
98 * encapsulation level varies and can't be deduced without actually looking into the packets. 98 * encapsulation level varies and can't be deduced without actually looking into the packets.
99 * 99 *
100 * For actually working with captured frames, it's useful to identify the packets via names and 100 * For actually working with captured frames, it's useful to identify the packets via names and
101 * insert them into a parent/child - relationship based on the encapsulation. This is why 101 * insert them into a parent/child - relationship based on the encapsulation. This is why
102 * all packet classes derive from QObject. The amount of overhead caused by the QObject is 102 * all packet classes derive from QObject. The amount of overhead caused by the QObject is
103 * not a problem in this case, because we're talking about a theoratical maximum of about 103 * not a problem in this case, because we're talking about a theoratical maximum of about
104 * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the 104 * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the
105 * QObject also cares about destroying the sub-, (child-) packets. 105 * QObject also cares about destroying the sub-, (child-) packets.
106 * 106 *
107 * This enables us to perform a simple look for packets of a certain type: 107 * This enables us to perform a simple look for packets of a certain type:
108 * @code 108 * @code
109 * OPacketCapturer* pcap = new OPacketCapturer(); 109 * OPacketCapturer* pcap = new OPacketCapturer();
110 * pcap->open( "eth0" ); 110 * pcap->open( "eth0" );
111 * OPacket* p = pcap->next(); 111 * OPacket* p = pcap->next();
112 * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists 112 * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists
113 * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; 113 * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl;
114 * 114 *
115 */ 115 */
116 116
117class OPacket : public QObject 117class OPacket : public QObject
118{ 118{
119 Q_OBJECT 119 Q_OBJECT
120 120
121 friend class OPacketCapturer; 121 friend class OPacketCapturer;
122 122
123 public: 123 public:
124 OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); 124 OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent );
125 virtual ~OPacket(); 125 virtual ~OPacket();
126 126
127 timevalstruct timeval() const; 127 timevalstruct timeval() const;
128 128
129 int caplen() const; 129 int caplen() const;
130 int len() const; 130 int len() const;
131 QString dump( int = 32 ) const; 131 QString dump( int = 32 ) const;
132 132
133 void updateStats( QMap<QString,int>&, QObjectList* ); 133 void updateStats( QMap<QString,int>&, QObjectList* );
134 134
135 private: 135 private:
136 136
137 void dumpStructure( QObjectList* ); 137 void dumpStructure( QObjectList* );
138 QString _dumpStructure( QObjectList* ); 138 QString _dumpStructure( QObjectList* );
139 139
140 private: 140 private:
141 const packetheaderstruct _hdr; // pcap packet header 141 const packetheaderstruct _hdr; // pcap packet header
142 const unsigned char* _data; // pcap packet data 142 const unsigned char* _data; // pcap packet data
143 const unsigned char* _end; // end of pcap packet data 143 const unsigned char* _end; // end of pcap packet data
144}; 144};
145 145
146/*====================================================================================== 146/*======================================================================================
147 * OEthernetPacket - DLT_EN10MB frame 147 * OEthernetPacket - DLT_EN10MB frame
148 *======================================================================================*/ 148 *======================================================================================*/
149 149
150class OEthernetPacket : public QObject 150class OEthernetPacket : public QObject
151{ 151{
152 Q_OBJECT 152 Q_OBJECT
153 153
154 public: 154 public:
155 OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); 155 OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 );
156 virtual ~OEthernetPacket(); 156 virtual ~OEthernetPacket();
157 157
158 OMacAddress sourceAddress() const; 158 OMacAddress sourceAddress() const;
159 OMacAddress destinationAddress() const; 159 OMacAddress destinationAddress() const;
160 int type() const; 160 int type() const;
161 161
162 private: 162 private:
163 const struct ether_header* _ether; 163 const struct ether_header* _ether;
164}; 164};
165 165
166/*====================================================================================== 166/*======================================================================================
167 * OPrismHeaderPacket - DLT_PRISM_HEADER frame 167 * OPrismHeaderPacket - DLT_PRISM_HEADER frame
168 *======================================================================================*/ 168 *======================================================================================*/
169 169
170class OPrismHeaderPacket : public QObject 170class OPrismHeaderPacket : public QObject
171{ 171{
172 Q_OBJECT 172 Q_OBJECT
173 173
174 public: 174 public:
175 OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); 175 OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 );
176 virtual ~OPrismHeaderPacket(); 176 virtual ~OPrismHeaderPacket();
177 177
178 unsigned int signalStrength() const; 178 unsigned int signalStrength() const;
179 179
180 private: 180 private:
181 const struct prism_hdr* _header; 181 const struct prism_hdr* _header;
182}; 182};
183 183
184/*====================================================================================== 184/*======================================================================================
185 * OWaveLanPacket - DLT_IEEE802_11 frame 185 * OWaveLanPacket - DLT_IEEE802_11 frame
186 *======================================================================================*/ 186 *======================================================================================*/
187 187
188class OWaveLanPacket : public QObject 188class OWaveLanPacket : public QObject
189{ 189{
190 Q_OBJECT 190 Q_OBJECT
191 191
192 public: 192 public:
193 OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); 193 OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 );
194 virtual ~OWaveLanPacket(); 194 virtual ~OWaveLanPacket();
195 195
196 int duration() const; 196 int duration() const;
197 bool fromDS() const; 197 bool fromDS() const;
198 bool toDS() const; 198 bool toDS() const;
199 virtual OMacAddress macAddress1() const; 199 virtual OMacAddress macAddress1() const;
200 virtual OMacAddress macAddress2() const; 200 virtual OMacAddress macAddress2() const;
201 virtual OMacAddress macAddress3() const; 201 virtual OMacAddress macAddress3() const;
202 virtual OMacAddress macAddress4() const; 202 virtual OMacAddress macAddress4() const;
203 bool usesPowerManagement() const; 203 bool usesPowerManagement() const;
204 int type() const; 204 int type() const;
205 int subType() const; 205 int subType() const;
206 int version() const; 206 int version() const;
207 bool usesWep() const; 207 bool usesWep() const;
208 208
209 private: 209 private:
210 const struct ieee_802_11_header* _wlanhdr; 210 const struct ieee_802_11_header* _wlanhdr;
211}; 211};
212 212
213 213
214/*====================================================================================== 214/*======================================================================================
215 * OWaveLanManagementPacket - type: management (T_MGMT) 215 * OWaveLanManagementPacket - type: management (T_MGMT)
216 *======================================================================================*/ 216 *======================================================================================*/
217 217
218class OWaveLanManagementPacket : public QObject 218class OWaveLanManagementPacket : public QObject
219{ 219{
220 Q_OBJECT 220 Q_OBJECT
221 221
222 public: 222 public:
223 OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); 223 OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 );
224 virtual ~OWaveLanManagementPacket(); 224 virtual ~OWaveLanManagementPacket();
225 225
226 QString managementType() const; 226 QString managementType() const;
227 227
228 int beaconInterval() const; 228 int beaconInterval() const;
229 int capabilities() const; // generic 229 int capabilities() const; // generic
230 230
231 bool canESS() const; 231 bool canESS() const;
232 bool canIBSS() const; 232 bool canIBSS() const;
233 bool canCFP() const; 233 bool canCFP() const;
234 bool canCFP_REQ() const; 234 bool canCFP_REQ() const;
235 bool canPrivacy() const; 235 bool canPrivacy() const;
236 236
237 private: 237 private:
238 const struct ieee_802_11_mgmt_header* _header; 238 const struct ieee_802_11_mgmt_header* _header;
239 const struct ieee_802_11_mgmt_body* _body; 239 const struct ieee_802_11_mgmt_body* _body;
240}; 240};
241 241
242 242
243/*====================================================================================== 243/*======================================================================================
244 * OWaveLanManagementSSID 244 * OWaveLanManagementSSID
245 *======================================================================================*/ 245 *======================================================================================*/
246 246
247class OWaveLanManagementSSID : public QObject 247class OWaveLanManagementSSID : public QObject
248{ 248{
249 Q_OBJECT 249 Q_OBJECT
250 250
251 public: 251 public:
252 OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); 252 OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 );
253 virtual ~OWaveLanManagementSSID(); 253 virtual ~OWaveLanManagementSSID();
254 254
255 QString ID() const; 255 QString ID() const;
256 256
257 private: 257 private:
258 const struct ssid_t* _data; 258 const struct ssid_t* _data;
259}; 259};
260 260
261/*====================================================================================== 261/*======================================================================================
262 * OWaveLanManagementRates 262 * OWaveLanManagementRates
263 *======================================================================================*/ 263 *======================================================================================*/
264 264
265class OWaveLanManagementRates : public QObject 265class OWaveLanManagementRates : public QObject
266{ 266{
267 Q_OBJECT 267 Q_OBJECT
268 268
269 public: 269 public:
270 OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); 270 OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 );
271 virtual ~OWaveLanManagementRates(); 271 virtual ~OWaveLanManagementRates();
272 272
273 private: 273 private:
274 const struct rates_t* _data; 274 const struct rates_t* _data;
275}; 275};
276 276
277/*====================================================================================== 277/*======================================================================================
278 * OWaveLanManagementCF 278 * OWaveLanManagementCF
279 *======================================================================================*/ 279 *======================================================================================*/
280 280
281class OWaveLanManagementCF : public QObject 281class OWaveLanManagementCF : public QObject
282{ 282{
283 Q_OBJECT 283 Q_OBJECT
284 284
285 public: 285 public:
286 OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); 286 OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 );
287 virtual ~OWaveLanManagementCF(); 287 virtual ~OWaveLanManagementCF();
288 288
289 private: 289 private:
290 const struct cf_t* _data; 290 const struct cf_t* _data;
291}; 291};
292 292
293/*====================================================================================== 293/*======================================================================================
294 * OWaveLanManagementFH 294 * OWaveLanManagementFH
295 *======================================================================================*/ 295 *======================================================================================*/
296 296
297class OWaveLanManagementFH : public QObject 297class OWaveLanManagementFH : public QObject
298{ 298{
299 Q_OBJECT 299 Q_OBJECT
300 300
301 public: 301 public:
302 OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); 302 OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 );
303 virtual ~OWaveLanManagementFH(); 303 virtual ~OWaveLanManagementFH();
304 304
305 private: 305 private:
306 const struct fh_t* _data; 306 const struct fh_t* _data;
307}; 307};
308 308
309/*====================================================================================== 309/*======================================================================================
310 * OWaveLanManagementDS 310 * OWaveLanManagementDS
311 *======================================================================================*/ 311 *======================================================================================*/
312 312
313class OWaveLanManagementDS : public QObject 313class OWaveLanManagementDS : public QObject
314{ 314{
315 Q_OBJECT 315 Q_OBJECT
316 316
317 public: 317 public:
318 OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); 318 OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 );
319 virtual ~OWaveLanManagementDS(); 319 virtual ~OWaveLanManagementDS();
320 320
321 int channel() const; 321 int channel() const;
322 322
323 private: 323 private:
324 const struct ds_t* _data; 324 const struct ds_t* _data;
325}; 325};
326 326
327/*====================================================================================== 327/*======================================================================================
328 * OWaveLanManagementTim 328 * OWaveLanManagementTim
329 *======================================================================================*/ 329 *======================================================================================*/
330 330
331class OWaveLanManagementTim : public QObject 331class OWaveLanManagementTim : public QObject
332{ 332{
333 Q_OBJECT 333 Q_OBJECT
334 334
335 public: 335 public:
336 OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); 336 OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 );
337 virtual ~OWaveLanManagementTim(); 337 virtual ~OWaveLanManagementTim();
338 338
339 private: 339 private:
340 const struct tim_t* _data; 340 const struct tim_t* _data;
341}; 341};
342 342
343/*====================================================================================== 343/*======================================================================================
344 * OWaveLanManagementIBSS 344 * OWaveLanManagementIBSS
345 *======================================================================================*/ 345 *======================================================================================*/
346 346
347class OWaveLanManagementIBSS : public QObject 347class OWaveLanManagementIBSS : public QObject
348{ 348{
349 Q_OBJECT 349 Q_OBJECT
350 350
351 public: 351 public:
352 OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); 352 OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 );
353 virtual ~OWaveLanManagementIBSS(); 353 virtual ~OWaveLanManagementIBSS();
354 354
355 private: 355 private:
356 const struct ibss_t* _data; 356 const struct ibss_t* _data;
357}; 357};
358 358
359/*====================================================================================== 359/*======================================================================================
360 * OWaveLanManagementChallenge 360 * OWaveLanManagementChallenge
361 *======================================================================================*/ 361 *======================================================================================*/
362 362
363class OWaveLanManagementChallenge : public QObject 363class OWaveLanManagementChallenge : public QObject
364{ 364{
365 Q_OBJECT 365 Q_OBJECT
366 366
367 public: 367 public:
368 OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); 368 OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 );
369 virtual ~OWaveLanManagementChallenge(); 369 virtual ~OWaveLanManagementChallenge();
370 370
371 private: 371 private:
372 const struct challenge_t* _data; 372 const struct challenge_t* _data;
373}; 373};
374 374
375/*====================================================================================== 375/*======================================================================================
376 * OWaveLanDataPacket - type: data (T_DATA) 376 * OWaveLanDataPacket - type: data (T_DATA)
377 *======================================================================================*/ 377 *======================================================================================*/
378 378
379class OWaveLanDataPacket : public QObject 379class OWaveLanDataPacket : public QObject
380{ 380{
381 Q_OBJECT 381 Q_OBJECT
382 382
383 public: 383 public:
384 OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); 384 OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 );
385 virtual ~OWaveLanDataPacket(); 385 virtual ~OWaveLanDataPacket();
386 386
387 private: 387 private:
388 const struct ieee_802_11_data_header* _header; 388 const struct ieee_802_11_data_header* _header;
389}; 389};
390 390
391/*====================================================================================== 391/*======================================================================================
392 * OWaveLanControlPacket - type: control (T_CTRL) 392 * OWaveLanControlPacket - type: control (T_CTRL)
393 *======================================================================================*/ 393 *======================================================================================*/
394 394
395class OWaveLanControlPacket : public QObject 395class OWaveLanControlPacket : public QObject
396{ 396{
397 Q_OBJECT 397 Q_OBJECT
398 398
399 public: 399 public:
400 OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); 400 OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 );
401 virtual ~OWaveLanControlPacket(); 401 virtual ~OWaveLanControlPacket();
402 402
403 private: 403 private:
404 const struct ieee_802_11_control_header* _header; 404 const struct ieee_802_11_control_header* _header;
405}; 405};
406 406
407/*====================================================================================== 407/*======================================================================================
408 * OLLCPacket - IEEE 802.2 Link Level Control 408 * OLLCPacket - IEEE 802.2 Link Level Control
409 *======================================================================================*/ 409 *======================================================================================*/
410 410
411class OLLCPacket : public QObject 411class OLLCPacket : public QObject
412{ 412{
413 Q_OBJECT 413 Q_OBJECT
414 414
415 public: 415 public:
416 OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); 416 OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 );
417 virtual ~OLLCPacket(); 417 virtual ~OLLCPacket();
418 418
419 private: 419 private:
420 const struct ieee_802_11_802_2_header* _header; 420 const struct ieee_802_11_802_2_header* _header;
421}; 421};
422 422
423/*====================================================================================== 423/*======================================================================================
424 * OIPPacket 424 * OIPPacket
425 *======================================================================================*/ 425 *======================================================================================*/
426 426
427class OIPPacket : public QObject 427class OIPPacket : public QObject
428{ 428{
429 Q_OBJECT 429 Q_OBJECT
430 430
431 public: 431 public:
432 OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); 432 OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 );
433 virtual ~OIPPacket(); 433 virtual ~OIPPacket();
434 434
435 QHostAddress fromIPAddress() const; 435 QHostAddress fromIPAddress() const;
436 QHostAddress toIPAddress() const; 436 QHostAddress toIPAddress() const;
437 437
438 int tos() const; 438 int tos() const;
439 int len() const; 439 int len() const;
440 int id() const; 440 int id() const;
441 int offset() const; 441 int offset() const;
442 int ttl() const; 442 int ttl() const;
443 int protocol() const; 443 int protocol() const;
444 int checksum() const; 444 int checksum() const;
445 445
446 private: 446 private:
447 const struct iphdr* _iphdr; 447 const struct iphdr* _iphdr;
448}; 448};
449 449
450/*====================================================================================== 450/*======================================================================================
451 * OARPPacket 451 * OARPPacket
452 *======================================================================================*/ 452 *======================================================================================*/
453 453
454class OARPPacket : public QObject 454class OARPPacket : public QObject
455{ 455{
456 Q_OBJECT 456 Q_OBJECT
457 457
458 public: 458 public:
459 OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); 459 OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 );
460 virtual ~OARPPacket(); 460 virtual ~OARPPacket();
461 461
462 QHostAddress senderIPV4Address() const; 462 QHostAddress senderIPV4Address() const;
463 OMacAddress senderMacAddress() const; 463 OMacAddress senderMacAddress() const;
464 QHostAddress targetIPV4Address() const; 464 QHostAddress targetIPV4Address() const;
465 OMacAddress targetMacAddress() const; 465 OMacAddress targetMacAddress() const;
466 466
467 //int type() const; 467 //int type() const;
468 QString type() const; 468 QString type() const;
469 469
470 private: 470 private:
471 const struct myarphdr* _arphdr; 471 const struct myarphdr* _arphdr;
472}; 472};
473 473
474/*====================================================================================== 474/*======================================================================================
475 * OUDPPacket 475 * OUDPPacket
476 *======================================================================================*/ 476 *======================================================================================*/
477 477
478class OUDPPacket : public QObject 478class OUDPPacket : public QObject
479{ 479{
480 Q_OBJECT 480 Q_OBJECT
481 481
482 public: 482 public:
483 OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); 483 OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 );
484 virtual ~OUDPPacket(); 484 virtual ~OUDPPacket();
485 485
486 int fromPort() const; 486 int fromPort() const;
487 int toPort() const; 487 int toPort() const;
488 int length() const; 488 int length() const;
489 int checksum() const; 489 int checksum() const;
490 490
491 private: 491 private:
492 const struct udphdr* _udphdr; 492 const struct udphdr* _udphdr;
493}; 493};
494 494
495/*====================================================================================== 495/*======================================================================================
496 * ODHCPPacket 496 * ODHCPPacket
497 *======================================================================================*/ 497 *======================================================================================*/
498 498
499class ODHCPPacket : public QObject 499class ODHCPPacket : public QObject
500{ 500{
501 Q_OBJECT 501 Q_OBJECT
502 502
503 public: 503 public:
504 ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); 504 ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 );
505 virtual ~ODHCPPacket(); 505 virtual ~ODHCPPacket();
506 506
507 QHostAddress clientAddress() const; 507 QHostAddress clientAddress() const;
508 QHostAddress yourAddress() const; 508 QHostAddress yourAddress() const;
509 QHostAddress serverAddress() const; 509 QHostAddress serverAddress() const;
510 QHostAddress relayAddress() const; 510 QHostAddress relayAddress() const;
511 511
512 OMacAddress clientMacAddress() const; 512 OMacAddress clientMacAddress() const;
513 513
514 bool isRequest() const; 514 bool isRequest() const;
515 bool isReply() const; 515 bool isReply() const;
516 QString type() const; 516 QString type() const;
517 517
518 private: 518 private:
519 const struct dhcp_packet* _dhcphdr; 519 const struct dhcp_packet* _dhcphdr;
520 unsigned char _type; 520 unsigned char _type;
521}; 521};
522 522
523/*====================================================================================== 523/*======================================================================================
524 * OTCPPacket 524 * OTCPPacket
525 *======================================================================================*/ 525 *======================================================================================*/
526 526
527class OTCPPacket : public QObject 527class OTCPPacket : public QObject
528{ 528{
529 Q_OBJECT 529 Q_OBJECT
530 530
531 public: 531 public:
532 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); 532 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 );
533 virtual ~OTCPPacket(); 533 virtual ~OTCPPacket();
534 534
535 int fromPort() const; 535 int fromPort() const;
536 int toPort() const; 536 int toPort() const;
537 int seq() const; 537 int seq() const;
538 int ack() const; 538 int ack() const;
539 int window() const; 539 int window() const;
540 int checksum() const; 540 int checksum() const;
541 541
542 private: 542 private:
543 const struct tcphdr* _tcphdr; 543 const struct tcphdr* _tcphdr;
544}; 544};
545 545
546 546
547/*====================================================================================== 547/*======================================================================================
548 * OPacketCapturer 548 * OPacketCapturer
549 *======================================================================================*/ 549 *======================================================================================*/
550 550
551/** 551/**
552 * @brief A class based wrapper for network packet capturing. 552 * @brief A class based wrapper for network packet capturing.
553 * 553 *
554 * This class is the base of a high-level interface to the well known packet capturing 554 * This class is the base of a high-level interface to the well known packet capturing
555 * library libpcap. 555 * library libpcap.
556 * @see http://tcpdump.org 556 * @see http://tcpdump.org
557 */ 557 */
558class OPacketCapturer : public QObject 558class OPacketCapturer : public QObject
559{ 559{
560 Q_OBJECT 560 Q_OBJECT
561 561
562 public: 562 public:
563 /** 563 /**
564 * Constructor. 564 * Constructor.
565 */ 565 */
566 OPacketCapturer( QObject* parent = 0, const char* name = 0 ); 566 OPacketCapturer( QObject* parent = 0, const char* name = 0 );
567 /** 567 /**
568 * Destructor. 568 * Destructor.
569 */ 569 */
570 ~OPacketCapturer(); 570 ~OPacketCapturer();
571 /** 571 /**
572 * Set the packet capturer to use blocking or non-blocking IO. This can be useful when 572 * Set the packet capturer to use blocking or non-blocking IO. This can be useful when
573 * not using the socket notifier, e.g. without an application object. 573 * not using the socket notifier, e.g. without an application object.
574 */ 574 */
575 void setBlocking( bool ); 575 void setBlocking( bool );
576 /** 576 /**
577 * @returns true if the packet capturer uses blocking IO calls. 577 * @returns true if the packet capturer uses blocking IO calls.
578 */ 578 */
579 bool blocking() const; 579 bool blocking() const;
580 /** 580 /**
581 * Close the packet capturer. This is automatically done in the destructor. 581 * Close the packet capturer. This is automatically done in the destructor.
582 */ 582 */
583 void close(); 583 void close();
584 /** 584 /**
585 * Close the output capture file. 585 * Close the output capture file.
586 */ 586 */
587 void closeDumpFile(); 587 void closeDumpFile();
588 /** 588 /**
589 * @returns the data link type. 589 * @returns the data link type.
590 * @see <pcap.h> for possible values. 590 * @see <pcap.h> for possible values.
591 */ 591 */
592 int dataLink() const; 592 int dataLink() const;
593 /** 593 /**
594 * Dump a packet to the output capture file. 594 * Dump a packet to the output capture file.
595 */ 595 */
596 void dump( OPacket* ); 596 void dump( OPacket* );
597 /** 597 /**
598 * @returns the file descriptor of the packet capturer. This is only useful, if 598 * @returns the file descriptor of the packet capturer. This is only useful, if
599 * not using the socket notifier, e.g. without an application object. 599 * not using the socket notifier, e.g. without an application object.
600 */ 600 */
601 int fileno() const; 601 int fileno() const;
602 /** 602 /**
603 * @returns the next @ref OPacket from the packet capturer. 603 * @returns the next @ref OPacket from the packet capturer.
604 * @note If blocking mode is true then this call might block. 604 * @note If blocking mode is true then this call might block.
605 */ 605 */
606 OPacket* next(); 606 OPacket* next();
607 /** 607 /**
608 * @returns the next @ref OPacket from the packet capturer, if
609 * one arrives within @a time milliseconds.
610 */
611 OPacket* next( int time );
612 /**
608 * Open the packet capturer to capture packets in live-mode from @a interface. 613 * Open the packet capturer to capture packets in live-mode from @a interface.
609 */ 614 */
610 bool open( const QString& interface ); 615 bool open( const QString& interface );
611 /** 616 /**
612 * Open the packet capturer to capture packets in offline-mode from @a file. 617 * Open the packet capturer to capture packets in offline-mode from @a file.
613 */ 618 */
614 bool open( const QFile& file ); 619 bool open( const QFile& file );
615 /** 620 /**
616 * Open a prerecorded tcpdump compatible capture file for use with @ref dump() 621 * Open a prerecorded tcpdump compatible capture file for use with @ref dump()
617 */ 622 */
618 bool openDumpFile( const QString& filename ); 623 bool openDumpFile( const QString& filename );
619 /** 624 /**
620 * @returns true if the packet capturer is open 625 * @returns true if the packet capturer is open
621 */ 626 */
622 bool isOpen() const; 627 bool isOpen() const;
623 /** 628 /**
624 * @returns the snapshot length of this packet capturer 629 * @returns the snapshot length of this packet capturer
625 */ 630 */
626 int snapShot() const; 631 int snapShot() const;
627 /** 632 /**
628 * @returns true if the input capture file has a different byte-order 633 * @returns true if the input capture file has a different byte-order
629 * than the byte-order of the running system. 634 * than the byte-order of the running system.
630 */ 635 */
631 bool swapped() const; 636 bool swapped() const;
632 /** 637 /**
633 * @returns the libpcap version string used to write the input capture file. 638 * @returns the libpcap version string used to write the input capture file.
634 */ 639 */
635 QString version() const; 640 QString version() const;
636 /** 641 /**
637 * @returns the packet statistic database. 642 * @returns the packet statistic database.
638 * @see QMap 643 * @see QMap
639 */ 644 */
640 const QMap<QString,int>& statistics() const; 645 const QMap<QString,int>& statistics() const;
641 646
642 signals: 647 signals:
643 /** 648 /**
644 * This signal is emitted, when a packet has been received. 649 * This signal is emitted, when a packet has been received.
645 */ 650 */
646 void receivedPacket( OPacket* ); 651 void receivedPacket( OPacket* );
647 652
648 protected slots: 653 protected slots:
649 void readyToReceive(); 654 void readyToReceive();
650 655
651 protected: 656 protected:
652 QString _name; // devicename 657 QString _name; // devicename
653 bool _open; // check this before doing pcap calls 658 bool _open; // check this before doing pcap calls
654 pcap_t* _pch; // pcap library handle 659 pcap_t* _pch; // pcap library handle
655 pcap_dumper_t* _pcd; // pcap dumper handle 660 pcap_dumper_t* _pcd; // pcap dumper handle
656 QSocketNotifier* _sn; // socket notifier for main loop 661 QSocketNotifier* _sn; // socket notifier for main loop
657 mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap 662 mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap
658 QMap<QString, int> _stats; // statistics; 663 QMap<QString, int> _stats; // statistics;
659}; 664};
660 665
661#endif // OPCAP_H 666#endif // OPCAP_H
662 667