Struct os_socketaddr::OsSocketAddr
[−]
[src]
pub struct OsSocketAddr { /* fields omitted */ }
A type for handling platform-native socket addresses (struct sockaddr
)
This type holds a buffer enough big to have 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 std::net::SocketAddr
.
See module level documentation for more details.
Methods
impl OsSocketAddr
[src]
pub fn new() -> Self
[src]
Create a new empty socket address
pub unsafe fn from_raw_parts(ptr: *const u8, len: usize) -> Self
[src]
Create a new socket address from a raw slice
Panics
Panics if len
is bigger that the size of libc::sockaddr_in6
pub fn from(addr: SocketAddr) -> Self
[src]
Create a new socket address from a std::net::SocketAddr
object
pub fn into_addr(self) -> Option<SocketAddr>
[src]
Attempt to convert the internal buffer into a std::net::SocketAddr
object
The internal buffer is assumed to be a libc::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.
pub fn len(&self) -> socklen_t
[src]
Return the length of the address
The result depends on the value of .sa_family
in the internal buffer:
AF_INET
-> the size ofsockaddr_in
AF_INET6
-> the size ofsockaddr_in6
- other -> 0
pub fn capacity(&self) -> socklen_t
[src]
Return the size of the internal buffer
pub fn as_ptr(&self) -> *const sockaddr
[src]
Get a pointer to the internal buffer
pub fn as_mut_ptr(&mut self) -> *mut sockaddr
[src]
Get a mutable pointer to the internal buffer
Trait Implementations
impl Copy for OsSocketAddr
[src]
impl Clone for OsSocketAddr
[src]
fn clone(&self) -> OsSocketAddr
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl AsRef<[u8]> for OsSocketAddr
[src]
fn as_ref(&self) -> &[u8]
[src]
Get the internal buffer as a byte slice
Note: the actual length of slice depends on the value of .sa_family
(see .len()
)
impl AsMut<[u8]> for OsSocketAddr
[src]
impl Into<Option<SocketAddr>> for OsSocketAddr
[src]
fn into(self) -> Option<SocketAddr>
[src]
Attempt to convert the internal buffer into a std::net::SocketAddr
object
The internal buffer is assumed to be a libc::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.
impl From<SocketAddr> for OsSocketAddr
[src]
fn from(addr: SocketAddr) -> Self
[src]
Performs the conversion.
impl From<Option<SocketAddr>> for OsSocketAddr
[src]
fn from(addr: Option<SocketAddr>) -> Self
[src]
Performs the conversion.