Trait a10::net::SocketAddress

source ·
pub trait SocketAddress: Sized {
    // Required methods
    unsafe fn as_ptr(&self) -> (*const sockaddr, socklen_t);
    unsafe fn as_mut_ptr(
        address: &mut MaybeUninit<Self>,
    ) -> (*mut sockaddr, socklen_t);
    unsafe fn init(address: MaybeUninit<Self>, length: socklen_t) -> Self;
}
Expand description

Trait that defines the behaviour of socket addresses.

Linux (Unix) uses different address types for different sockets, to support all of them A10 uses a trait to define the behaviour.

Current implementations include

For the last two types we need to keep track of the length of the address, for which it uses a tuple (addr, libc::socklen_t).

Required Methods§

source

unsafe fn as_ptr(&self) -> (*const sockaddr, socklen_t)

Returns itself as raw pointer and length.

§Safety

The pointer must be valid to read up to length bytes from.

The implementation must ensure that the pointer is valid, i.e. not null and pointing to memory owned by the address. Furthermore it must ensure that the returned length is, in combination with the pointer, valid. In other words the memory the pointer and length are pointing to must be a valid memory address and owned by the address.

Note that the above requirements are only required for implementations outside of A10. This trait is unfit for external use!

source

unsafe fn as_mut_ptr( address: &mut MaybeUninit<Self>, ) -> (*mut sockaddr, socklen_t)

Returns address as an adress storage and it’s length.

§Safety

Only initialised bytes may be written to the pointer returned.

The implementation must ensure that the pointer is valid, i.e. not null and pointing to memory owned by the address. Furthermore it must ensure that the returned length is, in combination with the pointer, valid. In other words the memory the pointer and length are pointing to must be a valid memory address and owned by the address.

Note that the above requirements are only required for implementations outside of A10. This trait is unfit for external use!

source

unsafe fn init(address: MaybeUninit<Self>, length: socklen_t) -> Self

Initialise address to which at least length bytes have been written (by the kernel).

§Safety

Caller must ensure that at least length bytes have been written to address.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl SocketAddress for (sockaddr, socklen_t)

Socket address.

source§

unsafe fn as_ptr(&self) -> (*const sockaddr, socklen_t)

source§

unsafe fn as_mut_ptr(this: &mut MaybeUninit<Self>) -> (*mut sockaddr, socklen_t)

source§

unsafe fn init(this: MaybeUninit<Self>, length: socklen_t) -> Self

source§

impl SocketAddress for (sockaddr_storage, socklen_t)

Any kind of address.

source§

unsafe fn as_ptr(&self) -> (*const sockaddr, socklen_t)

source§

unsafe fn as_mut_ptr(this: &mut MaybeUninit<Self>) -> (*mut sockaddr, socklen_t)

source§

unsafe fn init(this: MaybeUninit<Self>, length: socklen_t) -> Self

source§

impl SocketAddress for (sockaddr_un, socklen_t)

Unix address.

source§

unsafe fn as_ptr(&self) -> (*const sockaddr, socklen_t)

source§

unsafe fn as_mut_ptr(this: &mut MaybeUninit<Self>) -> (*mut sockaddr, socklen_t)

source§

unsafe fn init(this: MaybeUninit<Self>, length: socklen_t) -> Self

source§

impl SocketAddress for sockaddr_in6

IPv6 address.

source§

unsafe fn as_ptr(&self) -> (*const sockaddr, socklen_t)

source§

unsafe fn as_mut_ptr(this: &mut MaybeUninit<Self>) -> (*mut sockaddr, socklen_t)

source§

unsafe fn init(this: MaybeUninit<Self>, length: socklen_t) -> Self

source§

impl SocketAddress for sockaddr_in

IPv4 address.

source§

unsafe fn as_ptr(&self) -> (*const sockaddr, socklen_t)

source§

unsafe fn as_mut_ptr(this: &mut MaybeUninit<Self>) -> (*mut sockaddr, socklen_t)

source§

unsafe fn init(this: MaybeUninit<Self>, length: socklen_t) -> Self

Implementors§