QNetworkInterface Class
The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces. More...
| Header: | #include <QNetworkInterface> |
| qmake: | QT += network |
| Since: | Qt 4.2 |
This class was introduced in Qt 4.2.
Note: All functions in this class are reentrant.
Public Types
| enum | InterfaceFlag { IsUp, IsRunning, CanBroadcast, IsLoopBack, IsPointToPoint, CanMulticast } |
| enum | InterfaceType { Unknown, Loopback, Virtual, Ethernet, Wifi, …, Ieee1394 } |
Detailed Description
QNetworkInterface represents one network interface attached to the host where the program is being run. Each network interface may contain zero or more IP addresses, each of which is optionally associated with a netmask and/or a broadcast address. The list of such trios can be obtained with addressEntries(). Alternatively, when the netmask or the broadcast addresses or other information aren't necessary, use the allAddresses() convenience function to obtain just the IP addresses of the active interfaces.
QNetworkInterface also reports the interface's hardware address with hardwareAddress().
Not all operating systems support reporting all features. Only the IPv4 addresses are guaranteed to be listed by this class in all platforms. In particular, IPv6 address listing is only supported on Windows, Linux, macOS and the BSDs.
See also QNetworkAddressEntry.
Member Type Documentation
enum QNetworkInterface::InterfaceFlag
Specifies the flags associated with this network interface. The possible values are:
| Constant | Value | Description |
|---|---|---|
QNetworkInterface::IsUp | 0x1 | the network interface is "up" - enabled by administrative action |
QNetworkInterface::IsRunning | 0x2 | the network interface is operational: configured "up" and (typically) physically connected to a network |
QNetworkInterface::CanBroadcast | 0x4 | the network interface works in broadcast mode |
QNetworkInterface::IsLoopBack | 0x8 | the network interface is a loopback interface: that is, it's a virtual interface whose destination is the host computer itself |
QNetworkInterface::IsPointToPoint | 0x10 | the network interface is a point-to-point interface: that is, there is one, single other address that can be directly reached by it. |
QNetworkInterface::CanMulticast | 0x20 | the network interface supports multicasting |
Note that one network interface cannot be both broadcast-based and point-to-point.
enum QNetworkInterface::InterfaceType
Specifies the type of hardware (PHY layer, OSI level 1) this interface is, if it could be determined. Interface types that are not among those listed below will generally be listed as Unknown, though future versions of Qt may add new enumeration values.
The possible values are:
| Constant | Value | Description |
|---|---|---|
QNetworkInterface::Unknown | 0 | The interface type could not be determined or is not one of the other listed types. |
QNetworkInterface::Loopback | 1 | The virtual loopback interface, which is assigned the loopback IP addresses (127.0.0.1, ::1). |
QNetworkInterface::Virtual | 2 | A type of interface determined to be virtual, but not any of the other possible types. For example, tunnel interfaces are (currently) detected as virtual ones. |
QNetworkInterface::Ethernet | 3 | IEEE 802.3 Ethernet interfaces, though on many systems other types of IEEE 802 interfaces may also be detected as Ethernet (especially Wi-Fi). |
QNetworkInterface::Wifi | 8 | IEEE 802.11 Wi-Fi interfaces. Note that on some systems, QNetworkInterface may be unable to distinguish regular Ethernet from Wi-Fi and will not return this enum value. |
QNetworkInterface::Ieee80211 | Wifi | An alias for WiFi. |
QNetworkInterface::CanBus | 5 | ISO 11898 Controller Area Network bus interfaces, usually found on automotive systems. |
QNetworkInterface::Fddi | 7 | ANSI X3T12 Fiber Distributed Data Interface, a local area network over optical fibers. |
QNetworkInterface::Ppp | 6 | Point-to-Point Protocol interfaces, establishing a direct connection between two nodes over a lower transport layer (often serial over radio or physical line). |
QNetworkInterface::Slip | 4 | Serial Line Internet Protocol interfaces. |
QNetworkInterface::Phonet | 9 | Interfaces using the Linux Phonet socket family, for communication with cellular modems. See the Linux kernel documentation for more information. |
QNetworkInterface::Ieee802154 | 10 | IEEE 802.15.4 Personal Area Network interfaces, other than 6LoWPAN (see below). |
QNetworkInterface::SixLoWPAN | 11 | 6LoWPAN (IPv6 over Low-power Wireless Personal Area Networks) interfaces, which operate on IEEE 802.15.4 PHY, but have specific header compression schemes for IPv6 and UDP. This type of interface is often used for mesh networking. |
QNetworkInterface::Ieee80216 | 12 | IEEE 802.16 Wireless Metropolitan Area Network, also known under the commercial name "WiMAX". |
QNetworkInterface::Ieee1394 | 13 | IEEE 1394 interfaces (a.k.a. "FireWire"). |