#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "windows")]
mod windows;
#[cfg(target_os = "linux")]
pub use linux::{default_interface, list_interfaces, query_link_type, LinuxLive as PlatformLive};
#[cfg(target_os = "macos")]
pub use macos::{default_interface, list_interfaces, query_link_type, MacosLive as PlatformLive};
#[cfg(target_os = "windows")]
pub use windows::{default_interface, list_interfaces, query_link_type, WindowsLive as PlatformLive};
#[cfg(unix)]
use crate::error::Error;
use crate::error::Result;
#[cfg(any(target_os = "macos", target_os = "windows"))]
use crate::packet::LinkType;
use crate::packet::Packet;
#[cfg(any(target_os = "macos", target_os = "windows"))]
pub(super) fn dlt_to_link_type(dlt: u32) -> LinkType {
match dlt {
1 => LinkType::Ethernet, 101 => LinkType::RawIp, 113 => LinkType::LinuxSll, _ => LinkType::Ethernet,
}
}
#[cfg(unix)]
pub(super) fn io_err() -> Error {
std::io::Error::last_os_error().into()
}
pub struct Live(pub PlatformLive);
impl Live {
pub fn open(
iface: &str,
filter: Option<&pktbaffle::bpf::Program>,
snaplen: u32,
promiscuous: bool,
) -> Result<Self> {
PlatformLive::open(iface, filter, snaplen, promiscuous).map(Live)
}
pub fn next_packet(&mut self) -> Result<Packet> {
self.0.next_packet()
}
pub fn link_type(&self) -> crate::packet::LinkType {
self.0.link_type()
}
}