Skip to content

Refactored PcapHandle to utilize std::unique_ptr internally. #1753

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

Closed

Conversation

Dimi1010
Copy link
Collaborator

No description provided.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we have an /internal/ folder for headers that need to be public for compilation but shouldn't be included by users directly?

Copy link
Collaborator

@tigercosmos tigercosmos Mar 28, 2025

Choose a reason for hiding this comment

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

I am okay with the current way, but it's also fine to move the files.

Copy link
Collaborator Author

@Dimi1010 Dimi1010 Mar 28, 2025

Choose a reason for hiding this comment

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

It feels cleaner to have the "internal" public headers separated. That way, we don't have to worry about breaking changes if "internal" files are renamed or moved around due to people directly including them. And if they still do, that is on them.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, I agree with you. Just think we can put effort on more important parts (if there are such things)

Copy link
Collaborator Author

@Dimi1010 Dimi1010 Mar 28, 2025

Choose a reason for hiding this comment

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

Eh, it's possibly not the most important. But since this PR exposes a new public header (PcapUtils.h), that only defines internal symbols, I would prefer to have that decided now instead of maybe having to do a transition later, when it has already been placed next to the user API headers.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it. I don't have strong opion on this. Let see how @seladb says.

Copy link

codecov bot commented Mar 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.20%. Comparing base (5b6a51c) to head (abced57).
Report is 6 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1753      +/-   ##
==========================================
- Coverage   83.21%   83.20%   -0.01%     
==========================================
  Files         282      282              
  Lines       48719    48701      -18     
  Branches    10547    10542       -5     
==========================================
- Hits        40540    40523      -17     
- Misses       7052     7053       +1     
+ Partials     1127     1125       -2     
Flag Coverage Δ
alpine320 75.20% <50.00%> (+<0.01%) ⬆️
fedora40 75.25% <50.00%> (-0.02%) ⬇️
macos-13 80.72% <80.00%> (+<0.01%) ⬆️
macos-14 80.72% <80.00%> (+<0.01%) ⬆️
macos-15 80.69% <80.00%> (+<0.01%) ⬆️
mingw32 70.84% <100.00%> (-0.06%) ⬇️
mingw64 70.80% <100.00%> (-0.06%) ⬇️
npcap 85.24% <100.00%> (-0.08%) ⬇️
rhel94 75.08% <50.00%> (-0.02%) ⬇️
ubuntu2004 58.61% <50.00%> (-0.01%) ⬇️
ubuntu2004-zstd 58.73% <50.00%> (-0.04%) ⬇️
ubuntu2204 75.00% <50.00%> (-0.03%) ⬇️
ubuntu2204-icpx 61.36% <80.00%> (-0.01%) ⬇️
ubuntu2404 75.24% <50.00%> (-0.04%) ⬇️
unittest 83.20% <100.00%> (-0.01%) ⬇️
windows-2019 85.34% <100.00%> (-0.01%) ⬇️
windows-2022 85.36% <100.00%> (-0.02%) ⬇️
winpcap 85.33% <100.00%> (+<0.01%) ⬆️
xdp 50.70% <0.00%> (+<0.01%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Dimi1010 Dimi1010 marked this pull request as ready for review March 28, 2025 12:25
@Dimi1010 Dimi1010 requested a review from seladb as a code owner March 28, 2025 12:25
Copy link
Collaborator

@tigercosmos tigercosmos left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -34,6 +34,7 @@ set(
header/PcapFilter.h
header/PcapLiveDevice.h
header/PcapLiveDeviceList.h
header/PcapUtils.h
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should avoid exposing internal header files like PcapUtils.h.

The reason it is needed is because we use internal::PcapCloseDeleter inside a "public" header file, and we should find a way around it.

I tried using forward declaration of internal::PcapCloseDeleter but couldn't make it work so far. @Dimi1010 maybe you can make it work?

Other options are:

  • Move internal::PcapCloseDeleter to PcapDevice.h - not ideal, but I think it'll work
  • Define m_PcapDescriptor as "no type" like void* and assign the type in the .cpp file. However it's a pretty ugly workaround

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See this as a potential solution. I think this is the cleanest, tbh.
#1753 (comment)

internal::PcapCloseDeleter can't work as a forward declaration here as it is default constructed in the std::unique_ptr so it needs a concrete type.

Copy link
Owner

Choose a reason for hiding this comment

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

I think exposing an internal folder of headers is not a good solution either because exposing header files just because we have some technical limitations is not something we want. I think we should either find a workaround (even if it's not very nice), or just leave the code as it is

Copy link
Collaborator Author

@Dimi1010 Dimi1010 Mar 31, 2025

Choose a reason for hiding this comment

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

I have seen that pattern be used to separate the stable public headers from the unstable ones, that can change at any moment and users shouldn't rely upon. Most notably I have seen it in many boost libraries ("details" folders).

Moving internal::PcapCloseDeleter to PcapDevice.h creates a dependency between PcapFilter.cpp and PcapDevice.h, which I would prefer to not have.

I guess we can leave this as is for now tho.

Copy link
Owner

Choose a reason for hiding this comment

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

If it was "stable" vs "unstable" public API I'd agree that separating them into different folders could work. But exposing a "private API" (internal code) is probably not the best way to go.

I guess leaving it as is is fine if we can find a better solution...

@Dimi1010 Dimi1010 closed this Apr 2, 2025
@Dimi1010 Dimi1010 deleted the reafactor/pcap-close-deleter-pcap-handle branch May 2, 2025 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants