Class ointerface
Introduction This class stores information about a named host Ethernet interface. Instantiating it with either the interface index or the interface name causes it to collect the remaining information about the interfaces and make it available to your application. Once instantiated, you can access the interface Index, Name, Description, HardwareAddress and InternetAddress properties. This class is declared in ointerface.hpp and defined in ointerface.cpp. Application developers can access a collection of ointerface objects via the ointerfaces class.
Inheritance None.
Dependence This class depends on static classes omemory and oerror. This class references interface adapter related constants defined in header file net/if.h which should be available on most systems. An abridged version is provided in VisualStudioNET/include/net/if.h for systems that may not have it. This class references Ethernet related constants defined in header file net/ethernet.h which should be available on most systems. An abridged version is provided in VisualStudioNET/include/net/ethernet.h for systems that may not have it.
Properties
ointerface::Description char const * Description void Return the interface description string. On Linux, this property defaults to the interface Name property. On Windows, this property contains the hardware manufacturer name string, such as Realtek RTL83 Ethernet Adapter (Microsoft Packet Scheduler). On instantiation, this property contains an empty string.
ointerface::Index unsigned Index void Return the interface index. This is the number assigned to the interface by the operating system when it was discovered. It should not be confused with the ointerfaces::Index property. An index of 0 indicates that the interface is invalid. On instantiation, this property contains 0.
ointerface::Name char const * Name void Return the interface name string. On Linux, name strings are short, as in eth0, and do exceed IF_NAMESIZE characters. On Windows, name strings are longer, as in \Device\NPF_{4CFAABD5-C929-4942-914B-BDFE72B13611}, but do not exceed 255 characters. On instantiation, this property contains an empty string.
ointerface::HardwareAddress uint8_t const * HardwareAddress void Return the location of the interface hardware address. The hardware address is ETHER_ADDR_LEN binary bytes long. The hardware address is the same as the physical address, Ethernet address and MAC address.The hardware address location remains valid for the life of the object but the content may change if the Index or Name property changes. On instantiation, this property contains zeros.
ointerface::HardwareAddressString char const * HardwareAddressString void Return the location of the interface hardware address as a string. The string is 18 characters long including the NUL terminator, as in 00:B0:52:BA:BE:01. This property may be used anywhere that a NUL terminated string is permitted. The string address remains valid for the life of the object but the content may change if the Index or Name property is changed.
ointerface::InternetAddress uint8_t const * InternetAddress void Return the location of the interface internet address. The internet address is 4 binary bytes long. The internet address is the same as the IPv4 address. The internet address location remains valid for the life of the object but the content may change if the Index or Name property is changed. On instantiation, this property contains zeros.
ointerface::InternetAddressString char const * InternetAddressString void Return the location of the interface internet address string. The string is 16 characters long including the NUL terminator, as in 192.168.099.001. This property may be used anywhere that a NUL terminated string is permitted. The string address remains valid for the life of the object but the content may change if the Index or Name property changes.
Methods
ointerface::ExportHardwareAddress ointerface & ExportHardwareAddress void * memory Copy the interface hardware address to external memory in binary format. The hardware address is ETHER_ADDR_LEN bytes so length argument is needed.
ointerface::ExportInternetAddress ointerface & ExportInternetAddress void * memory Copy the interface internet address to external memory in binary format. The internet address is 4 bytes so length argument is needed.
Print ointerface & Print void Print instance properties on stdout in human-readable format. Output conisists of the index, hardware address string, internet address string, name and description properties, in that order. Print ointerface properties on stdout 2 00:0F:EA:4B:98:CB 192.168.170.179 eth3 eth3 This is typical output on a Linux or Mac OSX system. The device name (field 4) is short and the description (field 5) is the same as the device name. 1 00:0E:2E:03:5F:B8 192.168.099.033 \Device\NPF_{4CFAABD5-C929-4942-914B-BDFE72B13611} Realtek RTL8139 Family Fast Eth This is typical output on a Microsoft Windows system. The device name (field 4) is long and the description (field 5) is not the same as device name.
SetDescription ointerface & SetDescription char const * string Copy the interface text description from external memory. The string argument is truncated to 255 characters. The text description will change whenever the Index or Name properties change but changing the text description change the other properties.
Constructors This class must be instantiated using either an interface number or interface name. ointerface unsigned index Instantiate the class as the numbered interface. Terminate the program if the numbered interface does not exist. ointerface char const * name Instantiate the class as the named interface. Terminate the program if the named interfaces does not exist.