-
Notifications
You must be signed in to change notification settings - Fork 1
/
wname.c
61 lines (51 loc) · 1.74 KB
/
wname.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Simple utility to pull wireless name from Linux kernel using ioctl
Copyright (C) 2014 Doug Reese
Used as a learning experience in obtaining wireless info from
the Linux kernel using ioctl.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/wireless.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
int main(int argc, char **argv)
{
int ret;
struct ifreq req;
struct sockaddr_in *addr;
int s;
if (argc != 2) {
fprintf(stderr, "Need an interface name (like wlan0)\n");
return 1;
}
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
perror("Cannot open socket");
return 1;
}
strncpy(req.ifr_name, argv[1], sizeof(req.ifr_name));
ret = ioctl(s, SIOCGIWNAME, &req);
if (ret < 0) {
fprintf(stderr, "No wireless extension\n");
return 1;
}
printf("%s\n", req.ifr_name);
printf("%s\n", req.ifr_newname);
return 0;
}