pub trait SocketAddrExt: Sized {
// Required methods
fn read_from_user(
addr: UserConstPtr<sockaddr>,
addrlen: socklen_t,
) -> LinuxResult<Self>;
fn write_to_user(&self, addr: UserPtr<sockaddr>) -> LinuxResult<socklen_t>;
fn family(&self) -> u16;
fn addr_len(&self) -> socklen_t;
}
Expand description
Trait to extend SocketAddr
and its variants with methods for reading from and writing to user space.
Required Methods§
Sourcefn read_from_user(
addr: UserConstPtr<sockaddr>,
addrlen: socklen_t,
) -> LinuxResult<Self>
fn read_from_user( addr: UserConstPtr<sockaddr>, addrlen: socklen_t, ) -> LinuxResult<Self>
This method attempts to interpret the data pointed to by addr
with the
given addrlen
as a valid socket address of the implementing type.
Sourcefn write_to_user(&self, addr: UserPtr<sockaddr>) -> LinuxResult<socklen_t>
fn write_to_user(&self, addr: UserPtr<sockaddr>) -> LinuxResult<socklen_t>
This method serializes the current socket address instance into the
[sockaddr
] structure pointed to by addr
in user space.
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.
Implementations on Foreign Types§
Source§impl SocketAddrExt for SocketAddr
impl SocketAddrExt for SocketAddr
Source§fn read_from_user(
addr: UserConstPtr<sockaddr>,
addrlen: socklen_t,
) -> LinuxResult<Self>
fn read_from_user( addr: UserConstPtr<sockaddr>, addrlen: socklen_t, ) -> LinuxResult<Self>
Reads a SocketAddr
from user space.
This implementation first performs basic length validation. Then, it copies
the raw [sockaddr
] data from user space into a temporary kernel buffer.
Based on the address family ([AF_INET
] or [AF_INET6
]) extracted from the
copied data, it delegates the actual parsing to SocketAddrV4::read_from_user
or SocketAddrV6::read_from_user
.
Source§fn write_to_user(&self, addr: UserPtr<sockaddr>) -> LinuxResult<socklen_t>
fn write_to_user(&self, addr: UserPtr<sockaddr>) -> LinuxResult<socklen_t>
Writes the SocketAddr
to user space.
This implementation checks for a null user-space pointer. Then, it delegates
the actual writing to the specific SocketAddrV4
or SocketAddrV6
write_to_user
implementation based on the variant of self
.
Source§fn family(&self) -> u16
fn family(&self) -> u16
Gets the address family of the SocketAddr
.
Returns AF_INET
for IPv4 addresses or AF_INET6
for IPv6 addresses.
Source§fn addr_len(&self) -> socklen_t
fn addr_len(&self) -> socklen_t
Gets the encoded length of the SocketAddr
instance.
Returns the size in bytes that this SocketAddr
would occupy when
encoded as a [sockaddr_in
] (for IPv4) or [sockaddr_in6
] (for IPv6) structure.
Source§impl SocketAddrExt for SocketAddrV4
impl SocketAddrExt for SocketAddrV4
Source§fn read_from_user(
addr: UserConstPtr<sockaddr>,
addrlen: socklen_t,
) -> LinuxResult<Self>
fn read_from_user( addr: UserConstPtr<sockaddr>, addrlen: socklen_t, ) -> LinuxResult<Self>
Reads an SocketAddrV4
from user space.
Source§fn write_to_user(&self, addr: UserPtr<sockaddr>) -> LinuxResult<socklen_t>
fn write_to_user(&self, addr: UserPtr<sockaddr>) -> LinuxResult<socklen_t>
Writes the SocketAddrV4
to user space.
Source§fn family(&self) -> u16
fn family(&self) -> u16
Gets the address family for SocketAddrV4
.
Source§fn addr_len(&self) -> socklen_t
fn addr_len(&self) -> socklen_t
Gets the encoded length of SocketAddrV4
.
Source§impl SocketAddrExt for SocketAddrV6
impl SocketAddrExt for SocketAddrV6
Source§fn read_from_user(
addr: UserConstPtr<sockaddr>,
addrlen: socklen_t,
) -> LinuxResult<Self>
fn read_from_user( addr: UserConstPtr<sockaddr>, addrlen: socklen_t, ) -> LinuxResult<Self>
Reads an SocketAddrV6
from user space.
Source§fn write_to_user(&self, addr: UserPtr<sockaddr>) -> LinuxResult<socklen_t>
fn write_to_user(&self, addr: UserPtr<sockaddr>) -> LinuxResult<socklen_t>
Writes the SocketAddrV6
to user space.
Source§fn family(&self) -> u16
fn family(&self) -> u16
Gets the address family for SocketAddrV6
.
Source§fn addr_len(&self) -> socklen_t
fn addr_len(&self) -> socklen_t
Gets the encoded length of SocketAddrV6
.