OSDN Git Service

Add Android.mk
[android-x86/external-wireless-tools.git] / wireless_tools / macaddr.c
1 /*
2  *      macaddr
3  *
4  *      Program to return the MAC address of an Ethernet
5  *      adapter.  This was written to help configure the
6  *      adapter based on the MAC address rather than the
7  *      name.
8  *
9  *      Version 1.0     Eric Dittman    2001-10-19
10  *
11  *      This is released unther the GPL license.
12  */
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <unistd.h>
18 #include <sys/ioctl.h>
19 #include <sys/types.h>
20 #include <sys/socket.h>
21
22 #include "iwlib.h"
23
24 int main(int argc, char** argv)
25 {
26
27         int devsock;
28         struct ifreq ifbuffer;
29         char buf[20];
30
31         if ((argc != 2) || (argv[1][0] == '-')) {
32                 printf("Usage: macaddr interface\n");
33                 exit(1);
34         }
35
36         devsock = socket(AF_INET, SOCK_STREAM, 0);
37
38         if (devsock == -1) {
39                 perror("Failed opening socket");
40                 exit (1);
41         }
42
43         memset(&ifbuffer, 0, sizeof(ifbuffer));
44         strncpy(ifbuffer.ifr_name, argv[1], sizeof(ifbuffer.ifr_name));
45         if (ioctl(devsock, SIOCGIFHWADDR, &ifbuffer) == -1) {
46                 fprintf(stderr, "There is no MACADDR for %s\n", argv[1]);
47                 exit(1);
48         }
49         close(devsock);
50
51         puts(iw_saether_ntop(&ifbuffer.ifr_ifru.ifru_hwaddr, buf));
52
53         exit(0);
54 }