I use this in my CF tool: #include <sys/types.h>
#include <sys/socket.h> #include <sys/ioctl.h> #include <sys/sysctl.h> #include <net/if.h> #include <net/if_dl.h> #include <netinet/in.h> #include <arpa/inet.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> - (NSString *)getHWEthernetMAC { NSString *deviceName = @"en0"; // Ethernet device is en0 int mib[6]; size_t len; char *buf; unsigned char *ptr; struct if_msghdr *ifm; struct sockaddr_dl *sdl; mib[0] = CTL_NET; mib[1] = AF_ROUTE; mib[2] = 0; mib[3] = AF_LINK; mib[4] = NET_RT_IFLIST; if ((mib[5] = if_nametoindex([deviceName UTF8String])) == 0) { perror("if_nametoindex error"); exit(2); } if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { perror("1st sysctl error"); exit(2); } if ((buf = malloc(len)) == NULL) { perror("malloc error"); exit(2); } if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) { perror("2nd sysctl error"); exit(2); } ifm = (struct if_msghdr *)buf; sdl = (struct sockaddr_dl *)(ifm+1); ptr = (unsigned char *)LLADDR(sdl); return [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)]; } On Wed, Jun 24, 2009 at 2:58 AM, Laurent Cerveau <lcerv...@me.com> wrote: > You can use IOKit UserLibg get the MAC hardware address. I did not retest > it though (it comes from older code) so you probably have to check for small > bugs. > > laurent > > kern_return_t kernResult; > mach_port_t masterPort; > io_service_t tmpService, controllerService; > CFDataRef macAddressData; > CFMutableDictionaryRef classesToMatch; > > //Get the master port > kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort); > //Find the etherner 0 card criteria > classesToMatch = IOBSDNameMatching(masterPort,0,"en0"); > //find the corresponding service > tmpService = IOServiceGetMatchingService(masterPort, classesToMatch); > > // by asking for it specifically. > kernResult = IORegistryEntryGetParentEntry( tmpService, kIOServicePlane, > &controllerService ); > > //now we get the data and do something with them > macAddressData = (CFDataRef) IORegistryEntryCreateCFProperty( > controllerService,CFSTR(kIOMACAddress), kCFAllocatorDefault, 0); > > > //release what is needed > CFRelease(macAddressData); > IOObjectRelease(controllerService); > IOObjectRelease(tmpService); > > > On Jun 23, 2009, at 9:04 AM, Kiran Kumar wrote: > > Hi all, >> >> i am doing project to change MAC Address ,i want to display MACID in >> a single textbox like 00:15:e9:4c:c3:d7 >> >> or 00-15-e9-4c-c3-d7 can any one help me plz ... >> >> >> >> >> Thanks, >> kiran >> >> The information contained in this email and any attachments is >> confidential and may be subject to copyright or other intellectual property >> protection. If you are not the intended recipient, you are not authorized to >> use or disclose this information, and we request that you notify us by reply >> mail or telephone and delete the original message from your mail system. >> _______________________________________________ >> >> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) >> >> 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: >> http://lists.apple.com/mailman/options/cocoa-dev/lcerveau%40me.com >> >> This email sent to lcerv...@me.com >> > > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/kthemank%40gmail.com > > This email sent to kthem...@gmail.com > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com