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 a binding for pcap_loop #310

Closed
wants to merge 1 commit into from
Closed

Conversation

saethlin
Copy link
Contributor

@saethlin saethlin commented Oct 5, 2023

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 that tcpdump uses pcap_loop and since said tool is going through this crate, it was using pcap_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 of tcpdump.

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.

Copy link
Contributor

@Stargateur Stargateur left a comment

Choose a reason for hiding this comment

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

name it run (commun for loop in rust lib) instead of loop maybe, but I don't like the pcap in front for sure.

src/lib.rs Outdated Show resolved Hide resolved
self.handle.as_ptr(),
0,
Handler::<F>::callback,
ptr::addr_of_mut!(handler).cast(),
Copy link
Contributor

@Stargateur Stargateur Oct 5, 2023

Choose a reason for hiding this comment

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

I think it's fine but not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you mean to comment on here. Perhaps you mean ptr::addr_of_mut!? If the place it's passed has no projections, then there are no preconditions. And you can even addr_of!(*ptr) for any ptr: rust-lang/reference#1387

src/lib.rs Outdated
impl<T: State + ?Sized> Capture<T> {
pub fn pcap_loop<F>(&mut self, handler: F)
Copy link
Contributor

Choose a reason for hiding this comment

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

this method is unsafe by nature, since it's will call rust from C

src/raw.rs Outdated Show resolved Hide resolved
@Wojtek242
Copy link
Collaborator

Due to significant changes on main since this was proposed, I will close it. If you get around to addressing the comments and adapting to the current code base, I'll be happy to review it.

@Wojtek242 Wojtek242 closed this Feb 25, 2024
@saethlin
Copy link
Contributor Author

sigh I force-pushed to the branch before re-opening the PR which has killed the PR. I'll open a fresh one.

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.

3 participants