1

I try to write to a NdisProt driver and send raw ethernet packets. I imported some C++ comands to my C# program, so that I can access the driver. When I try to open a handle to the driver I always get a invalid handle. I already tried it with just "NdisProt" as the path, but it didn't solve it. Do you have any suggestions why i get a invalid handle?

private bool OpenDriver()
{
    // User the CreateFile API to open a handle to the file
    this.m_iHandle = CreateFile("\\\\.\\NdisProt,
    GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

    // Check to see if we got a valid handle
    if ((int)m_iHandle <= 0)
    {
        // If not, then return false and reset the handle to 0
        this.m_iHandle = IntPtr.Zero;
        return false;
    }

If you now any other solutions to send raw ethernet packets in a C# program please let me know.

Thanks for any help!

piet.t
  • 11,718
  • 21
  • 43
  • 52
LeoBiel
  • 33
  • 6

3 Answers3

1

Update: I just solved the problem by adding another manifest, so that the application is run as admin.

The solution with the NDIS Driver did still not work so I searched for another solution. I found the SharpPcap library. With that library I am able to modify the packets I want to send e.g. change the Destination-MAC-Adress.

Thanks for your answers!

LeoBiel
  • 33
  • 6
0

If you now any other solutions to send raw ethernet packets in a C# program please let me know.

What about Socket class?

Constructor:

public Socket (System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType),

where socketType can take the next value: SocketType.Raw

isnullxbh
  • 807
  • 13
  • 20
0

If you now any other solutions to send raw ethernet packets in a C# program please let me know.

You can import functions from Windows Winsock library and use SOCK_RAW flag when creating a socket.

int sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
M. Sol
  • 101
  • 5