Struct SockAddr
pub struct SockAddr { /* private fields */ }
The address of a socket.
SockAddrs may be constructed directly to and from the standard library
SocketAddr, SocketAddrV4, and SocketAddrV6 types.
Implementations
impl SockAddr
fn is_unnamed(&self) -> boolReturns true if this address is an unnamed address from the
AF_UNIXfamily (for local interprocess communication), false otherwise.fn as_unix(&self) -> Option<SocketAddr>Returns this address as Unix
SocketAddrif it is anAF_UNIXpathname address, otherwise returnsNone.fn as_pathname(&self) -> Option<&Path>Returns this address as a
Pathreference if it is anAF_UNIXpathname address, otherwise returnsNone.fn as_abstract_namespace(&self) -> Option<&[u8]>Returns this address as a slice of bytes representing an abstract address if it is an
AF_UNIXabstract address, otherwise returnsNone.Abstract addresses are a Linux extension, so this method returns
Noneon all non-Linux platforms.
impl SockAddr
fn vsock(cid: u32, port: u32) -> SockAddrConstructs a
SockAddrwith the familyAF_VSOCKand the provided CID/port.Errors
This function can never fail. In a future version of this library it will be made infallible.
fn as_vsock_address(&self) -> Option<(u32, u32)>Returns this address VSOCK CID/port if it is in the
AF_VSOCKfamily, otherwise returnNone.
impl SockAddr
const unsafe fn new(storage: SockAddrStorage, len: socklen_t) -> SockAddrCreate a
SockAddrfrom the underlying storage and its length.Safety
Caller must ensure that the address family and length match the type of storage address. For example if
storage.ss_familyis set toAF_INETthestoragemust be initialised assockaddr_in, setting the content and length appropriately.Examples
#unsafe fn try_init<F, T>(init: F) -> Result<(T, SockAddr)> where F: FnOnce(*mut SockAddrStorage, *mut socklen_t) -> Result<T>,Initialise a
SockAddrby calling the functioninit.The type of the address storage and length passed to the function
initis OS/architecture specific.The address is zeroed before
initis called and is thus valid to dereference and read from. The length initialised to the maximum length of the storage.Safety
Caller must ensure that the address family and length match the type of storage address. For example if
storage.ss_familyis set toAF_INETthestoragemust be initialised assockaddr_in, setting the content and length appropriately.Examples
#fn unix<P>(path: P) -> Result<SockAddr> where P: AsRef<Path>,Constructs a
SockAddrwith the familyAF_UNIXand the provided path.Returns an error if the path is longer than
SUN_LEN.unsafe fn set_length(&mut self, length: socklen_t)Set the length of the address.
Safety
Caller must ensure that the address up to
lengthbytes are properly initialised.const fn family(&self) -> sa_family_tReturns this address's family.
const fn domain(&self) -> DomainReturns this address's
Domain.const fn len(&self) -> socklen_tReturns the size of this address in bytes.
const fn as_ptr(&self) -> *const SockAddrStorageReturns a raw pointer to the address.
const fn as_storage(self) -> SockAddrStorageReturns the address as the storage.
const fn is_ipv4(&self) -> boolReturns true if this address is in the
AF_INET(IPv4) family, false otherwise.const fn is_ipv6(&self) -> boolReturns true if this address is in the
AF_INET6(IPv6) family, false otherwise.fn is_unix(&self) -> boolReturns true if this address is of a unix socket (for local interprocess communication), i.e. it is from the
AF_UNIXfamily, false otherwise.fn as_socket(&self) -> Option<SocketAddr>Returns this address as a
SocketAddrif it is in theAF_INET(IPv4) orAF_INET6(IPv6) family, otherwise returnsNone.fn as_socket_ipv4(&self) -> Option<SocketAddrV4>Returns this address as a
SocketAddrV4if it is in theAF_INETfamily.fn as_socket_ipv6(&self) -> Option<SocketAddrV6>Returns this address as a
SocketAddrV6if it is in theAF_INET6family.
Trait Implementations
impl Clone for SockAddr
fn clone(&self) -> SockAddr
impl Debug for SockAddr
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result
impl Eq for SockAddr
impl From<SocketAddr> for SockAddr
fn from(addr: SocketAddr) -> SockAddr
impl From<SocketAddrV4> for SockAddr
fn from(addr: SocketAddrV4) -> SockAddr
impl From<SocketAddrV6> for SockAddr
fn from(addr: SocketAddrV6) -> SockAddr
impl Hash for SockAddr
fn hash<H: Hasher>(&self, state: &mut H)
impl PartialEq for SockAddr
fn eq(&self, other: &Self) -> bool
Auto Trait Implementations
impl Freeze for SockAddr
impl RefUnwindSafe for SockAddr
impl Send for SockAddr
impl Sync for SockAddr
impl Unpin for SockAddr
impl UnsafeUnpin for SockAddr
impl UnwindSafe for SockAddr
Blanket Implementations
impl<T> Any for SockAddr
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for SockAddr
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for SockAddr
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for SockAddr
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for SockAddr
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for SockAddr
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for SockAddr
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for SockAddr
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for SockAddr
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>