async_icmp/platform.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
//! Helper functions to query pertinent platform-dependent behaviors.
use cfg_if::cfg_if;
/// Returns `true` if the current platform forces the ICMP Echo `id` to be the local port (big
/// endian) on sent messages.
///
/// See [`crate::socket::IcmpSocket::local_port`] and [`crate::socket::IcmpSocket::platform_echo_id`].
pub fn icmp_send_overwrite_echo_id_with_local_port() -> bool {
is_linux()
}
/// Returns `true` if the current platform includes the ipv4 header before the icmp message
/// when reading from a socket
pub(crate) fn ipv4_recv_prefix_ipv4_header() -> bool {
is_macos()
}
/// Returns `true` if the current platform requires calculating an ICMPv4 checksum on outgoing
/// messages.
pub(crate) fn ipv4_send_checksum_required() -> bool {
is_macos()
}
/// Returns `true` if the current platform sets a nonzero local port on a socket after a `bind()`
/// with `0.0.0.0:0` or `:::0`.
pub(crate) fn socket_bind_sets_nonzero_local_port() -> bool {
is_linux()
}
/// Returns true on macOS, false otherwise
fn is_macos() -> bool {
cfg_if! {
if #[cfg(target_os = "macos")] {
true
} else {
false
}
}
}
/// Returns true on Linux, false otherwise
fn is_linux() -> bool {
cfg_if! {
if #[cfg(target_os = "linux")] {
true
} else {
false
}
}
}