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