A Unix domain socket address
Represents a filesystem path or abstract namespace address for Unix domain sockets.
Example
use std::net::UnixAddr;
use std::fs::Path;
let addr = UnixAddr::from_path(Path::new("/tmp/my.sock")).unwrap();
println!("{}", addr);
Run this example
Fields
-
inner: sockaddr_un
-
len: usize
Methods
impl UnixAddr { ... }
-
Creates a Unix socket address from a filesystem path.
The path must not exceed the system's maximum path length for Unix sockets (typically 108 bytes on Linux, 104 on macOS).
Returns
Option::none()
if the path is too long.Example
use std::net::UnixAddr; use std::fs::Path; let addr = UnixAddr::from_path(Path::new("/tmp/my.sock")).unwrap();
Run this example -
fn unnamed() -> UnixAddr
Creates an unnamed Unix socket address.
Unnamed sockets are used for autobind - when you bind a socket without specifying a path, the kernel assigns it an abstract address.
Example
use std::net::UnixAddr; let addr = UnixAddr::unnamed();
Run this example -
Returns the path of this Unix socket address, if it has one.
Returns
Option::none()
for unnamed or abstract addresses.Example
use std::net::UnixAddr; use std::fs::Path; let addr = UnixAddr::from_path(Path::new("/tmp/my.sock")).unwrap(); assert_eq!(addr.path().unwrap(), Path::new("/tmp/my.sock"));
Run this example -
Returns true if this is an unnamed socket address.
Example
use std::net::UnixAddr; let addr = UnixAddr::unnamed(); assert!(addr.is_unnamed());
Run this example
Mixins
impl UnixAddr { ... }
-
-
Returns
false
if arguments are equal,true
otherwise