AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem opening device on Windows XP from Java

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> JVM, native methods and hardware
View previous topic :: View next topic  
Author Message
harshavm
Guest





PostPosted: Fri Jan 21, 2005 8:13 am    Post subject: Problem opening device on Windows XP from Java Reply with quote



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}.
Quote:
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


Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> JVM, native methods and hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.