I have installed the TAP-WIN32 Adapter V9 on my Windows 7 machine. I want to use TUN to read the IP packets out of the interface. I followed the C# sample from http://www.varsanofiev.com/inside/using_tuntap_under_windows.htm
I modified the code like below
IntPtr ptun = Marshal.AllocHGlobal(8);
Marshal.WriteInt32(ptun, 0, 0x0a030001);
Marshal.WriteInt32(ptun, 4, unchecked((int)0x00ffffFF));
bool val = DeviceIoControl (ptr, TAP_CONTROL_CODE (5, METHOD_BUFFERED) /*POINT TO POINT */, ptun, 8,ptun, 8, out len, IntPtr.Zero);
However, I still don't seem to get IP packets. I ran tcpdump on the other end and it complains "Wrong link layer encapsulation".
Is this the correct way of trying to get IP Packets out of TUN interface?
ETHERNET FRAME CHECK SEQUENCE NOT CORRECT
as response. In order for you to be able to read IP packets, after setting p2p like you did, you need to do some routing:route add <server_ip> mask 255.255.255.255 <router/modem gateway ip>
route add 128.0.0.0 mask 128.0.0.0 <tun/tap ip>
route add 0.0.0.0 mask 128.0.0.0 <tun/tap ip>
– BinahTAP_WIN_IOCTL_CONFIG_TUN
is defined at github.com/OpenVPN/tap-windows6/blob/… – Cathode