Discussion:
netvmini, DeviceIoControl with buffers (success), BytesReturned always zero ?
(too old to reply)
Skybuck Flying
2009-08-07 20:30:13 UTC
Permalink
Hello,

I installed two Microsoft Virtual Network Adapters (netvmini.sys).(WinXP x64
Pro)

In the user code below (translated from C example to Delphi)
one of the adapters is opened, and DeviceIoControl with buffers is
attempted.

However DeviceIoControl always returns with success and BytesReturned zero
?!?

I test by opening a game that sends network traffic over the virtual network
adapters.
The status window shows packets are being sent.

Why are these packets not returned in the DeviceIoControl buffers ?

Below is the c-to-delphi translated "user" code:
(all functions execute "successfull")

// *** begin of test program ***

program TestProgram;

{$APPTYPE CONSOLE}

uses
SysUtils,
Windows;

const
IOCTL_NETVMINI_READ_DATA = 2244608;
IOCTL_NETVMINI_WRITE_DATA = 2260996;

procedure Main;
var
vHandle : Thandle;
vBytesReturned : longword;

vInputBuffer : packed array[0..66000] of byte;
vOutputBuffer : packed array[0..66000] of byte;

begin
writeln('program started');

vHandle :=
CreateFile
(
'\\.\NETVMINI',
GENERIC_READ or GENERIC_WRITE,//FILE_READ_ATTRIBUTES | SYNCHRONIZE,
FILE_SHARE_READ,
nil, // no SECURITY_ATTRIBUTES structure
OPEN_EXISTING, // No special create flags
FILE_ATTRIBUTE_NORMAL, // No special attributes
longword(nil)
);

if vHandle <> INVALID_HANDLE_VALUE then
begin
writeln('open netvmini successfull.');

// send ioclt requests

// begin of while-experiment-test
while true do
begin

// doesn't seem to work, always returns 0 bytes returned ?!

// read request
if DeviceIoControl
(
vHandle,
IOCTL_NETVMINI_READ_DATA,
@vInputBuffer[0], 66000,
@vOutputBuffer[0], 66000,
vBytesReturned, nil
) then
begin
writeln('read IOCTL to netvmini successfull.');
writeln('vBytesReturned: ', vBytesReturned );

if vBytesReturned <> 0 then
begin
writeln('bingo');
readln;
end;
end else
begin
writeln('read IOCTL to netvmini failed.');
end;

// write request
if DeviceIoControl
(
vHandle,
IOCTL_NETVMINI_WRITE_DATA,
@vInputBuffer[0], 66000,
@vOutputBuffer[0], 66000,
vBytesReturned, nil
) then
begin
writeln('write IOCTL to netvmini successfull.');
writeln('vBytesReturned: ', vBytesReturned );

if vBytesReturned <> 0 then
begin
writeln('bingo');
readln;
end;
end else
begin
writeln('write IOCTL to netvmini failed.');
end;

// end of while-experiment-test
end;

if CloseHandle( vHandle ) then
begin
writeln('close netvmini successfull.');
end else
begin
writeln('close netvmini failed.');
end;

end else
begin
writeln('open netvmini failed.');
end;

writeln('program finished');
end;


begin
try
Main;
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
ReadLn;
end.

// *** end of test program ***

Bye,
Skybuck.
Skybuck Flying
2009-08-08 15:55:41 UTC
Permalink
Example converted to C.

Still don't work... let me know if it works on your computer ;)

// *** start of test program ***

// TestProgram.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

//#define UNICODE 1
//#define INITGUID
//#pragma warning(disable:4201) // nameless struct/union warning
#include <windows.h>
//#include <stdlib.h>
//#include <string.h>
//#include <setupapi.h>
//#include <dbt.h>
//#include <winioctl.h>

/*

Delphi version 0.01 and 0.02 created on 7 august 2009 by Skybuck Flying.
Delphi-To-C version 0.02 created on 8 august 2009 by Skybuck Flying.

*/

void Main()
{
int IOCTL_NETVMINI_READ_DATA = 2244608;
int IOCTL_NETVMINI_WRITE_DATA = 2260996;


HANDLE vHandle;
DWORD vBytesReturned;

short unsigned int vInputBuffer[66000];
short unsigned int vOutputBuffer[66000];

printf("program started\n");

vHandle =
CreateFile
(
TEXT("\\\\.\\NETVMINI"),
GENERIC_READ | GENERIC_WRITE,//FILE_READ_ATTRIBUTES | SYNCHRONIZE,
FILE_SHARE_READ,
NULL, // no SECURITY_ATTRIBUTES structure
OPEN_EXISTING, // No special create flags
FILE_ATTRIBUTE_NORMAL, // No special attributes
NULL
);

if (vHandle != INVALID_HANDLE_VALUE)
{
printf("open netvmini successfull.\n");

// send ioclt requests

while (1)
{
// doesn"t seem to work, always returns 0 bytes returned ?!

// read request
if (DeviceIoControl
(
vHandle,
IOCTL_NETVMINI_READ_DATA,
&vInputBuffer[0], 66000,
&vOutputBuffer[0], 66000,
&vBytesReturned, NULL
) != 0)
{
printf("read IOCTL to netvmini successfull.\n");
printf("vBytesReturned: %d \n", vBytesReturned );

if (vBytesReturned != 0)
{
printf("bingo");
getchar();
}
} else
{
printf("read IOCTL to netvmini failed.\n");
}

// write request
if (DeviceIoControl
(
vHandle,
IOCTL_NETVMINI_WRITE_DATA,
&vInputBuffer[0], 66000,
&vOutputBuffer[0], 66000,
&vBytesReturned, NULL
) != 0)
{
printf("write IOCTL to netvmini successfull.\n");
printf("vBytesReturned: %d \n", vBytesReturned );

if (vBytesReturned != 0)
{
printf("bingo\n");
getchar();
}
} else
{
printf("write IOCTL to netvmini failed.\n");
}

}

if (CloseHandle( vHandle ) != 0)
{
printf("close netvmini successfull.\n");
} else
{
printf("close netvmini failed.\n");
}

} else
{
printf("open netvmini failed.\n");
}

printf("program finished\n");
}

int _tmain(int argc, _TCHAR* argv[])
{
Main();
getchar();
return 0;
}

// *** end of test program ***

Bye,
Skybuck.
Skybuck Flying
2009-08-08 15:58:41 UTC
Permalink
I also tried adding the original constants with the include directives:

#define IOCTL_NETVMINI_READ_DATA \
CTL_CODE (FILE_DEVICE_UNKNOWN, 0, METHOD_BUFFERED, FILE_READ_ACCESS)

#define IOCTL_NETVMINI_WRITE_DATA \
CTL_CODE (FILE_DEVICE_UNKNOWN, 1, METHOD_BUFFERED, FILE_WRITE_ACCESS)

Doesn't matter, it still don't work, same values I guess ;)

Bye,
Skybuck.
Post by Skybuck Flying
Example converted to C.
Still don't work... let me know if it works on your computer ;)
// *** start of test program ***
// TestProgram.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
//#define UNICODE 1
//#define INITGUID
//#pragma warning(disable:4201) // nameless struct/union warning
#include <windows.h>
//#include <stdlib.h>
//#include <string.h>
//#include <setupapi.h>
//#include <dbt.h>
//#include <winioctl.h>
/*
Delphi version 0.01 and 0.02 created on 7 august 2009 by Skybuck Flying.
Delphi-To-C version 0.02 created on 8 august 2009 by Skybuck Flying.
*/
void Main()
{
int IOCTL_NETVMINI_READ_DATA = 2244608;
int IOCTL_NETVMINI_WRITE_DATA = 2260996;
HANDLE vHandle;
DWORD vBytesReturned;
short unsigned int vInputBuffer[66000];
short unsigned int vOutputBuffer[66000];
printf("program started\n");
vHandle =
CreateFile
(
TEXT("\\\\.\\NETVMINI"),
GENERIC_READ | GENERIC_WRITE,//FILE_READ_ATTRIBUTES | SYNCHRONIZE,
FILE_SHARE_READ,
NULL, // no SECURITY_ATTRIBUTES structure
OPEN_EXISTING, // No special create flags
FILE_ATTRIBUTE_NORMAL, // No special attributes
NULL
);
if (vHandle != INVALID_HANDLE_VALUE)
{
printf("open netvmini successfull.\n");
// send ioclt requests
while (1)
{
// doesn"t seem to work, always returns 0 bytes returned ?!
// read request
if (DeviceIoControl
(
vHandle,
IOCTL_NETVMINI_READ_DATA,
&vInputBuffer[0], 66000,
&vOutputBuffer[0], 66000,
&vBytesReturned, NULL
) != 0)
{
printf("read IOCTL to netvmini successfull.\n");
printf("vBytesReturned: %d \n", vBytesReturned );
if (vBytesReturned != 0)
{
printf("bingo");
getchar();
}
} else
{
printf("read IOCTL to netvmini failed.\n");
}
// write request
if (DeviceIoControl
(
vHandle,
IOCTL_NETVMINI_WRITE_DATA,
&vInputBuffer[0], 66000,
&vOutputBuffer[0], 66000,
&vBytesReturned, NULL
) != 0)
{
printf("write IOCTL to netvmini successfull.\n");
printf("vBytesReturned: %d \n", vBytesReturned );
if (vBytesReturned != 0)
{
printf("bingo\n");
getchar();
}
} else
{
printf("write IOCTL to netvmini failed.\n");
}
}
if (CloseHandle( vHandle ) != 0)
{
printf("close netvmini successfull.\n");
} else
{
printf("close netvmini failed.\n");
}
} else
{
printf("open netvmini failed.\n");
}
printf("program finished\n");
}
int _tmain(int argc, _TCHAR* argv[])
{
Main();
getchar();
return 0;
}
// *** end of test program ***
Bye,
Skybuck.
Skybuck Flying
2009-08-08 20:25:56 UTC
Permalink
I also just tested and tried to bind and ip/udp broadcast to the virtual
network adapters.

The blue lights in the notification area don't lit up...

(XP x64 Pro)

Bye,
Skybuck.
Skybuck Flying
2009-08-08 21:24:03 UTC
Permalink
Problems, problems, problems.

Wasting time, Wasting time, Wasting Time.

I am done with windows for the coming days.

All I want to do is create a virtual private network technology for the game
company of heroes.

And windows has not helped me achieved this goal for the past 15 years.

Tomorrow I will install linux plus wine, plus company of heroes.

And then I will see how hard it is to actually create vpn technology on
linux.

And if it works then my next pc will contain linux and microsoft can go to
hell forever ;)

Bye,
Skybuck.
Skybuck Flying
2009-08-08 21:28:29 UTC
Permalink
Now my windows can't even shutdown the c ?! WTF ?!

Might be because of tunngle and it's bad drivers ? maybe ?

Maybe IE8 problem ?

Maybe VMware problem ?

Maybe hack who knows ?!

Tomorrow I give windows one more try... and if it's still not working then I
give linux a try !

Bye,
Skybuck.
Post by Skybuck Flying
Problems, problems, problems.
Wasting time, Wasting time, Wasting Time.
I am done with windows for the coming days.
All I want to do is create a virtual private network technology for the
game company of heroes.
And windows has not helped me achieved this goal for the past 15 years.
Tomorrow I will install linux plus wine, plus company of heroes.
And then I will see how hard it is to actually create vpn technology on
linux.
And if it works then my next pc will contain linux and microsoft can go to
hell forever ;)
Bye,
Skybuck.
Skybuck Flying
2009-08-08 21:41:19 UTC
Permalink
I gave windows 7 one last try because I couldn't believe it was actually
this bad.

But apperently it is !

What a time waster !

Tomorrow it's linux time ;)

Bye,
Skybuck.
Post by Skybuck Flying
Now my windows can't even shutdown the c ?! WTF ?!
Might be because of tunngle and it's bad drivers ? maybe ?
Maybe IE8 problem ?
Maybe VMware problem ?
Maybe hack who knows ?!
Tomorrow I give windows one more try... and if it's still not working then
I give linux a try !
Bye,
Skybuck.
Post by Skybuck Flying
Problems, problems, problems.
Wasting time, Wasting time, Wasting Time.
I am done with windows for the coming days.
All I want to do is create a virtual private network technology for the
game company of heroes.
And windows has not helped me achieved this goal for the past 15 years.
Tomorrow I will install linux plus wine, plus company of heroes.
And then I will see how hard it is to actually create vpn technology on
linux.
And if it works then my next pc will contain linux and microsoft can go
to hell forever ;)
Bye,
Skybuck.
Skybuck Flying
2009-08-08 22:21:37 UTC
Permalink
No,

Apperently the infinite search is a problem in windows 7.

But there is a way around with via "add legacy hardware".

I managed to install the driver.

Windows 7 bitched a lot about it not being signed and such.

Now the big question is does it have tcp/ip bindings ?!?

So far it's hard to tell because the smart idiots/assholes decided to change
the whole fucking windows gui so everybody from xp will be searching their
ass off...

Now I have to search where the fuck the settings are if they are somewhere
at all ?!

Bye,
Skybuck.
Skybuck Flying
2009-08-08 22:52:58 UTC
Permalink
Well can't get the tcp/ip binding to the mtf driver.

I decided to try out the test programs anyway...

And discovered something weird.

The C program doesn't even work on Windows 7 !?!?

It was compile with visual studio 2008... and when the exe is started a
complaint is displayed:

Something like:

"Side-by-Side bullshit not working".

Well I must say my impression of Windows 7 after actually trying to use it
for something...

Something I am usually/normally pretty good with and that is basic windows
networking... my impression of windows 7 has totally changed.

I think windows 7 might actually be a more/worse piece of crap than Vista ?!

I even encoutered sloppy typo's ?!

A couple of years ago I thought Microsoft would die in about 10 years...

Now a few years later it seems it's happening...

It's amazing to actually see it happen before my own eyes ! ;)

Bye,
Skybuck.
Skybuck Flying
2009-08-09 00:35:49 UTC
Permalink
Ok,

Driver signing check disabled...

The C short example program doesn't work.

The Delphi program can't open the netvmini.

The long C example that came with it... does show a list of stuff..

It shows microsoft virtual network adapter etc...

But when it tries to do a IOCTL it doesn't work..

It said failed...

maybe this is because there is no connectivity...

So I shall try to enable the vm connection and see if that has something to
do with it...

Kinda strange though... it shouldn't matter that much ?

I even had a loopback adapter

I also installed some kind of point to point thing a few minutes back to see
if that fixed the driver problem.

I don't know if that might be causing problems... I don't see it anywhere ?!
;)

Ok gonna try a reboot and such.

Bye,
Skybuck.
Skybuck Flying
2009-08-09 06:03:05 UTC
Permalink
"Run as administrator" allows the netvmini to be openened.

Apperently the IOCTL code doesn't do anything except dbgprint a message...
probably called a "trace message" or so... and then it simply breaks ?!

So no wonder there is no data returned...

I also wonder if overlapped i/o and completion routines/callbacks are
possible with these drivers ? I am not sure...

This one is called a "serialized miniport" driver... not sure what that
means ?

Probably means overlapped i/o not possible ???

If not possible then buffers via ioctl will have to be copied into and
outfrom the driver... and so the driver would then need it's own internal
buffers...
for receiving and then copieing to user receive buffers.. and send buffers..
to copy send buffers from user... to be able to later send...

And copieing would be bad for performance :( but ok, better something than
nothing ;) :)

Would be cool if overlapped i/o was possible ??? Anybody know if it's
possible ?

Bye,
Skybuck.
Pavel A.
2009-08-09 10:34:49 UTC
Permalink
Hi,

Try this: http://logmein.com/products/hamachi/

You've made really amazing progress for a beginner, but apparently
doing what you want is too hard without learning a bit first.
There are no tutorials like "learn yourself Visual basic in 24 minutes"
for network drivers, unfortunately :(

Have fun with linux.
--pa
Post by Skybuck Flying
"Run as administrator" allows the netvmini to be openened.
Apperently the IOCTL code doesn't do anything except dbgprint a message...
probably called a "trace message" or so... and then it simply breaks ?!
So no wonder there is no data returned...
I also wonder if overlapped i/o and completion routines/callbacks are
possible with these drivers ? I am not sure...
This one is called a "serialized miniport" driver... not sure what that
means ?
Probably means overlapped i/o not possible ???
If not possible then buffers via ioctl will have to be copied into and
outfrom the driver... and so the driver would then need it's own internal
buffers...
for receiving and then copieing to user receive buffers.. and send
buffers.. to copy send buffers from user... to be able to later send...
And copieing would be bad for performance :( but ok, better something than
nothing ;) :)
Would be cool if overlapped i/o was possible ??? Anybody know if it's
possible ?
Bye,
Skybuck.
Skybuck Flying
2009-08-09 23:50:51 UTC
Permalink
Hamachi has tremendous lag, and somewhat packet loss.

I hope to do much better than it...

However seeing the lag (?) in DebugView makes me doubt a bit ;) :)

Bye,
Skybuck.
Post by Pavel A.
Hi,
Try this: http://logmein.com/products/hamachi/
You've made really amazing progress for a beginner, but apparently
doing what you want is too hard without learning a bit first.
There are no tutorials like "learn yourself Visual basic in 24 minutes"
for network drivers, unfortunately :(
Have fun with linux.
--pa
Post by Skybuck Flying
"Run as administrator" allows the netvmini to be openened.
Apperently the IOCTL code doesn't do anything except dbgprint a
message... probably called a "trace message" or so... and then it simply
breaks ?!
So no wonder there is no data returned...
I also wonder if overlapped i/o and completion routines/callbacks are
possible with these drivers ? I am not sure...
This one is called a "serialized miniport" driver... not sure what that
means ?
Probably means overlapped i/o not possible ???
If not possible then buffers via ioctl will have to be copied into and
outfrom the driver... and so the driver would then need it's own internal
buffers...
for receiving and then copieing to user receive buffers.. and send
buffers.. to copy send buffers from user... to be able to later send...
And copieing would be bad for performance :( but ok, better something
than nothing ;) :)
Would be cool if overlapped i/o was possible ??? Anybody know if it's
possible ?
Bye,
Skybuck.
Loading...