int get_mac(char binMAC[6])
{
int sock;
struct ifreq ifr;
unsigned char *puc;
memset(binMAC, 0, 6);
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == -1)
{
perror("socket");
return -1;
}
strcpy(ifr.ifr_name, "eth0");
if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0)
{
close(sock);
perror("ioctl");
return -1;
}
puc = ifr.ifr_hwaddr.sa_data;
close(sock);
memcpy(binMAC, puc, 6);
return 0;
}