Qt 4.8
Functions
qnetworkinterface.cpp File Reference
#include "qnetworkinterface.h"
#include "qnetworkinterface_p.h"
#include "qdebug.h"
#include "qendian.h"

Go to the source code of this file.

Functions

static QDebug flagsDebug (QDebug debug, QNetworkInterface::InterfaceFlags flags)
 
static QDebug operator<< (QDebug debug, const QNetworkAddressEntry &entry)
 
QDebug operator<< (QDebug debug, const QNetworkInterface &networkInterface)
 
static QList< QNetworkInterfacePrivate * > postProcess (QList< QNetworkInterfacePrivate *> list)
 

Function Documentation

◆ flagsDebug()

static QDebug flagsDebug ( QDebug  debug,
QNetworkInterface::InterfaceFlags  flags 
)
inlinestatic

Definition at line 596 of file qnetworkinterface.cpp.

Referenced by operator<<().

597 {
598  if (flags & QNetworkInterface::IsUp)
599  debug.nospace() << "IsUp ";
600  if (flags & QNetworkInterface::IsRunning)
601  debug.nospace() << "IsRunning ";
603  debug.nospace() << "CanBroadcast ";
604  if (flags & QNetworkInterface::IsLoopBack)
605  debug.nospace() << "IsLoopBack ";
607  debug.nospace() << "IsPointToPoint ";
609  debug.nospace() << "CanMulticast ";
610  return debug.nospace();
611 }
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92

◆ operator<<() [1/2]

static QDebug operator<< ( QDebug  debug,
const QNetworkAddressEntry entry 
)
inlinestatic

Definition at line 613 of file qnetworkinterface.cpp.

614 {
615  debug.nospace() << "(address = " << entry.ip();
616  if (!entry.netmask().isNull())
617  debug.nospace() << ", netmask = " << entry.netmask();
618  if (!entry.broadcast().isNull())
619  debug.nospace() << ", broadcast = " << entry.broadcast();
620  debug.nospace() << ')';
621  return debug.space();
622 }
bool isNull() const
Returns true if this host address is null (INADDR_ANY or in6addr_any).
QHostAddress ip() const
This function returns one IPv4 or IPv6 address found, that was found in a network interface...
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
QHostAddress broadcast() const
Returns the broadcast address associated with the IPv4 address and netmask.
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
QHostAddress netmask() const
Returns the netmask associated with the IP address.

◆ operator<<() [2/2]

QDebug operator<< ( QDebug  debug,
const QNetworkInterface networkInterface 
)

Definition at line 624 of file qnetworkinterface.cpp.

625 {
626  debug.nospace() << "QNetworkInterface(name = " << networkInterface.name()
627  << ", hardware address = " << networkInterface.hardwareAddress()
628  << ", flags = ";
629  flagsDebug(debug, networkInterface.flags());
630 #if defined(Q_CC_RVCT)
631  // RVCT gets confused with << networkInterface.addressEntries(), reason unknown.
632  debug.nospace() << ")\n";
633 #else
634  debug.nospace() << ", entries = " << networkInterface.addressEntries()
635  << ")\n";
636 #endif
637  return debug.space();
638 }
QString name() const
Returns the name of this network interface.
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
InterfaceFlags flags() const
Returns the flags associated with this network interface.
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
QList< QNetworkAddressEntry > addressEntries() const
Returns the list of IP addresses that this interface possesses along with their associated netmasks a...
static QDebug flagsDebug(QDebug debug, QNetworkInterface::InterfaceFlags flags)
QString hardwareAddress() const
Returns the low-level hardware address for this interface.

◆ postProcess()

static QList<QNetworkInterfacePrivate *> postProcess ( QList< QNetworkInterfacePrivate *>  list)
static

Definition at line 52 of file qnetworkinterface.cpp.

Referenced by QNetworkInterfaceManager::allInterfaces().

53 {
54  // Some platforms report a netmask but don't report a broadcast address
55  // Go through all available addresses and calculate the broadcast address
56  // from the IP and the netmask
57  //
58  // This is an IPv4-only thing -- IPv6 has no concept of broadcasts
59  // The math is:
60  // broadcast = IP | ~netmask
61 
64  for ( ; it != end; ++it) {
65  QList<QNetworkAddressEntry>::Iterator addr_it = (*it)->addressEntries.begin();
66  const QList<QNetworkAddressEntry>::Iterator addr_end = (*it)->addressEntries.end();
67  for ( ; addr_it != addr_end; ++addr_it) {
68  if (addr_it->ip().protocol() != QAbstractSocket::IPv4Protocol)
69  continue;
70 
71  if (!addr_it->netmask().isNull() && addr_it->broadcast().isNull()) {
72  QHostAddress bcast = addr_it->ip();
73  bcast = QHostAddress(bcast.toIPv4Address() | ~addr_it->netmask().toIPv4Address());
74  addr_it->setBroadcast(bcast);
75  }
76  }
77  }
78 
79  return list;
80 }
#define it(className, varName)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
quint32 toIPv4Address() const
Returns the IPv4 address as a number.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
Definition: qlist.h:181
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70
static const KeyPair *const end
The QList class is a template class that provides lists.
Definition: qdatastream.h:62