Skip to content

Commit

Permalink
Add MSG_CONFIRM and MSG_DONTROUTE to RecvFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm authored and Thomasdezeeuw committed Mar 12, 2024
1 parent faa59e9 commit c93cdcc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/sys/unix.rs
Expand Up @@ -573,6 +573,37 @@ impl RecvFlags {
pub const fn is_out_of_band(self) -> bool {
self.0 & libc::MSG_OOB != 0
}

/// Check if the confirm flag is set.
///
/// This is used by SocketCAN to indicate a frame was sent via the
/// socket it is received on. This flag can be interpreted as a
/// 'transmission confirmation'.
///
/// On Unix this corresponds to the `MSG_CONFIRM` flag.
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
#[cfg_attr(
docsrs,
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
)]
pub const fn is_confirm(self) -> bool {
self.0 & libc::MSG_CONFIRM != 0
}

/// Check if the don't route flag is set.
///
/// This is used by SocketCAN to indicate a frame was created
/// on the local host.
///
/// On Unix this corresponds to the `MSG_DONTROUTE` flag.
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
#[cfg_attr(
docsrs,
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
)]
pub const fn is_dontroute(self) -> bool {
self.0 & libc::MSG_DONTROUTE != 0
}
}

#[cfg(not(target_os = "redox"))]
Expand All @@ -584,6 +615,10 @@ impl std::fmt::Debug for RecvFlags {
s.field("is_out_of_band", &self.is_out_of_band());
#[cfg(not(target_os = "espidf"))]
s.field("is_truncated", &self.is_truncated());
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
s.field("is_confirm", &self.is_confirm());
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
s.field("is_dontroute", &self.is_dontroute());
s.finish()
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/socket.rs
Expand Up @@ -731,6 +731,10 @@ fn send_from_recv_to_vectored() {
#[cfg(all(unix, not(target_os = "redox")))]
assert_eq!(flags.is_out_of_band(), false);
assert_eq!(flags.is_truncated(), false);
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
assert_eq!(flags.is_confirm(), false);
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
assert_eq!(flags.is_dontroute(), false);
assert_eq!(
addr.as_socket_ipv6().unwrap(),
addr_a.as_socket_ipv6().unwrap()
Expand Down

0 comments on commit c93cdcc

Please sign in to comment.