summaryrefslogtreecommitdiff
path: root/libopie2/opienet/opcap.cpp
Unidiff
Diffstat (limited to 'libopie2/opienet/opcap.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp82
1 files changed, 82 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
@@ -400,32 +400,114 @@ int OUDPPacket::checksum() const
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