Skip to content

Commit

Permalink
Fix free and formatting (seladb#1656)
Browse files Browse the repository at this point in the history
  • Loading branch information
vcomito-apexai committed Jan 28, 2025
1 parent 01957ac commit 610710d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
24 changes: 8 additions & 16 deletions Pcap++/header/PcapLiveDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,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 @@ -206,10 +204,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 @@ -268,16 +264,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;

/**
Expand Down
34 changes: 19 additions & 15 deletions Pcap++/src/PcapLiveDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,36 +135,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 610710d

Please sign in to comment.