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

[Openvpn-devel] Problem with TAP under Win32: how read correcty



Hi guy,
i ve am writing a Win32 app that makes use of TAP
drivers bundled with OpenVPN. 
I ve looked at tun.c to understand how control and mange
the virtual interface, but i ve a big problem:
i can open the device, read driver verion, mtu etcc...
but when i try to read the data submitted by the os
with a ReadFile call, i obtain corrupted packets.
Now, my tap interface has to receive ipv6 traffic, but 
when i call ping6 on it, the buffer i read with ReadFile
is smaller (86 bytes vs 216) and differend from
a correct buffer i read under linux (where all works).

I post the code i use to open the device and read it,
can someone take a look and tell me if i ve missing 
something ? thanks!!!

--------------------------------------------
int device_number = 0;
while (true)
{
	device_guid = get_unspecified_device_guid (device_number, 
		guid_buffer, 
		sizeof (guid_buffer),
		tap_reg,
		panel_reg,
		&gc);

	if (!device_guid)
		printf("All TAP-Win32 adapters on this system are currently in
                 use.");

	/* Open Windows TAP-Win32 adapter */
	sprintf(device_path, 
               "%s%s%s",USERMODEDEVICEDIR,device_guid,TAPSUFFIX);

	user_data.tunFile = CreateFile (
		 	device_path,
			GENERIC_READ | GENERIC_WRITE,
			0, /* was: FILE_SHARE_READ */
			0,
			OPEN_EXISTING,
			FILE_ATTRIBUTE_SYSTEM,
			0
			);

	if (user_data.tunFile == INVALID_HANDLE_VALUE)
		printf("CreateFile failed on TAP device: %s\n", device_path);
         else
	{
		printf("CreateFile succeedeed on TAP device: %s\n", 
                           device_path);
		break;
	}
        
		device_number++;
}

actual_name = string_alloc (guid_buffer, NULL);
printf("TAP-WIN32 device [%s] opened\n\tpath: %s\n", actual_name, device_path);


/* Get drivers version */
ULONG info[3];
CLEAR (info);
if (DeviceIoControl (user_data.tunFile, TAP_IOCTL_GET_VERSION,&info, 
            sizeof (info),&info, sizeof (info), &len, NULL))
{
	printf("TAP-Win32 Driver Version %d.%d %s\n",(int) info[0],(int) 
           info[1],(info[2] ? "(DEBUG)" : ""));
}
    
if ( !(info[0] > TAP_WIN32_MIN_MAJOR || (info[0] == TAP_WIN32_MIN_MAJOR &&
info[1] >= TAP_WIN32_MIN_MINOR)) )
      printf("ERROR:  This version of the program requires a TAP-Win32   
       driver");

/* get driver MTU */
ULONG mtu;
if (DeviceIoControl (user_data.tunFile, TAP_IOCTL_GET_MTU,&mtu, s izeof
(mtu),&mtu, sizeof (mtu), &len, NULL))
     printf("TAP-Win32 MTU=%d\n", (int) mtu);


/* set driver media status to 'connected' */
ULONG status = TRUE;
if (!DeviceIoControl(user_data.tunFile,TAP_IOCTL_SET_MEDIA_STATUS,
        &status, sizeof (status),&status, sizeof (status), &len, NULL))
	      printf("WARNING: The TAP-Win32 driver rejected th call");
else
	printf("The TAP-Win32 driver accepted the 
          TAP_IOCTL_SET_MEDIA_STATUS DeviceIoControl call.\n");


/* READ ON DEVICE TAP 1 */ 
status = ReadFile(
		user_data.tunFile,  
		buffer,   // <-- here is the error
		2000,
		&dwBytesRead,
	
	NULL
		); 



____________________________________________________________
6X velocizzare la tua navigazione a 56k? 6X Web Accelerator di Libero!
Scaricalo su INTERNET GRATIS 6X http://www.libero.it



____________________________________________
Openvpn-devel mailing list
Openvpn-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/openvpn-devel