diff --git a/Packet++/header/IPv4Layer.h b/Packet++/header/IPv4Layer.h index b987090224..7e1e826333 100644 --- a/Packet++/header/IPv4Layer.h +++ b/Packet++/header/IPv4Layer.h @@ -242,9 +242,9 @@ namespace pcpp if (dataSize < 2) return res; - uint8_t valueOffset = (uint8_t)(1); + uint8_t valueOffset = static_cast(1); - while ((size_t)valueOffset < dataSize) + while (static_cast(valueOffset) < dataSize) { uint32_t curValue; memcpy(&curValue, m_Data->recordValue + valueOffset, sizeof(uint32_t)); @@ -253,7 +253,7 @@ namespace pcpp res.push_back(IPv4Address(curValue)); - valueOffset += (uint8_t)(4); + valueOffset += static_cast(4); } return res; @@ -281,12 +281,12 @@ namespace pcpp if (dataSize < 2) return res; - res.type = (IPv4TimestampOptionValue::TimestampType)m_Data->recordValue[1]; + res.type = static_cast(m_Data->recordValue[1]); - uint8_t valueOffset = (uint8_t)(2); + uint8_t valueOffset = static_cast(2); bool readIPAddr = (res.type == IPv4TimestampOptionValue::TimestampAndIP); - while ((size_t)valueOffset < dataSize) + while (static_cast(valueOffset) < dataSize) { uint32_t curValue; memcpy(&curValue, m_Data->recordValue + valueOffset, sizeof(uint32_t)); @@ -301,7 +301,7 @@ namespace pcpp if (res.type == IPv4TimestampOptionValue::TimestampAndIP) readIPAddr = !readIPAddr; - valueOffset += (uint8_t)(4); + valueOffset += static_cast(4); } return res; @@ -323,14 +323,14 @@ namespace pcpp */ static bool canAssign(const uint8_t* recordRawData, size_t tlvDataLen) { - auto data = (TLVRawData*)recordRawData; + auto data = reinterpret_cast(recordRawData); if (data == nullptr) return false; if (tlvDataLen < sizeof(TLVRawData::recordType)) return false; - if (getIPv4OptionType(data) == (uint8_t)IPV4OPT_EndOfOptionsList || data->recordType == (uint8_t)IPV4OPT_NOP) + if (getIPv4OptionType(data) == static_cast(IPV4OPT_EndOfOptionsList) || data->recordType == static_cast(IPV4OPT_NOP)) return true; return TLVRecord::canAssign(recordRawData, tlvDataLen); @@ -343,10 +343,10 @@ namespace pcpp if (m_Data == nullptr) return 0; - if (getIPv4OptionType() == (uint8_t)IPV4OPT_EndOfOptionsList || m_Data->recordType == (uint8_t)IPV4OPT_NOP) + if (getIPv4OptionType() == static_cast(IPV4OPT_EndOfOptionsList) || m_Data->recordType == static_cast(IPV4OPT_NOP)) return sizeof(uint8_t); - return (size_t)m_Data->recordLen; + return static_cast(m_Data->recordLen); } size_t getDataSize() const @@ -354,10 +354,10 @@ namespace pcpp if (m_Data == nullptr) return 0; - if (getIPv4OptionType() == (uint8_t)IPV4OPT_EndOfOptionsList || m_Data->recordType == (uint8_t)IPV4OPT_NOP) - return (size_t)0; + if (getIPv4OptionType() == static_cast(IPV4OPT_EndOfOptionsList) || m_Data->recordType == static_cast(IPV4OPT_NOP)) + return 0; - return (size_t)m_Data->recordLen - (2*sizeof(uint8_t)); + return static_cast(m_Data->recordLen) - (2*sizeof(uint8_t)); } private: @@ -369,7 +369,7 @@ namespace pcpp if (data == nullptr) return IPV4OPT_Unknown; - return (IPv4OptionTypes)data->recordType; + return static_cast(data->recordType); } }; @@ -637,7 +637,7 @@ namespace pcpp /** * @return Size of IPv4 header (including IPv4 options if exist) */ - size_t getHeaderLen() const { return (size_t)((uint16_t)(getIPv4Header()->internetHeaderLength) * 4) + m_TempHeaderExtension; } + size_t getHeaderLen() const { return static_cast(static_cast(getIPv4Header()->internetHeaderLength) * 4) + m_TempHeaderExtension; } /** * Calculate the following fields: diff --git a/Packet++/header/IPv6Layer.h b/Packet++/header/IPv6Layer.h index 584dbcae76..f603083d59 100644 --- a/Packet++/header/IPv6Layer.h +++ b/Packet++/header/IPv6Layer.h @@ -231,19 +231,19 @@ namespace pcpp while (curExt != NULL && dynamic_cast(curExt) == NULL) curExt = curExt->getNextHeader(); - return (TIPv6Extension*)curExt; + return static_cast(curExt); } template TIPv6Extension* IPv6Layer::addExtension(const TIPv6Extension& extensionHeader) { - int offsetToAddHeader = (int)getHeaderLen(); + int offsetToAddHeader = static_cast(getHeaderLen()); if (!extendLayer(offsetToAddHeader, extensionHeader.getExtensionLen())) { return NULL; } - TIPv6Extension* newHeader = new TIPv6Extension(this, (size_t)offsetToAddHeader); + TIPv6Extension* newHeader = new TIPv6Extension(this, static_cast(offsetToAddHeader)); (*newHeader) = extensionHeader; if (m_FirstExtension != NULL) diff --git a/Packet++/src/IPv6Layer.cpp b/Packet++/src/IPv6Layer.cpp index 72d97657a8..f6b5d78546 100644 --- a/Packet++/src/IPv6Layer.cpp +++ b/Packet++/src/IPv6Layer.cpp @@ -187,8 +187,7 @@ void IPv6Layer::removeAllExtensions() bool IPv6Layer::isFragment() const { - IPv6FragmentationHeader* fragHdr = getExtensionOfType(); - return (fragHdr != nullptr); + return getExtensionOfType() != nullptr; } void IPv6Layer::parseNextLayer() diff --git a/Pcap++/header/PcapLiveDevice.h b/Pcap++/header/PcapLiveDevice.h index d6dd5756d3..e4b88ba2f0 100644 --- a/Pcap++/header/PcapLiveDevice.h +++ b/Pcap++/header/PcapLiveDevice.h @@ -438,7 +438,7 @@ namespace pcpp * @param[in] packetPayloadLength The length of the IP layer of the packet * @return True if the packetPayloadLength is less than or equal to the device MTU */ - bool doMtuCheck(int packetPayloadLength); + bool doMtuCheck(int packetPayloadLength) const; /** * Send a RawPacket to the network diff --git a/Pcap++/src/PcapLiveDevice.cpp b/Pcap++/src/PcapLiveDevice.cpp index e368d71b5a..7a55a0a2bf 100644 --- a/Pcap++/src/PcapLiveDevice.cpp +++ b/Pcap++/src/PcapLiveDevice.cpp @@ -75,7 +75,7 @@ static pcap_direction_t directionTypeMap(PcapLiveDevice::PcapDirection direction PcapLiveDevice::PcapLiveDevice(pcap_if_t* pInterface, bool calculateMTU, bool calculateMacAddress, bool calculateDefaultGateway) : - IPcapDevice(), m_PcapSelectableFd(-1), m_DefaultGateway(IPv4Address::Zero), m_UsePoll(false) + IPcapDevice(), m_PcapSendDescriptor(nullptr), m_PcapSelectableFd(-1), m_DefaultGateway(IPv4Address::Zero), m_UsePoll(false) { m_DeviceMtu = 0; m_LinkType = LINKTYPE_ETHERNET; @@ -677,7 +677,7 @@ void PcapLiveDevice::getStatistics(PcapStats& stats) const stats.packetsDropByInterface = pcapStats.ps_ifdrop; } -bool PcapLiveDevice::doMtuCheck(int packetPayloadLength) +bool PcapLiveDevice::doMtuCheck(int packetPayloadLength) const { if (packetPayloadLength > static_cast(m_DeviceMtu)) { diff --git a/Pcap++/src/PcapRemoteDevice.cpp b/Pcap++/src/PcapRemoteDevice.cpp index b08733f10c..ac1ae9c46a 100644 --- a/Pcap++/src/PcapRemoteDevice.cpp +++ b/Pcap++/src/PcapRemoteDevice.cpp @@ -119,7 +119,7 @@ void PcapRemoteDevice::getStatistics(PcapStats& stats) const return; } stats.packetsRecv = tempStats->ps_capt; - stats.packetsDrop = tempStats->ps_drop + tempStats->ps_netdrop; + stats.packetsDrop = static_cast(tempStats->ps_drop) + tempStats->ps_netdrop; stats.packetsDropByInterface = tempStats->ps_ifdrop; }