Re: display Mac id
Re: display Mac id
- Subject: Re: display Mac id
- From: Chris Ridd <email@hidden>
- Date: Wed, 24 Jun 2009 14:51:45 +0100
On 24 Jun 2009, at 13:45, KK wrote:
- (NSString *)getHWEthernetMAC {
NSString *deviceName = @"en0"; // Ethernet device is en0
Embedding a device name seems a bit odd to me - why not use
getifaddrs() and walk the list of actual interfaces? Something like...
struct ifaddrs *ifp, *p;
if (getifaddrs(&ifp) != 0)
return 1;
for (p = ifp; p != NULL; p = p->ifa_next) {
if (p->ifa_addr && p->ifa_addr->sa_family == AF_LINK) {
struct sockaddr_dl *e = (struct sockaddr_dl *)p->ifa_addr;
/* Only look at ethernet addresses */
if (e->sdl_alen == ETHER_ADDR_LEN) {
unsigned char *a = LLADDR(e);
printf("%.2X%.2X%.2X%.2X%.2X%.2X\n",
a[0], a[1], a[2], a[3], a[4], a[5]);
}
}
}
freeifaddrs(ifp);
return 0;
Cheers,
Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden