f



Problem opening device on Windows XP from Java

Hi,

I am having trouble opening the TUN device (it is a virtual network
device developed by the OpenVPN project - http://openvpn.net) from Java
on Windows.

I found from the registry that the key for the device on my machine is
{5998ABF4-70CC-4B8C-9CBF-F2B985BAD4A2}.
>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, the FILE* returned is non-NULL and the HANDLE
returned is positive.

However, when I try to do the same in Java using the code below,

String tun_dev_name =
new String("\\\\.\\{5998ABF4-70CC-4B8C-9CBF-F2B985BAD4A2}.tap");
RandomAccessFile raf = new RandomAccessFile(tun_dev_name, "rw");

a "java.io.IOException: Invalid argument" is thrown. The same exception
is thrown when I try to open either FileInputStream or FileOutputStream
instead of RandomAccessFile.

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 now
NULL. I
have tried giving all permissions to my codebase using Java's
policytool, but that didn't help. BTW, I ran all this code on Windows
XP from cygwin.

Clearly this problem isn't with OpenVPN because I'm able to open the
device using both fopen and CreateFile from C. Please let me know if
one of you knows what the problem could be and what I need to do to fix
it. In case, this is not the right forum for this question, kindly let
me know which other forum I should pose this question on.
Thanks!
Harsha

0
harshavm
1/21/2005 8:13:07 AM
comp.lang.java.machine 606 articles. 0 followers. Post Follow

0 Replies
312 Views

Similar Articles

[PageSpeed] 35

Reply: