summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (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
@@ -409,6 +409,36 @@ ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* da
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
@@ -417,6 +447,58 @@ ODHCPPacket::~ODHCPPacket()
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 *======================================================================================*/
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
@@ -499,8 +499,18 @@ class ODHCPPacket : public QObject
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/*======================================================================================