I am trying to create a simple VPN application without any external drivers .
My Logic is :
I created a Microsoft Loop back adapter with the help of Devcon . Using this as my VPN driver for reading and writing packet (from Microsoft Loop back adapter ) . Also i want to create a Tunnel with this adapter . Can i do this logic ?
Next what i tried is , I opened this adapter handle with the help of “CreateFile” API and With the help of “ReadFile” API , i am reading packets .
code :
HANDLE hand;
// Obtain handle to Device File for custom driver with GUID of the microsoft Loopback adapter
hand = CreateFile(L"\\.\{GUID}", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
FILE_FLAG_NO_BUFFERING, NULL);
if (hand == INVALID_HANDLE_VALUE){
printf(“handle failed with error: %ld\n”, GetLastError());
}
else{
printf(“Handle sucess\n”);
CHAR readBuffer[32];
DWORD bytesRead = 0;
BOOL success = ReadFile(hand, readBuffer, sizeof(readBuffer), &bytesRead, NULL);
if (success)
printf(“Read File status is success \n”);
else
{
DWORD error = GetLastError();
printf(“read file error code : %ld\n”, GetLastError());
}
}
But after running this application , i got reading error like :
read file error code : 50
But CreateFile handle is got success . Any suggestions ? Any help ?