iPhone Wifi MacAddress

[sourcecode lang=”c”]
#if ! defined(IFT_ETHER)
#define IFT_ETHER 0x6/* Ethernet CSMACD */
#endif

– (IBAction)testAction:(id)sender
{
#pragma unused(sender)
BOOL success;
struct ifaddrs * addrs;
const struct ifaddrs * cursor;
const struct sockaddr_dl * dlAddr;
const uint8_t * base;
int i;

success = getifaddrs(&addrs) == 0;
if (success) {
cursor = addrs;
while (cursor != NULL) {
fprintf(stderr, “%s\n”, cursor->ifa_name);
if ( (cursor->ifa_addr->sa_family == AF_LINK)
&& (((const struct sockaddr_dl *) cursor->ifa_addr)->sdl_type == IFT_ETHER) ) {
dlAddr = (const struct sockaddr_dl *) cursor->ifa_addr;
fprintf(stderr, ” sdl_nlen = %d\n”, dlAddr->sdl_nlen);
fprintf(stderr, ” sdl_alen = %d\n”, dlAddr->sdl_alen);
base = (const uint8_t *) &dlAddr->sdl_data[dlAddr->sdl_nlen];
fprintf(stderr, ” “);
for (i = 0; i < dlAddr->sdl_alen; i++) {
if (i != 0) {
fprintf(stderr, “:”);
}
fprintf(stderr, “%02x”, base[i]);
}
fprintf(stderr, “\n”);
}
cursor = cursor->ifa_next;
}

freeifaddrs(addrs);
}
}
[/sourcecode]

Leave a Reply

Your email address will not be published.