async-icmp 0.2.1

Async ICMP library
Documentation
//! 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
        }
    }
}