async_icmp/
platform.rs

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