Skip to content

Commit

Permalink
Make PcapPlusPlus compile with YANET's compile options:
Browse files Browse the repository at this point in the history
- Avoid type qualifiers being ignored on function return type [-Werror=ignored-qualifiers]
- Avoid comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare]
- Fix comparison is always true due to limited range of data type [-Werror=type-limits]
- Compile out some constuctors from header files as those were using excepctions, and we have them disabled in dataplane
  • Loading branch information
ol-imorozko committed Dec 26, 2024
1 parent f81ced2 commit 9277125
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion 3rdParty/LightPcapNg/LightPcapNg/include/light_pcapng.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void light_pcapng_historgram(const light_pcapng pcapng, uint32_t (*key_master)(c
int light_get_block_info(const light_pcapng pcapng, light_info info_flag, void *info_data, size_t *data_size);
light_option light_get_option(const light_pcapng pcapng, uint16_t option_code);
uint16_t light_get_option_code(const light_option option);
const light_option light_get_next_option(const light_option option);
light_option light_get_next_option(const light_option option);
uint32_t *light_get_option_data(const light_option option);
uint16_t light_get_option_length(const light_option option);

Expand Down
6 changes: 3 additions & 3 deletions 3rdParty/LightPcapNg/LightPcapNg/src/light_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ light_pcapng light_read_stream(light_pcapng_stream pcapng)
}

// PCPP patch
if (light_read(pcapng->file, &block_type, sizeof(block_type)) == -1 ||
light_read(pcapng->file, &block_total_length, sizeof(block_total_length)) == -1) {
if (light_read(pcapng->file, &block_type, sizeof(block_type)) == (size_t)-1 ||
light_read(pcapng->file, &block_total_length, sizeof(block_total_length)) == (size_t)-1) {
pcapng->valid = 0;
return NULL;
}
Expand All @@ -131,7 +131,7 @@ light_pcapng light_read_stream(light_pcapng_stream pcapng)
block_data[1] = block_total_length;

// PCPP patch
if (light_read(pcapng->file, &block_data[2], block_total_length - 2 * sizeof(uint32_t)) == -1) {
if (light_read(pcapng->file, &block_data[2], block_total_length - 2 * sizeof(uint32_t)) == (size_t)-1) {
free(block_data);
pcapng->valid = 0;
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion 3rdParty/LightPcapNg/LightPcapNg/src/light_option.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ uint16_t light_get_option_code(const light_option option)
return option->custom_option_code;
}

const light_option light_get_next_option(const light_option option)
light_option light_get_next_option(const light_option option)
{
return option->next_option;
}
Expand Down
8 changes: 4 additions & 4 deletions 3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void light_read_record(light_file fd, light_pcapng *record)
//See the block type, if end of file this will tell us
uint32_t blockType, blockSize, bytesRead;
bytesRead = light_read(fd, &blockType, sizeof(blockType));
if (bytesRead != sizeof(blockType) || (bytesRead == EOF && feof(fd->file)))
if (bytesRead != sizeof(blockType) || (bytesRead == (uint32_t)EOF && feof(fd->file)))
{
current = NULL;
return;
Expand All @@ -318,7 +318,7 @@ void light_read_record(light_file fd, light_pcapng *record)

//Get block size
bytesRead = light_read(fd, &current->block_total_length, sizeof(blockSize));
if (bytesRead != sizeof(blockSize) || (bytesRead == EOF && feof(fd->file)))
if (bytesRead != sizeof(blockSize) || (bytesRead == (uint32_t)EOF && feof(fd->file)))
{
free(current);
current = NULL;
Expand All @@ -332,7 +332,7 @@ void light_read_record(light_file fd, light_pcapng *record)
const uint32_t bytesToRead = current->block_total_length - 2 * sizeof(blockSize) - sizeof(blockType);
uint32_t *local_data = calloc(bytesToRead, 1);
bytesRead = light_read(fd, local_data, bytesToRead);
if (bytesRead != bytesToRead || (bytesRead == EOF && feof(fd->file)))
if (bytesRead != bytesToRead || (bytesRead == (uint32_t)EOF && feof(fd->file)))
{
free(current);
free(local_data);
Expand All @@ -343,7 +343,7 @@ void light_read_record(light_file fd, light_pcapng *record)
//Need to move file to next record so read the footer, which is just the record length repeated
bytesRead = light_read(fd, &blockSize, sizeof(blockSize));
//Verify the two sizes match!!
if (blockSize != current->block_total_length || bytesRead != sizeof(blockSize) || (bytesRead == EOF && feof(fd->file)))
if (blockSize != current->block_total_length || bytesRead != sizeof(blockSize) || (bytesRead == (uint32_t)EOF && feof(fd->file)))
{
free(current);
free(local_data);
Expand Down
2 changes: 1 addition & 1 deletion 3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ light_pcapng_t *light_pcapng_open_write(const char* file_path, light_pcapng_file
}

light_pcapng next_block = blocks_to_write;
int i = 0;
size_t i = 0;
for (i = 0; i < file_info->interface_block_count; i++)
{
struct _light_interface_description_block interface_block;
Expand Down
4 changes: 2 additions & 2 deletions 3rdParty/LightPcapNg/LightPcapNg/src/light_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ size_t light_read(light_file fd, void *buf, size_t count)
if (fd->decompression_context == NULL)
{
size_t bytes_read = fread(buf, 1, count, fd->file);
return bytes_read != count ? -1 : bytes_read;
return bytes_read != count ? (size_t)-1 : bytes_read;
}
else
{
Expand All @@ -155,7 +155,7 @@ size_t light_write(light_file fd, const void *buf, size_t count)
if (fd->compression_context == NULL)
{
size_t bytes_written = fwrite(buf, 1, count, fd->file);
return bytes_written != count ? -1 : bytes_written;
return bytes_written != count ? (size_t)-1 : bytes_written;
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions Common++/header/IpAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ namespace pcpp
/// - IP_ADDRESS/NETMASK where IP_ADDRESS is a valid IP address representing the network prefix and NETMASK
/// 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.
#if defined(__cpp_exceptions)
IPNetwork(const std::string& addressAndNetmask)
{
try
Expand All @@ -671,6 +672,7 @@ namespace pcpp
m_IPv6Network = std::unique_ptr<IPv6Network>(new IPv6Network(addressAndNetmask));
}
}
#endif

/// A copy c'tor for this class
/// @param other The instance to copy from
Expand Down
9 changes: 9 additions & 0 deletions Common++/header/MacAddress.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <algorithm>
#include <cstdlib>
#include <initializer_list>
#include <iterator>
#include <ostream>
Expand Down Expand Up @@ -71,7 +72,11 @@ namespace pcpp
{
if (octets.size() != sizeof(m_Address))
{
#if defined(__cpp_exceptions)
throw std::invalid_argument("Invalid initializer list size, should be 6");
#else
std::abort();
#endif
}
std::copy(octets.begin(), octets.end(), std::begin(m_Address));
}
Expand Down Expand Up @@ -100,7 +105,11 @@ namespace pcpp
{
if (octets.size() != sizeof(m_Address))
{
#if defined(__cpp_exceptions)
throw std::invalid_argument("Invalid initializer list size, should be 6");
#else
std::abort();
#endif
}

std::copy(octets.begin(), octets.end(), std::begin(m_Address));
Expand Down
2 changes: 1 addition & 1 deletion Pcap++/src/MBufRawPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace pcpp
}
#endif

MBufRawPacket::MBufRawPacket(const MBufRawPacket& other)
MBufRawPacket::MBufRawPacket(const MBufRawPacket& other) : RawPacket()
{
m_DeleteRawDataAtDestructor = false;
m_MBuf = nullptr;
Expand Down

0 comments on commit 9277125

Please sign in to comment.