Skybuck Flying
2009-08-07 20:30:13 UTC
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.
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.