Annotation to Hardware Address
Annotation to Hardware Address
- Subject: Annotation to Hardware Address
- From: Max Seelemann <email@hidden>
- Date: Sat, 9 Aug 2003 00:32:59 +0200
Hi there.
I just want to tell you my experience with this topic.
The problem was how to get the Hardware Address of the first (built-in)
ethernet card.
There are two relatively easy way:
1)
- (NSString *)getEthernetAddress
{
NSString *str = @"";
OTInetGetInterfaceInfo(&myInetInterfaceInfo, 0);
if (myInetInterfaceInfo.fHWAddrLen > 0) {
for(i=0; i<myInetInterfaceInfo.fHWAddrLen; i++) {
str = [str stringByAppendingFormat: @"x",
myInetInterfaceInfo.fHWAddr[i]];
}
}
return str;
}
2)
- (NSString *)getEthernetAddress
{
NSString *str, *uuid;
uuid = (NSString *) CFUUIDCreateString(0, CFUUIDCreate(0));
str = [[uuid componentsSeparatedByString: @"-"] lastObject];
return str;
}
Do not use the second way. Normally it gives the same as the first
method,
but on some systems this can change when you (e.g.) switch between
AirPort and LAN. The first method is "safe" in this relation.
Thank you for your audience.
MAX
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.