nix
nix copied to clipboard
convert sockaddr_storage to std::net::SocketAddr
Is there any way to convert either of
libc::sockaddr_storage
nix::sys::socket::sockaddr_storage
to std::net::ScoketAddr?
I have looked into nix::sys::socket::SockaddrStorage but can't find what I am looking for.
No, not directly. You have to pull it apart into pieces and then create a new std::net::SocketAddr using the standard constructors.
No, not directly. You have to pull it apart into pieces and then create a new
std::net::SocketAddrusing the standard constructors.
How?
Can you please point me to any api which converts sockaddr_storage to nix::sys::socket::SockaddrStorage or any other nix type which I can work with?
Thank you,
If you're starting from a libc::sockaddr_storage, then use Nix's SockaddrStorage::from_raw. https://docs.rs/nix/latest/nix/sys/socket/trait.SockaddrLike.html#tymethod.from_raw .
I'm going to close this, assuming that I've answered your question. But feel free to reopen if not.