I am looking for a sample code in C++ which retrieves connected Access Point Info in Linux.
Similar feature is provided by WifiManager.GetConnectionInfo API in Android which returns BSSID,SSID,SignalStrength and other parameters for a connected AccesPoint in a android device.
Do we have any Wifi system API's available in LINUX like Windows?
The below post suggests usage of cfg80211, but I am not getting how to use this. http://www.linuxwireless.org/en/developers/Documentation/cfg80211/
please refer below mention function which will print the MAC address and Network SSID of the connected Access Point.
char *
get_essid (char *iface)
{
int fd;
struct iwreq w;
char essid[IW_ESSID_MAX_SIZE];
if (!iface) return NULL;
fd = socket(AF_INET, SOCK_DGRAM, 0);
printf("Socket desc is: %d\n", fd);
if(fd <0)
{
printf("Socket failed: %d", fd);
}
strncpy (w.ifr_ifrn.ifrn_name, iface, IFNAMSIZ);
memset (essid, 0, IW_ESSID_MAX_SIZE);
w.u.essid.pointer = (caddr_t *) essid;
w.u.data.length = IW_ESSID_MAX_SIZE;
w.u.data.flags = 0;
int ret = ioctl (fd, SIOCGIWESSID, &w);
printf("ioctl ret is : %d\n", ret);
ret = ioctl (fd, SIOCGIFHWADDR, &w);
printf("ioctl ap details ret is : %d\n", ret);
//get HWaddr
u_int8_t hd[6];
memcpy(hd,w.u.ap_addr.sa_data,sizeof(hd));
int i=0;
printf("HWaddr:");
for(i;i<6;i++)
{
printf("%02X:",hd[i]);
}
close (fd);
return strdup (essid);
}