Closed HalosGhost closed 6 years ago
rough proof of concept. Does essentially no error handling, but should return the currently-associated AP's ESSID.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stropts.h>
#include <unistd.h>
#include <linux/if.h>
#include <linux/wireless.h>
signed
get_essid (const char * iface, char * ssid);
signed
main (void) {
char essid[IW_ESSID_MAX_SIZE] = "";
signed err = get_essid("wl0", essid);
if ( !err ) { puts(essid); }
return EXIT_SUCCESS;
}
signed
get_essid (const char * iface, char * essid) {
if ( !iface ) {
return EXIT_FAILURE;
}
signed sock = socket(AF_INET, SOCK_DGRAM, 0);
struct iwreq w;
strncpy(w.ifr_ifrn.ifrn_name, iface, IFNAMSIZ);
w.u.essid.pointer = essid;
w.u.data.length = IW_ESSID_MAX_SIZE;
w.u.data.flags = 0;
ioctl(sock, SIOCGIWESSID, &w);
close(sock);
return EXIT_SUCCESS;
}
via 5602f1760df315b803f731f6201f87e757ed21f6
It would be really handy to know what SSID I am connected to.
Doing this in shell is very simple:
Converting this to C might be a bit intense, but it would be really nice.
Seems like the best way to figure out how to do this is to
copylearn fromiw