#[non_exhaustive]
pub enum SockAddr {
Inet(InetAddr),
Unix(UnixAddr),
Netlink(NetlinkAddr),
Alg(AlgAddr),
Link(LinkAddr),
Vsock(VsockAddr),
}
👎Deprecated since 0.24.0: use SockaddrLike or SockaddrStorage instead
Expand description
Represents a socket address
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Inet(InetAddr)
👎Deprecated since 0.24.0: use SockaddrLike or SockaddrStorage instead
Unix(UnixAddr)
👎Deprecated since 0.24.0: use SockaddrLike or SockaddrStorage instead
Netlink(NetlinkAddr)
👎Deprecated since 0.24.0: use SockaddrLike or SockaddrStorage instead
Alg(AlgAddr)
👎Deprecated since 0.24.0: use SockaddrLike or SockaddrStorage instead
Link(LinkAddr)
👎Deprecated since 0.24.0: use SockaddrLike or SockaddrStorage instead
Datalink address (MAC)
Vsock(VsockAddr)
👎Deprecated since 0.24.0: use SockaddrLike or SockaddrStorage instead
Implementations§
source§impl SockAddr
impl SockAddr
pub fn new_inet(addr: InetAddr) -> SockAddr
pub fn new_unix<P: ?Sized + NixPath>(path: &P) -> Result<SockAddr>
pub fn new_netlink(pid: u32, groups: u32) -> SockAddr
pub fn new_alg(alg_type: &str, alg_name: &str) -> SockAddr
pub fn new_vsock(cid: u32, port: u32) -> SockAddr
pub fn family(&self) -> AddressFamily
pub fn to_str(&self) -> String
👎Deprecated since 0.23.0: use .to_string() instead
sourcepub fn as_ffi_pair(&self) -> (&sockaddr, socklen_t)
pub fn as_ffi_pair(&self) -> (&sockaddr, socklen_t)
Conversion from nix’s SockAddr type to the underlying libc sockaddr type.
This is useful for interfacing with other libc functions that don’t yet have nix wrappers. Returns a reference to the underlying data type (as a sockaddr reference) along with the size of the actual data type. sockaddr is commonly used as a proxy for a superclass as C doesn’t support inheritance, so many functions that take a sockaddr * need to take the size of the underlying type as well and then internally cast it back.
Trait Implementations§
source§impl SockaddrLike for SockAddr
impl SockaddrLike for SockAddr
source§unsafe fn from_raw(
addr: *const sockaddr,
_len: Option<socklen_t>
) -> Option<Self>
unsafe fn from_raw(
addr: *const sockaddr,
_len: Option<socklen_t>
) -> Option<Self>
Unsafe constructor from a variable length source Read more
source§fn as_ptr(&self) -> *const sockaddr
fn as_ptr(&self) -> *const sockaddr
Returns a raw pointer to the inner structure. Useful for FFI.