aschmied
aschmied

Reputation: 986

Precise definition of "Primary Network Interface" on OSX

I'm considering using the MAC address as part of a machine identifier on OSX. The GetPrimaryMACAddress.c example on developer.apple.com demonstrates how to obtain the MAC address for the "primary" ethernet interface (https://developer.apple.com/library/mac/samplecode/GetPrimaryMACAddress/Listings/GetPrimaryMACAddress_GetPrimaryMACAddress_c.html). My question is "what is the precise definition of primary ethernet interface?" The comments describe it as the "built-in" network card. What happens on systems with more than one builtin interface? For example Mac Pros can have two wired plugs and older Macbook Pros have both a wired and wireless jack.

The only documentation I could find on this is the IONetworkInterface.h Reference (https://developer.apple.com/library/mac/documentation/Kernel/Reference/IONetworkInterface_header_reference/Reference/reference.html). It defines the kIOPrimaryInterface as describing "whether the interface is the primary or the built-in network interface." This doesn't answer my question about what happens when there are multiple builtin interfaces.

Upvotes: 0

Views: 935

Answers (1)

Marek H
Marek H

Reputation: 5566

According to Apple's open source page located here

I think you are looking for this specific code /* Returns a Base-64 encoded MD5 hash of 'username:primary-mac-address' */.

//------------------------------------------------------------------------------
// Returns true if the receiver of this method is the system's primary
// network interface.

bool IONetworkInterface::isPrimaryInterface() const
{
    IOService * provider  = _driver;
    bool        isPrimary = false;

    if ( provider ) provider = provider->getProvider();

    // Look for the built-in property in the ethernet entry.

    if ( provider && provider->getProperty("built-in") && getUnitNumber() == 0)
    {
        isPrimary = true;
    }

    return isPrimary;
}

Upvotes: 0

Related Questions