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
impl AsyncNdisapiAdapter
Sourcepub fn new(driver: Arc<Ndisapi>, adapter_handle: HANDLE) -> Result<Self>
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- AnArc<ndisapi::Ndisapi>that represents the network driver for the adapter.adapter_handle- AHANDLEthat 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.
Sourcepub fn set_adapter_mode(&self, flags: FilterFlags) -> Result<()>
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-FilterFlagsthat 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.
Sourcepub async fn read_packet(
&mut self,
packet: &mut IntermediateBuffer,
) -> Result<()>
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 EthRequestMut 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- AnIntermediateBufferwhich 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.
Sourcepub async fn read_packets<'a, const N: usize>(
&mut self,
packets: impl IntoIterator<Item = &'a mut IntermediateBuffer>,
) -> Result<usize>
pub async fn read_packets<'a, const N: usize>( &mut self, packets: impl IntoIterator<Item = &'a mut IntermediateBuffer>, ) -> Result<usize>
Asynchronously reads a number of packets from the network adapter and returns the number of packets successfully read.
This function creates an EthMRequestMut 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 IntermediateBufferwhich 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 theEthMRequest.
§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.
Sourcepub fn send_packet_to_adapter(
&self,
packet: &mut IntermediateBuffer,
) -> Result<()>
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- AnIntermediateBufferthat will be encapsulated in anEthPacketrepresenting 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.
Sourcepub fn send_packets_to_adapter<'a, const N: usize>(
&mut self,
packets: impl IntoIterator<Item = &'a IntermediateBuffer>,
) -> Result<usize>
pub fn send_packets_to_adapter<'a, const N: usize>( &mut self, packets: impl IntoIterator<Item = &'a IntermediateBuffer>, ) -> Result<usize>
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 references toIntermediateBufferobjects 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 theEthMRequestobject.I: The type of the iterator overIntermediateBufferobjects.
§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.
Sourcepub fn send_packet_to_mstcp(&self, packet: &IntermediateBuffer) -> Result<()>
pub fn send_packet_to_mstcp(&self, packet: &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 reference to anIntermediateBufferthat 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.
Sourcepub fn send_packets_to_mstcp<'a, const N: usize>(
&mut self,
packets: impl IntoIterator<Item = &'a IntermediateBuffer>,
) -> Result<usize>
pub fn send_packets_to_mstcp<'a, const N: usize>( &mut self, packets: impl IntoIterator<Item = &'a IntermediateBuffer>, ) -> Result<usize>
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 references toIntermediateBuffers 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 theEthMRequest.I: The type of the iterator overIntermediateBufferobjects.
§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.