Skip to content

Commit

Permalink
Add want_pktap
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Aug 27, 2024
1 parent 87d91b2 commit 131d71e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/01-build-and-test-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ jobs:
run: cargo build --lib --tests
env:
LIBPCAP_VER: '1.5.0'
- name: 'LIBPCAP_VER: 1.5.3'
run: cargo build --lib --tests
env:
LIBPCAP_VER: '1.5.3'
- name: 'LIBPCAP_VER: 1.7.2'
run: cargo build --lib --tests
env:
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl Version {
vec![
Version::new(1, 2, 1),
Version::new(1, 5, 0),
Version::new(1, 5, 3),
Version::new(1, 7, 2),
Version::new(1, 9, 0),
Version::new(1, 9, 1),
Expand Down
26 changes: 26 additions & 0 deletions src/capture/inactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ impl Capture<Inactive> {
self
}

/// Set want_pktap to true or false. The default is maintained by libpcap.
#[cfg(all(libpcap_1_5_3, target_os = "macos"))]
pub fn want_pktap(self, to: bool) -> Capture<Inactive> {
unsafe { raw::pcap_set_want_pktap(self.handle.as_ptr(), to as _) };

self
}

/// Set rfmon mode on or off. The default is maintained by pcap.
#[cfg(not(windows))]
pub fn rfmon(self, to: bool) -> Capture<Inactive> {
Expand Down Expand Up @@ -357,6 +365,24 @@ mod tests {
let _capture = capture.immediate_mode(false);
}

#[test]
#[cfg(all(libpcap_1_5_3, target_os = "macos"))]
fn test_want_pktap() {
let _m = RAWMTX.lock();

let mut dummy: isize = 777;
let pcap = as_pcap_t(&mut dummy);

let test_capture = test_capture::<Inactive>(pcap);
let capture = test_capture.capture;

let ctx = raw::pcap_set_want_pktap_context();
ctx.expect()
.withf_st(move |arg1, _| *arg1 == pcap)
.return_once(|_, _| 0);
let _capture = capture.want_pktap(true);
}

#[test]
#[cfg(not(windows))]
fn test_rfmon() {
Expand Down
19 changes: 19 additions & 0 deletions src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ pub mod ffi_unix {
}
}

#[cfg(target_os = "macos")]
#[cfg_attr(test, automock)]
pub mod ffi_macos {
use super::*;

#[cfg(libpcap_1_5_3)]
extern "C" {
pub fn pcap_set_want_pktap(arg1: *mut pcap_t, arg2: c_int) -> c_int;
}
}

#[cfg(windows)]
#[cfg_attr(test, automock)]
pub mod ffi_windows {
Expand Down Expand Up @@ -305,6 +316,10 @@ pub use ffi::*;
#[cfg(not(windows))]
pub use ffi_unix::*;

#[cfg(not(test))]
#[cfg(target_os = "macos")]
pub use ffi_macos::*;

#[cfg(not(test))]
#[cfg(windows)]
pub use ffi_windows::*;
Expand All @@ -316,6 +331,10 @@ pub use mock_ffi::*;
#[cfg(not(windows))]
pub use mock_ffi_unix::*;

#[cfg(test)]
#[cfg(target_os = "macos")]
pub use mock_ffi_macos::*;

#[cfg(test)]
#[cfg(windows)]
pub use mock_ffi_windows::*;
Expand Down

0 comments on commit 131d71e

Please sign in to comment.