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

Making from_libc_sockaddr public? #1663

Closed
apanda opened this issue Feb 14, 2022 · 3 comments
Closed

Making from_libc_sockaddr public? #1663

apanda opened this issue Feb 14, 2022 · 3 comments

Comments

@apanda
Copy link

apanda commented Feb 14, 2022

I was trying to use nix to go from a libc::sockaddr to a std::net::SockAddr. This is useful when using recvmsg to receive data off a UDP socket or when using the equivalent io_uring operations. I notice that from_libc_sockaddr (

pub(crate) unsafe fn from_libc_sockaddr(addr: *const libc::sockaddr) -> Option<SockAddr> {
) implements this functionality, but is marked as crate only. I was wondering if it would acceptable to mark it as public.

The change is of course trivial to make, I wanted to create an issue just to understand if there were concerns around marking it pub. One possible concern I can imagine is that it is marked unsafe at the moment, I imagine this is because of the pointer cast but I have to admit I am not sure how to make it safer because the code already ensures that the passed pointer is not null, so the checks required would need to ensure that the pointer is to a 4-byte allocation, which is non-trivial. On the other hand, maybe unsafe exports are unavoidable from nix and there are already cases, e.g., ptsname (

nix/src/pty.rs

Line 175 in 83cd1da

pub unsafe fn ptsname(fd: &PtyMaster) -> Result<String> {
), where nix exports unsafe code.

The current situation requires that I copy the code into my project (or rewrite a more restricted version), and I want to avoid that if possible. Let me know if this is acceptable and I am happy to submit a PR.

@rtzoeller
Copy link
Collaborator

I don't have any objections to making this public (other than wanting documentation about what is actually supported by it), but I know @asomers is touching SockAddr in changes related to #1544. @asomers any issues making this public?

@asomers
Copy link
Member

asomers commented Mar 5, 2022

Yes, I think the need to make this public will go away once I finish the sockaddr changes. I know I haven't touched that branch in awhile. I'll try to get to it this week, after I reach a stopping point on another project.

@asomers
Copy link
Member

asomers commented Mar 24, 2022

This is public now, as a result of #1684, except it's new name is SockaddrStorage::from_raw.

@asomers asomers closed this as completed Mar 24, 2022
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

No branches or pull requests

3 participants