#[repr(C)]
pub union SockaddrStorage {
/* private fields */
}
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
sourceimpl SockaddrStorage
impl SockaddrStorage
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
sourceimpl Clone for SockaddrStorage
impl Clone for SockaddrStorage
sourcefn clone(&self) -> SockaddrStorage
fn clone(&self) -> SockaddrStorage
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for SockaddrStorage
impl Debug for SockaddrStorage
sourceimpl Display for SockaddrStorage
impl Display for SockaddrStorage
sourceimpl From<SocketAddr> for SockaddrStorage
impl From<SocketAddr> for SockaddrStorage
sourcefn from(s: SocketAddr) -> Self
fn from(s: SocketAddr) -> Self
Converts to this type from the input type.
sourceimpl From<SocketAddrV4> for SockaddrStorage
impl From<SocketAddrV4> for SockaddrStorage
sourcefn from(s: SocketAddrV4) -> Self
fn from(s: SocketAddrV4) -> Self
Converts to this type from the input type.
sourceimpl From<SocketAddrV6> for SockaddrStorage
impl From<SocketAddrV6> for SockaddrStorage
sourcefn from(s: SocketAddrV6) -> Self
fn from(s: SocketAddrV6) -> Self
Converts to this type from the input type.
sourceimpl Hash for SockaddrStorage
impl Hash for SockaddrStorage
sourceimpl PartialEq<SockaddrStorage> for SockaddrStorage
impl PartialEq<SockaddrStorage> for SockaddrStorage
sourceimpl SockaddrLike for SockaddrStorage
impl SockaddrLike for SockaddrStorage
sourceunsafe 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
sourcefn as_ptr(&self) -> *const sockaddr
fn as_ptr(&self) -> *const sockaddr
Returns a raw pointer to the inner structure. Useful for FFI.
sourcefn family(&self) -> Option<AddressFamily>
fn family(&self) -> Option<AddressFamily>
Return the address family of this socket Read more
impl Copy for SockaddrStorage
impl Eq for SockaddrStorage
Auto Trait Implementations
impl RefUnwindSafe for SockaddrStorage
impl Send for SockaddrStorage
impl Sync for SockaddrStorage
impl Unpin for SockaddrStorage
impl UnwindSafe for SockaddrStorage
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more