Skip to main content

winptap_native/
lib.rs

1//! Independent native Packet Monitor receive backend, for Windows x64.
2#[cfg(windows)]
3mod buffer;
4pub mod compat;
5#[cfg(windows)]
6mod device;
7#[cfg(windows)]
8mod discovery;
9#[cfg(windows)]
10mod filter;
11#[cfg(windows)]
12mod ioctl;
13pub mod protocol;
14#[cfg(windows)]
15mod session;
16use winptap_core::*;
17pub fn open(config: Config) -> Result<Box<dyn Session>> {
18    config.validate()?;
19    compat::require_supported_platform()?;
20    #[cfg(windows)]
21    {
22        Ok(Box::new(session::NativeSession::open(config)?))
23    }
24    #[cfg(not(windows))]
25    {
26        Err(Error::UnsupportedPlatform)
27    }
28}
29pub fn capabilities() -> Result<Capabilities> {
30    compat::require_supported_platform()?;
31    #[cfg(windows)]
32    let _probe = device::DeviceHandle::open()?;
33    Ok(Capabilities {
34        backend: Backend::NativeIoctl,
35        ethernet: true,
36        receive: true,
37        transmit_observation: false,
38        interface_selection: true,
39        capture_filtering: true,
40        max_snaplen: 9000,
41        shared_memory: true,
42        drop_statistics: true,
43        asynchronous: true,
44    })
45}
46pub fn devices() -> Result<Vec<Device>> {
47    compat::require_supported_platform()?;
48    #[cfg(windows)]
49    {
50        discovery::enumerate(&device::DeviceHandle::open()?)
51    }
52    #[cfg(not(windows))]
53    {
54        Err(Error::UnsupportedPlatform)
55    }
56}