Skip to content

Commit

Permalink
add pcap stub for non-linux
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraef committed Jul 11, 2024
1 parent 8476aa0 commit d0ac5f4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion skunk/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//#[cfg(feature = "http")]
//pub mod http;
#[cfg(all(feature = "pcap", unix))]
#[cfg(feature = "pcap")]
pub mod pcap;
#[cfg(feature = "socks")]
pub mod socks;
Expand Down
14 changes: 12 additions & 2 deletions skunk/src/proxy/pcap/os/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#[cfg(unix)]
#[cfg(target_os = "linux")]
mod unix;

#[cfg(unix)]
#[cfg(target_os = "linux")]
pub use self::unix::{
interface_from_name,
list_interfaces,
Socket,
};

#[cfg(not(target_os = "linux"))]
mod stub;

#[cfg(not(target_os = "linux"))]
pub use self::stub::{
interface_from_name,
list_interfaces,
Socket,
};
43 changes: 43 additions & 0 deletions skunk/src/proxy/pcap/os/stub.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::{io::Error, os::fd::{AsRawFd, RawFd}};

use tokio::io::ReadBuf;

use crate::proxy::pcap::{interface::Interface, socket::Mode};


fn warn_stub() {
tracing::warn!("Packet capture is not available on this platform");
}

pub fn list_interfaces() -> Result<Vec<Interface>, Error> {
warn_stub();
Ok(vec![])
}

pub fn interface_from_name(_name: &str) -> Result<Option<Interface>, Error> {
warn_stub();
Ok(None)
}

#[derive(Debug)]
pub enum Socket {}

impl Socket {
pub fn open(_interface: &Interface, _mode: Mode) -> Result<Self, Error> {
unreachable!();
}

pub async fn receive(&self, _buf: &mut ReadBuf<'_>) -> Result<usize, Error> {
unreachable!();
}

pub async fn send(&self, _buf: &[u8]) -> Result<(), Error> {
unreachable!();
}
}

impl AsRawFd for Socket {
fn as_raw_fd(&self) -> RawFd {
unreachable!();
}
}

0 comments on commit d0ac5f4

Please sign in to comment.