• 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: KK <email@hidden>
  • Date: Wed, 24 Jun 2009 08:45:57 -0400

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:@"xxxxxx", *ptr, *(ptr+1),
*(ptr+2),

*(ptr+3), *(ptr+4), *(ptr+5)];

}

On Wed, Jun 24, 2009 at 2:58 AM, Laurent Cerveau <email@hidden> 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 (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
>>
>
> _______________________________________________
>
> 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
>
_______________________________________________

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

  • Follow-Ups:
    • Re: display Mac id
      • From: Chris Ridd <email@hidden>
References: 
 >display Mac id (From: Kiran Kumar <email@hidden>)
 >Re: display Mac id (From: Laurent Cerveau <email@hidden>)

  • Prev by Date: Re: How apply a mask (xxx-xxx-xxxx for phone #) to a text field while inputting?
  • Next by Date: Re: Cocoa and email (SMTP/POP3)
  • Previous by thread: Re: display Mac id
  • Next by thread: Re: display Mac id
  • Index(es):
    • Date
    • Thread