Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Domain {
pub const IPV6: Domain = Domain(sys::AF_INET6);

/// Returns the correct domain for `address`.
pub fn for_address(address: SocketAddr) -> Domain {
pub const fn for_address(address: SocketAddr) -> Domain {
match address {
SocketAddr::V4(_) => Domain::IPV4,
SocketAddr::V6(_) => Domain::IPV6,
Expand Down Expand Up @@ -252,9 +252,9 @@ impl RecvFlags {
/// This flag is only used for datagram-based sockets,
/// not for stream sockets.
///
/// On Unix this corresponds to the MSG_TRUNC flag.
/// On Windows this corresponds to the WSAEMSGSIZE error code.
pub fn is_truncated(self) -> bool {
/// On Unix this corresponds to the `MSG_TRUNC` flag.
/// On Windows this corresponds to the `WSAEMSGSIZE` error code.
pub const fn is_truncated(self) -> bool {
self.0 & sys::MSG_TRUNC != 0
}
}
11 changes: 11 additions & 0 deletions src/sockaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ impl SockAddr {
}
}

/// Constructs a `SockAddr` from its raw components.
pub(crate) const fn from_raw(storage: sockaddr_storage, len: socklen_t) -> SockAddr {
SockAddr { storage, len }
}

/// Returns this address's family.
pub fn family(&self) -> sa_family_t {
self.storage.ss_family
Expand All @@ -54,6 +59,12 @@ impl SockAddr {
&self.storage as *const _ as *const _
}

/// Returns a raw pointer to the address storage.
#[cfg(unix)]
pub(crate) fn as_storage_ptr(&self) -> *const sockaddr_storage {
&self.storage
}

/// Returns this address as a `SocketAddr` if it is in the `AF_INET` (IP v4)
/// or `AF_INET6` (IP v6) family, otherwise returns `None`.
pub fn as_std(&self) -> Option<SocketAddr> {
Expand Down
Loading