diff --git a/Common++/header/pcapplusplus/IpAddress.h b/Common++/header/pcapplusplus/IpAddress.h index 243dae0ef9..48db6f722e 100644 --- a/Common++/header/pcapplusplus/IpAddress.h +++ b/Common++/header/pcapplusplus/IpAddress.h @@ -40,7 +40,7 @@ namespace pcpp * A constructor that creates an instance of the class out of 4-byte integer value. * @param[in] addrAsInt The address as 4-byte integer in network byte order */ - IPv4Address(const uint32_t addrAsInt) + explicit IPv4Address(const uint32_t addrAsInt) { memcpy(m_Bytes.data(), &addrAsInt, sizeof(addrAsInt)); } @@ -49,7 +49,7 @@ namespace pcpp * A constructor that creates an instance of the class out of 4-byte array. * @param[in] bytes The address as 4-byte array in network byte order */ - IPv4Address(const uint8_t bytes[4]) + explicit IPv4Address(const uint8_t bytes[4]) { memcpy(m_Bytes.data(), bytes, 4 * sizeof(uint8_t)); } @@ -58,7 +58,7 @@ namespace pcpp * A constructor that creates an instance of the class out of a 4-byte standard array. * @param[in] bytes The address as 4-byte standard array in network byte order */ - IPv4Address(const std::array& bytes) : m_Bytes(bytes) + explicit IPv4Address(const std::array& bytes) : m_Bytes(bytes) {} /** @@ -67,7 +67,7 @@ namespace pcpp * @param[in] addrAsString The std::string representation of the address * @throws std::invalid_argument The provided string does not represent a valid IPv4 address. */ - IPv4Address(const std::string& addrAsString); + explicit IPv4Address(const std::string& addrAsString); /** * @return A 4-byte integer in network byte order representing the IPv4 address @@ -207,7 +207,7 @@ namespace pcpp * A constructor that creates an instance of the class out of 16-byte array. * @param[in] bytes The address as 16-byte array in network byte order */ - IPv6Address(const uint8_t bytes[16]) + explicit IPv6Address(const uint8_t bytes[16]) { memcpy(m_Bytes.data(), bytes, 16 * sizeof(uint8_t)); } @@ -216,7 +216,7 @@ namespace pcpp * A constructor that creates an instance of the class out of a 16-byte standard array. * @param[in] bytes The address as 16-byte standard array in network byte order */ - IPv6Address(const std::array& bytes) : m_Bytes(bytes) + explicit IPv6Address(const std::array& bytes) : m_Bytes(bytes) {} /** @@ -225,7 +225,7 @@ namespace pcpp * @param[in] addrAsString The std::string representation of the address * @throws std::invalid_argument The provided string does not represent a valid IPv6 address. */ - IPv6Address(const std::string& addrAsString); + explicit IPv6Address(const std::string& addrAsString); /** * Returns a view of the IPv6 address as a 16-byte raw C-style array @@ -382,14 +382,14 @@ namespace pcpp * A constructor that creates an instance of the class out of IPv4Address. * @param[in] addr A const reference to instance of IPv4Address */ - IPAddress(const IPv4Address& addr) : m_Type(IPv4AddressType), m_IPv4(addr) + explicit IPAddress(const IPv4Address& addr) : m_Type(IPv4AddressType), m_IPv4(addr) {} /** * A constructor that creates an instance of the class out of IPv6Address. * @param[in] addr A const reference to instance of IPv6Address */ - IPAddress(const IPv6Address& addr) : m_Type(IPv6AddressType), m_IPv6(addr) + explicit IPAddress(const IPv6Address& addr) : m_Type(IPv6AddressType), m_IPv6(addr) {} /** @@ -596,7 +596,7 @@ namespace pcpp * a valid netmask * @throws std::invalid_argument The provided string does not represent a valid address and netmask format. */ - IPv4Network(const std::string& addressAndNetmask); + explicit IPv4Network(const std::string& addressAndNetmask); /** * @return The prefix length, for example: the prefix length of 10.10.10.10/255.0.0.0 is 8 @@ -713,7 +713,7 @@ namespace pcpp * and IPV6_NETMASK is a valid IPv6 netmask * @throws std::invalid_argument The provided string does not represent a valid address and netmask format. */ - IPv6Network(const std::string& addressAndNetmask); + explicit IPv6Network(const std::string& addressAndNetmask); /** * @return The prefix length, for example: the prefix length of 3546::/ffff:: is 16 @@ -852,7 +852,7 @@ namespace pcpp * is a valid netmask for this type of network (IPv4 or IPv6 network) * @throws std::invalid_argument The provided string does not represent a valid address and netmask format. */ - IPNetwork(const std::string& addressAndNetmask) + explicit IPNetwork(const std::string& addressAndNetmask) { try { diff --git a/Common++/header/pcapplusplus/MacAddress.h b/Common++/header/pcapplusplus/MacAddress.h index 29333aa02d..4e46602b13 100644 --- a/Common++/header/pcapplusplus/MacAddress.h +++ b/Common++/header/pcapplusplus/MacAddress.h @@ -54,7 +54,7 @@ namespace pcpp * @param[in] addr the string representing the MAC address in format "00:00:00:00:00:00" */ template ::value>::type> - MacAddress(const T& addr) : MacAddress(static_cast(addr)) + explicit MacAddress(const T& addr) : MacAddress(static_cast(addr)) {} /** diff --git a/Common++/src/IpAddress.cpp b/Common++/src/IpAddress.cpp index 281d6a675e..6558e5f403 100644 --- a/Common++/src/IpAddress.cpp +++ b/Common++/src/IpAddress.cpp @@ -285,14 +285,14 @@ namespace pcpp IPv4Address IPv4Network::getLowestAddress() const { std::bitset<32> bitset(m_Mask); - return bitset.count() < 32 ? m_NetworkPrefix + htobe32(1) : m_NetworkPrefix; + return bitset.count() < 32 ? IPv4Address(m_NetworkPrefix + htobe32(1)) : IPv4Address(m_NetworkPrefix); } IPv4Address IPv4Network::getHighestAddress() const { auto tempAddress = static_cast(m_NetworkPrefix | ~m_Mask); std::bitset<32> bitset(m_Mask); - return bitset.count() < 32 ? tempAddress - htobe32(1) : tempAddress; + return bitset.count() < 32 ? IPv4Address(tempAddress - htobe32(1)) : IPv4Address(tempAddress); } uint64_t IPv4Network::getTotalAddressCount() const @@ -496,13 +496,13 @@ namespace pcpp { if (getPrefixLen() == 128) { - return m_NetworkPrefix; + return IPv6Address(m_NetworkPrefix); } uint8_t lowestAddress[IPV6_ADDR_SIZE]; memcpy(lowestAddress, m_NetworkPrefix, IPV6_ADDR_SIZE); lowestAddress[IPV6_ADDR_SIZE - 1]++; - return lowestAddress; + return IPv6Address(lowestAddress); } IPv6Address IPv6Network::getHighestAddress() const @@ -514,7 +514,7 @@ namespace pcpp result[byteIndex] = m_NetworkPrefix[byteIndex] | ~m_Mask[byteIndex]; } - return result; + return IPv6Address(result); } uint64_t IPv6Network::getTotalAddressCount() const diff --git a/Packet++/header/pcapplusplus/ArpLayer.h b/Packet++/header/pcapplusplus/ArpLayer.h index d2293f3f5d..1ef9b2d097 100644 --- a/Packet++/header/pcapplusplus/ArpLayer.h +++ b/Packet++/header/pcapplusplus/ArpLayer.h @@ -119,7 +119,7 @@ namespace pcpp */ inline IPv4Address getSenderIpAddr() const { - return getArpHeader()->senderIpAddr; + return IPv4Address(getArpHeader()->senderIpAddr); } /** @@ -128,7 +128,7 @@ namespace pcpp */ inline IPv4Address getTargetIpAddr() const { - return getArpHeader()->targetIpAddr; + return IPv4Address(getArpHeader()->targetIpAddr); } // implement abstract methods diff --git a/Packet++/header/pcapplusplus/DhcpLayer.h b/Packet++/header/pcapplusplus/DhcpLayer.h index fc37911601..d90f7a3e63 100644 --- a/Packet++/header/pcapplusplus/DhcpLayer.h +++ b/Packet++/header/pcapplusplus/DhcpLayer.h @@ -416,7 +416,7 @@ namespace pcpp */ IPv4Address getValueAsIpAddr() const { - return getValueAs(); + return IPv4Address(getValueAs()); } /** @@ -669,7 +669,7 @@ namespace pcpp */ IPv4Address getClientIpAddress() const { - return getDhcpHeader()->clientIpAddress; + return IPv4Address(getDhcpHeader()->clientIpAddress); } /** @@ -687,7 +687,7 @@ namespace pcpp */ IPv4Address getServerIpAddress() const { - return getDhcpHeader()->serverIpAddress; + return IPv4Address(getDhcpHeader()->serverIpAddress); } /** @@ -704,7 +704,7 @@ namespace pcpp */ IPv4Address getYourIpAddress() const { - return getDhcpHeader()->yourIpAddress; + return IPv4Address(getDhcpHeader()->yourIpAddress); } /** @@ -721,7 +721,7 @@ namespace pcpp */ IPv4Address getGatewayIpAddress() const { - return getDhcpHeader()->gatewayIpAddress; + return IPv4Address(getDhcpHeader()->gatewayIpAddress); } /** diff --git a/Packet++/header/pcapplusplus/IPv4Layer.h b/Packet++/header/pcapplusplus/IPv4Layer.h index 72ffadc2c9..732f45886a 100644 --- a/Packet++/header/pcapplusplus/IPv4Layer.h +++ b/Packet++/header/pcapplusplus/IPv4Layer.h @@ -514,7 +514,7 @@ namespace pcpp */ IPAddress getSrcIPAddress() const override { - return getSrcIPv4Address(); + return IPAddress(getSrcIPv4Address()); } /** @@ -523,7 +523,7 @@ namespace pcpp */ IPv4Address getSrcIPv4Address() const { - return getIPv4Header()->ipSrc; + return IPv4Address(getIPv4Header()->ipSrc); } /** @@ -542,7 +542,7 @@ namespace pcpp */ IPAddress getDstIPAddress() const override { - return getDstIPv4Address(); + return IPAddress(getDstIPv4Address()); } /** @@ -551,7 +551,7 @@ namespace pcpp */ IPv4Address getDstIPv4Address() const { - return getIPv4Header()->ipDst; + return IPv4Address(getIPv4Header()->ipDst); } /** diff --git a/Packet++/header/pcapplusplus/IPv6Layer.h b/Packet++/header/pcapplusplus/IPv6Layer.h index 7f80dfd094..37d11f1deb 100644 --- a/Packet++/header/pcapplusplus/IPv6Layer.h +++ b/Packet++/header/pcapplusplus/IPv6Layer.h @@ -108,7 +108,7 @@ namespace pcpp */ IPAddress getSrcIPAddress() const override { - return getSrcIPv6Address(); + return IPAddress(getSrcIPv6Address()); } /** @@ -117,7 +117,7 @@ namespace pcpp */ IPv6Address getSrcIPv6Address() const { - return getIPv6Header()->ipSrc; + return IPv6Address(getIPv6Header()->ipSrc); } /** @@ -145,7 +145,7 @@ namespace pcpp */ IPAddress getDstIPAddress() const override { - return getDstIPv6Address(); + return IPAddress(getDstIPv6Address()); } /** @@ -154,7 +154,7 @@ namespace pcpp */ IPv6Address getDstIPv6Address() const { - return getIPv6Header()->ipDst; + return IPv6Address(getIPv6Header()->ipDst); } /** diff --git a/Packet++/header/pcapplusplus/IcmpLayer.h b/Packet++/header/pcapplusplus/IcmpLayer.h index 9c9166516d..824e7b23fb 100644 --- a/Packet++/header/pcapplusplus/IcmpLayer.h +++ b/Packet++/header/pcapplusplus/IcmpLayer.h @@ -274,7 +274,7 @@ namespace pcpp */ IPv4Address getAddress() const { - return routerAddress; + return IPv4Address(routerAddress); } }; #pragma pack(pop) diff --git a/Packet++/header/pcapplusplus/IgmpLayer.h b/Packet++/header/pcapplusplus/IgmpLayer.h index 321c46366a..8005119ada 100644 --- a/Packet++/header/pcapplusplus/IgmpLayer.h +++ b/Packet++/header/pcapplusplus/IgmpLayer.h @@ -95,7 +95,7 @@ namespace pcpp */ IPv4Address getMulticastAddress() const { - return multicastAddress; + return IPv4Address(multicastAddress); } /** @@ -189,7 +189,7 @@ namespace pcpp */ IPv4Address getGroupAddress() const { - return getIgmpHeader()->groupAddress; + return IPv4Address(getIgmpHeader()->groupAddress); } /** diff --git a/Packet++/src/TcpLayer.cpp b/Packet++/src/TcpLayer.cpp index d53041dec9..d494395aa7 100644 --- a/Packet++/src/TcpLayer.cpp +++ b/Packet++/src/TcpLayer.cpp @@ -281,7 +281,7 @@ namespace pcpp checksumRes = pcpp::computePseudoHdrChecksum(reinterpret_cast(tcpHdr), getDataLen(), - IPAddress::IPv4AddressType, PACKETPP_IPPROTO_TCP, srcIP, dstIP); + IPAddress::IPv4AddressType, PACKETPP_IPPROTO_TCP, IPAddress(srcIP), IPAddress(dstIP)); PCPP_LOG_DEBUG("calculated IPv4 TCP checksum = 0x" << std::uppercase << std::hex << checksumRes); } @@ -291,7 +291,7 @@ namespace pcpp const IPv6Address dstIP = static_cast(m_PrevLayer)->getDstIPv6Address(); checksumRes = computePseudoHdrChecksum(reinterpret_cast(tcpHdr), getDataLen(), - IPAddress::IPv6AddressType, PACKETPP_IPPROTO_TCP, srcIP, dstIP); + IPAddress::IPv6AddressType, PACKETPP_IPPROTO_TCP, IPAddress(srcIP), IPAddress(dstIP)); PCPP_LOG_DEBUG("calculated IPv6 TCP checksum = 0xX" << std::uppercase << std::hex << checksumRes); } diff --git a/Packet++/src/UdpLayer.cpp b/Packet++/src/UdpLayer.cpp index 34b4f46c1b..981a621c1e 100644 --- a/Packet++/src/UdpLayer.cpp +++ b/Packet++/src/UdpLayer.cpp @@ -62,7 +62,7 @@ namespace pcpp IPv4Address dstIP = ((IPv4Layer*)m_PrevLayer)->getDstIPv4Address(); checksumRes = pcpp::computePseudoHdrChecksum((uint8_t*)udpHdr, getDataLen(), IPAddress::IPv4AddressType, - PACKETPP_IPPROTO_UDP, srcIP, dstIP); + PACKETPP_IPPROTO_UDP, IPAddress(srcIP), IPAddress(dstIP)); PCPP_LOG_DEBUG("calculated IPv4 UDP checksum = 0x" << std::uppercase << std::hex << checksumRes); } @@ -72,7 +72,7 @@ namespace pcpp IPv6Address dstIP = ((IPv6Layer*)m_PrevLayer)->getDstIPv6Address(); checksumRes = computePseudoHdrChecksum((uint8_t*)udpHdr, getDataLen(), IPAddress::IPv6AddressType, - PACKETPP_IPPROTO_UDP, srcIP, dstIP); + PACKETPP_IPPROTO_UDP, IPAddress(srcIP), IPAddress(dstIP)); PCPP_LOG_DEBUG("calculated IPv6 UDP checksum = 0xX" << std::uppercase << std::hex << checksumRes); } diff --git a/Packet++/src/VrrpLayer.cpp b/Packet++/src/VrrpLayer.cpp index e42fe02d4b..e5c49e03ac 100644 --- a/Packet++/src/VrrpLayer.cpp +++ b/Packet++/src/VrrpLayer.cpp @@ -351,10 +351,10 @@ namespace pcpp { if (getAddressType() == IPAddress::IPv4AddressType) { - return IPv4Address(*((uint32_t*)data)); + return IPAddress(IPv4Address(*((uint32_t*)data))); } - return IPv6Address(data); + return IPAddress(IPv6Address(data)); } bool VrrpLayer::isIPAddressValid(IPAddress& ipAddress) const diff --git a/Pcap++/header/pcapplusplus/PcapFileDevice.h b/Pcap++/header/pcapplusplus/PcapFileDevice.h index 8f48787388..a10e6adc7f 100644 --- a/Pcap++/header/pcapplusplus/PcapFileDevice.h +++ b/Pcap++/header/pcapplusplus/PcapFileDevice.h @@ -451,7 +451,7 @@ namespace pcpp * @param[in] nanosecondsPrecision A boolean indicating whether to write timestamps in nano-precision. If set to * false, timestamps will be written in micro-precision */ - PcapFileWriterDevice(const std::string& fileName, LinkLayerType linkLayerType = LINKTYPE_ETHERNET, + explicit PcapFileWriterDevice(const std::string& fileName, LinkLayerType linkLayerType = LINKTYPE_ETHERNET, bool nanosecondsPrecision = false); /**