Re: UInt8 > NSString
Re: UInt8 > NSString
- Subject: Re: UInt8 > NSString
- From: arri <email@hidden>
- Date: Mon, 5 Mar 2007 15:31:56 +0100
thanks!
that works like charm.
for convenience i also moved the functions from the to an obj-c file,
and implemented the mainMacAddress() function as an obj-c method in
the implementation of the calling class.
thanks,
arri
On Mar 5, 2007, at 14:47 48, Dominik Pich wrote:
Easiest would be to modify the method to return a NSString, I think.
Code:
--------
NSString mainMacAddress()
{
kern_return_t kernResult = KERN_SUCCESS; // on PowerPC this is an
int (4 bytes)
io_iterator_t intfIterator;
UInt8 MACAddress[kIOEthernetAddressSize];
NSString string;
kernResult = FindEthernetInterfaces(&intfIterator);
if (KERN_SUCCESS != kernResult) {
//printf("FindEthernetInterfaces returned 0xx\n",
kernResult);
string =[NSString stringWithString:@"000000000000"];
} else {
kernResult = GetMACAddress(intfIterator, MACAddress, sizeof
(MACAddress));
if (KERN_SUCCESS != kernResult) {
string =[NSString stringWithString:@"000000000000"];
} else {
string =[NSString stringWithFormat@"xxxxxx",
MACAddress[0], MACAddress[1], MACAddress[2], MACAddress[3],
MACAddress[4], MACAddress[5]];
}
}
(void) IOObjectRelease(intfIterator); // Release the iterator.
return string;
}
----
EOF - Typed in mail so there can be syntax errors.
If you instead, prefer to keep the method and not modify it.
use string =[NSString stringWithFormat:@"%s" resultingCharPointer];
or string =[NSString stringWithBytes:resultingCharPointer
length:strlen(resultingCharPointer)+1];
or string =[NSString stringWithBytes:resultingCharPointer length:
12 /*hardcode same buffersize as in method*/];
Regards,
Dominik
On Mar 5, 2007, at 14:52 51, Jones Curtis wrote:
Change that line:
NSString string;
to
NSString * string;
and you'll be in business. Probably wouldn't hurt to initialize it
("= nil") at the same time, too.
_______________________________________________
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:
This email sent to email@hidden