More flakes work
Removed old git submodules Started adding Windows cross compilation support
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use std::net::{Ipv4Addr, SocketAddrV4, UdpSocket};
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "pcap")]
|
||||
use std::{sync::Arc, thread};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "pcap")]
|
||||
use anyhow::{anyhow, bail};
|
||||
|
||||
use packets::{self, EthernetPkt};
|
||||
@@ -17,7 +17,7 @@ pub enum Interface {
|
||||
impl Interface {
|
||||
pub fn new(ttype: TransportType, port: u16) -> anyhow::Result<Interface> {
|
||||
match ttype {
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "pcap")]
|
||||
TransportType::RawUdp => {
|
||||
let mut interfaces = pcap_sys::PcapDevIterator::new()?;
|
||||
let interface_name = interfaces
|
||||
@@ -52,7 +52,7 @@ impl Interface {
|
||||
retry!(interface.set_promisc(false));
|
||||
retry!(interface.set_timeout(10));
|
||||
|
||||
let mut interface = retry!(interface.activate());
|
||||
let interface = retry!(interface.activate());
|
||||
|
||||
retry!(interface.set_filter(&format!("inbound and port {port}"), true, None));
|
||||
|
||||
@@ -65,7 +65,7 @@ impl Interface {
|
||||
|
||||
Ok(Interface::RawUdp(interface, port))
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
#[cfg(not(feature = "pcap"))]
|
||||
TransportType::RawUdp => {
|
||||
panic!("transport not available!");
|
||||
}
|
||||
@@ -78,7 +78,7 @@ impl Interface {
|
||||
|
||||
pub fn split(self) -> anyhow::Result<(InterfaceSender, InterfaceReceiver)> {
|
||||
match self {
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "pcap")]
|
||||
Self::RawUdp(interface, _) => {
|
||||
let arc = Arc::new(interface);
|
||||
Ok((
|
||||
@@ -98,7 +98,7 @@ impl Interface {
|
||||
}
|
||||
|
||||
pub enum InterfaceSender {
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "pcap")]
|
||||
RawUdp(Arc<pcap_sys::Interface<pcap_sys::DevActivated>>),
|
||||
Udp(UdpSocket),
|
||||
}
|
||||
@@ -106,7 +106,7 @@ pub enum InterfaceSender {
|
||||
impl InterfaceSender {
|
||||
pub fn sendpacket(&self, packet: EthernetPkt) -> anyhow::Result<()> {
|
||||
match self {
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "pcap")]
|
||||
Self::RawUdp(interf) => Ok(interf.sendpacket(packet)?),
|
||||
Self::Udp(interf) => {
|
||||
use packets::*;
|
||||
@@ -128,7 +128,7 @@ impl InterfaceSender {
|
||||
}
|
||||
|
||||
pub enum InterfaceReceiver {
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "pcap")]
|
||||
RawUdp(Arc<pcap_sys::Interface<pcap_sys::DevActivated>>),
|
||||
Udp(UdpSocket, u16),
|
||||
}
|
||||
@@ -139,7 +139,7 @@ impl InterfaceReceiver {
|
||||
F: FnMut(packets::EthernetPacket) -> anyhow::Result<()>,
|
||||
{
|
||||
match self {
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "pcap")]
|
||||
Self::RawUdp(interf) => interf.listen(
|
||||
move |_, packet| {
|
||||
let _ = (f)(packet.to_owned());
|
||||
@@ -176,7 +176,7 @@ impl InterfaceReceiver {
|
||||
},
|
||||
};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "pcap")]
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user