|
1 | 1 | #[cfg(any(doc, target_os = "android", target_os = "linux"))]
|
2 | 2 | use super::{recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to, SocketAncillary};
|
3 | 3 | use super::{sockaddr_un, SocketAddr};
|
| 4 | +#[cfg(any(doc, target_os = "netbsd", target_os = "freebsd"))] |
| 5 | +use crate::ffi::CStr; |
4 | 6 | #[cfg(any(doc, target_os = "android", target_os = "linux"))]
|
5 | 7 | use crate::io::{IoSlice, IoSliceMut};
|
6 | 8 | use crate::net::Shutdown;
|
@@ -807,6 +809,86 @@ impl UnixDatagram {
|
807 | 809 | self.0.set_nonblocking(nonblocking)
|
808 | 810 | }
|
809 | 811 |
|
| 812 | + /// Moves the socket to pass unix credentials as control message in [`SocketAncillary`]. |
| 813 | + /// |
| 814 | + /// Set the socket option `SO_PASSCRED`. |
| 815 | + /// |
| 816 | + /// # Examples |
| 817 | + /// |
| 818 | + #[cfg_attr( |
| 819 | + any( |
| 820 | + target_os = "android", |
| 821 | + target_os = "linux", |
| 822 | + target_os = "netbsd", |
| 823 | + target_os = "freebsd", |
| 824 | + ), |
| 825 | + doc = "```no_run" |
| 826 | + )] |
| 827 | + #[cfg_attr( |
| 828 | + not(any( |
| 829 | + target_os = "android", |
| 830 | + target_os = "linux", |
| 831 | + target_os = "netbsd", |
| 832 | + target_os = "freebsd" |
| 833 | + )), |
| 834 | + doc = "```ignore" |
| 835 | + )] |
| 836 | + /// #![feature(unix_socket_ancillary_data)] |
| 837 | + /// use std::os::unix::net::UnixDatagram; |
| 838 | + /// |
| 839 | + /// fn main() -> std::io::Result<()> { |
| 840 | + /// let sock = UnixDatagram::unbound()?; |
| 841 | + /// sock.set_passcred(true).expect("set_passcred function failed"); |
| 842 | + /// Ok(()) |
| 843 | + /// } |
| 844 | + /// ``` |
| 845 | + #[cfg(any( |
| 846 | + doc, |
| 847 | + target_os = "android", |
| 848 | + target_os = "linux", |
| 849 | + target_os = "netbsd", |
| 850 | + target_os = "freebsd" |
| 851 | + ))] |
| 852 | + #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] |
| 853 | + pub fn set_passcred(&self, passcred: bool) -> io::Result<()> { |
| 854 | + self.0.set_passcred(passcred) |
| 855 | + } |
| 856 | + |
| 857 | + /// Get the current value of the socket for passing unix credentials in [`SocketAncillary`]. |
| 858 | + /// This value can be change by [`set_passcred`]. |
| 859 | + /// |
| 860 | + /// Get the socket option `SO_PASSCRED`. |
| 861 | + /// |
| 862 | + /// [`set_passcred`]: UnixDatagram::set_passcred |
| 863 | + #[cfg(any( |
| 864 | + doc, |
| 865 | + target_os = "android", |
| 866 | + target_os = "linux", |
| 867 | + target_os = "netbsd", |
| 868 | + target_os = "freebsd" |
| 869 | + ))] |
| 870 | + #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] |
| 871 | + pub fn passcred(&self) -> io::Result<bool> { |
| 872 | + self.0.passcred() |
| 873 | + } |
| 874 | + |
| 875 | + /// Set a filter name on the socket to filter incoming connections to defer it before accept(2) |
| 876 | + /// |
| 877 | + /// an empty name allows to remove this connection's filter |
| 878 | + #[cfg(any(doc, target_os = "netbsd", target_os = "freebsd"))] |
| 879 | + #[unstable(feature = "acceptfilter", issue = "none")] |
| 880 | + pub fn set_acceptfilter(&self, name: &CStr) -> io::Result<()> { |
| 881 | + self.0.set_acceptfilter(name) |
| 882 | + } |
| 883 | + |
| 884 | + /// Get a filter name if one had been set previously on the socket. |
| 885 | + /// |
| 886 | + #[cfg(any(doc, target_os = "netbsd", target_os = "freebsd"))] |
| 887 | + #[unstable(feature = "acceptfilter", issue = "none")] |
| 888 | + pub fn acceptfilter(&self) -> io::Result<&CStr> { |
| 889 | + self.0.acceptfilter() |
| 890 | + } |
| 891 | + |
810 | 892 | /// Set the id of the socket for network filtering purpose
|
811 | 893 | ///
|
812 | 894 | #[cfg_attr(
|
|
0 commit comments