Wireless API for Linux in C or Java

Wireless API for Linux in C or Java

With newer kernels the framework for managing wireless cards is called nl80211. It's netlink based, so you can use libnl to issue commands and parse answers. More information:

https://wireless.wiki.kernel.org/en/developers/documentation/nl80211

Currently iw is the command line utility that utilizes nl80211, so you can list available hardware, scan, etc:

https://wireless.wiki.kernel.org/en/users/documentation/iw

Its source code is easy to study and reuse in your own project, just check out their git repo.

Which API provides wireless networks notifications in linux?

If NetworkManager is running, it is accessible via its DBUS API -- see the WirelessNetworkAppeared and WirelessNetworkDisappeared events.

Otherwise, you'll have to deal with wext yourself (this is what NM uses underneath), you'd be interested in the IWEVREGISTERED and IWEVEXPIRED events coming over the NETLINK_ROUTE interface.

How to find a list of wireless networks (SSID's) in Java, C#, and/or C?

For C#, take a look at the Managed Wifi API, which is a wrapper for the Native Wifi API provided with Windows XP SP2 and later.

I have not tested this code, but looking at the Managed Wifi API sample code, this should list the available SSIDs.

WlanClient client = new WlanClient();
foreach ( WlanClient.WlanInterface wlanIface in client.Interfaces )
{
// Lists all available networks
Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList( 0 );
foreach ( Wlan.WlanAvailableNetwork network in networks )
{
Console.WriteLine( "Found network with SSID {0}.", GetStringForSSID(network.dot11Ssid));
}
}

static string GetStringForSSID(Wlan.Dot11Ssid ssid)
{
return Encoding.ASCII.GetString( ssid.SSID, 0, (int) ssid.SSIDLength );
}

Do wireless programmable remotes for PC-s exist?

You can find quite a few remotes supporting LIRC/WinLIRC at their site or here.

As for Java API support for LIRC, try here.

How To Compile C++ Code that has a 'wlanapi.h' and 'windows.h' dependency

I have found a Solution to this problem.

In the Question I asked about the easiest possible way to compile a code with such dependencies as 'wlanapi' and 'windows.h'.

The easiest way is to install 'Microsoft Visual Studio' on Windows box and then compile the code in the relevant IDE.

For Example the code in the question is a C++ code, so I would compile it ('Build') in Visual C++

For anyone who looks at this and is trying to compile a code that uses deep windows APIs, on a linux box, please know that it is a bad bad idea. Compile it under 'Windows SDK' or Visual Studio on a Windows box.

Can I get SSID and MAC address from C code in Linux?


Done

Thank you all for your help, especially to Iliya Iliev and to this library.
It works perfectly.

It exactly what I've been searching for!

I just add it to my main project.

#include "../wifi_scan.h"
#include <stdio.h>
#include <unistd.h>

const char *bssid_to_string(const uint8_t bssid[BSSID_LENGTH], char bssid_string[BSSID_STRING_LENGTH])
{
snprintf(bssid_string, BSSID_STRING_LENGTH, "%02x:%02x:%02x:%02x:%02x:%02x",
bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
printf("%x\n", bssid[5]);
return bssid_string;
}

int main(int argc, char **argv){

struct wifi_scan *wifi=NULL;
struct station_info station;
char mac[BSSID_STRING_LENGTH];

wifi=wifi_scan_init(argv[1]);
wifi_scan_station(wifi, &station);

printf("ssid = %s mac = %s \n", station.ssid, bssid_to_string(station.bssid, mac));

wifi_scan_close(wifi);

}


Related Topics



Leave a reply



Submit