#[cfg(any(
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
target_os = "dragonfly"
))]
pub(crate) mod bsd;
#[cfg(any(
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
target_os = "dragonfly"
))]
pub(crate) mod bsd_v6;
pub(crate) mod factory;
#[cfg_attr(target_os = "windows", allow(dead_code))]
pub(crate) mod icmp;
#[cfg_attr(
not(any(
target_os = "macos",
target_os = "linux",
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
target_os = "dragonfly"
)),
allow(dead_code)
)]
pub(crate) mod icmpv6;
#[cfg(target_os = "linux")]
pub mod linux;
#[cfg(target_os = "linux")]
pub(crate) mod linux_v6;
#[cfg(target_os = "macos")]
pub(crate) mod macos;
#[cfg(target_os = "macos")]
pub(crate) mod macos_v6;
pub mod traits;
pub mod utils;
#[cfg(target_os = "windows")]
pub(crate) mod windows;
#[cfg(target_os = "windows")]
pub(crate) mod windows_v6;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum IpVersion {
V4,
V6,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum ProbeProtocol {
Icmp,
Udp,
Tcp,
}
impl ProbeProtocol {
pub fn description(&self) -> &'static str {
match self {
ProbeProtocol::Icmp => "ICMP",
ProbeProtocol::Udp => "UDP",
ProbeProtocol::Tcp => "TCP",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum SocketMode {
Raw,
Dgram,
Stream,
}
impl SocketMode {
pub fn description(&self) -> &'static str {
match self {
SocketMode::Raw => "Raw",
SocketMode::Dgram => "Datagram",
SocketMode::Stream => "Stream",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ProbeMode {
pub ip_version: IpVersion,
pub protocol: ProbeProtocol,
pub socket_mode: SocketMode,
}
impl ProbeMode {
pub fn description(&self) -> String {
format!(
"{} {} {}",
match self.socket_mode {
SocketMode::Raw => "Raw",
SocketMode::Dgram => "Datagram",
SocketMode::Stream => "Stream",
},
match self.protocol {
ProbeProtocol::Icmp => match self.ip_version {
IpVersion::V4 => "ICMP",
IpVersion::V6 => "ICMPv6",
},
ProbeProtocol::Udp => "UDP",
ProbeProtocol::Tcp => "TCP",
},
match self.ip_version {
IpVersion::V4 => "IPv4",
IpVersion::V6 => "IPv6",
}
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_probe_mode_description() {
let mode = ProbeMode {
ip_version: IpVersion::V4,
protocol: ProbeProtocol::Icmp,
socket_mode: SocketMode::Dgram,
};
assert_eq!(mode.description(), "Datagram ICMP IPv4");
let mode = ProbeMode {
ip_version: IpVersion::V6,
protocol: ProbeProtocol::Udp,
socket_mode: SocketMode::Raw,
};
assert_eq!(mode.description(), "Raw UDP IPv6");
}
#[test]
fn test_ip_version() {
assert_eq!(IpVersion::V4, IpVersion::V4);
assert_ne!(IpVersion::V4, IpVersion::V6);
}
}