tap windows set TUN MTU

0

I was trying to set up TUN-TAP device in Windows using this sample code (all driver already installed correctly): 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);

Is there a way to set TUN MTU? I couldn't find anything about that in C#.

Thank you.

c#
windows
adapter
tap
mtu
asked on Stack Overflow Nov 19, 2015 by bepperk • edited Jun 20, 2020 by Community

1 Answer

0

Openvpn TUN driver read MTU setting from registry.

[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"
answered on Stack Overflow Apr 30, 2016 by user934335

User contributions licensed under CC BY-SA 3.0