Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

Commit

Permalink
Merge branch 'github-issue-5' of https://github.com/carlbrown/JucheLog
Browse files Browse the repository at this point in the history
…into work-4520
  • Loading branch information
drewcrawford committed Jan 17, 2012
2 parents 5b76eb2 + 5703e60 commit 868f803
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
7 changes: 3 additions & 4 deletions JucheLog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
3AE325F414AEC64400DF6E38 /* JucheLogTestMac.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AE325F314AEC64400DF6E38 /* JucheLogTestMac.m */; };
3AE325F914AEC64B00DF6E38 /* JucheLogTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AB6D16A14AEB5D9003B6E52 /* JucheLogTests.m */; };
3AE325FA14AEC67000DF6E38 /* JucheLogMac.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AB6D17914AEB5EC003B6E52 /* JucheLogMac.framework */; };
3AE325FC14AEC99700DF6E38 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AE325FB14AEC99700DF6E38 /* IOKit.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -124,7 +123,6 @@
3AE325F214AEC64400DF6E38 /* JucheLogTestMac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JucheLogTestMac.h; sourceTree = "<group>"; };
3AE325F314AEC64400DF6E38 /* JucheLogTestMac.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = JucheLogTestMac.m; sourceTree = "<group>"; };
3AE325F514AEC64400DF6E38 /* JucheLogTestMac-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "JucheLogTestMac-Prefix.pch"; sourceTree = "<group>"; };
3AE325FB14AEC99700DF6E38 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = SDKs/MacOSX10.7.sdk/System/Library/Frameworks/IOKit.framework; sourceTree = DEVELOPER_DIR; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -150,7 +148,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3AE325FC14AEC99700DF6E38 /* IOKit.framework in Frameworks */,
3AB6D17B14AEB5EC003B6E52 /* Cocoa.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -192,7 +189,6 @@
3AB6D13C14AEB5D9003B6E52 = {
isa = PBXGroup;
children = (
3AE325FB14AEC99700DF6E38 /* IOKit.framework */,
3AB6D14C14AEB5D9003B6E52 /* JucheLog */,
3AB6D16314AEB5D9003B6E52 /* JucheLogTests */,
3AB6D18014AEB5EC003B6E52 /* JucheLogMac */,
Expand Down Expand Up @@ -1124,6 +1120,7 @@
3AE325DE14AEC49900DF6E38 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
3AE325DF14AEC49900DF6E38 /* Build configuration list for PBXNativeTarget "Juche_arbitrary_test_hostTests" */ = {
isa = XCConfigurationList;
Expand All @@ -1132,6 +1129,7 @@
3AE325E114AEC49900DF6E38 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
3AE325F614AEC64400DF6E38 /* Build configuration list for PBXNativeTarget "JucheLogTestMac" */ = {
isa = XCConfigurationList;
Expand All @@ -1140,6 +1138,7 @@
3AE325F814AEC64400DF6E38 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
49 changes: 40 additions & 9 deletions JucheLog/JucheLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,58 @@
#import "JucheLog.h"
#import "UnifiedQueue.h"
#import "JucheBackend.h"

@interface JucheLog () {
NSMutableArray *stack;
NSMutableArray *cleanStack;
}
@end

#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <net/if_dl.h>
#include <ifaddrs.h>

static NSMutableDictionary *loggers;
@implementation JucheLog

+(NSString *) getMacAddress {

struct ifaddrs * addrs;
struct ifaddrs * cursor;
const struct sockaddr_dl * dlAddr;
const unsigned char* base;
int i;

NSMutableString *retVal=[NSMutableString stringWithCapacity:18];

if (getifaddrs(&addrs) == 0) {
cursor = addrs;
while (cursor != 0 && ([retVal length] <17)) {
if ( (cursor->ifa_addr->sa_family == AF_LINK)
&& (((const struct sockaddr_dl *) cursor->ifa_addr)->sdl_type == 0x6) && strcmp("lo0", cursor->ifa_name)!=0 ) {
dlAddr = (const struct sockaddr_dl *) cursor->ifa_addr;
base = (const unsigned char*) &dlAddr->sdl_data[dlAddr->sdl_nlen];
for (i = 0; i < dlAddr->sdl_alen; i++) {
[retVal appendFormat:@"%02X:", base[i]];
}
//delete the last :
[retVal deleteCharactersInRange:NSMakeRange(([retVal length]-1), 1)];
}
cursor = cursor->ifa_next;
}

freeifaddrs(addrs);
}
return retVal;
}

+ (NSString *)uniqueID
{
#ifdef TARGET_OS_MAC
NSString *serialNumberString = nil;
io_struct_inband_t iokit_entry;
uint32_t bufferSize = 4096; // this signals the longest entry we will take
io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
IORegistryEntryGetProperty(ioRegistryRoot, kIOPlatformSerialNumberKey, iokit_entry, &bufferSize);
serialNumberString = [NSString stringWithCString: iokit_entry encoding: NSASCIIStringEncoding];
IOObjectRelease((unsigned int) iokit_entry);
IOObjectRelease(ioRegistryRoot);
return serialNumberString;
return [JucheLog getMacAddress];
#else
return @"Not implemented";
#endif
Expand Down

0 comments on commit 868f803

Please sign in to comment.