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

no .as_unix_addr() / .as_unix_addr_mut() on SockaddrStorage #1800

Closed
isomer opened this issue Aug 18, 2022 · 2 comments
Closed

no .as_unix_addr() / .as_unix_addr_mut() on SockaddrStorage #1800

isomer opened this issue Aug 18, 2022 · 2 comments

Comments

@isomer
Copy link
Contributor

isomer commented Aug 18, 2022

As above, there's no .as_unix_addr() / .as_unix_addr_mut() methods on SockaddrStorage.

Comparing the list from https://docs.rs/nix/latest/nix/sys/socket/trait.SockaddrLike.html#implementors to https://docs.rs/nix/latest/nix/sys/socket/union.SockaddrStorage.html#implementations :

  • SockAddr deprecated not needed.
  • AlgAddr => as_alg_addr / as_alg_addr_mut
  • LinkAddr => as_link_addr / as_link_addr_mut
  • NetlinkAddr => as_netlink_addr / as_netlink_addr_mut
  • SockaddrIn => as_sockaddr_in / as_sockaddr_in_mut
  • SockaddrIn6 => as_sockaddr_in6 / as_sockaddr_in6_mut
  • UnixAddr => missing
  • VsockAddr => as_vsock_addr / as_vsok_addr_mut
  • SockaddrStorage => identity, not needed.
@asomers-ax
Copy link
Contributor

That's deliberate. Such a method could be implemented on the BSDs. But Linux doesn't have a sun_len field, which means you can't cast a sockaddr_storage to a sockaddr_un without having some other source for information about its valid length.

@asomers
Copy link
Member

asomers commented Dec 10, 2022

Fixed by #1871 . We had to add a sun_len field to the structure on Linux, so it isn't zero-cost anymore. But that enables methods like these.

@asomers asomers closed this as completed Dec 10, 2022
vandry added a commit to vandry/erbium that referenced this issue Dec 28, 2023
Under linux, sockaddr_un does not have a length field, but the nix Rust
wrapper for it does keep track of the length, and this must be managed
correctly or else UnixAddr::path() will return strings that are too
long. Without this change I get either:

Error: Failed to listen on /var/lib/erbium/control<binary garbage>:
path must be shorter than libc::sockaddr_un.sun_path

or

Error: Failed to cleanup /var/lib/erbium/control: file name contained
an unexpected NUL byte

Prior to the resolution of nix-rust/nix#1800
passing the maximum size of a sockaddr_un path was probably the right
thing to do, but now it seems it is no longer correct, and furthermore
there is now a .as_unix_addr() method on SockaddrStorage.
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