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
- IPv4 addresses:
libc::sockaddr_in
, - IPv6 addresses:
libc::sockaddr_in6
, - Unix addresses:
libc::sockaddr_un
, - Storage of any address
libc::sockaddr_storage
kind.
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§
sourceunsafe fn as_ptr(&self) -> (*const sockaddr, socklen_t)
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!
sourceunsafe fn as_mut_ptr(
address: &mut MaybeUninit<Self>,
) -> (*mut sockaddr, socklen_t)
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!
sourceunsafe fn init(address: MaybeUninit<Self>, length: socklen_t) -> Self
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§
Implementations on Foreign Types§
source§impl SocketAddress for (sockaddr, socklen_t)
impl SocketAddress for (sockaddr, socklen_t)
Socket address.
source§impl SocketAddress for (sockaddr_storage, socklen_t)
impl SocketAddress for (sockaddr_storage, socklen_t)
Any kind of address.
source§impl SocketAddress for (sockaddr_un, socklen_t)
impl SocketAddress for (sockaddr_un, socklen_t)
Unix address.
source§impl SocketAddress for sockaddr_in6
impl SocketAddress for sockaddr_in6
IPv6 address.
source§impl SocketAddress for sockaddr_in
impl SocketAddress for sockaddr_in
IPv4 address.