Page 1 of 1

cannot set TUN mode for TAP-Win32 driver programmatically

Posted: Thu May 31, 2012 6:05 pm
by sherwoodluo
I am developing a customized application which reads IP packets from TUN interface and then send it over peer-to-peer transports. For this purposed I installed OpenVPN 2.2.2 and used the TAP-Win32 driver coming along with it (version 9.9).

From the various posts I found online, the following steps were performed in my application to setup TUN interface:

1) Use the OpenVPN "Add New Tap Virtual Adapter" utility to add a tap device.
2) Manually configure the device IP address in Windows Control Panel.
3) Obtain the TAP device GUID.
4) Use this GUID and CreateFile() to obtain a device handle.
5) (Optional) Use TAP_IOCTL_GET_MTU to get the device supported MTU. (I used this to verify DeviceIoControl() can be successfully fulfilled.
6) Use TAP_IOCTL_CONFIG_TUN to set the device in TUN mode, with network/local address/netmask as parameters.
7) Use TAP_IOCTL_SET_MEDIA_STATUS to set the virtual interface as connected.
8) Use Windows "route" command to add subnet routes to the virtual interface.

While the return code from 4) to 8) were all successful. The device still behaves as a TAP rather than TUN. When I am issuing ping to the addresses within the subnet, I observed ARP inquiries on the virtual interface (using Wireshark) but no IP packets. What should I do to make sure it behaves as a TUN?

Appreciate the help.

Re: cannot set TUN mode for TAP-Win32 driver programmaticall

Posted: Thu Sep 20, 2012 8:24 pm
by vijayaplv
Were you able to accomplish this? I am also facing the same issue. If so please share your approach.

Re: cannot set TUN mode for TAP-Win32 driver programmatically

Posted: Wed Jun 27, 2018 8:09 am
by ayoub
Were you able to accomplish this? I am also facing the same issue. If so please share your approach.