#include <netinterface.h>
Signals | |
| void | unavailable () |
Public Member Functions | |
| NetInterface (const QString &id, NetInterfaceManager *manager) | |
| ~NetInterface () | |
| bool | isValid () const |
| QString | id () const |
| QString | name () const |
| QList< QHostAddress > | addresses () const |
| QHostAddress | gateway () const |
NetInterface provides information about a particular network interface. Construct it by passing the interface id of interest (e.g. "eth0") and a NetInterfaceManager parent object. Interface ids can be obtained from NetInterfaceManager.
To test if a NetInterface is valid, call isValid(). Use name() to return a display-friendly name of the interface. The addresses() function returns a list of IP addresses for this interface. There may be a gateway IP address associated with this interface, which can be fetched with gateway().
Here's an example of how to print the IP addresses of eth0:
NetInterface iface("eth0"); if(iface.isValid()) { QList<QHostAddress> addrs = iface.addresses(); for(int n = 0; n < addrs.count(); ++n) printf("%s\n", qPrintable(addrs[n].toString())); }
If the interface goes away, the unavailable() signal is emitted and the NetInterface becomes invalid.
|
||||||||||||
|
Constructs a new interface object with the given id and manager. If id is not a valid interface id, then the object will not be valid (isValid() will return false). Normally it is not necessary to check for validity, since interface ids obtained from NetInterfaceManager are guaranteed to be valid until the event loop resumes.
|
|
|
Destroys the interface object.
|
|
|
Returns the addresses of this interface. There will always be at least one address. In some cases there might be multiple, such as on Unix where it is possible for the same interface to have both an IPv4 and an IPv6 address. |
|
|
Returns the gateway of this interface. If there is no gateway associated with this interface, a null QHostAddress is returned. |
|
|
Returns the id of this interface. This is the id that was passed in the constructor. |
|
|
Returns true if the interface is valid, otherwise returns false.
|
|
|
Returns a display-friendly name of this interface. The name may be the same as the id.
|
|
|
Notifies when the interface becomes unavailable. Once this signal is emitted, the NetInterface object becomes invalid and is no longer very useful. A new NetInterface object must be created if a valid object with current information is desired.
|
1.4.6