Interface
open class Interface : CustomStringConvertible, CustomDebugStringConvertible
This class represents a network interface in your system. For example, en0 with a certain IP address.
It is a wrapper around the getifaddrs system call.
Typical use of this class is to first call Interface.allInterfaces() and then use the properties of the interface(s) that you need.
See
/usr/include/ifaddrs.h
-
Undocumented
Declaration
Swift
public var id: UUID -
The network interface family (IPv4 or IPv6).
See moreDeclaration
Swift
public enum Family : Int -
Returns all network interfaces in your system. If you have an interface name (e.g.
en0) that has multiple IP addresses (e.g. one IPv4 address and a few IPv6 addresses), then they will be returned as separate instances of Interface.Declaration
Swift
public static func allInterfaces() -> [Interface]Return Value
An array containing all network interfaces in your system.
-
Returns a new Interface instance that does not represent a real network interface, but can be used for (unit) testing.
Declaration
Swift
public static func createTestDummy(_ name: String, family: Family, address: String, multicastSupported: Bool, broadcastAddress: String?) -> InterfaceReturn Value
An instance of Interface that does not represent a real network interface.
-
Initialize a new Interface with the given properties.
Declaration
Swift
public init(name: String, family: Family, address: String?, netmask: String?, running: Bool, up: Bool, loopback: Bool, multicastSupported: Bool, broadcastAddress: String?) -
Creates the network format representation of the interface’s IP address. Wraps
inet_pton.Declaration
Swift
open var addressBytes: [UInt8]? { get } -
IFF_RUNNINGflag ofifaddrs->ifa_flags.Declaration
Swift
open var isRunning: Bool { get } -
IFF_UPflag ofifaddrs->ifa_flags.Declaration
Swift
open var isUp: Bool { get } -
IFF_LOOPBACKflag ofifaddrs->ifa_flags.Declaration
Swift
open var isLoopback: Bool { get } -
IFF_MULTICASTflag ofifaddrs->ifa_flags.Declaration
Swift
open var supportsMulticast: Bool { get } -
Field
ifaddrs->ifa_name.Declaration
Swift
public let name: String -
Field
ifaddrs->ifa_addr->sa_family.Declaration
Swift
public let family: Family -
Extracted from
ifaddrs->ifa_addr, supports both IPv4 and IPv6.Declaration
Swift
public let address: String? -
Extracted from
ifaddrs->ifa_netmask, supports both IPv4 and IPv6.Declaration
Swift
public let netmask: String? -
Extracted from
ifaddrs->ifa_dstaddr. Not applicable for IPv6.Declaration
Swift
public let broadcastAddress: String? -
Returns the interface name.
Declaration
Swift
open var description: String { get } -
Returns a string containing a few properties of the Interface.
Declaration
Swift
open var debugDescription: String { get }
View on GitHub
Interface Class Reference