C/C++ Linux MAC Address of all interfaces
I am using the following code to retrieve all MAC addresses for current computer: ifreq ifr; ifconf ifc; char buf[1024]; int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); if (sock == -1) { ... }; ifc.ifc_len = sizeof(buf); ifc.ifc_buf = buf; if (ioctl(sock, SIOCGIFCONF, &ifc) == -1) { ... } ifreq *it = ifc.ifc_req; const ifreq* const end = it + (ifc.ifc_len / sizeof(ifreq)); for (; it != end; ++it) { strcpy(ifr.ifr_name, it->ifr_name); if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) { if (!(ifr.ifr_flags & IFF_LOOPBACK)) { if (ioctl(sock, SIOCGIFHWADDR, &ifr) == 0) { unsigned char mac_address[6];