Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for timestamp related options (#1656) #1657

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

vcomito-apexai
Copy link

@vcomito-apexai vcomito-apexai commented Dec 10, 2024

As described by #1656

@seladb would it be possible to enable the CI?

@@ -308,6 +340,34 @@ namespace pcpp
}
#endif

if (config.timestampProvider)
{
ret = pcap_set_tstamp_type(pcap, timestampProviderMap(config.timestampProvider));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to libpcap docs we should first call pcap_list_tstamp_types to figure out which type are possible for this device. I'm not sure what happens if we set a type that isn't supported...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seladb the behavior is described here:
https://www.tcpdump.org/manpages/libpcap-1.10.5/pcap_set_tstamp_type.3pcap.html

if I read it correctly, this means that:

  1. the error will be printed
  2. the default timestamp type will be used.

Let me know if you prefer to add the check and e.g. throw an exception if the timestamp is not supported

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vcomito-apexai ! I think it's ok to log an error

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added @seladb

Pcap++/header/PcapLiveDevice.h Outdated Show resolved Hide resolved
Pcap++/header/PcapLiveDevice.h Outdated Show resolved Hide resolved
@vcomito-apexai vcomito-apexai force-pushed the 1656-add-hardware-timestamp-config-support branch from 2ead59f to 2b27626 Compare December 10, 2024 15:24
@egecetin egecetin linked an issue Dec 10, 2024 that may be closed by this pull request
@vcomito-apexai
Copy link
Author

@seladb @Dimi1010

It seems that clang-tidy finds issues unrelated to this PR https://github.com/seladb/PcapPlusPlus/pull/1657/checks

How may I address those? In a separate PR?

@vcomito-apexai vcomito-apexai force-pushed the 1656-add-hardware-timestamp-config-support branch from 2b27626 to be0c2a8 Compare December 11, 2024 07:12
@vcomito-apexai vcomito-apexai force-pushed the 1656-add-hardware-timestamp-config-support branch from be0c2a8 to 01957ac Compare December 11, 2024 07:44
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 27.14286% with 51 lines in your changes missing coverage. Please review.

Project coverage is 83.08%. Comparing base (f81ced2) to head (01957ac).

Files with missing lines Patch % Lines
Pcap++/src/PcapLiveDevice.cpp 25.00% 48 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1657      +/-   ##
==========================================
- Coverage   83.16%   83.08%   -0.09%     
==========================================
  Files         277      277              
  Lines       48193    48263      +70     
  Branches     9966    10222     +256     
==========================================
+ Hits        40080    40097      +17     
- Misses       7234     7267      +33     
- Partials      879      899      +20     
Flag Coverage Δ
alpine320 75.09% <20.58%> (-0.07%) ⬇️
fedora40 75.12% <20.58%> (-0.08%) ⬇️
macos-13 80.57% <21.31%> (-0.09%) ⬇️
macos-14 80.57% <21.31%> (-0.09%) ⬇️
macos-15 80.54% <21.31%> (-0.09%) ⬇️
mingw32 70.88% <50.00%> (-0.04%) ⬇️
mingw64 70.82% <50.00%> (-0.06%) ⬇️
npcap 85.29% <66.66%> (-0.03%) ⬇️
rhel94 74.95% <20.58%> (-0.08%) ⬇️
ubuntu2004 58.57% <17.64%> (-0.05%) ⬇️
ubuntu2004-zstd 58.69% <17.64%> (-0.05%) ⬇️
ubuntu2204 74.90% <20.58%> (-0.07%) ⬇️
ubuntu2204-icpx 61.27% <16.39%> (-0.18%) ⬇️
ubuntu2404 75.12% <20.58%> (-0.08%) ⬇️
unittest 83.08% <27.14%> (-0.09%) ⬇️
windows-2019 85.32% <66.66%> (-0.03%) ⬇️
windows-2022 85.35% <66.66%> (-0.03%) ⬇️
winpcap 85.31% <66.66%> (-0.02%) ⬇️
xdp 50.47% <0.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vcomito-apexai
Copy link
Author

@seladb @Dimi1010

It seems that clang-tidy finds issues unrelated to this PR https://github.com/seladb/PcapPlusPlus/pull/1657/checks

How may I address those? In a separate PR?

ah, appearently they are fixed after rebase 👌

@vcomito-apexai
Copy link
Author

@seladb @Dimi1010
It seems that clang-tidy finds issues unrelated to this PR https://github.com/seladb/PcapPlusPlus/pull/1657/checks
How may I address those? In a separate PR?

ah, appearently they are fixed after rebase 👌

Hello @seladb @Dimi1010

Any more changes I should apply to the PR :) ?

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not have to free supportedTstampTypes here?

{
int tstampType = timestampProviderMap(timestampProvider);
int* supportedTstampTypes = nullptr;
const int numSupportedTstampTypes = pcap_list_tstamp_types(pcap, &supportedTstampTypes);
Copy link
Collaborator

@Dimi1010 Dimi1010 Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be useful to wrap supportedTstampTypes into a std::unique_ptr with a custom deleter, as that would handle the deallocation automatically when the ptr goes out of scope.

static bool isTimestampProviderSupportedByDevice(pcap_t* pcap,
const PcapLiveDevice::TimestampProvider timestampProvider)
{
int tstampType = timestampProviderMap(timestampProvider);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can use auto instead of int

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't actually save you much in this case tho, does it? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add config support for libpcap hardware timestamp
3 participants