Results 1 to 1 of 1
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)
...
- 04-03-2007 #1Just Joined!
- Join Date
- Aug 2006
- Posts
- 76
SIOCGIFHWADDR not working.... :(
the output of the code is as below....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 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..


Reply With Quote