Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C++;创建NdisProt驱动程序的句柄_C#_C++_Ndis_Raw Ethernet - Fatal编程技术网

C# C++;创建NdisProt驱动程序的句柄

C# C++;创建NdisProt驱动程序的句柄,c#,c++,ndis,raw-ethernet,C#,C++,Ndis,Raw Ethernet,我尝试写入NdisProt驱动程序并发送原始以太网数据包。我把一些C++的COMSONCE导入到我的C语言程序中,这样我就可以访问这个驱动程序。当我试图给司机打开把手时,我总是得到一个无效的把手。我已经用“NdisProt”作为路径进行了尝试,但没有解决它。你有什么建议为什么我得到一个无效的句柄 private bool OpenDriver() { // User the CreateFile API to open a handle to the file this.m_iH

我尝试写入NdisProt驱动程序并发送原始以太网数据包。我把一些C++的COMSONCE导入到我的C语言程序中,这样我就可以访问这个驱动程序。当我试图给司机打开把手时,我总是得到一个无效的把手。我已经用“NdisProt”作为路径进行了尝试,但没有解决它。你有什么建议为什么我得到一个无效的句柄

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;
    }
private bool OpenDriver()
{
//使用CreateFile API打开文件句柄
this.m\u iHandle=CreateFile(“\\\\.\\NdisProt),
泛型_写入|泛型_读取,0,0,打开_存在,文件_属性_正常,0);
//检查一下我们是否有一个有效的句柄
如果((int)m_i句柄
如果您现在有任何其他解决方案可以在C中发送原始以太网数据包#
请让我知道

上课呢

建造商:

public Socket (System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType),
其中socketType可以取下一个值:
socketType.Raw

如果您现在有任何其他解决方案可以在C#程序中发送原始以太网数据包,请告诉我

您可以从Windows Winsock库导入函数,并在创建套接字时使用标志

int sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);

更新:我刚刚通过添加另一个清单解决了这个问题,这样应用程序就可以作为管理员运行

带有NDIS驱动程序的解决方案仍然不起作用,因此我搜索了另一个解决方案。我找到了SharpPcap库。通过该库,我可以修改我要发送的数据包,例如更改目标MAC地址


感谢您的回答!

您有权打开此文件吗?我必须做什么才能获得权限?尝试以root权限(管理员身份)运行应用程序,并通过GetLastError检查错误(请参阅)不幸的是,当以管理员身份运行VS时,它并没有解决问题。我只想发送带有源MAC地址、目标MAC地址和一些随机数据的数据包。我想这在原始套接字中是不可能的。@LeoBiel,好的,你是对的。它需要导入系统C库。@LeoBiel,请检查:这是基础(codeproject.com/Articles/5292/Raw-Ethernet-Packet-Sending)我正在处理,但我无法处理ndisdriver@LeoBiel,所以,您应该通过GetLastError检查错误(如我前面所说)