std/os/freebsd/
net.rs

1//! FreeBSD-specific networking functionality.
2
3#![unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
4
5use crate::ffi::CStr;
6use crate::io;
7use crate::os::unix::net;
8use crate::sealed::Sealed;
9use crate::sys_common::AsInner;
10
11/// FreeBSD-specific functionality for `AF_UNIX` sockets [`UnixDatagram`]
12/// and [`UnixStream`].
13///
14/// [`UnixDatagram`]: net::UnixDatagram
15/// [`UnixStream`]: net::UnixStream
16#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
17pub trait UnixSocketExt: Sealed {
18    /// Query the current setting of socket option `LOCAL_CREDS_PERSISTENT`.
19    #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
20    fn local_creds_persistent(&self) -> io::Result<bool>;
21
22    /// Enable or disable socket option `LOCAL_CREDS_PERSISTENT`.
23    ///
24    /// This option enables the credentials of the sending process to be
25    /// received as a control message in [`AncillaryData`].
26    ///
27    /// [`AncillaryData`]: net::AncillaryData
28    ///
29    /// # Examples
30    ///
31    /// ```no_run
32    /// #![feature(unix_socket_ancillary_data)]
33    /// use std::os::freebsd::net::UnixSocketExt;
34    /// use std::os::unix::net::UnixDatagram;
35    ///
36    /// fn main() -> std::io::Result<()> {
37    ///     let sock = UnixDatagram::unbound()?;
38    ///     sock.set_local_creds_persistent(true).expect("set_local_creds_persistent failed");
39    ///     Ok(())
40    /// }
41    /// ```
42    #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
43    fn set_local_creds_persistent(&self, local_creds_persistent: bool) -> io::Result<()>;
44
45    /// Gets a filter name if one had been set previously on the socket.
46    #[unstable(feature = "acceptfilter", issue = "121891")]
47    fn acceptfilter(&self) -> io::Result<&CStr>;
48
49    /// Set or disable a filter on the socket to filter incoming connections
50    /// to defer it before accept(2)
51    #[unstable(feature = "acceptfilter", issue = "121891")]
52    fn set_acceptfilter(&self, name: &CStr) -> io::Result<()>;
53}
54
55#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
56impl UnixSocketExt for net::UnixDatagram {
57    fn local_creds_persistent(&self) -> io::Result<bool> {
58        self.as_inner().local_creds_persistent()
59    }
60
61    fn set_local_creds_persistent(&self, local_creds_persistent: bool) -> io::Result<()> {
62        self.as_inner().set_local_creds_persistent(local_creds_persistent)
63    }
64
65    fn acceptfilter(&self) -> io::Result<&CStr> {
66        self.as_inner().acceptfilter()
67    }
68
69    fn set_acceptfilter(&self, name: &CStr) -> io::Result<()> {
70        self.as_inner().set_acceptfilter(name)
71    }
72}
73
74#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
75impl UnixSocketExt for net::UnixStream {
76    fn local_creds_persistent(&self) -> io::Result<bool> {
77        self.as_inner().local_creds_persistent()
78    }
79
80    fn set_local_creds_persistent(&self, local_creds_persistent: bool) -> io::Result<()> {
81        self.as_inner().set_local_creds_persistent(local_creds_persistent)
82    }
83
84    fn acceptfilter(&self) -> io::Result<&CStr> {
85        self.as_inner().acceptfilter()
86    }
87
88    fn set_acceptfilter(&self, name: &CStr) -> io::Result<()> {
89        self.as_inner().set_acceptfilter(name)
90    }
91}