rust-pcap / pcap

Rust language pcap library
Apache License 2.0
620 stars 144 forks source link

Make all methods for constructing objects out of RawFd or raw pointers unsafe #143

Closed Wojtek242 closed 3 years ago

Wojtek242 commented 4 years ago

As per #127, constructing objects out of a RawFd is unsafe as the objects assume they are the sole owner of the file descriptor. This mimics the design of the FromRawFd trait. However, I decided not to implement that trait because

If the trait is preferable in the future, we can think about it.

Closes #127.

Wojtek242 commented 3 years ago

Hi @sekineh, thanks for the review! I have updated the code now, but I now also made all functions that take a raw pointer unsafe as well. After all these functions cannot guarantee that the pointers point to valid memory. I was inspired by #81 and I figured that I might as well make sure all unsafety is done correctly.

I'm new to this whole unsafe thing (I rarely wrote code where my own functions were unsafe) so I hope the changes are justified (hence asking for a new review).