Overview
The NetworkInterface object has the information (name, MAC address, IP address) of a network interface that the computer is connected to.
Tasks
Creating a NetworkInterface object
Network Interface Properties
Network Interface Property Checks
- (Boolean)hasIP ;
- (Boolean)hasHardwareAddress ;
- (Boolean)nameIs:(char*)iname ;
Instance Methods
hardwareAddress
The MAC address of the network interface that is associated with the receiver. Returns six octets that makes up the MAC address. The octets will be all zero if the network is not accessible externally.
- (unsigned char*)hardwareAddress
Return Value
Byte array that contains the six octets comprising the MAC address.
hasHardwareAddress
Check if a MAC address is associated with the network interface. This should return all interfaces that are capable of making UDP connections (including FireWire).
- (Boolean)hasHardwareAddress
Return Value
True if there is a MAC address for this network interface.
hasIPAddress
Check if a IP address is associated with the network interface. An active Ethernet port has an IP address. However, an Ethernet port (e.g., second Ethernet port on a Mac Pro) that is directly connected to a Metis device may not have an IP address assigned until the Metis device is powered on.
- (Boolean)hasIPAddress
Return Value
True if there is a IP address for this network interface.
initWithInternetHost:hosts:
Initializes NetworkInterface object with data from an internet host (ifaddrs) structure that is obtained from the getifaddrs system call. The head of the linked list from system call is sent in as the hosts argument.
The MAC address and IP address is obtained during initialization. Only Ethernet interfaces will have a non-zero address MAC address, and only Ethernet interfaces that are connected to some other devices will have an IP address. -hasHardwareAddress and -hasIP can be used to find if a MAC address or an IP address exists.
- (id)initWithInternetHost:(struct ifaddrs*)ifa hosts:(struct ifaddrs*)hosts
Parameters
ifa
structure of a
specific ifaddrs entry,
hosts
head of the
linked list of ifaddrs structures.
Return Value
The initialized NetworkInterface object.
ipAddress
The IP address of the network interface that is associated with the receiver. Returns 0 (INADDR_ANY) if an IP address does not exist.
- (in_addr_t)ipAddress
Return Value
IP Address.
name
The name of the network interface for the receiver, e.g., "en0".
- (char*)name
Return Value
Name of the network interface.