nightcoder
asked on
how to get the MAC address of the network card
Coding for a Macromedia Director app,
i need to determine via a small C++ Xtra the famous MAC network address,and also all data i can recover from ATA disks and SCSI disks...
Some useful functions to do this are contained in system.h and winio.h under Vc++ on Win
But i need to develope this for MacOs X too..
And as a newbie.. i HAVE to use codewarrior 8.3 and os10.2
(the macromedia SDK is provided of a CodeWarrior template to communicate with Director)
Will be apprecied all about this, the Classes name,the specific functions, the header i have to include...but especially some code sample too from remote urls...i feels lost
Thanks!
Nc
i need to determine via a small C++ Xtra the famous MAC network address,and also all data i can recover from ATA disks and SCSI disks...
Some useful functions to do this are contained in system.h and winio.h under Vc++ on Win
But i need to develope this for MacOs X too..
And as a newbie.. i HAVE to use codewarrior 8.3 and os10.2
(the macromedia SDK is provided of a CodeWarrior template to communicate with Director)
Will be apprecied all about this, the Classes name,the specific functions, the header i have to include...but especially some code sample too from remote urls...i feels lost
Thanks!
Nc
The MAC address is available through the System Profiler utility.
ASKER
:)
would seems obvious i have to organize resulting data into my c++ code
actually i think my c++ Xtra really cannot deal with the system profiler app.
thanks anyway
would seems obvious i have to organize resulting data into my c++ code
actually i think my c++ Xtra really cannot deal with the system profiler app.
thanks anyway
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Really a great ! thanks for tips on man...
i'm a newbie on mac os x .....
sometime a silly thing maybe a big rock
i'm a newbie on mac os x .....
sometime a silly thing maybe a big rock
I have written an Xtra that does exactly this. Here is the piece of code from mine to do it. Adapted from code available on Apples developer web site. So, it's only fair I pass it on.
Cheers.
#include <string.h>
#include <stdlib.h>
#if TARGET_API_MAC_CARBON
#include <Carbon.h>
#else
#include <NameRegistry.h>
#endif
#if TARGET_API_MAC_CARBON
OSStatus GetPCIBuiltInEnetAddr(UInt 8 *enetaddr)
{
OSStatus err = noErr;
InetInterfaceInfo myInetInterfaceInfo;
int i;
OTInetGetInterfaceInfo(&my InetInterf aceInfo,kD efaultInet Interface) ;
for(i=0;i<myInetInterfaceI nfo.fHWAdd rLen;i++)
enetaddr[i] = myInetInterfaceInfo.fHWAdd r[i];
return noErr;
}
#else
OSStatus GetPCIBuiltInEnetAddr(UInt 8 *enetaddr)
{
OSStatus err = noErr;
RegEntryIter cookie;
RegEntryID theFoundEntry;
unsigned char enetAddrStr[32] = "\plocal-mac-address";
RegCStrEntryNamePtr enetAddrCStr = p2cstr( enetAddrStr );
RegEntryIterationOp iterOp;
UInt8 enetAddr[6];
Boolean done = false;
RegPropertyValueSize theSize;
err = RegistryEntryIDInit( &theFoundEntry );
if (err != noErr)
{
return err;
}
err = RegistryEntryIterateCreate ( &cookie );
if (err != noErr)
{
return err;
}
iterOp = kRegIterDescendants;
err = RegistryEntrySearch( &cookie, iterOp, &theFoundEntry, &done, enetAddrCStr, nil, 0);
if (err == noErr)
{
theSize = sizeof(enetAddr);;
err = RegistryPropertyGet(&theFo undEntry, enetAddrCStr, &enetAddr, &theSize );
if (err == noErr)
BlockMove(enetAddr, enetaddr, sizeof(enetAddr));
}
RegistryEntryIterateDispos e( &cookie );
return noErr;
}
#endif
MoaError GetENetAddrScript_IMoaMmXS cript::XX_ GetStringA ddress(PMo aDrCallInf o callPtr)
{
/* variable declarations */
MoaError err = kMoaErr_NoErr;
OSStatus osErr;
UInt8 enetaddr[6];
MoaChar buf[256] = "";
MoaLong i = 0;
osErr = GetPCIBuiltInEnetAddr((UIn t8*)enetad dr);
if (osErr == noErr)
{
sprintf(buf, "%02X %02X %02X %02X %02X %02X", (int)enetaddr[0], (int)enetaddr[1], (int)enetaddr[2], (int)enetaddr[3], (int)enetaddr[4], (int)enetaddr[5]);
}
else
{
goto exit_gracefully;
}
pObj->pValueInterface->Str ingToValue (buf, &callPtr->resultValue);
exit_gracefully:
return(err);
}
Cheers.
#include <string.h>
#include <stdlib.h>
#if TARGET_API_MAC_CARBON
#include <Carbon.h>
#else
#include <NameRegistry.h>
#endif
#if TARGET_API_MAC_CARBON
OSStatus GetPCIBuiltInEnetAddr(UInt
{
OSStatus err = noErr;
InetInterfaceInfo myInetInterfaceInfo;
int i;
OTInetGetInterfaceInfo(&my
for(i=0;i<myInetInterfaceI
enetaddr[i] = myInetInterfaceInfo.fHWAdd
return noErr;
}
#else
OSStatus GetPCIBuiltInEnetAddr(UInt
{
OSStatus err = noErr;
RegEntryIter cookie;
RegEntryID theFoundEntry;
unsigned char enetAddrStr[32] = "\plocal-mac-address";
RegCStrEntryNamePtr enetAddrCStr = p2cstr( enetAddrStr );
RegEntryIterationOp iterOp;
UInt8 enetAddr[6];
Boolean done = false;
RegPropertyValueSize theSize;
err = RegistryEntryIDInit( &theFoundEntry );
if (err != noErr)
{
return err;
}
err = RegistryEntryIterateCreate
if (err != noErr)
{
return err;
}
iterOp = kRegIterDescendants;
err = RegistryEntrySearch( &cookie, iterOp, &theFoundEntry, &done, enetAddrCStr, nil, 0);
if (err == noErr)
{
theSize = sizeof(enetAddr);;
err = RegistryPropertyGet(&theFo
if (err == noErr)
BlockMove(enetAddr, enetaddr, sizeof(enetAddr));
}
RegistryEntryIterateDispos
return noErr;
}
#endif
MoaError GetENetAddrScript_IMoaMmXS
{
/* variable declarations */
MoaError err = kMoaErr_NoErr;
OSStatus osErr;
UInt8 enetaddr[6];
MoaChar buf[256] = "";
MoaLong i = 0;
osErr = GetPCIBuiltInEnetAddr((UIn
if (osErr == noErr)
{
sprintf(buf, "%02X %02X %02X %02X %02X %02X", (int)enetaddr[0], (int)enetaddr[1], (int)enetaddr[2], (int)enetaddr[3], (int)enetaddr[4], (int)enetaddr[5]);
}
else
{
goto exit_gracefully;
}
pObj->pValueInterface->Str
exit_gracefully:
return(err);
}