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.
14 #include <sys/ioctl.h>
15 #include <sys/types.h>
16 #include <sys/socket.h>
18 #include <linux/socket.h>
21 int main(int argc, char** argv) {
24 struct ifreq ifbuffer;
28 printf("Usage: macaddr interface\n");
32 devsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
35 printf("Failed opening socket\n");
39 memset(&ifbuffer, 0, sizeof(ifbuffer));
40 strcpy(ifbuffer.ifr_name, argv[1]);
41 if (ioctl(devsock, SIOCGIFHWADDR, &ifbuffer) == -1) {
42 printf("There is no MACADDR for %s\n", argv[1]);
47 for (i = 0; i < IFHWADDRLEN; i++)
48 printf("%02X", (unsigned char) ifbuffer.ifr_ifru.ifru_hwaddr.sa_data[i]);