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

Centralize code for fetching pcap devices. #1434

Merged
merged 12 commits into from
Jun 8, 2024

Conversation

Dimi1010
Copy link
Collaborator

@Dimi1010 Dimi1010 commented Jun 5, 2024

Part of #1431. Implements point 7.

{
PCPP_LOG_ERROR("Error searching for devices: " << errbuf);
PCPP_LOG_ERROR(e.what());
Copy link
Collaborator

Choose a reason for hiding this comment

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

recommend to have a meaningful error message here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The error messages are actually the same as before. It is just that the DeviceUtil functions have the error messages thrown in a runtime_error as the exception reason and this code catches that and logs the message in the exception.

pcap_if_t* currInterface = interfaceList;
while (currInterface != nullptr)

for (pcap_if_t* currInterface = interfaceList.get(); currInterface != nullptr; currInterface = currInterface->next)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice catch

}
catch (const std::exception& e)
{
PCPP_LOG_ERROR(e.what());
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

Comment on lines 29 to 30
header/DeviceUtils.h
header/MemoryUtils.h
Copy link
Owner

Choose a reason for hiding this comment

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

These 2 new files contain internal utils, so they shouldn't be exposed as part of the API...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Where do you want me to put them then?

Copy link
Owner

Choose a reason for hiding this comment

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

I'm not a CMake expert, but I think there is a way to decide which header files are "public" (meaning exposed as part of PcapPlusPlus API) and which are "private". This may also affect our doxygen API documentation: https://pcapplusplus.github.io/api-docs/next/ (which currently looks at all the header files in Pcap++/header 😕 )

Maybe @clementperon can help here?

Copy link
Collaborator Author

@Dimi1010 Dimi1010 Jun 6, 2024

Choose a reason for hiding this comment

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

Well, removed the headers from the public header list. (fb685bf)

Things appear to be building fine, and the only difference is that the headers are missing from the include folder of the install command output.

Don't know if anything has changed in the docs generation. The CI action still shows that the headers are being parsed.

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 that's ok. For doxygen we probably need to exclude these files in Doxyfile and Doxyfile-ci which are in the web-site repo. Here is how to exclude files:
https://stackoverflow.com/questions/34776315/doxygen-special-command-to-ignore-a-file

Do you want to open a PR for it or prefer I do it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, maybe we can mark the documentation as internal for doxygen in the code?

Something like this: https://stackoverflow.com/a/18443973/11922936
That way the docs won't be generated for the public documentation but it will retain the option for generating internal documentation if we want one in the future.

Copy link
Collaborator Author

@Dimi1010 Dimi1010 Jun 7, 2024

Choose a reason for hiding this comment

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

Enclosed the internal namespace in a conditional doxygen section (617273e). I think this might remove the namespace's contents from the public documentation.

Copy link
Owner

Choose a reason for hiding this comment

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

Nice!! You can test it locally or merge this PR and I'll test it later. It's not a blocker for merging because the documentation isn't final for a non-releases and we can fix it later if needed

Copy link
Collaborator

Choose a reason for hiding this comment

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

let's make it in another PR if necessary.

Pcap++/header/DeviceUtils.h Outdated Show resolved Hide resolved
Pcap++/header/MemoryUtils.h Outdated Show resolved Hide resolved
Copy link
Owner

@seladb seladb left a comment

Choose a reason for hiding this comment

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

See one comment, otherwise LGTM

Pcap++/header/DeviceUtils.h Outdated Show resolved Hide resolved
@tigercosmos tigercosmos merged commit 93eca5b into seladb:dev Jun 8, 2024
39 checks passed
@Dimi1010 Dimi1010 deleted the feature/pcap-device-utils branch June 8, 2024 06:50
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.

Centralize code calling Libpcap/Winpcap/Npcap to fetch devices into a utility header.
3 participants