pub struct AsyncNdisapiAdapter { /* private fields */ }
Expand description

The struct AsyncNdisapiAdapter represents a network adapter with its associated driver and relevant handles.

Implementations§

source§

impl AsyncNdisapiAdapter

source

pub fn new(driver: Arc<Ndisapi>, adapter_handle: HANDLE) -> Result<Self>

Constructs a new AsyncNdisapiAdapter.

This function takes a network driver and the handle of the network adapter as arguments. It then creates a Win32 event and sets it for packet capture for the specified adapter. Finally, it creates a new AsyncNdisapiAdapter with the driver, adapter handle, and a Win32EventStream created with the event handle.

Arguments
  • driver - An Arc<ndisapi::Ndisapi> that represents the network driver for the adapter.
  • adapter_handle - A HANDLE that represents the handle of the network adapter.
Safety

This function contains unsafe code blocks due to the FFI call to CreateEventW and the potential for a null or invalid adapter handle. The caller should ensure that the passed network driver and the adapter handle are properly initialized and safe to use in this context.

Errors

Returns an error if the Win32 event creation fails, or if setting the packet capture event for the adapter fails, or if creating the Win32EventStream fails.

Returns

Returns an Ok(Self) if the AsyncNdisapiAdapter is successfully created, where Self is the newly created AsyncNdisapiAdapter.

source

pub fn set_adapter_mode(&self, flags: FilterFlags) -> Result<()>

Sets the operating mode for the network adapter.

This function takes a set of FilterFlags as an argument which represent the desired operating mode, and applies them to the network adapter.

Arguments
  • flags - FilterFlags that represent the desired operating mode for the network adapter.
Errors

Returns an error if the driver fails to set the operating mode for the network adapter.

Returns

Returns Ok(()) if the operating mode was successfully set for the network adapter.

source

pub async fn read_packet( &mut self, packet: &mut IntermediateBuffer ) -> Result<()>

Asynchronously reads a packet from the network adapter, filling the provided IntermediateBuffer.

This function initializes an EthRequest with the handle to the adapter and the provided IntermediateBuffer. Then it tries to read a packet from the network adapter. If the initial read operation fails, the function awaits the next event from the Win32EventStream before retrying the read operation.

Arguments
  • packet - An IntermediateBuffer which will be filled with the data from the network adapter if a packet is successfully read.
Safety

This function contains unsafe code blocks due to the FFI call to GetLastError().

Errors

Returns an error if the driver fails to read a packet from the network adapter, or if the await operation on the event stream fails. In case of driver failure, the specific error returned is the last occurred error, retrieved via a call to GetLastError().

Returns

Returns Ok(()) if the packet is successfully read from the network adapter.

source

pub async fn read_packets<'a, const N: usize, I>( &mut self, packets: I ) -> Result<usize>where I: Iterator<Item = &'a mut IntermediateBuffer>,

Asynchronously reads a number of packets from the network adapter and returns the number of packets successfully read.

This function creates an EthMRequest with the provided IntermediateBuffers and the handle to the adapter. It then attempts to read packets from the network adapter. If the initial read operation fails, the function waits for a packet event before retrying the read operation.

Arguments
  • packets - An iterator over &mut IntermediateBuffer which will be filled with the data from the network adapter if packets are successfully read.
Safety

This function contains unsafe code blocks due to the FFI call to GetLastError().

Type Parameters
  • N: A compile-time constant representing the maximum size of the EthMRequest.
Errors

Returns an error if the driver fails to read packets from the network adapter, or if the await operation on the packet event fails. In case of driver failure, the specific error returned is the last occurred error, obtained via a call to GetLastError().

Returns

Returns Ok(usize) if packets are successfully read from the network adapter, where usize is the number of packets read.

source

pub fn send_packet_to_adapter( &self, packet: &mut IntermediateBuffer ) -> Result<()>

Sends an Ethernet packet to the network adapter.

This function takes an IntermediateBuffer as an argument, wraps it into an EthPacket, and sends it to the network adapter. This is accomplished by creating an EthRequest structure, which includes the EthPacket and the handle to the adapter. This request is then passed to the driver API for transmission.

Arguments
  • packet - An IntermediateBuffer that will be encapsulated in an EthPacket representing the Ethernet packet to be sent.
Safety

This function contains unsafe code blocks due to the FFI call to GetLastError(). Ensure that the IntermediateBuffer passed as argument is properly initialized and safe to use in this context.

Errors

Returns an error if the driver fails to send the packet to the network adapter. The specific error returned is the last occurred error, obtained via a call to GetLastError().

Returns

Returns Ok(()) if the packet is successfully sent to the network adapter.

source

pub fn send_packets_to_adapter<'a, const N: usize, I>( &mut self, packets: I ) -> Result<usize>where I: Iterator<Item = &'a mut IntermediateBuffer>,

Sends a specified number of Ethernet packets to the network adapter synchronously.

This function initializes an EthMRequest object using an iterator over IntermediateBuffer objects and the handle to the network adapter. It then attempts to send these packets to the network adapter. If the sending process fails, an error is returned.

Arguments
  • packets - An iterator over mutable references to IntermediateBuffer objects that contain the Ethernet packets to be sent to the network adapter.
Safety

This function contains unsafe code blocks due to the Foreign Function Interface (FFI) call to GetLastError(). Ensure that the input IntermediateBuffer objects are properly initialized and safe to use in this context.

Type Parameters
  • N: A compile-time constant that determines the maximum size of the EthMRequest object.
  • I: The type of the iterator over IntermediateBuffer objects.
Errors

This function returns an error if the driver fails to send packets to the network adapter. The specific error returned is the last error occurred, obtained via a call to GetLastError().

Returns

On successful operation, this function returns an Ok(usize) that represents the number of packets successfully sent to the network adapter. If the operation fails, an error is returned.

source

pub fn send_packet_to_mstcp( &self, packet: &mut IntermediateBuffer ) -> Result<()>

Sends an Ethernet packet upwards through the network stack to the Microsoft TCP/IP protocol driver.

This function creates an EthRequest object with the EthPacket to be sent and the handle to the network adapter. This EthRequest is then passed to the driver API to send the packet upwards through the network stack.

Arguments
  • packet - A mutable reference to an IntermediateBuffer that represents the Ethernet packet to be sent.
Safety

This function is marked unsafe due to the Foreign Function Interface (FFI) call to GetLastError(). Ensure that the input IntermediateBuffer is properly initialized and safe to use in this context.

Errors

This function returns an error if the driver fails to send the packet upwards through the network stack. The specific error returned is the last error that occurred, obtained via a call to GetLastError().

Returns

On successful operation, this function returns Ok(()). If the operation fails, an error is returned.

source

pub fn send_packets_to_mstcp<'a, const N: usize, I>( &mut self, packets: I ) -> Result<usize>where I: Iterator<Item = &'a mut IntermediateBuffer>,

Sends a sequence of Ethernet packets upwards through the network stack to the Microsoft TCP/IP protocol driver synchronously.

This function creates an EthMRequest object with the provided iterator over IntermediateBuffers and the handle to the network adapter. It then tries to send these packets upwards through the network stack.

Arguments
  • packets - An iterator over mutable references to IntermediateBuffers representing the Ethernet packets to be sent.
Safety

This function is marked unsafe due to the Foreign Function Interface (FFI) call to GetLastError(). Ensure that the input IntermediateBuffers are properly initialized and safe to use in this context.

Type Parameters
  • N: The compile-time constant specifying the maximum size of the EthMRequest.
  • I: The type of the iterator over IntermediateBuffer objects.
Errors

This function returns an error if the driver fails to send the packets upwards through the network stack. The specific error returned is the last error that occurred, obtained via a call to GetLastError().

Returns

On successful operation, this function returns Ok(usize), where usize is the number of packets sent. If the operation fails, an error is returned.

Trait Implementations§

source§

impl Drop for AsyncNdisapiAdapter

source§

fn drop(&mut self)

The drop method will be called automatically when the AsyncNdisapiAdapter object goes out of scope.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.