Hi. My question is about how actually the driver sends packets to the adapter, because I seems like have success on the sending but I can not see the actual result anywhere, in my own driver capturing or in the Wireshark everything is just empty… Can you clarify is it actually normal or I do something wrong?
Here is my C# function to send the packet to the adapter. Maybe I made a mistake or something.
public unsafe void SendPacket(Span<byte> bytes, int adapterIndex)
{
var _driver = NdisApi.Open();
var availableNetworkAdapters = _driver.GetNetworkAdapters().ToList();
fixed (byte* dataPinnedPtr = bytes)
{
// Allocate memory
var bufPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(INTERMEDIATE_BUFFER)));
var intBuff = new INTERMEDIATE_BUFFER
{
m_Length = (uint)bytes.Length,
m_Flags = 0,
};
for (var i = 0; i < MAX_ETHER_FRAME; i++)
{
intBuff.m_IBuffer[i] = dataPinnedPtr[i];
}
Marshal.StructureToPtr(intBuff, bufPtr, false);
var ethRequest = new ETH_REQUEST
{
hAdapterHandle = availableNetworkAdapters[adapterIndex].Handle,
EthPacket = new NDISRD_ETH_Packet
{
Buffer = bufPtr
}
};
var result = _driver.SendPacketToAdapter(ref ethRequest);
Debug.WriteLine($”Result: {result}”);
// Free allocated memory
Marshal.FreeHGlobal(bufPtr);
}
_driver.Close();
}