Union nix::sys::socket::SockaddrStorage
source · #[repr(C)]
pub union SockaddrStorage {
/* private fields */
}
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.as_raw_fd(), &localhost).expect("bind");
let ss: SockaddrStorage = getsockname(fd.as_raw_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_alg_addr(&self) -> Option<&AlgAddr>
pub fn as_alg_addr(&self) -> Option<&AlgAddr>
Safely and falliably downcast to an immutable reference
sourcepub fn as_alg_addr_mut(&mut self) -> Option<&mut AlgAddr>
pub fn as_alg_addr_mut(&mut self) -> Option<&mut AlgAddr>
Safely and falliably downcast to a mutable 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
sourcepub fn as_netlink_addr(&self) -> Option<&NetlinkAddr>
pub fn as_netlink_addr(&self) -> Option<&NetlinkAddr>
Safely and falliably downcast to an immutable reference
sourcepub fn as_netlink_addr_mut(&mut self) -> Option<&mut NetlinkAddr>
pub fn as_netlink_addr_mut(&mut self) -> Option<&mut NetlinkAddr>
Safely and falliably downcast to a mutable reference
sourcepub fn as_vsock_addr(&self) -> Option<&VsockAddr>
pub fn as_vsock_addr(&self) -> Option<&VsockAddr>
Safely and falliably downcast to an immutable reference
sourcepub fn as_vsock_addr_mut(&mut self) -> Option<&mut VsockAddr>
pub fn as_vsock_addr_mut(&mut self) -> Option<&mut VsockAddr>
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
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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
source§impl From<SocketAddrV4> for SockaddrStorage
impl From<SocketAddrV4> for SockaddrStorage
source§fn from(s: SocketAddrV4) -> Self
fn from(s: SocketAddrV4) -> Self
source§impl From<SocketAddrV6> for SockaddrStorage
impl From<SocketAddrV6> for SockaddrStorage
source§fn from(s: SocketAddrV6) -> Self
fn from(s: SocketAddrV6) -> Self
source§impl Hash for SockaddrStorage
impl Hash for SockaddrStorage
source§impl PartialEq for SockaddrStorage
impl PartialEq 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,
source§fn len(&self) -> socklen_t
fn len(&self) -> socklen_t
impl Copy for SockaddrStorage
impl Eq for SockaddrStorage
Auto Trait Implementations§
impl Freeze for SockaddrStorage
impl RefUnwindSafe for SockaddrStorage
impl Send for SockaddrStorage
impl Sync for SockaddrStorage
impl Unpin for SockaddrStorage
impl UnwindSafe for SockaddrStorage
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)