std/os/net/linux_ext/socket.rs
1//! Linux and Android-specific socket functionality.
2
3use crate::io;
4use crate::os::unix::net;
5use crate::sys::AsInner;
6
7/// Linux-specific functionality for `AF_UNIX` sockets [`UnixDatagram`]
8/// and [`UnixStream`].
9///
10/// [`UnixDatagram`]: net::UnixDatagram
11/// [`UnixStream`]: net::UnixStream
12#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
13pub impl(self) trait UnixSocketExt {
14 /// Query the current setting of socket option `SO_PASSCRED`.
15 #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
16 fn passcred(&self) -> io::Result<bool>;
17
18 /// Enable or disable socket option `SO_PASSCRED`.
19 ///
20 /// This option enables the credentials of the sending process to be
21 /// received as a control message in [`AncillaryData`].
22 ///
23 /// [`AncillaryData`]: net::AncillaryData
24 ///
25 /// # Examples
26 ///
27 /// ```no_run
28 /// #![feature(unix_socket_ancillary_data)]
29 /// #[cfg(target_os = "linux")]
30 /// use std::os::linux::net::UnixSocketExt;
31 /// #[cfg(target_os = "android")]
32 /// use std::os::android::net::UnixSocketExt;
33 /// use std::os::unix::net::UnixDatagram;
34 ///
35 /// fn main() -> std::io::Result<()> {
36 /// let sock = UnixDatagram::unbound()?;
37 /// sock.set_passcred(true).expect("set_passcred failed");
38 /// Ok(())
39 /// }
40 /// ```
41 #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
42 fn set_passcred(&self, passcred: bool) -> io::Result<()>;
43}
44
45#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
46impl UnixSocketExt for net::UnixDatagram {
47 fn passcred(&self) -> io::Result<bool> {
48 self.as_inner().passcred()
49 }
50
51 fn set_passcred(&self, passcred: bool) -> io::Result<()> {
52 self.as_inner().set_passcred(passcred)
53 }
54}
55
56#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
57impl UnixSocketExt for net::UnixStream {
58 fn passcred(&self) -> io::Result<bool> {
59 self.as_inner().passcred()
60 }
61
62 fn set_passcred(&self, passcred: bool) -> io::Result<()> {
63 self.as_inner().set_passcred(passcred)
64 }
65}