#[repr(C)]
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

source

pub fn new() -> Self

Create a new empty socket address (all bytes initialised to 0)

source

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

source

pub unsafe fn from_raw_parts(ptr: *const u8, len: usize) -> Self

👎Deprecated since 0.2.4: use copy_from_raw()

Create a new socket address from a raw slice

source

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

source

pub fn from(addr: SocketAddr) -> Self

Create a new socket address from a SocketAddr object

source

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.

source

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:

source

pub fn capacity(&self) -> socklen_t

Return the size of the internal buffer

source

pub fn as_ptr(&self) -> *const sockaddr

Get a pointer to the internal buffer

source

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

source§

fn as_mut(&mut self) -> &mut [u8]

Get the internal buffer as a mutable slice

source§

impl AsRef<[u8]> for OsSocketAddr

source§

fn as_ref(&self) -> &[u8]

Get the internal buffer as a byte slice

Note: the actual length of slice depends on the value of .sa_family (see .len())

source§

impl Clone for OsSocketAddr

source§

fn clone(&self) -> OsSocketAddr

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for OsSocketAddr

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Option<SocketAddr>> for OsSocketAddr

source§

fn from(addr: Option<SocketAddr>) -> Self

Converts to this type from the input type.
source§

impl From<SocketAddr> for OsSocketAddr

source§

fn from(addr: SocketAddr) -> Self

Converts to this type from the input type.
source§

impl FromStr for OsSocketAddr

§

type Err = AddrParseError

The associated error which can be returned from parsing.
source§

fn from_str(val: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Into<Option<SocketAddr>> for OsSocketAddr

source§

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

source§

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.

§

type Error = BadFamilyError

The type returned in the event of a conversion error.
source§

impl Copy for OsSocketAddr

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.