pub union OsSocketAddr {
/* private fields */
}Expand description
A type for handling platform-native socket addresses (struct sockaddr)
This type has a buffer big enough to hold a libc::sockaddr_in or libc::sockaddr_in6 struct. Its content can be arbitrary written using .as_mut() or .as_mut_ptr().
It also provides the conversion functions:
- from/into
SocketAddr - from
(*const sockaddr, socklen_t) - into
(*mut sockaddr, *mut socklen_t)
See crate level documentation.
Implementations§
Source§impl OsSocketAddr
impl OsSocketAddr
Sourcepub unsafe fn copy_from_raw(ptr: *const sockaddr, len: socklen_t) -> Self
pub unsafe fn copy_from_raw(ptr: *const sockaddr, len: socklen_t) -> Self
Create a new socket address from a raw byte slice
The location pointed by ptr is assumed to hold a struct sockaddr whose length in bytes
is given by len.
Its content is copied into a new OsSocketAddr object. If len is greater than the size
of sockaddr_in6 then the resulting address is truncated. If less, then the extra bytes
are zeroed.
If ptr is NULL, then the resulting address is zeroed.
See also OsSocketAddr::copy_to_raw
Sourcepub unsafe fn from_raw_parts(ptr: *const u8, len: usize) -> Self
👎Deprecated since 0.2.4: use copy_from_raw()
pub unsafe fn from_raw_parts(ptr: *const u8, len: usize) -> Self
Create a new socket address from a raw slice
Sourcepub unsafe fn copy_to_raw(
&self,
ptr: *mut sockaddr,
len: *mut socklen_t,
) -> Result<(), BadFamilyError>
pub unsafe fn copy_to_raw( &self, ptr: *mut sockaddr, len: *mut socklen_t, ) -> Result<(), BadFamilyError>
Copy the socket address into a raw byte slice
The value pointed by len must be initialised with the length in bytes of the buffer
pointed by ptr. On return it contains the actual size of the returned address.
If the provided buffer is too small, then the returned address is truncated (and len will
have a greater value than before the call).
If ptr is NULL then the function does nothing.
If the value of .sa_family does not resolve to AF_INET or AF_INET6 then the function
sets *len to 0 and returns an error.
See also OsSocketAddr::copy_from_raw
Sourcepub fn from(addr: SocketAddr) -> Self
pub fn from(addr: SocketAddr) -> Self
Create a new socket address from a SocketAddr object
Sourcepub fn into_addr(self) -> Option<SocketAddr>
pub fn into_addr(self) -> Option<SocketAddr>
Attempt to convert the internal buffer into a SocketAddr object
The internal buffer is assumed to be a sockaddr.
If the value of .sa_family resolves to AF_INET or AF_INET6 then the buffer is
converted into SocketAddr, otherwise the function returns None.
Sourcepub fn len(&self) -> socklen_t
pub fn len(&self) -> socklen_t
Return the length of the address
The result depends on the value of .sa_family in the internal buffer:
AF_INET-> the size of sockaddr_inAF_INET6-> the size of sockaddr_in6- other -> 0
Sourcepub fn as_mut_ptr(&mut self) -> *mut sockaddr
pub fn as_mut_ptr(&mut self) -> *mut sockaddr
Get a mutable pointer to the internal buffer
Trait Implementations§
Source§impl AsMut<[u8]> for OsSocketAddr
impl AsMut<[u8]> for OsSocketAddr
Source§impl AsRef<[u8]> for OsSocketAddr
impl AsRef<[u8]> for OsSocketAddr
Source§impl Clone for OsSocketAddr
impl Clone for OsSocketAddr
Source§fn clone(&self) -> OsSocketAddr
fn clone(&self) -> OsSocketAddr
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OsSocketAddr
impl Debug for OsSocketAddr
Source§impl From<Option<SocketAddr>> for OsSocketAddr
impl From<Option<SocketAddr>> for OsSocketAddr
Source§fn from(addr: Option<SocketAddr>) -> Self
fn from(addr: Option<SocketAddr>) -> Self
Source§impl From<SocketAddr> for OsSocketAddr
impl From<SocketAddr> for OsSocketAddr
Source§fn from(addr: SocketAddr) -> Self
fn from(addr: SocketAddr) -> Self
Source§impl FromStr for OsSocketAddr
impl FromStr for OsSocketAddr
Source§impl Into<Option<SocketAddr>> for OsSocketAddr
impl Into<Option<SocketAddr>> for OsSocketAddr
Source§fn into(self) -> Option<SocketAddr>
fn into(self) -> Option<SocketAddr>
Attempt to convert the internal buffer into a SocketAddr object
The internal buffer is assumed to be a sockaddr.
If the value of .sa_family resolves to AF_INET or AF_INET6 then the buffer is
converted into SocketAddr, otherwise the function returns None.
Source§impl TryInto<SocketAddr> for OsSocketAddr
impl TryInto<SocketAddr> for OsSocketAddr
Source§fn try_into(self) -> Result<SocketAddr, BadFamilyError>
fn try_into(self) -> Result<SocketAddr, BadFamilyError>
Attempt to convert the internal buffer into a SocketAddr object
The internal buffer is assumed to be a sockaddr.
If the value of .sa_family resolves to AF_INET or AF_INET6 then the buffer is
converted into SocketAddr, otherwise the function returns an error.