use std::io;
use std::option::Option;
use packet::ethernet::{EtherType, EthernetPacket, MutableEthernetPacket};
use util::NetworkInterface;
#[cfg(windows)]
#[path = "winpcap.rs"]
mod backend;
#[cfg(all(not(feature = "netmap"),
target_os = "linux"
)
)]
#[path = "linux.rs"]
mod backend;
#[cfg(all(not(feature = "netmap"),
any(target_os = "freebsd",
target_os = "macos")
)
)]
#[path = "bpf.rs"]
mod backend;
#[cfg(feature = "netmap")]
#[path = "netmap.rs"]
mod backend;
#[derive(Clone, Copy)]
pub enum DataLinkChannelType {
Layer2,
Layer3(EtherType),
}
#[inline]
pub fn datalink_channel(network_interface: &NetworkInterface,
write_buffer_size: usize,
read_buffer_size: usize,
channel_type: DataLinkChannelType)
-> io::Result<(Box<DataLinkSender>, Box<DataLinkReceiver>)> {
backend::datalink_channel(network_interface,
write_buffer_size,
read_buffer_size,
channel_type)
}
pub trait DataLinkSender : Send {
#[inline]
fn build_and_send(&mut self,
num_packets: usize,
packet_size: usize,
func: &mut FnMut(MutableEthernetPacket))
-> Option<io::Result<()>>;
#[inline]
fn send_to(&mut self,
packet: &EthernetPacket,
dst: Option<NetworkInterface>)
-> Option<io::Result<()>>;
}
pub trait DataLinkReceiver : Send {
#[inline]
fn iter<'a>(&'a mut self) -> Box<DataLinkChannelIterator + 'a>;
}
pub trait DataLinkChannelIterator<'a> {
#[inline]
fn next(&mut self) -> io::Result<EthernetPacket>;
}