点击窗口设置TUN MTU

时间:2015-11-19 13:57:23

标签: c# windows adapter tap mtu

我正在尝试使用此示例代码在Windows中设置TUN-TAP设备(所有驱动程序已正确安装): here

        IntPtr ptr = CreateFile(UsermodeDeviceSpace + this.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);
        DeviceIoControl(ptr, TAP_CONTROL_CODE(6, METHOD_BUFFERED) /* TAP_IOCTL_SET_MEDIA_STATUS */, pstatus, 4,
                pstatus, 4, out len, IntPtr.Zero);
        IntPtr ptun = Marshal.AllocHGlobal(12);
        Console.WriteLine("MTU? {0}",Marshal.ReadInt32(ptun, 12).ToString("X"));
        Marshal.WriteInt32(ptun, 0, 0x0100030a);
        Marshal.WriteInt32(ptun, 4, 0x0000030a);            
        Marshal.WriteInt32(ptun, 8, unchecked((int)0x00ffffff));
        Marshal.WriteInt32(ptun, 12, 0x00000809); //MTU????
        DeviceIoControl(ptr, TAP_CONTROL_CODE(10, METHOD_BUFFERED) /* TAP_IOCTL_CONFIG_TUN */, ptun, 12,
            ptun, 12, out len, IntPtr.Zero);
        //Console.WriteLine(ptr);
        // SetMTU(this.TUN_MTU);
        Tap = new FileStream(ptr, FileAccess.ReadWrite, true, TUNBufferLen, true);

有没有办法设置TUN MTU?我在C#中找不到任何相关内容。

谢谢。

1 个答案:

答案 0 :(得分:0)

Openvpn TUN驱动程序从注册表中读取MTU设置。

select * from colours c1, colours c2 where c1.colour = "*la*" 
join c2 where c2.ID=c1.ID and c2.colour= "*lb*"