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;
31 if ((argc != 2) || (argv[1][0] == '-')) {
32 printf("Usage: macaddr interface\n");
36 devsock = socket(AF_INET, SOCK_STREAM, 0);
39 perror("Failed opening socket");
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]);
51 puts(iw_saether_ntop(&ifbuffer.ifr_ifru.ifru_hwaddr, buf));