diff --git a/library/std/src/os/freebsd/net.rs b/library/std/src/os/freebsd/net.rs index 68f39ab349a72..bd5a8460a6f79 100644 --- a/library/std/src/os/freebsd/net.rs +++ b/library/std/src/os/freebsd/net.rs @@ -2,7 +2,7 @@ #![unstable(feature = "unix_socket_ancillary_data", issue = "76915")] -use crate::ffi::CStr; +use crate::ffi::{CStr, CString}; use crate::io; use crate::os::unix::net; use crate::sys::AsInner; @@ -43,7 +43,7 @@ pub impl(self) trait UnixSocketExt { /// Gets a filter name if one had been set previously on the socket. #[unstable(feature = "acceptfilter", issue = "121891")] - fn acceptfilter(&self) -> io::Result<&CStr>; + fn acceptfilter(&self) -> io::Result; /// Set or disable a filter on the socket to filter incoming connections /// to defer it before accept(2) @@ -61,7 +61,7 @@ impl UnixSocketExt for net::UnixDatagram { self.as_inner().set_local_creds_persistent(local_creds_persistent) } - fn acceptfilter(&self) -> io::Result<&CStr> { + fn acceptfilter(&self) -> io::Result { self.as_inner().acceptfilter() } @@ -80,7 +80,7 @@ impl UnixSocketExt for net::UnixStream { self.as_inner().set_local_creds_persistent(local_creds_persistent) } - fn acceptfilter(&self) -> io::Result<&CStr> { + fn acceptfilter(&self) -> io::Result { self.as_inner().acceptfilter() } diff --git a/library/std/src/os/netbsd/net.rs b/library/std/src/os/netbsd/net.rs index a77302ddbc675..d9c7ea2dc6486 100644 --- a/library/std/src/os/netbsd/net.rs +++ b/library/std/src/os/netbsd/net.rs @@ -2,7 +2,7 @@ #![unstable(feature = "unix_socket_ancillary_data", issue = "76915")] -use crate::ffi::CStr; +use crate::ffi::{CStr, CString}; use crate::io; use crate::os::unix::net; use crate::sys::AsInner; @@ -43,7 +43,7 @@ pub impl(self) trait UnixSocketExt { /// Gets a filter name if one had been set previously on the socket. #[unstable(feature = "acceptfilter", issue = "121891")] - fn acceptfilter(&self) -> io::Result<&CStr>; + fn acceptfilter(&self) -> io::Result; /// Set or disable a filter on the socket to filter incoming connections /// to defer it before accept(2) @@ -61,7 +61,7 @@ impl UnixSocketExt for net::UnixDatagram { self.as_inner().set_local_creds(local_creds) } - fn acceptfilter(&self) -> io::Result<&CStr> { + fn acceptfilter(&self) -> io::Result { self.as_inner().acceptfilter() } @@ -80,7 +80,7 @@ impl UnixSocketExt for net::UnixStream { self.as_inner().set_local_creds(local_creds) } - fn acceptfilter(&self) -> io::Result<&CStr> { + fn acceptfilter(&self) -> io::Result { self.as_inner().acceptfilter() } diff --git a/library/std/src/sys/net/connection/socket/unix.rs b/library/std/src/sys/net/connection/socket/unix.rs index 3336dc4cf9233..19677f314b93c 100644 --- a/library/std/src/sys/net/connection/socket/unix.rs +++ b/library/std/src/sys/net/connection/socket/unix.rs @@ -1,7 +1,7 @@ use libc::{MSG_PEEK, c_int, c_void, size_t, sockaddr, socklen_t}; #[cfg(not(any(target_os = "espidf", target_os = "nuttx")))] -use crate::ffi::CStr; +use crate::ffi::{CStr, CString}; use crate::io::{self, BorrowedBuf, BorrowedCursor, IoSlice, IoSliceMut}; use crate::net::{Shutdown, SocketAddr}; use crate::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}; @@ -522,13 +522,13 @@ impl Socket { } #[cfg(any(target_os = "freebsd", target_os = "netbsd"))] - pub fn acceptfilter(&self) -> io::Result<&CStr> { + pub fn acceptfilter(&self) -> io::Result { let arg: libc::accept_filter_arg = unsafe { getsockopt(self, libc::SOL_SOCKET, libc::SO_ACCEPTFILTER)? }; let s: &[u8] = unsafe { core::slice::from_raw_parts(arg.af_name.as_ptr() as *const u8, 16) }; let name = CStr::from_bytes_with_nul(s).unwrap(); - Ok(name) + Ok(name.to_owned()) } #[cfg(any(target_os = "solaris", target_os = "illumos"))]