Skip to content

Commit

Permalink
explicit for CPPcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
clementperon committed Oct 6, 2024
1 parent 11a2699 commit 9ccfe50
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 43 deletions.
24 changes: 12 additions & 12 deletions Common++/header/pcapplusplus/IpAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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<uint8_t, 4>& bytes) : m_Bytes(bytes)
explicit IPv4Address(const std::array<uint8_t, 4>& bytes) : m_Bytes(bytes)
{}

/**
Expand All @@ -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
Expand Down Expand Up @@ -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));
}
Expand All @@ -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<uint8_t, 16>& bytes) : m_Bytes(bytes)
explicit IPv6Address(const std::array<uint8_t, 16>& bytes) : m_Bytes(bytes)
{}

/**
Expand All @@ -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
Expand Down Expand Up @@ -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)
{}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion Common++/header/pcapplusplus/MacAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace pcpp
* @param[in] addr the string representing the MAC address in format "00:00:00:00:00:00"
*/
template <typename T, typename = typename std::enable_if<std::is_convertible<T, std::string>::value>::type>
MacAddress(const T& addr) : MacAddress(static_cast<std::string>(addr))
explicit MacAddress(const T& addr) : MacAddress(static_cast<std::string>(addr))
{}

/**
Expand Down
10 changes: 5 additions & 5 deletions Common++/src/IpAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(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
Expand Down Expand Up @@ -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
Expand All @@ -514,7 +514,7 @@ namespace pcpp
result[byteIndex] = m_NetworkPrefix[byteIndex] | ~m_Mask[byteIndex];
}

return result;
return IPv6Address(result);
}

uint64_t IPv6Network::getTotalAddressCount() const
Expand Down
4 changes: 2 additions & 2 deletions Packet++/header/pcapplusplus/ArpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace pcpp
*/
inline IPv4Address getSenderIpAddr() const
{
return getArpHeader()->senderIpAddr;
return IPv4Address(getArpHeader()->senderIpAddr);
}

/**
Expand All @@ -128,7 +128,7 @@ namespace pcpp
*/
inline IPv4Address getTargetIpAddr() const
{
return getArpHeader()->targetIpAddr;
return IPv4Address(getArpHeader()->targetIpAddr);
}

// implement abstract methods
Expand Down
10 changes: 5 additions & 5 deletions Packet++/header/pcapplusplus/DhcpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ namespace pcpp
*/
IPv4Address getValueAsIpAddr() const
{
return getValueAs<uint32_t>();
return IPv4Address(getValueAs<uint32_t>());
}

/**
Expand Down Expand Up @@ -669,7 +669,7 @@ namespace pcpp
*/
IPv4Address getClientIpAddress() const
{
return getDhcpHeader()->clientIpAddress;
return IPv4Address(getDhcpHeader()->clientIpAddress);
}

/**
Expand All @@ -687,7 +687,7 @@ namespace pcpp
*/
IPv4Address getServerIpAddress() const
{
return getDhcpHeader()->serverIpAddress;
return IPv4Address(getDhcpHeader()->serverIpAddress);
}

/**
Expand All @@ -704,7 +704,7 @@ namespace pcpp
*/
IPv4Address getYourIpAddress() const
{
return getDhcpHeader()->yourIpAddress;
return IPv4Address(getDhcpHeader()->yourIpAddress);
}

/**
Expand All @@ -721,7 +721,7 @@ namespace pcpp
*/
IPv4Address getGatewayIpAddress() const
{
return getDhcpHeader()->gatewayIpAddress;
return IPv4Address(getDhcpHeader()->gatewayIpAddress);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions Packet++/header/pcapplusplus/IPv4Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ namespace pcpp
*/
IPAddress getSrcIPAddress() const override
{
return getSrcIPv4Address();
return IPAddress(getSrcIPv4Address());
}

/**
Expand All @@ -523,7 +523,7 @@ namespace pcpp
*/
IPv4Address getSrcIPv4Address() const
{
return getIPv4Header()->ipSrc;
return IPv4Address(getIPv4Header()->ipSrc);
}

/**
Expand All @@ -542,7 +542,7 @@ namespace pcpp
*/
IPAddress getDstIPAddress() const override
{
return getDstIPv4Address();
return IPAddress(getDstIPv4Address());
}

/**
Expand All @@ -551,7 +551,7 @@ namespace pcpp
*/
IPv4Address getDstIPv4Address() const
{
return getIPv4Header()->ipDst;
return IPv4Address(getIPv4Header()->ipDst);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions Packet++/header/pcapplusplus/IPv6Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace pcpp
*/
IPAddress getSrcIPAddress() const override
{
return getSrcIPv6Address();
return IPAddress(getSrcIPv6Address());
}

/**
Expand All @@ -117,7 +117,7 @@ namespace pcpp
*/
IPv6Address getSrcIPv6Address() const
{
return getIPv6Header()->ipSrc;
return IPv6Address(getIPv6Header()->ipSrc);
}

/**
Expand Down Expand Up @@ -145,7 +145,7 @@ namespace pcpp
*/
IPAddress getDstIPAddress() const override
{
return getDstIPv6Address();
return IPAddress(getDstIPv6Address());
}

/**
Expand All @@ -154,7 +154,7 @@ namespace pcpp
*/
IPv6Address getDstIPv6Address() const
{
return getIPv6Header()->ipDst;
return IPv6Address(getIPv6Header()->ipDst);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/pcapplusplus/IcmpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ namespace pcpp
*/
IPv4Address getAddress() const
{
return routerAddress;
return IPv4Address(routerAddress);
}
};
#pragma pack(pop)
Expand Down
4 changes: 2 additions & 2 deletions Packet++/header/pcapplusplus/IgmpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace pcpp
*/
IPv4Address getMulticastAddress() const
{
return multicastAddress;
return IPv4Address(multicastAddress);
}

/**
Expand Down Expand Up @@ -189,7 +189,7 @@ namespace pcpp
*/
IPv4Address getGroupAddress() const
{
return getIgmpHeader()->groupAddress;
return IPv4Address(getIgmpHeader()->groupAddress);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Packet++/src/TcpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ namespace pcpp

checksumRes =
pcpp::computePseudoHdrChecksum(reinterpret_cast<uint8_t*>(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);
}
Expand All @@ -291,7 +291,7 @@ namespace pcpp
const IPv6Address dstIP = static_cast<IPv6Layer*>(m_PrevLayer)->getDstIPv6Address();

checksumRes = computePseudoHdrChecksum(reinterpret_cast<uint8_t*>(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);
}
Expand Down
4 changes: 2 additions & 2 deletions Packet++/src/UdpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions Packet++/src/VrrpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Pcap++/header/pcapplusplus/PcapFileDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down

0 comments on commit 9ccfe50

Please sign in to comment.