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:

ConstantValueDescription
QNetworkInterface::IsUp0x1the network interface is "up" - enabled by administrative action
QNetworkInterface::IsRunning0x2the network interface is operational: configured "up" and (typically) physically connected to a network
QNetworkInterface::CanBroadcast0x4the network interface works in broadcast mode
QNetworkInterface::IsLoopBack0x8the network interface is a loopback interface: that is, it's a virtual interface whose destination is the host computer itself
QNetworkInterface::IsPointToPoint0x10the network interface is a point-to-point interface: that is, there is one, single other address that can be directly reached by it.
QNetworkInterface::CanMulticast0x20the 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:

ConstantValueDescription
QNetworkInterface::Unknown0The interface type could not be determined or is not one of the other listed types.
QNetworkInterface::Loopback1The virtual loopback interface, which is assigned the loopback IP addresses (127.0.0.1, ::1).
QNetworkInterface::Virtual2A 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::Ethernet3IEEE 802.3 Ethernet interfaces, though on many systems other types of IEEE 802 interfaces may also be detected as Ethernet (especially Wi-Fi).
QNetworkInterface::Wifi8IEEE 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::Ieee80211WifiAn alias for WiFi.
QNetworkInterface::CanBus5ISO 11898 Controller Area Network bus interfaces, usually found on automotive systems.
QNetworkInterface::Fddi7ANSI X3T12 Fiber Distributed Data Interface, a local area network over optical fibers.
QNetworkInterface::Ppp6Point-to-Point Protocol interfaces, establishing a direct connection between two nodes over a lower transport layer (often serial over radio or physical line).
QNetworkInterface::Slip4Serial Line Internet Protocol interfaces.
QNetworkInterface::Phonet9Interfaces using the Linux Phonet socket family, for communication with cellular modems. See the Linux kernel documentation for more information.
QNetworkInterface::Ieee80215410IEEE 802.15.4 Personal Area Network interfaces, other than 6LoWPAN (see below).
QNetworkInterface::SixLoWPAN116LoWPAN (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::Ieee8021612IEEE 802.16 Wireless Metropolitan Area Network, also known under the commercial name "WiMAX".
QNetworkInterface::Ieee139413IEEE 1394 interfaces (a.k.a. "FireWire").