@@ -408,8 +408,7 @@ namespace pcpp
408
408
/* *
409
409
* A d'tor for this class, currently does nothing
410
410
*/
411
- virtual ~DhcpOption ()
412
- {}
411
+ ~DhcpOption () override = default ;
413
412
414
413
/* *
415
414
* Retrieve DHCP option data as IPv4 address. Relevant only if option value is indeed an IPv4 address
@@ -444,7 +443,8 @@ namespace pcpp
444
443
if (m_Data == nullptr || m_Data->recordLen - valueOffset < 1 )
445
444
return " " ;
446
445
447
- return std::string ((const char *)m_Data->recordValue + valueOffset, (int )m_Data->recordLen - valueOffset);
446
+ return std::string (reinterpret_cast <const char *>(m_Data->recordValue ) + valueOffset,
447
+ static_cast <int >(m_Data->recordLen ) - valueOffset);
448
448
}
449
449
450
450
/* *
@@ -458,7 +458,7 @@ namespace pcpp
458
458
void setValueString (const std::string& stringValue, int valueOffset = 0 )
459
459
{
460
460
// calculate the maximum length of the destination buffer
461
- size_t len = ( size_t ) m_Data->recordLen - ( size_t ) valueOffset;
461
+ size_t len = static_cast < size_t >( m_Data->recordLen ) - static_cast < size_t >( valueOffset) ;
462
462
463
463
// use the length of input string if a buffer is large enough for whole string
464
464
if (stringValue.length () < len)
@@ -475,38 +475,41 @@ namespace pcpp
475
475
*/
476
476
static bool canAssign (const uint8_t * recordRawData, size_t tlvDataLen)
477
477
{
478
- auto data = ( TLVRawData*) recordRawData;
478
+ auto data = reinterpret_cast < TLVRawData const *>( recordRawData) ;
479
479
if (data == nullptr )
480
480
return false ;
481
481
482
482
if (tlvDataLen < sizeof (TLVRawData::recordType))
483
483
return false ;
484
484
485
- if (data->recordType == (uint8_t )DHCPOPT_END || data->recordType == (uint8_t )DHCPOPT_PAD)
485
+ if (data->recordType == static_cast <uint8_t >(DHCPOPT_END) ||
486
+ data->recordType == static_cast <uint8_t >(DHCPOPT_PAD))
486
487
return true ;
487
488
488
489
return TLVRecord<uint8_t , uint8_t >::canAssign (recordRawData, tlvDataLen);
489
490
}
490
491
491
492
// implement abstract methods
492
493
493
- size_t getTotalSize () const
494
+ size_t getTotalSize () const override
494
495
{
495
496
if (m_Data == nullptr )
496
497
return 0 ;
497
498
498
- if (m_Data->recordType == (uint8_t )DHCPOPT_END || m_Data->recordType == (uint8_t )DHCPOPT_PAD)
499
+ if (m_Data->recordType == static_cast <uint8_t >(DHCPOPT_END) ||
500
+ m_Data->recordType == static_cast <uint8_t >(DHCPOPT_PAD))
499
501
return sizeof (uint8_t );
500
502
501
- return sizeof (uint8_t ) * 2 + ( size_t ) m_Data->recordLen ;
503
+ return sizeof (uint8_t ) * 2 + static_cast < size_t >( m_Data->recordLen ) ;
502
504
}
503
505
504
- size_t getDataSize () const
506
+ size_t getDataSize () const override
505
507
{
506
508
if (m_Data == nullptr )
507
509
return 0 ;
508
510
509
- if (m_Data->recordType == (uint8_t )DHCPOPT_END || m_Data->recordType == (uint8_t )DHCPOPT_PAD)
511
+ if (m_Data->recordType == static_cast <uint8_t >(DHCPOPT_END) ||
512
+ m_Data->recordType == static_cast <uint8_t >(DHCPOPT_PAD))
510
513
return 0 ;
511
514
512
515
return m_Data->recordLen ;
@@ -530,7 +533,7 @@ namespace pcpp
530
533
* @param[in] optionValueLen DHCP option value length in bytes
531
534
*/
532
535
DhcpOptionBuilder (DhcpOptionTypes optionType, const uint8_t * optionValue, uint8_t optionValueLen)
533
- : TLVRecordBuilder(( uint8_t ) optionType, optionValue, optionValueLen)
536
+ : TLVRecordBuilder(static_cast < uint8_t >( optionType) , optionValue, optionValueLen)
534
537
{}
535
538
536
539
/* *
@@ -540,7 +543,7 @@ namespace pcpp
540
543
* @param[in] optionValue A 1-byte option value
541
544
*/
542
545
DhcpOptionBuilder (DhcpOptionTypes optionType, uint8_t optionValue)
543
- : TLVRecordBuilder(( uint8_t ) optionType, optionValue)
546
+ : TLVRecordBuilder(static_cast < uint8_t >( optionType) , optionValue)
544
547
{}
545
548
546
549
/* *
@@ -550,7 +553,7 @@ namespace pcpp
550
553
* @param[in] optionValue A 2-byte option value
551
554
*/
552
555
DhcpOptionBuilder (DhcpOptionTypes optionType, uint16_t optionValue)
553
- : TLVRecordBuilder(( uint8_t ) optionType, optionValue)
556
+ : TLVRecordBuilder(static_cast < uint8_t >( optionType) , optionValue)
554
557
{}
555
558
556
559
/* *
@@ -560,7 +563,7 @@ namespace pcpp
560
563
* @param[in] optionValue A 4-byte option value
561
564
*/
562
565
DhcpOptionBuilder (DhcpOptionTypes optionType, uint32_t optionValue)
563
- : TLVRecordBuilder(( uint8_t ) optionType, optionValue)
566
+ : TLVRecordBuilder(static_cast < uint8_t >( optionType) , optionValue)
564
567
{}
565
568
566
569
/* *
@@ -570,7 +573,7 @@ namespace pcpp
570
573
* @param[in] optionValue The IPv4 address option value
571
574
*/
572
575
DhcpOptionBuilder (DhcpOptionTypes optionType, const IPv4Address& optionValue)
573
- : TLVRecordBuilder(( uint8_t ) optionType, optionValue)
576
+ : TLVRecordBuilder(static_cast < uint8_t >( optionType) , optionValue)
574
577
{}
575
578
576
579
/* *
@@ -580,7 +583,7 @@ namespace pcpp
580
583
* @param[in] optionValue The string option value
581
584
*/
582
585
DhcpOptionBuilder (DhcpOptionTypes optionType, const std::string& optionValue)
583
- : TLVRecordBuilder(( uint8_t ) optionType, optionValue)
586
+ : TLVRecordBuilder(static_cast < uint8_t >( optionType) , optionValue)
584
587
{}
585
588
586
589
/* *
@@ -640,8 +643,7 @@ namespace pcpp
640
643
/* *
641
644
* A destructor for this layer
642
645
*/
643
- virtual ~DhcpLayer ()
644
- {}
646
+ ~DhcpLayer () override = default ;
645
647
646
648
/* *
647
649
* Get a pointer to the DHCP header. Notice this points directly to the data, so every change will change the
@@ -650,15 +652,15 @@ namespace pcpp
650
652
*/
651
653
dhcp_header* getDhcpHeader () const
652
654
{
653
- return ( dhcp_header*) m_Data;
655
+ return reinterpret_cast < dhcp_header*>( m_Data) ;
654
656
}
655
657
656
658
/* *
657
659
* @return The BootP opcode of this message
658
660
*/
659
661
BootpOpCodes getOpCode () const
660
662
{
661
- return ( BootpOpCodes) getDhcpHeader ()->opCode ;
663
+ return static_cast < BootpOpCodes>( getDhcpHeader ()->opCode ) ;
662
664
}
663
665
664
666
/* *
@@ -834,13 +836,13 @@ namespace pcpp
834
836
/* *
835
837
* Does nothing for this layer (DhcpLayer is always last)
836
838
*/
837
- void parseNextLayer ()
839
+ void parseNextLayer () override
838
840
{}
839
841
840
842
/* *
841
843
* @return The size of @ref dhcp_header + size of options
842
844
*/
843
- size_t getHeaderLen () const
845
+ size_t getHeaderLen () const override
844
846
{
845
847
return m_DataLen;
846
848
}
@@ -855,11 +857,11 @@ namespace pcpp
855
857
* - @ref dhcp_header#hardwareType = 1 (Ethernet)
856
858
* - @ref dhcp_header#hardwareAddressLength = 6 (MAC address length)
857
859
*/
858
- void computeCalculateFields ();
860
+ void computeCalculateFields () override ;
859
861
860
- std::string toString () const ;
862
+ std::string toString () const override ;
861
863
862
- OsiModelLayer getOsiModelLayer () const
864
+ OsiModelLayer getOsiModelLayer () const override
863
865
{
864
866
return OsiModelApplicationLayer;
865
867
}
0 commit comments