From 012e788adcd8a41bdb028b5a6dc6dd1738dd2f9c Mon Sep 17 00:00:00 2001 From: Jarred Allen Date: Mon, 17 Jul 2023 11:33:43 -0700 Subject: More PR feedback --- src/sys/socket/addr.rs | 64 +++++++------------------------------------------- 1 file changed, 9 insertions(+), 55 deletions(-) (limited to 'src/sys/socket/addr.rs') diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 12cdc7a4..88bd6f5a 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -931,14 +931,17 @@ pub trait SockaddrLike: private::SockaddrLikePriv { /// Set the length of this socket address /// - /// This method may only be called on socket addresses whose lenghts are dynamic, and it + /// This method may only be called on socket addresses whose lengths are dynamic, and it /// returns an error if called on a type whose length is static. /// /// # Safety /// /// `new_length` must be a valid length for this type of address. Specifically, reads of that /// length from `self` must be valid. - unsafe fn set_length(&mut self, new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic>; + #[doc(hidden)] + unsafe fn set_length(&mut self, _new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { + Err(SocketAddressLengthNotDynamic) + } } /// The error returned by [`SockaddrLike::set_length`] on an address whose length is statically @@ -984,10 +987,6 @@ impl SockaddrLike for () { fn len(&self) -> libc::socklen_t { 0 } - - unsafe fn set_length(&mut self, _new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { - Err(SocketAddressLengthNotDynamic) - } } /// An IPv4 socket address @@ -1057,10 +1056,6 @@ impl SockaddrLike for SockaddrIn { } Some(Self(ptr::read_unaligned(addr as *const _))) } - - unsafe fn set_length(&mut self, _new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { - Err(SocketAddressLengthNotDynamic) - } } #[cfg(feature = "net")] @@ -1180,10 +1175,6 @@ impl SockaddrLike for SockaddrIn6 { } Some(Self(ptr::read_unaligned(addr as *const _))) } - - unsafe fn set_length(&mut self, _new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { - Err(SocketAddressLengthNotDynamic) - } } #[cfg(feature = "net")] @@ -1415,19 +1406,7 @@ impl SockaddrLike for SockaddrStorage { unsafe fn set_length(&mut self, new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { match self.as_unix_addr_mut() { Some(addr) => { - cfg_if! { - if #[cfg(any(target_os = "android", - target_os = "fuchsia", - target_os = "illumos", - target_os = "linux", - target_os = "redox", - ))] { - addr.sun_len = new_length as u8; - } else { - addr.sun.sun_len = new_length as u8; - } - } - Ok(()) + addr.set_length(new_length) }, None => Err(SocketAddressLengthNotDynamic), } @@ -1825,10 +1804,6 @@ pub mod netlink { } Some(Self(ptr::read_unaligned(addr as *const _))) } - - unsafe fn set_length(&mut self, _new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { - Err(SocketAddressLengthNotDynamic) - } } impl AsRef for NetlinkAddr { @@ -1878,10 +1853,6 @@ pub mod alg { } Some(Self(ptr::read_unaligned(addr as *const _))) } - - unsafe fn set_length(&mut self, _new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { - Err(SocketAddressLengthNotDynamic) - } } impl AsRef for AlgAddr { @@ -1981,7 +1952,7 @@ pub mod sys_control { use std::{fmt, mem, ptr}; use std::os::unix::io::RawFd; use crate::{Errno, Result}; - use super::{private, SockaddrLike, SocketAddressLengthNotDynamic}; + use super::{private, SockaddrLike}; // FIXME: Move type into `libc` #[repr(C)] @@ -2022,10 +1993,6 @@ pub mod sys_control { } Some(Self(ptr::read_unaligned(addr as *const _))) } - - unsafe fn set_length(&mut self, _new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { - Err(SocketAddressLengthNotDynamic) - } } impl AsRef for SysControlAddr { @@ -2090,7 +2057,7 @@ pub mod sys_control { mod datalink { feature! { #![feature = "net"] - use super::{fmt, mem, private, ptr, SockaddrLike, SocketAddressLengthNotDynamic}; + use super::{fmt, mem, private, ptr, SockaddrLike}; /// Hardware Address #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] @@ -2168,10 +2135,6 @@ mod datalink { } Some(Self(ptr::read_unaligned(addr as *const _))) } - - unsafe fn set_length(&mut self, _new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { - Err(SocketAddressLengthNotDynamic) - } } impl AsRef for LinkAddr { @@ -2197,7 +2160,7 @@ mod datalink { mod datalink { feature! { #![feature = "net"] - use super::{fmt, mem, private, ptr, SockaddrLike, SocketAddressLengthNotDynamic}; + use super::{fmt, mem, private, ptr, SockaddrLike}; /// Hardware Address #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] @@ -2296,10 +2259,6 @@ mod datalink { } Some(Self(ptr::read_unaligned(addr as *const _))) } - - unsafe fn set_length(&mut self, _new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { - Err(SocketAddressLengthNotDynamic) - } } impl AsRef for LinkAddr { @@ -2307,7 +2266,6 @@ mod datalink { &self.0 } } - } } @@ -2348,10 +2306,6 @@ pub mod vsock { } Some(Self(ptr::read_unaligned(addr as *const _))) } - - unsafe fn set_length(&mut self, _new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { - Err(SocketAddressLengthNotDynamic) - } } impl AsRef for VsockAddr { -- cgit v1.2.3