Parse unix address from sockaddr without length#2564
Parse unix address from sockaddr without length#2564pronebird wants to merge 2 commits intonix-rust:masterfrom
Conversation
|
What new behavior is enabled, exactly? A test would be helpful to understand your aim. Also, you need a changelog entry. |
That SockaddrStorage::from_raw(sockaddr_un_ptr, None)I think that should work since the length is actually held inside of the pointer and can be obtained automatically. I can add a test and change entry. |
|
There's a reason that it doesn't work. It's deliberate. The purpose of the length argument is to tell Nix how much of the struct is actually initialized. In C, pointers to sockaddrs are often not fully initialized, or even allocated. But reading uninitialized memory in Rust is UB. So that argument is important. |
|
The length argument is The else branch is happily converting the whole range of types, i.e:
So all this functionality is already there and it feels that there is just an omission in |
|
So it seems that the following is not true for all platforms: assert!(
UnixAddr::size() <= mem::size_of::<libc::sockaddr_storage>() as libc::socklen_t
); |
|
I think this could be useful on apple platforms where |
What does this PR do
I noticed that feeding
*const sockaddr_unintoSockaddrStoragewithout length returnsNone. I had impression that it should actually work.However extracting
sa_lenmanually and feeding it intoSockaddrStrorageworks as expected and I am able to cast it toUnixAddrlater on by callingSockaddrStorage::as_unix_addr().Checklist:
CONTRIBUTING.md