废话少说直接上代码
bool GetMac(char *pBuffer)
{
struct ifreq *ifr;
struct ifconf ifc;
int s, i;
int numif;
// find number of interfaces.
memset(&ifc, 0, sizeof(ifc));
ifc.ifc_ifcu.ifcu_req = NULL;
ifc.ifc_len = 0;
if ((s = ::socket(PF_INET, SOCK_STREAM, 0)) < 0)
{
CCLog("SgProfile::GetMac 111111");
return false;
}
if (ioctl(s, SIOCGIFCONF, &ifc) < 0)
{
CCLog("SgProfile::GetMac 222222");
return false;
}
if ((ifr = (ifreq*) malloc(ifc.ifc_len)) == NULL)
{
CCLog("SgProfile::GetMac 333333");
return false;
}
ifc.ifc_ifcu.ifcu_req = ifr;
if (ioctl(s, SIOCGIFCONF, &ifc) < 0)
{
CCLog("SgProfile::GetMac 333333 ioctl SIOCGIFCONF error!");
return false;
}
numif = ifc.ifc_len / sizeof(struct ifreq);
for (i = 0; i < numif; i++)
{
struct ifreq *r = &ifr[i];
struct sockaddr_in *sin = (struct sockaddr_i