-
Notifications
You must be signed in to change notification settings - Fork 149
Add a binding for pcap_loop #335
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
Conversation
On the previous PR, @Stargateur said
I don't agree with this statement. A safe function is only unsound if a call to it can cause safe code to execute UB. Can you explain how the API I'm proposing to add can enable safe code to execute UB? |
I'm not sure what to do about the coverage regression on Windows. I feel like I'm already hacking the metrics to add the panic-path coverage on Linux. Amusingly, cargo-llvm-cov does not agree that this crate has 100% code coverage due to uncovered error paths, but I suppose grcov doesn't understand those. |
Windows doesn't run integration tests due to #275. To fix coverage, please add unit tests to If you don't have a Windows machine you can check that coverage locally by running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saethlin thanks for the contribution! I have now also looked at the code (only two minor comments) and I would be happy to merge it once all the issues, including unit tests, are resolved.
The unit tests are a new addition to allow this repo to test Windows without running integration tests which cause most pipelines to fail due to an error that doesn't seem to be an issue outside of CI (#275). Since they're new, I expect some teething pains so I'm happy to help out in their prep. My suggestion would be to first look at the other tests in the module as they all have a similar predictable pattern.
I also agree with your comment about unsafe
. This function itself does not need to be unsafe
.
if you catch unwind in the function like you did I think it should be safe. Unfortunately I expect some cost in runtime for this. |
That's a good question. Currently I can't figure out what I'd change about this codegen though: https://godbolt.org/z/xe7xzEeTa It's just a straight call and return on the non-panicking path. Perhaps there's some inlining impact, but it also looks like all the code falls away if we compile with aborting panics. |
ping @Wojtek242 I don't know how you manage your review queue so I'm generating a notification for you in case that's how. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @Wojtek242 I don't know how you manage your review queue so I'm generating a notification for you in case that's how.
Thanks for the ping! I wasn't sure if you're done with the changes. The changes so far look good, but you still haven't handled the return code of pcap_loop
. Is that something you think you could still handle? The rest looks good to me as is.
Right! I gave it a shot. It's not clear to me how errors from the library are supposed to be handled; I see |
It looks like CI is trying to update
|
The changes look good to me! Yea, I've seen the rustup failures on windows on the nightly CI. I have no idea why they decided to fail now all of a sudden. Either way that won't block this PR. I'll merge this soon-ish when I'll also have some time to push an update to crates. |
They're probably failing because there was recently a rustup release. Previously, the code wouldn't try to actually update the binary. https://blog.rust-lang.org/2024/03/11/Rustup-1.27.0.html |
Resuming #310
I recently ran into a situation where a tool I help maintain and
tcpdump
had different behavior with a somewhat exotic libpcap implementation. I eventually tracked this down to the fact thattcpdump
usespcap_loop
and since said tool is going through this crate, it was usingpcap_next_ex
. This difference was actually a bug in the libpcap implementation, I spent a frustrating amount of time convincing people that the bug was in libpcap, because I couldn't closely imitate the libpcap calls oftcpdump
.Since that time, I've been wanting a way to call
pcap_loop
from this crate, because that would have made my life a lot easier. So I finally got around to putting one together, here it is.I don't really care about the public API. Ideas like a better name are very welcome.