|
From: Harsha V. M. <ha...@cs...> - 2005-01-16 07:37:00
|
Hi,
I am a graduate student in Computer Science at the University of
Washington. I have been trying to use the TUN/TAP device as a means of
capturing incoming and outgoing packets. To make my system portable across
Windows and Linux, I have been using Java for development, because of which
I have run into a problem.
I installed v1.6 of the TUN/TAP device on my Windows XP machine. I then
found from the registry that the key for the device on my machine is
{5998ABF4-70CC-4B8C-9CBF-F2B985BAD4A2} (under the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}
subtree).
From elsewhere on the web, I found that on Windows this device can be
addressed as \\.\{5998ABF4-70CC-4B8C-9CBF-F2B985BAD4A2}.tap
I then wrote up a short C code,
char *tun_dev_name = "\\\\.\\{5998ABF4-70CC-4B8C-9CBF-F2B985BAD4A2}.tap";
FILE *f = fopen(tun_dev_name, "rw");
fclose(f);
HANDLE h = CreateFile(tun_dev_name, GENERIC_WRITE | GENERIC_READ, 0, 0, \
OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0);
CloseHandle(h);
In the above code, both the FILE* and the HANDLE returned are non-NULL.
However, when I try to do the same in Java using
String tun_dev_name =
new String("\\\\.\\{5998ABF4-70CC-4B8C-9CBF-F2B985BAD4A2}.tap");
RandomAccessFile raf = new RandomAccessFile(tun_dev_name, "rw");
a java.io.IOException is thrown with the message "Invalid argument". In
fact, when I invoke the above C code as a native method from within Java,
though a valid HANDLE is still returned, the FILE* returned is NULL. I
have tried giving all permissions to my codebase using Java's policytool,
but that didn't help.
The above problem persists with any of the 2.0 beta versions as well.
I was unsure whether this problem is more pertinent to the devel or the
users mailing list. So, I'm forwarding this on both. Sorry about that!
Any help in this regard would be greatly appreciated.
Thanks!
Harsha Madhyastha
Graduate Student
Department of CSE
University of Washington
|