Using Rasapi32.INSTANCE.RasGetConnectStatus

21 views
Skip to first unread message

Sébastien Col

unread,
Jan 24, 2017, 1:10:50 AM1/24/17
to Java Native Access
Hi,
I'm trying to get a PPP connection's status using Rasapi32.INSTANCE.RasGetConnectStatus. Unfortunately, this method is expecting a ByReference structure, but the WinRas.RASCONNSTATUS.ByReference doesn't exist.
Am I misunderstanding the usage of this method and the concept of ByReference?
Or maybe I could submit a contribution, for example in the Rasapi32Util class?

Thanks for any information.
Regards,
Sebastien

Timothy Wall

unread,
Jan 25, 2017, 12:16:36 PM1/25/17
to jna-...@googlegroups.com
JNA uses by reference semantics for structures when used as parameters, so you don't need an explicit `ByReference` in this case.

These are the default, inferred semantics.  You only need to explicitly specify the tagging interface if you want the _other_ semantics.
struct* -> params and return values
struct -> struct fields

--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sébastien Col

unread,
Jan 27, 2017, 6:14:34 AM1/27/17
to jna-...@googlegroups.com
Hi Timothy,
Thanks for your answer. Unfortunately I don't get it, sorry.
I don't understand what kind of object I'm supposed to pass as a 2nd argument to the call to RasGetConnectStatus(HANDLE var1, com.sun.jna.Structure.ByReference var2) if I want to be able to manipulate the RASCONNSTATUS in order to retrieve the IP address of the remote host.
Tank you for your help cause I'm stuck right now.
Regards,
Sebastien

--
You received this message because you are subscribed to a topic in the Google Groups "Java Native Access" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jna-users/PIfiqbvaRqg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jna-users+unsubscribe@googlegroups.com.

Matthias Bläsing

unread,
Jan 29, 2017, 10:33:41 AM1/29/17
to Java Native Access
Hi Sebastien,


Am Freitag, 27. Januar 2017 12:14:34 UTC+1 schrieb Sébastien Col:
Hi Timothy,
Thanks for your answer. Unfortunately I don't get it, sorry.
I don't understand what kind of object I'm supposed to pass as a 2nd argument to the call to RasGetConnectStatus(HANDLE var1, com.sun.jna.Structure.ByReference var2) if I want to be able to manipulate the RASCONNSTATUS in order to retrieve the IP address of the remote host.
Tank you for your help cause I'm stuck right now.


I see two options:

1. Add the ByReference and ByValue implementations as nested classes in RASCONNSTATUS or
2. Add int RasGetConnectStatus(HANDLE hrasconn, RASCONNSTATUS lprasconnstatus); to the bindings and deprecate int RasGetConnectStatus(HANDLE hrasconn, RASCONNSTATUS.ByReference lprasconnstatus);

I'd lean two the second option, as that causes less mess (and the other methods of this class should get similar treatment). A pull request would be appreciated.

Greetings

Matthias

Sébastien Col

unread,
Jan 31, 2017, 7:54:02 AM1/31/17
to jna-...@googlegroups.com
Hi Matthias,
I've started by extending the WinRas interface in my code in order to add the ByReference to the RASCONNSTATUS static class. I'm able to pass it to the RasGetConnectStatus method.
I can see that the RASCONNSTATUS has its rasconnstate property valued with 8192 which means that I successfully connected to the remote server.
The problem now is that the remoteEndPoint doesn't have any IP address valued, it's all zeros, both v4 and v6.

I'd be glad to submit a pull request, but can I build only the Java part of JNA?
Or do I have to also get into the "Windows" code, for which I'm really not competent...
Don't even have a Visual Studio...

Regards,
Sebastien


--

Matthias Bläsing

unread,
Jan 31, 2017, 4:00:16 PM1/31/17
to Java Native Access
Hi Sébastien,


Am Dienstag, 31. Januar 2017 13:54:02 UTC+1 schrieb Sébastien Col:
Hi Matthias,
I've started by extending the WinRas interface in my code in order to add the ByReference to the RASCONNSTATUS static class. I'm able to pass it to the RasGetConnectStatus method.
I can see that the RASCONNSTATUS has its rasconnstate property valued with 8192 which means that I successfully connected to the remote server.
The problem now is that the remoteEndPoint doesn't have any IP address valued, it's all zeros, both v4 and v6.

The RASTUNNELENDPOINT is a union of an IPv4 and an IPv6 address. Please see if calling read() on the embedded structures helps.
 
I'd be glad to submit a pull request, but can I build only the Java part of JNA?
Or do I have to also get into the "Windows" code, for which I'm really not competent...
Don't even have a Visual Studio...

Yeah - I started also at that point and in fact that is IMHO the nice part of JNA, you don't need a C compiler if you don't mess with the native parts.

While the jna core also needs a c compiler for unittests, the platform module can be tested/run independently.

If your on netbeans, just open the platform project and you can build + run unittests from the context menu.

HTH

Matthias
Reply all
Reply to author
Forward
0 new messages