]>
git.proxmox.com Git - rustc.git/blob - library/std/src/os/net/linux_ext/addr.rs
1 //! Linux and Android-specific extensions to socket addresses.
3 use crate::os
::unix
::net
::SocketAddr
;
4 use crate::sealed
::Sealed
;
6 /// Platform-specific extensions to [`SocketAddr`].
7 #[unstable(feature = "unix_socket_abstract", issue = "85410")]
8 pub trait SocketAddrExt
: Sealed
{
9 /// Creates a Unix socket address in the abstract namespace.
11 /// The abstract namespace is a Linux-specific extension that allows Unix
12 /// sockets to be bound without creating an entry in the filesystem.
13 /// Abstract sockets are unaffected by filesystem layout or permissions,
14 /// and no cleanup is necessary when the socket is closed.
16 /// An abstract socket address name may contain any bytes, including zero.
20 /// Returns an error if the name is longer than `SUN_LEN - 1`.
25 /// #![feature(unix_socket_abstract)]
26 /// use std::os::unix::net::{UnixListener, SocketAddr};
27 /// use std::os::linux::net::SocketAddrExt;
29 /// fn main() -> std::io::Result<()> {
30 /// let addr = SocketAddr::from_abstract_name(b"hidden")?;
31 /// let listener = match UnixListener::bind_addr(&addr) {
34 /// println!("Couldn't bind: {err:?}");
41 fn from_abstract_name
<N
>(name
: &N
) -> crate::io
::Result
<SocketAddr
>
45 /// Returns the contents of this address if it is in the abstract namespace.
50 /// #![feature(unix_socket_abstract)]
51 /// use std::os::unix::net::{UnixListener, SocketAddr};
52 /// use std::os::linux::net::SocketAddrExt;
54 /// fn main() -> std::io::Result<()> {
55 /// let name = b"hidden";
56 /// let name_addr = SocketAddr::from_abstract_name(name)?;
57 /// let socket = UnixListener::bind_addr(&name_addr)?;
58 /// let local_addr = socket.local_addr().expect("Couldn't get local address");
59 /// assert_eq!(local_addr.as_abstract_name(), Some(&name[..]));
63 fn as_abstract_name(&self) -> Option
<&[u8]>;