#include <stdio.h>
#include <ifaddrs.h>
#include <netpacket/packet.h>
int main (int argc, const char * argv[])
{
struct ifaddrs *ifaddr=NULL;
struct ifaddrs *ifa = NULL;
int i = 0;
if (getifaddrs(&ifaddr) == -1)
{
perror("getifaddrs");
}
else
{
for ( ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
{
if ( (ifa->ifa_addr) && (ifa->ifa_addr->sa_family == AF_PACKET) )
{
struct sockaddr_ll *s = (struct sockaddr_ll*)ifa->ifa_addr;
printf("%-8s ", ifa->ifa_name);
for (i=0; i <s->sll_halen; i++)
{
printf("%02x%c", (s->sll_addr[i]), (i+1!=s->sll_halen)?':':'\n');
}
}
}
freeifaddrs(ifaddr);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxpZmFkZHJzLmg+CiNpbmNsdWRlIDxuZXRwYWNrZXQvcGFja2V0Lmg+CgppbnQgbWFpbiAoaW50IGFyZ2MsIGNvbnN0IGNoYXIgKiBhcmd2W10pCnsKICAgIHN0cnVjdCBpZmFkZHJzICppZmFkZHI9TlVMTDsKICAgIHN0cnVjdCBpZmFkZHJzICppZmEgPSBOVUxMOwogICAgaW50IGkgPSAwOwoKICAgIGlmIChnZXRpZmFkZHJzKCZpZmFkZHIpID09IC0xKQogICAgewogICAgICAgICBwZXJyb3IoImdldGlmYWRkcnMiKTsKICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICAgZm9yICggaWZhID0gaWZhZGRyOyBpZmEgIT0gTlVMTDsgaWZhID0gaWZhLT5pZmFfbmV4dCkKICAgICAgICAgewogICAgICAgICAgICAgaWYgKCAoaWZhLT5pZmFfYWRkcikgJiYgKGlmYS0+aWZhX2FkZHItPnNhX2ZhbWlseSA9PSBBRl9QQUNLRVQpICkKICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgc3RydWN0IHNvY2thZGRyX2xsICpzID0gKHN0cnVjdCBzb2NrYWRkcl9sbCopaWZhLT5pZmFfYWRkcjsKICAgICAgICAgICAgICAgICAgcHJpbnRmKCIlLThzICIsIGlmYS0+aWZhX25hbWUpOwogICAgICAgICAgICAgICAgICBmb3IgKGk9MDsgaSA8cy0+c2xsX2hhbGVuOyBpKyspCiAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgIHByaW50ZigiJTAyeCVjIiwgKHMtPnNsbF9hZGRyW2ldKSwgKGkrMSE9cy0+c2xsX2hhbGVuKT8nOic6J1xuJyk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgIH0KICAgICAgICAgfQogICAgICAgICBmcmVlaWZhZGRycyhpZmFkZHIpOwogICAgfQogICAgcmV0dXJuIDA7Cn0=