Link to home
Start Free TrialLog in
Avatar of nightcoder
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
Avatar of weed
weed
Flag of United States of America image

The MAC address is available through the System Profiler utility.
Avatar of nightcoder
nightcoder

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
ASKER CERTIFIED SOLUTION
Avatar of Tommy Braas
Tommy Braas
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 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(UInt8 *enetaddr)
{
      OSStatus                  err = noErr;
      InetInterfaceInfo      myInetInterfaceInfo;
      int                              i;
      
      OTInetGetInterfaceInfo(&myInetInterfaceInfo,kDefaultInetInterface);
      
      for(i=0;i<myInetInterfaceInfo.fHWAddrLen;i++)
        enetaddr[i] = myInetInterfaceInfo.fHWAddr[i];
      
      return noErr;
}
#else
OSStatus       GetPCIBuiltInEnetAddr(UInt8 *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(&theFoundEntry, enetAddrCStr, &enetAddr, &theSize );
          if (err == noErr)
                BlockMove(enetAddr, enetaddr, sizeof(enetAddr));
      }

    RegistryEntryIterateDispose( &cookie );

      return noErr;
}
#endif

MoaError GetENetAddrScript_IMoaMmXScript::XX_GetStringAddress(PMoaDrCallInfo callPtr)
{
      /* variable declarations */
      MoaError      err = kMoaErr_NoErr;
      OSStatus      osErr;
      UInt8            enetaddr[6];
      
      MoaChar            buf[256] = "";
      MoaLong            i = 0;

      osErr = GetPCIBuiltInEnetAddr((UInt8*)enetaddr);
      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->StringToValue(buf, &callPtr->resultValue);

exit_gracefully:
      return(err);
}