summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-10-04 01:34:13 (UTC)
committer mickeyl <mickeyl>2003-10-04 01:34:13 (UTC)
commita4793f5226e9eb5c8a718cca9335c23530e08b08 (patch) (unidiff)
tree9e18d900f9c0a96170c8221ba4e60e7b7937cf39
parente2716e3862915582d0ce48aaacc967f5b0cf6550 (diff)
downloadopie-a4793f5226e9eb5c8a718cca9335c23530e08b08.zip
opie-a4793f5226e9eb5c8a718cca9335c23530e08b08.tar.gz
opie-a4793f5226e9eb5c8a718cca9335c23530e08b08.tar.bz2
Although not yet complete, the DHCP decoding is now usable
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp82
-rw-r--r--libopie2/opienet/opcap.h10
2 files changed, 92 insertions, 0 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index f1f2b4b..7a6f61b 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -364,104 +364,186 @@ OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QOb
364 if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || 364 if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC ||
365 toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) 365 toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC )
366 { 366 {
367 qDebug( "seems to be part of a DHCP conversation => creating DHCP packet." ); 367 qDebug( "seems to be part of a DHCP conversation => creating DHCP packet." );
368 new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); 368 new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this );
369 } 369 }
370} 370}
371 371
372 372
373OUDPPacket::~OUDPPacket() 373OUDPPacket::~OUDPPacket()
374{ 374{
375} 375}
376 376
377 377
378int OUDPPacket::fromPort() const 378int OUDPPacket::fromPort() const
379{ 379{
380 return EXTRACT_16BITS( &_udphdr->source ); 380 return EXTRACT_16BITS( &_udphdr->source );
381} 381}
382 382
383 383
384int OUDPPacket::toPort() const 384int OUDPPacket::toPort() const
385{ 385{
386 return EXTRACT_16BITS( &_udphdr->dest ); 386 return EXTRACT_16BITS( &_udphdr->dest );
387} 387}
388 388
389 389
390int OUDPPacket::length() const 390int OUDPPacket::length() const
391{ 391{
392 return EXTRACT_16BITS( &_udphdr->len ); 392 return EXTRACT_16BITS( &_udphdr->len );
393} 393}
394 394
395 395
396int OUDPPacket::checksum() const 396int OUDPPacket::checksum() const
397{ 397{
398 return EXTRACT_16BITS( &_udphdr->check ); 398 return EXTRACT_16BITS( &_udphdr->check );
399} 399}
400 400
401 401
402/*====================================================================================== 402/*======================================================================================
403 * ODHCPPacket 403 * ODHCPPacket
404 *======================================================================================*/ 404 *======================================================================================*/
405 405
406 406
407ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) 407ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent )
408 :QObject( parent, "DHCP" ), _dhcphdr( data ) 408 :QObject( parent, "DHCP" ), _dhcphdr( data )
409 409
410{ 410{
411 qDebug( "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." ); 411 qDebug( "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." );
412 qDebug( "DHCP opcode seems to be %02d - '%s'", _dhcphdr->op, isRequest() ? "REQUEST" : "REPLY" );
413 qDebug( "clientAddress: %s", (const char*) clientAddress().toString() );
414 qDebug( " yourAddress: %s", (const char*) yourAddress().toString() );
415 qDebug( "serverAddress: %s", (const char*) serverAddress().toString() );
416 qDebug( " relayAddress: %s", (const char*) relayAddress().toString() );
417 qDebug( "parsing DHCP options..." );
418
419 _type = 0;
420
421 const unsigned char* option = &_dhcphdr->options[4];
422 char tag = -1;
423 char len = -1;
424
425 while ( ( tag = *option++ ) != -1 /* end of option field */ )
426 {
427 len = *option++;
428 qDebug( "recognized DHCP option #%d, length %d", tag, len );
429
430 if ( tag == DHO_DHCP_MESSAGE_TYPE )
431 _type = *option;
432
433 option += len;
434 if ( option >= end )
435 {
436 qWarning( "DHCP parsing ERROR: sanity check says the packet is at its end!" );
437 break;
438 }
439 }
440
441 qDebug( "DHCP type seems to be '%s'", (const char*) type() );
412} 442}
413 443
414 444
415ODHCPPacket::~ODHCPPacket() 445ODHCPPacket::~ODHCPPacket()
416{ 446{
417} 447}
418 448
419 449
450bool ODHCPPacket::isRequest() const
451{
452 return ( _dhcphdr->op == 01 );
453}
454
455
456bool ODHCPPacket::isReply() const
457{
458 return ( _dhcphdr->op == 02 );
459}
460
461
462QString ODHCPPacket::type() const
463{
464 switch ( _type )
465 {
466 case 1: return "DISCOVER";
467 case 2: return "OFFER";
468 case 3: return "REQUEST";
469 case 4: return "DECLINE";
470 case 5: return "ACK";
471 case 6: return "NAK";
472 case 7: return "RELEASE";
473 case 8: return "INFORM";
474 default: qWarning( "ODHCPPacket::type(): invalid DHCP type (%d) !", _dhcphdr->op ); return "<unknown>";
475 }
476}
477
478
479QHostAddress ODHCPPacket::clientAddress() const
480{
481 return EXTRACT_32BITS( &_dhcphdr->ciaddr );
482}
483
484
485QHostAddress ODHCPPacket::yourAddress() const
486{
487 return EXTRACT_32BITS( &_dhcphdr->yiaddr );
488}
489
490
491QHostAddress ODHCPPacket::serverAddress() const
492{
493 return EXTRACT_32BITS( &_dhcphdr->siaddr );
494}
495
496
497QHostAddress ODHCPPacket::relayAddress() const
498{
499 return EXTRACT_32BITS( &_dhcphdr->giaddr );
500}
501
420/*====================================================================================== 502/*======================================================================================
421 * OTCPPacket 503 * OTCPPacket
422 *======================================================================================*/ 504 *======================================================================================*/
423 505
424 506
425OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) 507OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent )
426 :QObject( parent, "TCP" ), _tcphdr( data ) 508 :QObject( parent, "TCP" ), _tcphdr( data )
427 509
428{ 510{
429 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); 511 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." );
430} 512}
431 513
432 514
433OTCPPacket::~OTCPPacket() 515OTCPPacket::~OTCPPacket()
434{ 516{
435} 517}
436 518
437 519
438int OTCPPacket::fromPort() const 520int OTCPPacket::fromPort() const
439{ 521{
440 return EXTRACT_16BITS( &_tcphdr->source ); 522 return EXTRACT_16BITS( &_tcphdr->source );
441} 523}
442 524
443 525
444int OTCPPacket::toPort() const 526int OTCPPacket::toPort() const
445{ 527{
446 return EXTRACT_16BITS( &_tcphdr->dest ); 528 return EXTRACT_16BITS( &_tcphdr->dest );
447} 529}
448 530
449 531
450int OTCPPacket::seq() const 532int OTCPPacket::seq() const
451{ 533{
452 return EXTRACT_16BITS( &_tcphdr->seq ); 534 return EXTRACT_16BITS( &_tcphdr->seq );
453} 535}
454 536
455 537
456int OTCPPacket::ack() const 538int OTCPPacket::ack() const
457{ 539{
458 return EXTRACT_16BITS( &_tcphdr->ack_seq ); 540 return EXTRACT_16BITS( &_tcphdr->ack_seq );
459} 541}
460 542
461 543
462int OTCPPacket::window() const 544int OTCPPacket::window() const
463{ 545{
464 return EXTRACT_16BITS( &_tcphdr->window ); 546 return EXTRACT_16BITS( &_tcphdr->window );
465} 547}
466 548
467 549
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h
index 0c9e7da..a031dd1 100644
--- a/libopie2/opienet/opcap.h
+++ b/libopie2/opienet/opcap.h
@@ -454,98 +454,108 @@ class OARPPacket : public QObject
454 OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); 454 OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 );
455 virtual ~OARPPacket(); 455 virtual ~OARPPacket();
456 456
457 QHostAddress senderIPV4Address() const; 457 QHostAddress senderIPV4Address() const;
458 OMacAddress senderMacAddress() const; 458 OMacAddress senderMacAddress() const;
459 QHostAddress targetIPV4Address() const; 459 QHostAddress targetIPV4Address() const;
460 OMacAddress targetMacAddress() const; 460 OMacAddress targetMacAddress() const;
461 461
462 //int type() const; 462 //int type() const;
463 QString type() const; 463 QString type() const;
464 464
465 private: 465 private:
466 const struct myarphdr* _arphdr; 466 const struct myarphdr* _arphdr;
467}; 467};
468 468
469/*====================================================================================== 469/*======================================================================================
470 * OUDPPacket 470 * OUDPPacket
471 *======================================================================================*/ 471 *======================================================================================*/
472 472
473class OUDPPacket : public QObject 473class OUDPPacket : public QObject
474{ 474{
475 Q_OBJECT 475 Q_OBJECT
476 476
477 public: 477 public:
478 OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); 478 OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 );
479 virtual ~OUDPPacket(); 479 virtual ~OUDPPacket();
480 480
481 int fromPort() const; 481 int fromPort() const;
482 int toPort() const; 482 int toPort() const;
483 int length() const; 483 int length() const;
484 int checksum() const; 484 int checksum() const;
485 485
486 private: 486 private:
487 const struct udphdr* _udphdr; 487 const struct udphdr* _udphdr;
488}; 488};
489 489
490/*====================================================================================== 490/*======================================================================================
491 * ODHCPPacket 491 * ODHCPPacket
492 *======================================================================================*/ 492 *======================================================================================*/
493 493
494class ODHCPPacket : public QObject 494class ODHCPPacket : public QObject
495{ 495{
496 Q_OBJECT 496 Q_OBJECT
497 497
498 public: 498 public:
499 ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); 499 ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 );
500 virtual ~ODHCPPacket(); 500 virtual ~ODHCPPacket();
501 501
502 QHostAddress clientAddress() const;
503 QHostAddress yourAddress() const;
504 QHostAddress serverAddress() const;
505 QHostAddress relayAddress() const;
506
507 bool isRequest() const;
508 bool isReply() const;
509 QString type() const;
510
502 private: 511 private:
503 const struct dhcp_packet* _dhcphdr; 512 const struct dhcp_packet* _dhcphdr;
513 unsigned char _type;
504}; 514};
505 515
506/*====================================================================================== 516/*======================================================================================
507 * OTCPPacket 517 * OTCPPacket
508 *======================================================================================*/ 518 *======================================================================================*/
509 519
510class OTCPPacket : public QObject 520class OTCPPacket : public QObject
511{ 521{
512 Q_OBJECT 522 Q_OBJECT
513 523
514 public: 524 public:
515 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); 525 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 );
516 virtual ~OTCPPacket(); 526 virtual ~OTCPPacket();
517 527
518 int fromPort() const; 528 int fromPort() const;
519 int toPort() const; 529 int toPort() const;
520 int seq() const; 530 int seq() const;
521 int ack() const; 531 int ack() const;
522 int window() const; 532 int window() const;
523 int checksum() const; 533 int checksum() const;
524 534
525 private: 535 private:
526 const struct tcphdr* _tcphdr; 536 const struct tcphdr* _tcphdr;
527}; 537};
528 538
529 539
530/*====================================================================================== 540/*======================================================================================
531 * OPacketCapturer 541 * OPacketCapturer
532 *======================================================================================*/ 542 *======================================================================================*/
533 543
534/** 544/**
535 * @brief A class based wrapper for network packet capturing. 545 * @brief A class based wrapper for network packet capturing.
536 * 546 *
537 * This class is the base of a high-level interface to the well known packet capturing 547 * This class is the base of a high-level interface to the well known packet capturing
538 * library libpcap. 548 * library libpcap.
539 * @see http://tcpdump.org 549 * @see http://tcpdump.org
540 */ 550 */
541class OPacketCapturer : public QObject 551class OPacketCapturer : public QObject
542{ 552{
543 Q_OBJECT 553 Q_OBJECT
544 554
545 public: 555 public:
546 /** 556 /**
547 * Constructor. 557 * Constructor.
548 */ 558 */
549 OPacketCapturer( QObject* parent = 0, const char* name = 0 ); 559 OPacketCapturer( QObject* parent = 0, const char* name = 0 );
550 /** 560 /**
551 * Destructor. 561 * Destructor.