Skip to content

Commit bfc65a6

Browse files
committed
Re-add sockaddr_storage_to_addr and mark as deprecated due to unsoundness
1 parent e53cee3 commit bfc65a6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/sys/socket/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,25 @@ pub fn getsockname(fd: RawFd) -> Result<SockAddr> {
17961796
}
17971797
}
17981798

1799+
1800+
/// Return the appropriate `SockAddr` type from a `sockaddr_storage` of a
1801+
/// certain size.
1802+
///
1803+
/// **This function is deprecated, as its use is likely to be unsound. It has been
1804+
/// replaced by [`SockAddr::from_raw_sockaddr()`].**
1805+
///
1806+
/// In C this would usually be done by casting. The `len` argument
1807+
/// should be the number of bytes in the `sockaddr_storage` that are actually
1808+
/// allocated and valid. It must be at least as large as all the useful parts
1809+
/// of the structure. Note that in the case of a `sockaddr_un`, `len` need not
1810+
/// include the terminating null.
1811+
#[deprecated(since = "0.23.0", note = "Usage of this is likely to be unsound, use SockAddr::from_raw_sockaddr instead")]
1812+
pub fn sockaddr_storage_to_addr(
1813+
addr: &sockaddr_storage,
1814+
len: usize) -> Result<SockAddr> {
1815+
unsafe { SockAddr::from_raw_sockaddr(addr as *const sockaddr_storage as *const sockaddr, len) }
1816+
}
1817+
17991818
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
18001819
pub enum Shutdown {
18011820
/// Further receptions will be disallowed.

0 commit comments

Comments
 (0)