Sending a packet to Adapter, can’t see anywhere

Home Forums Discussions General Sending a packet to Adapter, can’t see anywhere

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #13891
    BrianC
    Participant

      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();
      }

      #13892
      Vadim Smirnov
      Keymaster

        The ability to capture a sent packet depends on how the drivers are layered. In some cases, it might not be possible. I recommend trying to capture the packet using Wireshark on the destination machine.
        If the adapter handle is configured correctly, you should be able to send any packet on a wired network. However, with WiFi, the situation is more complex since the MAC addresses must be accurate.

      Viewing 2 posts - 1 through 2 (of 2 total)
      • You must be logged in to reply to this topic.