Skip to content

Commit

Permalink
Fix free and formatting (#1656)
Browse files Browse the repository at this point in the history
  • Loading branch information
vcomito-apexai committed Jan 29, 2025
1 parent 53f681a commit 3d8975d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 35 deletions.
8 changes: 6 additions & 2 deletions Common++/src/SystemUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ namespace pcpp

bool directoryExists(const std::string& dirPath)
{
struct stat info{};
struct stat info
{
};

if (stat(dirPath.c_str(), &info) != 0)
{
Expand Down Expand Up @@ -368,7 +370,9 @@ namespace pcpp
#if defined(_WIN32)
SetConsoleCtrlHandler((PHANDLER_ROUTINE)handlerRoutine, TRUE);
#else
struct sigaction action{};
struct sigaction action
{
};
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler = handlerRoutine;
sigemptyset(&action.sa_mask);
Expand Down
3 changes: 2 additions & 1 deletion Packet++/src/DnsResourceData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ namespace pcpp
{
if (m_DataLen == 0 || m_Data == nullptr)
{
PCPP_LOG_ERROR("Input data is null or illegal" << "|m_DataLen:" << m_DataLen);
PCPP_LOG_ERROR("Input data is null or illegal"
<< "|m_DataLen:" << m_DataLen);
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion Packet++/src/VrrpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ namespace pcpp
auto* ipLayer = m_Packet->getLayerOfType<pcpp::IPLayer>();
if (ipLayer == nullptr)
{
PCPP_LOG_ERROR("Calculate checksum failed, for can not get IPLayer" << "");
PCPP_LOG_ERROR("Calculate checksum failed, for can not get IPLayer"
<< "");
return 0;
}

Expand Down
24 changes: 8 additions & 16 deletions Pcap++/header/PcapLiveDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ namespace pcpp
PCPP_OUT
};

/**
* Set which source provides timestamps associated to each captured packet
* (you can read more here: <https://www.tcpdump.org/manpages/pcap-tstamp.7.html>)
*/
/// Set which source provides timestamps associated to each captured packet
/// (you can read more here: <https://www.tcpdump.org/manpages/pcap-tstamp.7.html>)
enum class TimestampProvider
{
/** host-provided, unknown characteristics, default */
Expand All @@ -189,10 +187,8 @@ namespace pcpp
HostHighPrecUnsynced
};

/**
* Set the precision of timestamps associated to each captured packet
* (you can read more here: <https://www.tcpdump.org/manpages/pcap-tstamp.7.html>)
*/
/// Set the precision of timestamps associated to each captured packet
/// (you can read more here: <https://www.tcpdump.org/manpages/pcap-tstamp.7.html>)
enum class TimestampPrecision
{
/** use timestamps with microsecond precision, default */
Expand Down Expand Up @@ -240,16 +236,12 @@ namespace pcpp
/// In Unix-like system, use poll() for blocking mode.
bool usePoll;

/**
* Set which timestamp provider is used.
* Depending on the capture device and the software on the host, different types of time stamp can be used
*/
/// Set which timestamp provider is used.
/// Depending on the capture device and the software on the host, different types of time stamp can be used
TimestampProvider timestampProvider;

/**
* Set which timestamp precision is used.
* Depending on the capture device and the software on the host, different precision can be used
*/
/// Set which timestamp precision is used.
/// Depending on the capture device and the software on the host, different precision can be used
TimestampPrecision timestampPrecision;

/// A c'tor for this struct
Expand Down
34 changes: 19 additions & 15 deletions Pcap++/src/PcapLiveDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,36 +137,40 @@ namespace pcpp
static bool isTimestampProviderSupportedByDevice(pcap_t* pcap,
const PcapLiveDevice::TimestampProvider timestampProvider)
{
int tstampType = timestampProviderMap(timestampProvider);
int* supportedTstampTypes = nullptr;
const auto tstampType = timestampProviderMap(timestampProvider);

// Use unique_ptr with a custom deleter directly
std::unique_ptr<int[], void (*)(int*)> supportedTstampTypes(nullptr, [](int* ptr) {
if (ptr != nullptr)
{
pcap_free_tstamp_types(ptr);
}
});

const int numSupportedTstampTypes = pcap_list_tstamp_types(pcap, &supportedTstampTypes);

bool isSupported = false;
if (numSupportedTstampTypes < 0)
{
std::cerr << "Error retrieving timestamp types: " << pcap_geterr(pcap) << " - default Host will be used"
<< std::endl;
isSupported = false;
return false;
}
else if (numSupportedTstampTypes == 1)

if (numSupportedTstampTypes == 1)
{
// If 1 is returned, then the only available typestamp is TimestampProvider::Host;
// If 1 is returned, then the only available timestamp is TimestampProvider::Host
return timestampProvider == PcapLiveDevice::TimestampProvider::Host;
}
else

for (int i = 0; i < numSupportedTstampTypes; ++i)
{
for (int i = 0; i < numSupportedTstampTypes; ++i)
if (supportedTstampTypes[i] == tstampType)
{
if (supportedTstampTypes[i] == tstampType)
{
isSupported = true;
break;
}
return true;
}
}

pcap_free_tstamp_types(supportedTstampTypes);
return isSupported;
return false;
}

static void setTimestampProvider(pcap_t* pcap, const PcapLiveDevice::TimestampProvider timestampProvider)
Expand Down

0 comments on commit 3d8975d

Please sign in to comment.