Union nix::sys::socket::SockaddrStorage
source · #[repr(C)]
pub union SockaddrStorage {
/* private fields */
}
Available on crate feature
socket
only.Expand description
A container for any sockaddr type
Just like C’s sockaddr_storage
, this type is large enough to hold any type
of sockaddr. It can be used as an argument with functions like
bind
and getsockname
. Though it is
a union, it can be safely accessed through the as_*
methods.
Example
let localhost = SockaddrIn::from_str("127.0.0.1:8081").unwrap();
let fd = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(),
None).unwrap();
bind(fd, &localhost).expect("bind");
let ss: SockaddrStorage = getsockname(fd).expect("getsockname");
assert_eq!(&localhost, ss.as_sockaddr_in().unwrap());
Implementations§
source§impl SockaddrStorage
impl SockaddrStorage
sourcepub fn as_unix_addr(&self) -> Option<&UnixAddr>
pub fn as_unix_addr(&self) -> Option<&UnixAddr>
Downcast to an immutable [UnixAddr]
reference.
sourcepub fn as_unix_addr_mut(&mut self) -> Option<&mut UnixAddr>
pub fn as_unix_addr_mut(&mut self) -> Option<&mut UnixAddr>
Downcast to a mutable [UnixAddr]
reference.
sourcepub fn as_link_addr(&self) -> Option<&LinkAddr>
pub fn as_link_addr(&self) -> Option<&LinkAddr>
Safely and falliably downcast to an immutable reference
sourcepub fn as_link_addr_mut(&mut self) -> Option<&mut LinkAddr>
pub fn as_link_addr_mut(&mut self) -> Option<&mut LinkAddr>
Safely and falliably downcast to a mutable reference
sourcepub fn as_sockaddr_in(&self) -> Option<&SockaddrIn>
pub fn as_sockaddr_in(&self) -> Option<&SockaddrIn>
Safely and falliably downcast to an immutable reference
sourcepub fn as_sockaddr_in_mut(&mut self) -> Option<&mut SockaddrIn>
pub fn as_sockaddr_in_mut(&mut self) -> Option<&mut SockaddrIn>
Safely and falliably downcast to a mutable reference
sourcepub fn as_sockaddr_in6(&self) -> Option<&SockaddrIn6>
pub fn as_sockaddr_in6(&self) -> Option<&SockaddrIn6>
Safely and falliably downcast to an immutable reference
sourcepub fn as_sockaddr_in6_mut(&mut self) -> Option<&mut SockaddrIn6>
pub fn as_sockaddr_in6_mut(&mut self) -> Option<&mut SockaddrIn6>
Safely and falliably downcast to a mutable reference
Trait Implementations§
source§impl Clone for SockaddrStorage
impl Clone for SockaddrStorage
source§fn clone(&self) -> SockaddrStorage
fn clone(&self) -> SockaddrStorage
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for SockaddrStorage
impl Debug for SockaddrStorage
source§impl Display for SockaddrStorage
impl Display for SockaddrStorage
source§impl From<SocketAddr> for SockaddrStorage
impl From<SocketAddr> for SockaddrStorage
source§fn from(s: SocketAddr) -> Self
fn from(s: SocketAddr) -> Self
Converts to this type from the input type.
source§impl From<SocketAddrV4> for SockaddrStorage
impl From<SocketAddrV4> for SockaddrStorage
source§fn from(s: SocketAddrV4) -> Self
fn from(s: SocketAddrV4) -> Self
Converts to this type from the input type.
source§impl From<SocketAddrV6> for SockaddrStorage
impl From<SocketAddrV6> for SockaddrStorage
source§fn from(s: SocketAddrV6) -> Self
fn from(s: SocketAddrV6) -> Self
Converts to this type from the input type.
source§impl Hash for SockaddrStorage
impl Hash for SockaddrStorage
source§impl PartialEq<SockaddrStorage> for SockaddrStorage
impl PartialEq<SockaddrStorage> for SockaddrStorage
source§impl SockaddrLike for SockaddrStorage
impl SockaddrLike for SockaddrStorage
source§unsafe fn from_raw(addr: *const sockaddr, l: Option<socklen_t>) -> Option<Self>where
Self: Sized,
unsafe fn from_raw(addr: *const sockaddr, l: Option<socklen_t>) -> Option<Self>where
Self: Sized,
Unsafe constructor from a variable length source Read more
source§fn len(&self) -> socklen_t
fn len(&self) -> socklen_t
Return the length of valid data in the sockaddr structure. Read more