1//! Functionality for working with AF\_UNIX addresses.
23use tor_general_addr::unix;
45/// Helper: construct an unnamed SocketAddr.
6#[cfg(unix)]
7pub(crate) fn new_unnamed_socketaddr() -> std::io::Result<unix::SocketAddr> {
8// There SHOULD be a better way to do this in legitimate Rust!
9 // But sadly, there isn't.
10unix::SocketAddr::from_pathname("")
11}
1213/// Error: Tried to perform an operation on an unsupported kind of AF\_UNIX address.
14///
15/// (For example, you can't bind or connect to an unnamed address.)
16#[derive(Clone, Debug, thiserror::Error)]
17#[error("Operation not supported on this kind of AF_UNIX address")]
18#[non_exhaustive]
19pub struct UnsupportedAfUnixAddressType;
2021/// Deprecated name for `UnsupportedAfUnixAddressType`
22#[deprecated]
23pub type UnsupportedUnixAddressType = UnsupportedAfUnixAddressType;
2425impl From<UnsupportedAfUnixAddressType> for std::io::Error {
26fn from(value: UnsupportedAfUnixAddressType) -> Self {
27 std::io::Error::new(std::io::ErrorKind::Unsupported, value)
28 }
29}
3031#[cfg(test)]
32mod test {
33use super::*;
3435#[test]
36 #[cfg(unix)]
37fn unnamed() {
38let u = new_unnamed_socketaddr().expect("couldn't construct unnamed AF_UNIX socketaddr");
39assert!(u.is_unnamed());
40assert!(u.as_pathname().is_none());
4142let n = unix::SocketAddr::from_pathname("/home/arachnidsGrip/.arti/SOCKET")
43 .expect("Couldn't construct named socketaddr");
44assert!(!n.is_unnamed());
45 }
46}