Anyone knows how to use it from pascal ?
I am even willing to pay for a component that simplifies TAP-win32 use.

Mailing lists / fpc-pascal / 2010-05
10 messages · 4 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Anyone knows how to use it from pascal ?
I am even willing to pay for a component that simplifies TAP-win32 use.
What does TAP stand for?
Felipe Monteiro de Carvalho wroteWhat does TAP stand for?
see http://en.wikipedia.org/wiki/TUN/TAP for some pointers.
Marc
TAP-Win32 is the win32 equivalent of linux/unix tun tap devices.
i need to:
- discover installed taps
- set device options (Dont need ip and etc, just the basic ioctls)
- read and write to device (after set up it becomes just a simple file)
i tried this :
Uses Windows, Classes;
Const
TAP_Device = '\\\\.\\Global\\{44F7688F-77FA-43DC-8D8F-9CBA23E01BB0}.tap';
Var
Handle : Integer;
Buffer : Pointer;
Stream : THandleStream;
Count : Integer;
Begin
Handle := CreateFile(PChar(TAP_Device), GENERIC_READ Or
GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM Or
FILE_FLAG_OVERLAPPED, 0);
WriteLn(Handle);
Stream := THandleStream.Create(Handle);
Buffer := GetMem(2048);
Repeat
Count := Stream.Read(Buffer^, 2048);
If Count > 0 Then
WriteLn('Got ', Count, ' bytes !');
Stream.Write(Buffer^, Count);
Until False;
Stream.Free;
FreeMem(Buffer, 2048);
CloseHandle(Handle);
End.(translated from a C# example)
but the handle returned is always -1
(The guid is correct as returned by openvpn)
2010/5/13 Marc Weustink :
Hello FPC-Pascal,
Thursday, May 13, 2010, 10:42:37 PM, you wrote:
JAGdFJ> Handle := CreateFile(PChar(TAP_Device), GENERIC_READ Or
JAGdFJ> GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM Or
JAGdFJ> FILE_FLAG_OVERLAPPED, 0);Try using:
Handle:=CreateFileA(PChar(TAP_Device), GENERIC_READ or GENERIC_WRITE,
0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);Overlapped attribute is an error for sure as non overlapped structure is being passed. In fact I think that no FILE_xxxx is > (translated from a C# example)
Maybe the example is wrong ;)
handle still returns -1
2010/5/13 José Mejuto :
This is the C# example i found :
http://www.varsanofiev.com/inside/TunTest.cs
2010/5/13 Jorge Aldo G. de F. Junior :
Hello FPC-Pascal,
Friday, May 14, 2010, 12:14:31 AM, you wrote:
JAGdFJ> This is the C# example i found :
JAGdFJ> http://www.varsanofiev.com/inside/TunTest.cs
Also this line is wrong IMHO:
TAP_Device = '\\\\.\\Global\\{44F7688F-77FA-43DC-8D8F-9CBA23E01BB0}.tap';it should be:
TAP_Device = '\\.\Global\{44F7688F-77FA-43DC-8D8F-9CBA23E01BB0}.tap';Pascal does not need the slash escape sequence.
Uses
Windows,
Classes,
BlckSock;Const
TAP_Device = '\\.\Global\{44F7688F-77FA-43DC-8D8F-9CBA23E01BB0}.tap'#00;
TAP_Buffer = 8192;
Var
Handle : Integer;
Buffer : Pointer;
Stream : THandleStream;
Count : Integer;
Begin
Handle := CreateFileA(PChar(TAP_Device), GENERIC_READ or
GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, 0);
Stream := THandleStream.Create(Handle);
Buffer := GetMem(TAP_Buffer);
Repeat
Count := Stream.Read(Buffer^, TAP_Buffer);
If Count > 0 Then
Stream.Write(Buffer^, Count);
Until False;
Stream.Free;
FreeMem(Buffer, TAP_Buffer);
CloseHandle(Handle);
End.=========
i am able to receive packets setting up a tap device with a fixed ip and doing ping to the gateway address...
now i need to decipher the ioctl calls...
2010/5/13 José Mejuto :
Hello FPC-Pascal,
Friday, May 14, 2010, 1:34:08 PM, you wrote:
JAGdFJ> i am able to receive packets setting up a tap device with a fixed ip
JAGdFJ> and doing ping to the gateway address...
JAGdFJ> now i need to decipher the ioctl calls...
Sorry, I can not help more, I had never used TAP and even I do not know what it is (except a brief definition in wikipedia).