11#pragma once
22
3- #include < stdint.h >
4- #include < string.h >
3+ #include < cstdint >
4+ #include < cstring >
55#include < string>
66#include < algorithm>
77#include < ostream>
@@ -145,7 +145,7 @@ namespace pcpp
145145
146146 uint32_t IPv4Address::toInt () const
147147 {
148- uint32_t addr;
148+ uint32_t addr = 0 ;
149149 memcpy (&addr, m_Bytes.data (), m_Bytes.size () * sizeof (uint8_t ));
150150 return addr;
151151 }
@@ -276,7 +276,7 @@ namespace pcpp
276276 {
277277 public:
278278 // / An enum representing the address type: IPv4 or IPv6
279- enum AddressType
279+ enum AddressType : uint8_t
280280 {
281281 // / IPv4 address type
282282 IPv4AddressType,
@@ -395,7 +395,9 @@ namespace pcpp
395395 bool IPAddress::operator ==(const IPAddress& rhs) const
396396 {
397397 if (isIPv4 ())
398+ {
398399 return rhs.isIPv4 () ? (m_IPv4 == rhs.m_IPv4 ) : false ;
400+ }
399401
400402 return rhs.isIPv6 () ? m_IPv6 == rhs.m_IPv6 : false ;
401403 }
@@ -433,7 +435,7 @@ namespace pcpp
433435 // / A constructor that creates an instance of the class out of an address and a full prefix length,
434436 // / essentially making a network of consisting of only 1 address.
435437 // / @param address An address representing the network prefix.
436- explicit IPv4Network (const IPv4Address& address) : IPv4Network(address, 32u )
438+ explicit IPv4Network (const IPv4Address& address) : IPv4Network(address, 32U )
437439 {}
438440
439441 // / A constructor that creates an instance of the class out of an address representing the network prefix
@@ -476,7 +478,7 @@ namespace pcpp
476478 // / @return The network prefix, for example: the network prefix of 10.10.10.10/16 is 10.10.0.0
477479 IPv4Address getNetworkPrefix () const
478480 {
479- return IPv4Address ( m_NetworkPrefix) ;
481+ return m_NetworkPrefix;
480482 }
481483
482484 // / @return The lowest non-reserved IPv4 address in this network, for example: the lowest address
@@ -505,10 +507,10 @@ namespace pcpp
505507 std::string toString () const ;
506508
507509 private:
508- uint32_t m_NetworkPrefix;
509- uint32_t m_Mask;
510+ uint32_t m_NetworkPrefix{} ;
511+ uint32_t m_Mask{} ;
510512
511- bool isValidNetmask (const IPv4Address& netmaskAddress);
513+ static bool isValidNetmask (const IPv4Address& netmaskAddress);
512514 void initFromAddressAndPrefixLength (const IPv4Address& address, uint8_t prefixLen);
513515 void initFromAddressAndNetmask (const IPv4Address& address, const IPv4Address& netmaskAddress);
514516 };
@@ -521,7 +523,7 @@ namespace pcpp
521523 // / A constructor that creates an instance of the class out of an address and a full prefix length,
522524 // / essentially making a network of consisting of only 1 address.
523525 // / @param address An address representing the network prefix.
524- explicit IPv6Network (const IPv6Address& address) : IPv6Network(address, 128u )
526+ explicit IPv6Network (const IPv6Address& address) : IPv6Network(address, 128U )
525527 {}
526528
527529 // / A constructor that creates an instance of the class out of an address representing the network prefix
@@ -564,7 +566,7 @@ namespace pcpp
564566 // / @return The network prefix, for example: the network prefix of 3546:f321::/16 is 3546::
565567 IPv6Address getNetworkPrefix () const
566568 {
567- return IPv6Address ( m_NetworkPrefix) ;
569+ return { m_NetworkPrefix } ;
568570 }
569571
570572 // / @return The lowest non-reserved IPv6 address in this network, for example: the lowest address in 3546::/16
@@ -593,10 +595,10 @@ namespace pcpp
593595 std::string toString () const ;
594596
595597 private:
596- uint8_t m_NetworkPrefix[16 ];
597- uint8_t m_Mask[16 ];
598+ uint8_t m_NetworkPrefix[16 ]{} ;
599+ uint8_t m_Mask[16 ]{} ;
598600
599- bool isValidNetmask (const IPv6Address& netmaskAddress);
601+ static bool isValidNetmask (const IPv6Address& netmaskAddress);
600602 void initFromAddressAndPrefixLength (const IPv6Address& address, uint8_t prefixLen);
601603 void initFromAddressAndNetmask (const IPv6Address& address, const IPv6Address& netmaskAddress);
602604 };
@@ -609,7 +611,7 @@ namespace pcpp
609611 // / A constructor that creates an instance of the class out of an IP address and a full prefix length,
610612 // / essentially making a network of consisting of only 1 address.
611613 // / @param address An address representing the network prefix.
612- explicit IPNetwork (const IPAddress& address) : IPNetwork(address, address.isIPv4() ? 32u : 128u )
614+ explicit IPNetwork (const IPAddress& address) : IPNetwork(address, address.isIPv4() ? 32U : 128U )
613615 {}
614616
615617 // / A constructor that creates an instance of the class out of an address representing the network prefix
@@ -692,14 +694,14 @@ namespace pcpp
692694 // / @return A reference to the assignee
693695 IPNetwork& operator =(const IPNetwork& other)
694696 {
697+ // NOLINTBEGIN(cppcoreguidelines-c-copy-assignment-signature,misc-unconventional-assign-operator)
695698 if (other.isIPv4Network ())
696699 {
697700 return this ->operator =(*other.m_IPv4Network );
698701 }
699- else
700- {
701- return this ->operator =(*other.m_IPv6Network );
702- }
702+
703+ return this ->operator =(*other.m_IPv6Network );
704+ // NOLINTEND(cppcoreguidelines-c-copy-assignment-signature,misc-unconventional-assign-operator)
703705 }
704706
705707 // / Overload of an assignment operator.
@@ -796,15 +798,13 @@ namespace pcpp
796798
797799 return m_IPv4Network->includes (address.getIPv4 ());
798800 }
799- else
800- {
801- if (address.isIPv4 ())
802- {
803- return false ;
804- }
805801
806- return m_IPv6Network->includes (address.getIPv6 ());
802+ if (address.isIPv4 ())
803+ {
804+ return false ;
807805 }
806+
807+ return m_IPv6Network->includes (address.getIPv6 ());
808808 }
809809
810810 // / @param network An IP network
@@ -820,15 +820,13 @@ namespace pcpp
820820
821821 return m_IPv4Network->includes (*network.m_IPv4Network );
822822 }
823- else
824- {
825- if (network.isIPv4Network ())
826- {
827- return false ;
828- }
829823
830- return m_IPv6Network->includes (*network.m_IPv6Network );
824+ if (network.isIPv4Network ())
825+ {
826+ return false ;
831827 }
828+
829+ return m_IPv6Network->includes (*network.m_IPv6Network );
832830 }
833831
834832 // / @return A string representation of the network in a format of NETWORK_PREFIX/PREFIX_LEN, for example:
@@ -843,40 +841,40 @@ namespace pcpp
843841 std::unique_ptr<IPv6Network> m_IPv6Network;
844842 };
845843
846- inline std::ostream& operator <<(std::ostream& os , const pcpp::IPv4Address& ipv4Address)
844+ inline std::ostream& operator <<(std::ostream& oss , const pcpp::IPv4Address& ipv4Address)
847845 {
848- os << ipv4Address.toString ();
849- return os ;
846+ oss << ipv4Address.toString ();
847+ return oss ;
850848 }
851849
852- inline std::ostream& operator <<(std::ostream& os , const pcpp::IPv6Address& ipv6Address)
850+ inline std::ostream& operator <<(std::ostream& oss , const pcpp::IPv6Address& ipv6Address)
853851 {
854- os << ipv6Address.toString ();
855- return os ;
852+ oss << ipv6Address.toString ();
853+ return oss ;
856854 }
857855
858- inline std::ostream& operator <<(std::ostream& os , const pcpp::IPAddress& ipAddress)
856+ inline std::ostream& operator <<(std::ostream& oss , const pcpp::IPAddress& ipAddress)
859857 {
860- os << ipAddress.toString ();
861- return os ;
858+ oss << ipAddress.toString ();
859+ return oss ;
862860 }
863861
864- inline std::ostream& operator <<(std::ostream& os , const pcpp::IPv4Network& network)
862+ inline std::ostream& operator <<(std::ostream& oss , const pcpp::IPv4Network& network)
865863 {
866- os << network.toString ();
867- return os ;
864+ oss << network.toString ();
865+ return oss ;
868866 }
869867
870- inline std::ostream& operator <<(std::ostream& os , const pcpp::IPv6Network& network)
868+ inline std::ostream& operator <<(std::ostream& oss , const pcpp::IPv6Network& network)
871869 {
872- os << network.toString ();
873- return os ;
870+ oss << network.toString ();
871+ return oss ;
874872 }
875873
876- inline std::ostream& operator <<(std::ostream& os , const pcpp::IPNetwork& network)
874+ inline std::ostream& operator <<(std::ostream& oss , const pcpp::IPNetwork& network)
877875 {
878- os << network.toString ();
879- return os ;
876+ oss << network.toString ();
877+ return oss ;
880878 }
881879
882880} // namespace pcpp
0 commit comments