[OpenVPN home] [Date Prev] [Date Index] [Date Next]
[OpenVPN mailing lists] [Thread Prev] [Thread Index] [Thread Next]
Google
 
Web openvpn.net

[Openvpn-users] Using TUN on Windows


  • Subject: [Openvpn-users] Using TUN on Windows
  • From: "Alan Duca" <idduka@xxxxxxxxx>
  • Date: Tue, 23 Oct 2007 17:30:22 +0200

Hi all,

   I am very new to openVPN, and VPNs in general, so please bear with me :)

   I am interested in creating a small application (on Windows) that makes use of TUN in order to push ip-framed packets to user-level. I have successfully written a small application which interfaces the TAP-Win32 adapter in TAP mode (not TUN mode), and pushes ethernet -framed packets to user-level. However, I am not succeeding at doing the same in TUN mode...

   I realize that there is a vital difference between TUN and TAP: a TAP device is a virtual adapter, while TUN is a virtual Point-to-Point IP link. I also know that in order to utilize TUN mode, you would have to specify a point to point link to the virtual adapter on the system. But several questions remain: Why is there a need for a point to point link? What should the endpoints of this point to point link be?

   I tried to set up this point to point link as follows:

      char local_ep_bytes[4] = {172, 22, 60, 1};                           
             //ip of installed TAP-Win32 adapter
      char remote_ep_bytes[4] = {172, 22, 60, 2};                                     //non-existant ip
      int *local_ep = (int*)(&local_ep_bytes);
      int *remote_ep = (int*)(&remote_ep_bytes);
     
      ULONG end_points[2];
      end_points[0] = htonl(*local_ep);
      end_points[1] = htonl(*remote_ep);

      if(!DeviceIoControl (h_fil,                                                                   //handle to file representing TAP-Win32 adapter
                           CTL_CODE (FILE_DEVICE_UNKNOWN, 5, METHOD_BUFFERED, FILE_ANY_ACCESS),
                           end_points,                                                               //point-to-point endpoints
                           sizeof (end_points),
                           end_points,
                           sizeof (end_points),
                           &retBytes,
                           NULL))
      {
         printf("ERROR: The TAP-Win32 driver rejected a DeviceIoControl call to set Point-to-Point mode");
      }


   The call to this method succeeds, but the file with handle h_fil does not ever get any data written to it.

   I am finding this very confusing. The main question here is: what is the fundamental difference between working in TAP mode, and working in TUN mode, and what has to be done in an application in order to deal with this difference.

   Any help would be greatly appreciated!


Thanks,
Alan.