tags:

views:

208

answers:

2

There are a number of ways to obtain a machine's network adapters & related info such as Sigar & java.net's getNetworkInterfaces(). However, using either of these means, I am unable to determine whether a certain adapter is wireless (unless the name/description explicitly says so).

Are there any ways to determine this through code? (I'd like to be able to do so in both Windows & Linux, but I am willing to deal with system specific solutions).

+1  A: 

Edit: removed the part that is not relevant

maybe you could use the JNI (java native interface) to call a C-function which gets this flag... with C, this should be possible (though possible that the code would become unportable)

Edit: For linux, i found the following. Downloaded the source-code of wireless-tools, including iwconfig. They included library, iwlib.c, simply extracts the names of the interface from /proc/net/wireless or /proc/net/dev

You can get the sources from here, this is from Fedora. As the library extracts its data from a path of a standardized file-system, the only thing you need to have is kernel-support for procfs.

Now i can only lead you to the file "iwlib.c", function

void iw_enum_devices(int skfd, iw_enum_handler fn, char * args[], int count)

i don't know about those parameters, but the source code is commented. Maybe you will have to compare the list you get from java with the one you receive through this JNI-hack...

Guess it's a lot of work for a "little task"; hope you find your way through...

regards

Atmocreations
I mentioned looking at the name/description for an indication the card is wireless. That solution isn't suitable. Also, as I said I don't mind if the solution is system specific - so that would inherently mean that JNI is okay with different solutions for each system).Now, you mention a C-function that gets this flag - what would that be? I have found no such a thing.
dborba
excuse me, must have read wrong... you're right. i've been looking as well, didn't find anything yet.if i see some C-function that returns whether an interface is wireless, i will post it. somehow it cannot be too difficult i guess, because iwconfig is able to distinguish, as well. maybe we just got to take a look at that one.regards
Atmocreations
updated the answer with an approach. removed the points you disagreed with before... regards
Atmocreations
A: 

If you want to build a platform specific JNI implementation of your functionality, the Windows API function you can use to get a list of wireless network interfaces is WlanEnumInterfaces in Wlanapi.h. You'll need to link Wlanapi.lib/.dll. Also, see the documentation.

I'd recommend that you build a little JNI library with two functions:

getWirlessInterfaceCount();
getWirelessInterfaceAddr(int nIf, char *addr);

Where you actually make sure the 6 bytes for the address are allocated on the Java side and just filled in on the native side. That way you don't need to worry about memory management on the native side. You can wrap those two JNI calls in a Java method like

List<NetworkInterface> getWirelesNetworkInterfaces();

.... which calls the two JNI methods, gets the list of all interfaces via the NetworkInterface API and throws out all interfaces whose address was not returned by the JNI methods.

VoidPointer