Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.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#_Windows_Network Programming_Tun - Fatal编程技术网

C# 将点击窗口设备置于点击模式

C# 将点击窗口设备置于点击模式,c#,windows,network-programming,tun,C#,Windows,Network Programming,Tun,我正在使用TAP窗口(来自OpenVPN项目)创建一个界面,如所述和所述。我以第一篇文章中提供的示例代码为基础: const string UsermodeDeviceSpace = "\\\\.\\Global\\"; string devGuid = GetDeviceGuid(); IntPtr ptr= CreateFile(UsermodeDeviceSpace+devGuid+".tap", FileAccess.ReadWrite, FileShare.ReadWr

我正在使用TAP窗口(来自OpenVPN项目)创建一个界面,如所述和所述。我以第一篇文章中提供的示例代码为基础:

const string UsermodeDeviceSpace = "\\\\.\\Global\\";
string devGuid = GetDeviceGuid();
IntPtr ptr= CreateFile(UsermodeDeviceSpace+devGuid+".tap",
    FileAccess.ReadWrite,
    FileShare.ReadWrite,
    0,
    FileMode.Open,
    FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 
    IntPtr.Zero);
int len;
IntPtr pstatus = Marshal.AllocHGlobal(4);
Marshal.WriteInt32(pstatus, 1);
// Set media status to connected
DeviceIoControl (ptr, 
    TAP_CONTROL_CODE (6, METHOD_BUFFERED), pstatus, 4,
    pstatus, 
    4, 
    out len, 
    IntPtr.Zero);
IntPtr ptun = Marshal.AllocHGlobal(12);
Marshal.WriteInt32(ptun, 0, 0x0100030a); // 10.0.0.1, Interface address
Marshal.WriteInt32(ptun, 4, 0x0000030a); // 10.0.0.0, Network
Marshal.WriteInt32(ptun, 8, unchecked((int)0x00ffffff)); // 255.255.255.0, Netmask
// Config TUN
DeviceIoControl (ptr, 
    TAP_CONTROL_CODE (10, METHOD_BUFFERED)
    ptun, 
    12,
ptun, 
    12, 
    out len, 
    IntPtr.Zero);
tap = new FileStream(ptr, FileAccess.ReadWrite, true, 10000, true);
// Setup callbacks, etc. here.
while (true)
{
    // Read from the device
}
设备似乎处于TUN模式——当我获取数据包的有效负载时,以太网报头不包括在内。 强制接口在TAP模式下运行的正确方法是什么


我正在VirtualBox中的32位Windows 7虚拟机上运行该代码。

我正在处理这个示例。我意识到当你打这个电话时:

IntPtr ptun = Marshal.AllocHGlobal(12);
Marshal.WriteInt32(ptun, 0, 0x0100030a); // 10.0.0.1, Interface address
Marshal.WriteInt32(ptun, 4, 0x0000030a); // 10.0.0.0, Network
Marshal.WriteInt32(ptun, 8, unchecked((int)0x00ffffff)); // 255.255.255.0, Netmask
// Config TUN
DeviceIoControl (ptr, 
    TAP_CONTROL_CODE (10, METHOD_BUFFERED)
    ptun, 
    12,
    ptun, 
    12, 
    out len, 
    IntPtr.Zero);
当界面处于TUN模式时。我所做的只是忽略这个(我没有调用DeviceIoControl),然后忽略文件流接收到的所有数据包