Code:
int getmacaddress(char* dev, unsigned char *ipmac);
int main()
{
int mac;
unsigned char dot_not_mac[25];
mac=getmacaddress("eth0",dot_not_mac);
printf(" the MAC address is %s\n",dot_not_mac);
return 0;
}
int getmacaddress(char* dev,unsigned char *ipmac)
{
int skfd=0;
struct ifreq ifr;
strcpy(ifr.ifr_name,dev);
skfd = socket(AF_INET,SOCK_DGRAM,0);
if(skfd<0)
{
DEBUG1("Can't open socket!\n");
return -1;
}
if(ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0)
{
DEBUG1("Can't read local mac address!\n");
return -1;
}
memcpy(ipmac,ifr.ifr_hwaddr.sa_data,6);
close(skfd);
return 0;
}
the output of the code is as below....
the MAC address is
can anyone tell me what is wrong with this code... this code is not working...it is not printing MAC address.... please help me..
thanks..