Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QNetworkInterface Class

TheQNetworkInterface class provides a listing of the host's IP addresses and network interfaces.More...

Header:#include <QNetworkInterface>
Since: Qt 4.2

Note: All functions in this class arereentrant.

Public Types

enumInterfaceFlag { IsUp, IsRunning, CanBroadcast, IsLoopBack, IsPointToPoint, CanMulticast }
flagsInterfaceFlags

Public Functions

QNetworkInterface()
QNetworkInterface(const QNetworkInterface & other)
~QNetworkInterface()
QList<QNetworkAddressEntry>addressEntries() const
InterfaceFlagsflags() const
QStringhardwareAddress() const
QStringhumanReadableName() const
intindex() const
boolisValid() const
QStringname() const
QNetworkInterface &operator=(const QNetworkInterface & other)

Static Public Members

QList<QHostAddress>allAddresses()
QList<QNetworkInterface>allInterfaces()
QNetworkInterfaceinterfaceFromIndex(int index)
QNetworkInterfaceinterfaceFromName(const QString & name)

Detailed Description

TheQNetworkInterface class provides a listing of the host's IP addresses and network interfaces.

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 withaddressEntries(). Alternatively, when the netmask or the broadcast addresses aren't necessary, use theallAddresses() convenience function to obtain just the IP addresses.

QNetworkInterface also reports the interface's hardware address withhardwareAddress().

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 XP and more recent versions, Linux, MacOS X and the BSDs.

See alsoQNetworkAddressEntry.

Member Type Documentation

enum QNetworkInterface::InterfaceFlag
flags QNetworkInterface::InterfaceFlags

Specifies the flags associated with this network interface. The possible values are:

ConstantValueDescription
QNetworkInterface::IsUp0x1the network interface is active
QNetworkInterface::IsRunning0x2the network interface has resources allocated
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.

The InterfaceFlags type is a typedef forQFlags<InterfaceFlag>. It stores an OR combination of InterfaceFlag values.

Member Function Documentation

QNetworkInterface::QNetworkInterface()

Constructs an empty network interface object.

QNetworkInterface::QNetworkInterface(constQNetworkInterface & other)

Creates a copy of theQNetworkInterface object contained inother.

QNetworkInterface::~QNetworkInterface()

Frees the resources associated with theQNetworkInterface object.

QList<QNetworkAddressEntry> QNetworkInterface::addressEntries() const

Returns the list of IP addresses that this interface possesses along with their associated netmasks and broadcast addresses.

If the netmask or broadcast address information is not necessary, you can call theallAddresses() function to obtain just the IP addresses.

[static]QList<QHostAddress> QNetworkInterface::allAddresses()

This convenience function returns all IP addresses found on the host machine. It is equivalent to callingaddressEntries() on all the objects returned byallInterfaces() to obtain lists ofQHostAddress objects then calling QHostAddress::ip() on each of these.

[static]QList<QNetworkInterface> QNetworkInterface::allInterfaces()

Returns a listing of all the network interfaces found on the host machine.

InterfaceFlags QNetworkInterface::flags() const

Returns the flags associated with this network interface.

QString QNetworkInterface::hardwareAddress() const

Returns the low-level hardware address for this interface. On Ethernet interfaces, this will be a MAC address in string representation, separated by colons.

Other interface types may have other types of hardware addresses. Implementations should not depend on this function returning a valid MAC address.

QString QNetworkInterface::humanReadableName() const

Returns the human-readable name of this network interface on Windows, such as "Local Area Connection", if the name could be determined. If it couldn't, this function returns the same asname(). The human-readable name is a name that the user can modify in the Windows Control Panel, so it may change during the execution of the program.

On Unix, this function currently always returns the same asname(), since Unix systems don't store a configuration for human-readable names.

This function was introduced in Qt 4.5.

int QNetworkInterface::index() const

Returns the interface system index, if known. This is an integer assigned by the operating system to identify this interface and it generally doesn't change. It matches the scope ID field in IPv6 addresses.

If the index isn't known, this function returns 0.

This function was introduced in Qt 4.5.

[static]QNetworkInterface QNetworkInterface::interfaceFromIndex(int index)

Returns aQNetworkInterface object for the interface whose internal ID isindex. Network interfaces have a unique identifier called the "interface index" to distinguish it from other interfaces on the system. Often, this value is assigned progressively and interfaces being removed and then added again get a different value every time.

This index is also found in the IPv6 address' scope ID field.

[static]QNetworkInterface QNetworkInterface::interfaceFromName(constQString & name)

Returns aQNetworkInterface object for the interface namedname. If no such interface exists, this function returns an invalidQNetworkInterface object.

See alsoname() andisValid().

bool QNetworkInterface::isValid() const

Returns true if thisQNetworkInterface object contains valid information about a network interface.

QString QNetworkInterface::name() const

Returns the name of this network interface. On Unix systems, this is a string containing the type of the interface and optionally a sequence number, such as "eth0", "lo" or "pcn0". On Windows, it's an internal ID that cannot be changed by the user.

QNetworkInterface & QNetworkInterface::operator=(constQNetworkInterface & other)

Copies the contents of theQNetworkInterface object contained inother into this one.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp