• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: display Mac id
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >display Mac id (From: Kiran Kumar <email@hidden>)
 >Re: display Mac id (From: Laurent Cerveau <email@hidden>)
 >Re: display Mac id (From: KK <email@hidden>)

  • Prev by Date: Re: Screen capture Cocoa framework
  • Next by Date: Re: Screen capture Cocoa framework
  • Previous by thread: Re: display Mac id
  • Next by thread: Re: display Mac id
  • Index(es):
    • Date
    • Thread