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
9 * Version 1.0 Eric Dittman 2001-10-19
11 * This is released unther the GPL license.
18 #include <sys/ioctl.h>
19 #include <sys/types.h>
20 #include <sys/socket.h>
24 int main(int argc, char** argv)
28 struct ifreq ifbuffer;
30 if ((argc != 2) || (argv[1][0] == '-')) {
31 printf("Usage: macaddr interface\n");
35 devsock = socket(AF_INET, SOCK_STREAM, 0);
38 perror("Failed opening socket");
42 memset(&ifbuffer, 0, sizeof(ifbuffer));
43 strncpy(ifbuffer.ifr_name, argv[1], sizeof(ifbuffer.ifr_name));
44 if (ioctl(devsock, SIOCGIFHWADDR, &ifbuffer) == -1) {
45 fprintf(stderr, "There is no MACADDR for %s\n", argv[1]);
50 puts(iw_ether_ntoa((struct ether_addr *) ifbuffer.ifr_ifru.ifru_hwaddr.sa_data));