UInt8 > NSString
Subject : UInt8 > NSString
From: arri <email@hidden >
Date: Mon, 5 Mar 2007 14:19:09 +0100
Delivered-to: email@hidden
Delivered-to: email@hidden
hoi list,
i'm aware my question comes from the lack of knowledge about
datatypes and pointers (C, carbon etc..)
but for now i'd like to get this working quickly.
i'm using the 'GetPrimaryMACAddress' example from apple's site in
order to retrieve the main MAC-address of the local machine;
http://developer.apple.com/samplecode/GetPrimaryMACAddress/index.html
the example outputs to stdout, now i modified it so that the main()
function is a function i can call from cocoa like this:
static char * mainMacAddress()
{
kern_return_t kernResult = KERN_SUCCESS; // on PowerPC this is an
int (4 bytes)
io_iterator_t intfIterator;
UInt8 MACAddress[kIOEthernetAddressSize];
char addr[12];
kernResult = FindEthernetInterfaces(&intfIterator);
if (KERN_SUCCESS != kernResult) {
//printf("FindEthernetInterfaces returned 0x%08x\n",
kernResult);
sprintf(addr,"000000000000");
} else {
kernResult = GetMACAddress(intfIterator, MACAddress, sizeof
(MACAddress));
if (KERN_SUCCESS != kernResult) {
sprintf(addr,"000000000000");
} else {
sprintf(addr,"%02x%02x%02x%02x%02x%02x",
MACAddress[0], MACAddress[1], MACAddress[2], MACAddress[3],
MACAddress[4], MACAddress[5]);
}
}
(void) IOObjectRelease(intfIterator); // Release the iterator.
return (char*) addr;
}
and then elsewhere i call that function and create an NSString with
the result like this:
char *adr = mainMacAddress();
macAddress = [NSString stringWithCString:adr];
the compiler gives me a warning (function returns address of local
variable), but it works on intel-mac. on ppc it just returns rubbish.
what would be the correct way of doing what i want?
thanks,
arri
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden
This email sent to email@hidden
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.