Last active
September 5, 2022 21:34
-
-
Save lf-/90912626f24246540e52 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
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <sys/ioctl.h> | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <linux/wireless.h> | |
#include <errno.h> | |
int main(int argc, const char* argv[]) { | |
if (argc != 2) { | |
fprintf(stderr, "Bad usage\n"); | |
fprintf(stderr, "Usage: %s ifname\n", argv[0]); | |
return -1; | |
} | |
struct iwreq req; | |
strcpy(req.ifr_ifrn.ifrn_name, argv[1]); | |
int fd, status; | |
fd = socket(AF_INET, SOCK_DGRAM, 0); | |
char* buffer; | |
buffer = calloc(32, sizeof(char)); | |
req.u.essid.pointer = buffer; | |
req.u.essid.length = 32; | |
if (ioctl(fd, SIOCGIWESSID, &req) == -1) { | |
fprintf(stderr, "Failed ESSID get on interface %s: %s\n", argv[1], strerror(errno)); | |
} else { | |
printf("%s", (char*)req.u.essid.pointer); | |
} | |
free(buffer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment