Trait AsSocketAddress

Source
pub unsafe trait AsSocketAddress: Sized {
    // Required methods
    fn as_sockaddr(&self) -> *const sockaddr;
    fn len(&self) -> socklen_t;
    fn as_sockaddr_mut(address: &mut MaybeUninit<Self>) -> *mut sockaddr;
    fn max_len() -> socklen_t;
    fn finalize(address: MaybeUninit<Self>, len: socklen_t) -> Result<Self>;

    // Provided method
    fn family(&self) -> sa_family_t { ... }
}
Expand description

A type that is binary compatible with a socket address.

§Safety

It must be valid to construct a new address as [std::mem::MaybeUninit::new_zeroed()] and then write the socket address to the pointer returned by [as_sockaddr_mut()].

Required Methods§

Source

fn as_sockaddr(&self) -> *const sockaddr

Get a pointer to the socket address.

In reality, this should point to a struct that is compatible with libc::sockaddr, but is not libc::sockaddr itself.

Source

fn len(&self) -> socklen_t

Get the lengths of the socket address.

This is the length of the entire socket address, including the sa_family field.

Source

fn as_sockaddr_mut(address: &mut MaybeUninit<Self>) -> *mut sockaddr

Get a mutable pointer to the socket address.

In reality, this should point to a struct that is compatible with libc::sockaddr, but is not libc::sockaddr itself.

Source

fn max_len() -> socklen_t

Get the maximum size of for the socket address.

This is used to tell the kernel how much it is allowed to write to the memory pointed at by as_sockaddr_mut().

Source

fn finalize(address: MaybeUninit<Self>, len: socklen_t) -> Result<Self>

Finalize a socket address that has been written into by the kernel.

This should check the address family and the length to ensure the address is valid. The length is the length of the entire socket address, including the sa_family field.

Provided Methods§

Source

fn family(&self) -> sa_family_t

Get the address family of the socket address.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§