Skip to content

Making from_libc_sockaddr public? #1663

Closed
@apanda

Description

@apanda

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions