#include <netinterface.h>
Signals | |
| void | interfaceAvailable (const QString &id) |
Public Member Functions | |
| NetInterfaceManager (QObject *parent=0) | |
| ~NetInterfaceManager () | |
| QStringList | interfaces () const |
Static Public Member Functions | |
| static QString | interfaceForAddress (const QHostAddress &a) |
NetInterfaceManager keeps track of all available network interfaces.
An interface is considered available if it exists, is "Up", has at least one IP address, and is non-Loopback.
The interfaces() function returns a list of available interface ids. These ids can be used with NetInterface to get information about the interfaces. For example, here is how you could print the names of the available interfaces:
NetInterfaceManager netman; QStringList id_list = netman.interfaces(); for(int n = 0; n < id_list.count(); ++n) { NetInterface iface(id_list[n], &netman); printf("name: [%s]\n", qPrintable(iface.name())); }
When a new network interface is available, the interfaceAvailable() signal will be emitted. Note that interface unavailability is not notified by NetInterfaceManager. Instead, use NetInterface to monitor a specific network interface for unavailability.
Interface ids obtained through NetInterfaceManager are guaranteed to be valid until the event loop resumes, or until the next call to interfaces() or interfaceForAddress().
|
|
Constructs a new manager object with the given parent.
|
|
|
Destroys the manager object.
|
|
|
Notifies when an interface becomes available. The id parameter is the interface id, ready to use with NetInterface. |
|
|
Looks up an interface id by IP address. This function looks for an interface that has the address a. If there is no such interface, a null string is returned. This is useful for determing the network interface associated with an outgoing QTcpSocket:
QString iface = NetInterfaceManager::interfaceForAddress(tcpSocket->localAddress());
|
|
|
Returns the list of available interface ids.
|
1.4.6