Created
January 1, 2020 10:40
-
-
Save devendranaga/7f0a80d0f185f5dcb6084bf7eae80811 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* program to demonstrate wireless ioctl | |
*/ | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <math.h> | |
#include <net/if.h> | |
#include <sys/ioctl.h> | |
#include <linux/wireless.h> | |
int main() | |
{ | |
int sock; | |
sock = socket(AF_INET, SOCK_DGRAM, 0); | |
if (sock < 0) { | |
return -1; | |
} | |
struct iwreq req; | |
memset(&req, 0, sizeof(req)); | |
strcpy(req.ifr_ifrn.ifrn_name, "wlxd0374533247a"); | |
int ret; | |
ret = ioctl(sock, SIOCGIWNAME, &req); | |
if (ret < 0) { | |
return -1; | |
} | |
printf("name: %s\n", req.u.name); | |
memset(&req, 0, sizeof(req)); | |
strcpy(req.ifr_ifrn.ifrn_name, "wlxd0374533247a"); | |
char id[255]; | |
req.u.essid.pointer = id; | |
req.u.essid.length = 255; | |
ret = ioctl(sock, SIOCGIWESSID, &req); | |
if (ret < 0) { | |
perror("ioctl"); | |
return -1; | |
} | |
printf("essid: %s\n", req.u.essid.pointer); | |
memset(&req, 0, sizeof(req)); | |
strcpy(req.ifr_ifrn.ifrn_name, "wlxd0374533247a"); | |
ret = ioctl(sock, SIOCGIWFREQ, &req); | |
if (ret < 0) { | |
perror("ioctl"); | |
return -1; | |
} | |
printf("freq %f\n", ((double)req.u.freq.m ) / 1000000000); | |
memset(&req, 0, sizeof(req)); | |
strcpy(req.ifr_name, "wlxd0374533247a"); | |
ret = ioctl(sock, SIOCGIWRATE, &req); | |
if (ret < 0) { | |
perror("ioctl"); | |
return -1; | |
} | |
printf("rate %f\n", req.u.bitrate.value / 1000000.0); | |
memset(&req, 0, sizeof(req)); | |
strncpy(req.ifr_name, "wlxd0374533247a", IFNAMSIZ); | |
ret = ioctl(sock, SIOCGIWAP, &req); | |
if (ret < 0) { | |
perror("ioctl"); | |
return -1; | |
} | |
uint8_t *apmac = req.u.ap_addr.sa_data; | |
printf("apmac %02x:%02x:%02x:%02x:%02x:%02x\n", | |
apmac[0], apmac[1], apmac[2], apmac[3], apmac[4], apmac[5]); | |
memset(&req, 0, sizeof(req)); | |
strncpy(req.ifr_name, "wlxd0374533247a", IFNAMSIZ); | |
char nickname[256]; | |
req.u.essid.pointer = nickname; | |
req.u.essid.length = sizeof(nickname); | |
ret = ioctl(sock, SIOCGIWNICKN, &req); | |
if (ret < 0) { | |
perror("ioctl"); | |
return -1; | |
} | |
printf("nickname %s\n", nickname); | |
close(sock); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment