Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.svn
._*
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
@implementation NSString(MD5Addition)

- (NSString *) stringFromMD5{

if(self == nil || [self length] == 0)
return nil;

const char *value = [self UTF8String];

unsigned char outputBuffer[CC_MD5_DIGEST_LENGTH];
CC_MD5(value, strlen(value), outputBuffer);

NSMutableString *outputString = [[NSMutableString alloc] initWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for(NSInteger count = 0; count < CC_MD5_DIGEST_LENGTH; count++){
[outputString appendFormat:@"%02x",outputBuffer[count]];
}
return [outputString autorelease];

return outputString;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import "UIDevice+IdentifierAddition.h"
#import "NSString+MD5Addition.h"

#include <vector>

#include <sys/socket.h> // Per msqr
#include <sys/sysctl.h>
#include <net/if.h>
Expand All @@ -29,48 +31,59 @@ @implementation UIDevice (IdentifierAddition)
// Return the local MAC addy
// Courtesy of FreeBSD hackers email list
// Accidentally munged during previous update. Fixed thanks to erica sadun & mlamb.
- (NSString *) macaddress{

int mib[6];
size_t len;
char *buf;
unsigned char *ptr;
struct if_msghdr *ifm;
struct sockaddr_dl *sdl;
- (NSString *) macaddress
{
static const unsigned int MIB_SIZE = 6;
int mib[6] =
{
CTL_NET,
AF_ROUTE,
0,
AF_LINK,
NET_RT_IFLIST
};

mib[0] = CTL_NET;
mib[1] = AF_ROUTE;
mib[2] = 0;
mib[3] = AF_LINK;
mib[4] = NET_RT_IFLIST;
size_t len = 0;
char *buf = NULL;
unsigned char *ptr = NULL;
struct if_msghdr *ifm = {0};
struct sockaddr_dl *sdl = {0};

std::vector<unsigned char> bufGuard;


if ((mib[5] = if_nametoindex("en0")) == 0) {
printf("Error: if_nametoindex error\n");
return NULL;
if ((mib[5] = if_nametoindex("en0")) == 0)
{
NSLog(@"Error: if_nametoindex error\n");
return nil;
}

if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
printf("Error: sysctl, take 1\n");
return NULL;
if (sysctl(mib, MIB_SIZE, NULL, &len, NULL, 0) < 0)
{
NSLog(@"Error: sysctl, take 1\n");
return nil;
}


if ((buf = malloc(len)) == NULL) {
printf("Could not allocate memory. error!\n");
return NULL;
bufGuard.resize( len, 0 );
if ( 0 == len || bufGuard.empty() )
{
NSLog( @"Could not allocate memory. error!\n" );
return nil;
}
buf = reinterpret_cast<char*>( &bufGuard[ 0 ] );


if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
if (sysctl(mib, MIB_SIZE, buf, &len, NULL, 0) < 0)
{
printf("Error: sysctl, take 2");
free(buf);
return NULL;
}

ifm = (struct if_msghdr *)buf;
sdl = (struct sockaddr_dl *)(ifm + 1);
ptr = (unsigned char *)LLADDR(sdl);
ifm = reinterpret_cast<struct if_msghdr *>( buf );
sdl = reinterpret_cast<struct sockaddr_dl *>(ifm + 1);
ptr = reinterpret_cast<unsigned char *>( LLADDR(sdl) );
NSString *outstring = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X",
*ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
free(buf);

return outstring;
}
Expand Down