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

Fix a bug in calling pselect #394

Merged
merged 1 commit into from
Jan 8, 2020
Merged

Conversation

zhangxp1998
Copy link
Contributor

Per pselect man pages, the kth bit of self.fd_set must be set if we are interested in file descriptor k. libpnet does this once in here, when the datalink receiver/sender is initialized. However, if no descriptors are available during a pselect call, the kernel will clear self.fd_set, and next time when pnet calls pselect, it will pass a fd_set with all bits 0. The kernel will interpret this as "I don't care if any of the file descriptors are available", and will happily return 0 even if there are some packets available. See screenshot, all bits in the fd_set bit mask are set to 0(this is not supposed to happen!).

Xnip2020-01-03_16-46-22

This caused an issue in another rust open source project, see discussion here.

@JuxhinDB
Copy link
Member

JuxhinDB commented Jan 8, 2020

Apologies for the late reply from our end. Looking into this now and will update you shortly.

@zhangxp1998
Copy link
Contributor Author

For reference, linux's implementation sets the bit mask before every pselect call:

libc::FD_SET(self.socket.fd, &mut self.fd_set as *mut libc::fd_set);

@JuxhinDB
Copy link
Member

JuxhinDB commented Jan 8, 2020

This is a nice catch, thanks a lot for fixing it @zhangxp1998. I just went over the diff and have no issues with this. Will be merging shortly :-)

Do you require a version bump?

@zhangxp1998
Copy link
Contributor Author

Do you require a version bump?

Yes please!

@JuxhinDB JuxhinDB merged commit 10f90ce into libpnet:master Jan 8, 2020
@JuxhinDB
Copy link
Member

JuxhinDB commented Jan 8, 2020

@zhangxp1998 -- version bump in progress. Bear with me if I'm a tad slow. :-)

@JuxhinDB JuxhinDB mentioned this pull request Jan 8, 2020
@JuxhinDB
Copy link
Member

JuxhinDB commented Jan 8, 2020

@zhangxp1998 Version has been bumped to 0.25.0

@zhangxp1998
Copy link
Contributor Author

@zhangxp1998 Version has been bumped to 0.25.0

Awesome! Thanks a lot!

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.

None yet

2 participants