点击窗口设置TUN MTU
本文关键字:TUN MTU 设置 窗口 | 更新日期: 2023-09-27 18:22:45
我试图使用以下示例代码在Windows中设置TUN-TAP设备(所有驱动程序都已正确安装):http://www.varsanofiev.com/inside/TunTest.cs
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#中找不到任何关于它的信息。
谢谢。
Openvpn TUN驱动程序从注册表读取MTU设置。
[HKEY_LOCAL_MACHINE'SYSTEM'ControlSet001'Control'Class'{4D36E972-E325-11CE-BFC1-08002BE10318}'0021]
"NewDeviceInstall"=dword:00000001
"NetCfgInstanceId"="{F63BF017-1532-4476-A7AB-C0AB756A4EE7}"
"*IfType"=dword:00000006
"Characteristics"=dword:00000081
"NetLuidIndex"=dword:00000014
"DeviceInstanceID"="ROOT''NET''0001"
"InstallTimeStamp"=hex:e0,07,04,00,04,00,1c,00,0e,00,2d,00,24,00,50,00
"Manufacturer"="TAP-Win32 Provider OAS"
"ProductName"="TAP-Win32 Adapter OAS"
"ComponentId"="tapoas"
"AllowNonAdmin"="1"
"MediaStatus"="0"
"MTU"="1500"
"InfPath"="oem44.inf"
"InfSection"="tapoas.ndi"
"ProviderName"="TAP-Win32 Provider OAS"
"DriverDateData"=hex:00,00,0b,41,53,df,ca,01
"DriverDate"="4-19-2010"
"DriverVersion"="9.0.0.7"
"MatchingDeviceId"="tapoas"
"DriverDesc"="TAP-Win32 Adapter OAS"
[HKEY_LOCAL_MACHINE'SYSTEM'ControlSet001'Control'Class'{4D36E972-E325-11CE-BFC1-08002BE10318}'0021'Ndi'params'MTU]
"ParamDesc"="MTU"
"Type"="int"
"Default"="1500"
"Optional"="0"
"Min"="100"
"Max"="1500"
"Step"="1"