~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/network/kernel/qnetworkinterface.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtNetwork module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include "qnetworkinterface.h"
 
43
#include "qnetworkinterface_p.h"
 
44
 
 
45
#include "qdebug.h"
 
46
#include "qendian.h"
 
47
 
 
48
#ifndef QT_NO_NETWORKINTERFACE
 
49
 
 
50
QT_BEGIN_NAMESPACE
 
51
 
 
52
static QList<QNetworkInterfacePrivate *> postProcess(QList<QNetworkInterfacePrivate *> list)
 
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
 
 
62
    QList<QNetworkInterfacePrivate *>::Iterator it = list.begin();
 
63
    const QList<QNetworkInterfacePrivate *>::Iterator end = list.end();
 
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
}
 
81
 
 
82
Q_GLOBAL_STATIC(QNetworkInterfaceManager, manager)
 
83
 
 
84
QNetworkInterfaceManager::QNetworkInterfaceManager()
 
85
{
 
86
}
 
87
 
 
88
QNetworkInterfaceManager::~QNetworkInterfaceManager()
 
89
{
 
90
}
 
91
 
 
92
QSharedDataPointer<QNetworkInterfacePrivate> QNetworkInterfaceManager::interfaceFromName(const QString &name)
 
93
{
 
94
    QList<QSharedDataPointer<QNetworkInterfacePrivate> > interfaceList = allInterfaces();
 
95
    QList<QSharedDataPointer<QNetworkInterfacePrivate> >::ConstIterator it = interfaceList.constBegin();
 
96
    for ( ; it != interfaceList.constEnd(); ++it)
 
97
        if ((*it)->name == name)
 
98
            return *it;
 
99
 
 
100
    return empty;
 
101
}
 
102
 
 
103
QSharedDataPointer<QNetworkInterfacePrivate> QNetworkInterfaceManager::interfaceFromIndex(int index)
 
104
{
 
105
    QList<QSharedDataPointer<QNetworkInterfacePrivate> > interfaceList = allInterfaces();
 
106
    QList<QSharedDataPointer<QNetworkInterfacePrivate> >::ConstIterator it = interfaceList.constBegin();
 
107
    for ( ; it != interfaceList.constEnd(); ++it)
 
108
        if ((*it)->index == index)
 
109
            return *it;
 
110
 
 
111
    return empty;
 
112
}
 
113
 
 
114
QList<QSharedDataPointer<QNetworkInterfacePrivate> > QNetworkInterfaceManager::allInterfaces()
 
115
{
 
116
    QList<QNetworkInterfacePrivate *> list = postProcess(scan());
 
117
    QList<QSharedDataPointer<QNetworkInterfacePrivate> > result;
 
118
 
 
119
    foreach (QNetworkInterfacePrivate *ptr, list)
 
120
        result << QSharedDataPointer<QNetworkInterfacePrivate>(ptr);
 
121
 
 
122
    return result;
 
123
}
 
124
 
 
125
QString QNetworkInterfacePrivate::makeHwAddress(int len, uchar *data)
 
126
{
 
127
    QString result;
 
128
    for (int i = 0; i < len; ++i) {
 
129
        if (i)
 
130
            result += QLatin1Char(':');
 
131
 
 
132
        char buf[3];
 
133
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && defined(_MSC_VER) && _MSC_VER >= 1400
 
134
        sprintf_s(buf, 3, "%02hX", ushort(data[i]));
 
135
#else
 
136
        sprintf(buf, "%02hX", ushort(data[i]));
 
137
#endif
 
138
        result += QLatin1String(buf);
 
139
    }
 
140
    return result;
 
141
}
 
142
 
 
143
/*!
 
144
    \class QNetworkAddressEntry
 
145
    \brief The QNetworkAddressEntry class stores one IP address
 
146
    supported by a network interface, along with its associated
 
147
    netmask and broadcast address.
 
148
 
 
149
    \since 4.2
 
150
    \reentrant
 
151
    \ingroup network
 
152
    \ingroup shared
 
153
    \inmodule QtNetwork
 
154
 
 
155
    Each network interface can contain zero or more IP addresses, which
 
156
    in turn can be associated with a netmask and/or a broadcast
 
157
    address (depending on support from the operating system).
 
158
 
 
159
    This class represents one such group.
 
160
*/
 
161
 
 
162
/*!
 
163
    Constructs an empty QNetworkAddressEntry object.
 
164
*/
 
165
QNetworkAddressEntry::QNetworkAddressEntry()
 
166
    : d(new QNetworkAddressEntryPrivate)
 
167
{
 
168
}
 
169
 
 
170
/*!
 
171
    Constructs a QNetworkAddressEntry object that is a copy of the
 
172
    object \a other.
 
173
*/
 
174
QNetworkAddressEntry::QNetworkAddressEntry(const QNetworkAddressEntry &other)
 
175
    : d(new QNetworkAddressEntryPrivate(*other.d.data()))
 
176
{
 
177
}
 
178
 
 
179
/*!
 
180
    Makes a copy of the QNetworkAddressEntry object \a other.
 
181
*/
 
182
QNetworkAddressEntry &QNetworkAddressEntry::operator=(const QNetworkAddressEntry &other)
 
183
{
 
184
    *d.data() = *other.d.data();
 
185
    return *this;
 
186
}
 
187
 
 
188
/*!
 
189
    \fn void QNetworkAddressEntry::swap(QNetworkAddressEntry &other)
 
190
    \since 5.0
 
191
 
 
192
    Swaps this network address entry instance with \a other. This
 
193
    function is very fast and never fails.
 
194
*/
 
195
 
 
196
/*!
 
197
    Destroys this QNetworkAddressEntry object.
 
198
*/
 
199
QNetworkAddressEntry::~QNetworkAddressEntry()
 
200
{
 
201
}
 
202
 
 
203
/*!
 
204
    Returns true if this network address entry is the same as \a
 
205
    other.
 
206
*/
 
207
bool QNetworkAddressEntry::operator==(const QNetworkAddressEntry &other) const
 
208
{
 
209
    if (d == other.d) return true;
 
210
    if (!d || !other.d) return false;
 
211
    return d->address == other.d->address &&
 
212
        d->netmask == other.d->netmask &&
 
213
        d->broadcast == other.d->broadcast;
 
214
}
 
215
 
 
216
/*!
 
217
    \fn bool QNetworkAddressEntry::operator!=(const QNetworkAddressEntry &other) const
 
218
 
 
219
    Returns true if this network address entry is different from \a
 
220
    other.
 
221
*/
 
222
 
 
223
/*!
 
224
    This function returns one IPv4 or IPv6 address found, that was
 
225
    found in a network interface.
 
226
*/
 
227
QHostAddress QNetworkAddressEntry::ip() const
 
228
{
 
229
    return d->address;
 
230
}
 
231
 
 
232
/*!
 
233
    Sets the IP address the QNetworkAddressEntry object contains to \a
 
234
    newIp.
 
235
*/
 
236
void QNetworkAddressEntry::setIp(const QHostAddress &newIp)
 
237
{
 
238
    d->address = newIp;
 
239
}
 
240
 
 
241
/*!
 
242
    Returns the netmask associated with the IP address. The
 
243
    netmask is expressed in the form of an IP address, such as
 
244
    255.255.0.0.
 
245
 
 
246
    For IPv6 addresses, the prefix length is converted to an address
 
247
    where the number of bits set to 1 is equal to the prefix
 
248
    length. For a prefix length of 64 bits (the most common value),
 
249
    the netmask will be expressed as a QHostAddress holding the
 
250
    address FFFF:FFFF:FFFF:FFFF::
 
251
 
 
252
    \sa prefixLength()
 
253
*/
 
254
QHostAddress QNetworkAddressEntry::netmask() const
 
255
{
 
256
    return d->netmask;
 
257
}
 
258
 
 
259
/*!
 
260
    Sets the netmask that this QNetworkAddressEntry object contains to
 
261
    \a newNetmask. Setting the netmask also sets the prefix length to
 
262
    match the new netmask.
 
263
 
 
264
    \sa setPrefixLength()
 
265
*/
 
266
void QNetworkAddressEntry::setNetmask(const QHostAddress &newNetmask)
 
267
{
 
268
    if (newNetmask.protocol() != ip().protocol()) {
 
269
        d->netmask = QNetmaskAddress();
 
270
        return;
 
271
    }
 
272
 
 
273
    d->netmask.setAddress(newNetmask);
 
274
}
 
275
 
 
276
/*!
 
277
    \since 4.5
 
278
    Returns the prefix length of this IP address. The prefix length
 
279
    matches the number of bits set to 1 in the netmask (see
 
280
    netmask()). For IPv4 addresses, the value is between 0 and 32. For
 
281
    IPv6 addresses, it's contained between 0 and 128 and is the
 
282
    preferred form of representing addresses.
 
283
 
 
284
    This function returns -1 if the prefix length could not be
 
285
    determined (i.e., netmask() returns a null QHostAddress()).
 
286
 
 
287
    \sa netmask()
 
288
*/
 
289
int QNetworkAddressEntry::prefixLength() const
 
290
{
 
291
    return d->netmask.prefixLength();
 
292
}
 
293
 
 
294
/*!
 
295
    \since 4.5
 
296
    Sets the prefix length of this IP address to \a length. The value
 
297
    of \a length must be valid for this type of IP address: between 0
 
298
    and 32 for IPv4 addresses, between 0 and 128 for IPv6
 
299
    addresses. Setting to any invalid value is equivalent to setting
 
300
    to -1, which means "no prefix length".
 
301
 
 
302
    Setting the prefix length also sets the netmask (see netmask()).
 
303
 
 
304
    \sa setNetmask()
 
305
*/
 
306
void QNetworkAddressEntry::setPrefixLength(int length)
 
307
{
 
308
    d->netmask.setPrefixLength(d->address.protocol(), length);
 
309
}
 
310
 
 
311
/*!
 
312
    Returns the broadcast address associated with the IPv4
 
313
    address and netmask. It can usually be derived from those two by
 
314
    setting to 1 the bits of the IP address where the netmask contains
 
315
    a 0. (In other words, by bitwise-OR'ing the IP address with the
 
316
    inverse of the netmask)
 
317
 
 
318
    This member is always empty for IPv6 addresses, since the concept
 
319
    of broadcast has been abandoned in that system in favor of
 
320
    multicast. In particular, the group of hosts corresponding to all
 
321
    the nodes in the local network can be reached by the "all-nodes"
 
322
    special multicast group (address FF02::1).
 
323
*/
 
324
QHostAddress QNetworkAddressEntry::broadcast() const
 
325
{
 
326
    return d->broadcast;
 
327
}
 
328
 
 
329
/*!
 
330
    Sets the broadcast IP address of this QNetworkAddressEntry object
 
331
    to \a newBroadcast.
 
332
*/
 
333
void QNetworkAddressEntry::setBroadcast(const QHostAddress &newBroadcast)
 
334
{
 
335
    d->broadcast = newBroadcast;
 
336
}
 
337
 
 
338
/*!
 
339
    \class QNetworkInterface
 
340
    \brief The QNetworkInterface class provides a listing of the host's IP
 
341
    addresses and network interfaces.
 
342
 
 
343
    \since 4.2
 
344
    \reentrant
 
345
    \ingroup network
 
346
    \ingroup shared
 
347
    \inmodule QtNetwork
 
348
 
 
349
    QNetworkInterface represents one network interface attached to the
 
350
    host where the program is being run. Each network interface may
 
351
    contain zero or more IP addresses, each of which is optionally
 
352
    associated with a netmask and/or a broadcast address. The list of
 
353
    such trios can be obtained with addressEntries(). Alternatively,
 
354
    when the netmask or the broadcast addresses aren't necessary, use
 
355
    the allAddresses() convenience function to obtain just the IP
 
356
    addresses.
 
357
 
 
358
    QNetworkInterface also reports the interface's hardware address with
 
359
    hardwareAddress().
 
360
 
 
361
    Not all operating systems support reporting all features. Only the
 
362
    IPv4 addresses are guaranteed to be listed by this class in all
 
363
    platforms. In particular, IPv6 address listing is only supported
 
364
    on Windows XP and more recent versions, Linux, MacOS X and the
 
365
    BSDs.
 
366
 
 
367
    \sa QNetworkAddressEntry
 
368
*/
 
369
 
 
370
/*!
 
371
    \enum QNetworkInterface::InterfaceFlag
 
372
    Specifies the flags associated with this network interface. The
 
373
    possible values are:
 
374
 
 
375
    \value IsUp                 the network interface is active
 
376
    \value IsRunning            the network interface has resources
 
377
                                allocated
 
378
    \value CanBroadcast         the network interface works in
 
379
                                broadcast mode
 
380
    \value IsLoopBack           the network interface is a loopback
 
381
                                interface: that is, it's a virtual
 
382
                                interface whose destination is the
 
383
                                host computer itself
 
384
    \value IsPointToPoint       the network interface is a
 
385
                                point-to-point interface: that is,
 
386
                                there is one, single other address
 
387
                                that can be directly reached by it.
 
388
    \value CanMulticast         the network interface supports
 
389
                                multicasting
 
390
 
 
391
    Note that one network interface cannot be both broadcast-based and
 
392
    point-to-point.
 
393
*/
 
394
 
 
395
/*!
 
396
    Constructs an empty network interface object.
 
397
*/
 
398
QNetworkInterface::QNetworkInterface()
 
399
    : d(0)
 
400
{
 
401
}
 
402
 
 
403
/*!
 
404
    Frees the resources associated with the QNetworkInterface object.
 
405
*/
 
406
QNetworkInterface::~QNetworkInterface()
 
407
{
 
408
}
 
409
 
 
410
/*!
 
411
    Creates a copy of the QNetworkInterface object contained in \a
 
412
    other.
 
413
*/
 
414
QNetworkInterface::QNetworkInterface(const QNetworkInterface &other)
 
415
    : d(other.d)
 
416
{
 
417
}
 
418
 
 
419
/*!
 
420
    Copies the contents of the QNetworkInterface object contained in \a
 
421
    other into this one.
 
422
*/
 
423
QNetworkInterface &QNetworkInterface::operator=(const QNetworkInterface &other)
 
424
{
 
425
    d = other.d;
 
426
    return *this;
 
427
}
 
428
 
 
429
/*!
 
430
    \fn void QNetworkInterface::swap(QNetworkInterface &other)
 
431
    \since 5.0
 
432
 
 
433
    Swaps this network interface instance with \a other. This function
 
434
    is very fast and never fails.
 
435
*/
 
436
 
 
437
/*!
 
438
    Returns true if this QNetworkInterface object contains valid
 
439
    information about a network interface.
 
440
*/
 
441
bool QNetworkInterface::isValid() const
 
442
{
 
443
    return !name().isEmpty();
 
444
}
 
445
 
 
446
/*!
 
447
    \since 4.5
 
448
    Returns the interface system index, if known. This is an integer
 
449
    assigned by the operating system to identify this interface and it
 
450
    generally doesn't change. It matches the scope ID field in IPv6
 
451
    addresses.
 
452
 
 
453
    If the index isn't known, this function returns 0.
 
454
*/
 
455
int QNetworkInterface::index() const
 
456
{
 
457
    return d ? d->index : 0;
 
458
}
 
459
 
 
460
/*!
 
461
    Returns the name of this network interface. On Unix systems, this
 
462
    is a string containing the type of the interface and optionally a
 
463
    sequence number, such as "eth0", "lo" or "pcn0". On Windows, it's
 
464
    an internal ID that cannot be changed by the user.
 
465
*/
 
466
QString QNetworkInterface::name() const
 
467
{
 
468
    return d ? d->name : QString();
 
469
}
 
470
 
 
471
/*!
 
472
    \since 4.5
 
473
 
 
474
    Returns the human-readable name of this network interface on
 
475
    Windows, such as "Local Area Connection", if the name could be
 
476
    determined. If it couldn't, this function returns the same as
 
477
    name(). The human-readable name is a name that the user can modify
 
478
    in the Windows Control Panel, so it may change during the
 
479
    execution of the program.
 
480
 
 
481
    On Unix, this function currently always returns the same as
 
482
    name(), since Unix systems don't store a configuration for
 
483
    human-readable names.
 
484
*/
 
485
QString QNetworkInterface::humanReadableName() const
 
486
{
 
487
    return d ? !d->friendlyName.isEmpty() ? d->friendlyName : name() : QString();
 
488
}
 
489
 
 
490
/*!
 
491
    Returns the flags associated with this network interface.
 
492
*/
 
493
QNetworkInterface::InterfaceFlags QNetworkInterface::flags() const
 
494
{
 
495
    return d ? d->flags : InterfaceFlags(0);
 
496
}
 
497
 
 
498
/*!
 
499
    Returns the low-level hardware address for this interface. On
 
500
    Ethernet interfaces, this will be a MAC address in string
 
501
    representation, separated by colons.
 
502
 
 
503
    Other interface types may have other types of hardware
 
504
    addresses. Implementations should not depend on this function
 
505
    returning a valid MAC address.
 
506
*/
 
507
QString QNetworkInterface::hardwareAddress() const
 
508
{
 
509
    return d ? d->hardwareAddress : QString();
 
510
}
 
511
 
 
512
/*!
 
513
    Returns the list of IP addresses that this interface possesses
 
514
    along with their associated netmasks and broadcast addresses.
 
515
 
 
516
    If the netmask or broadcast address information is not necessary,
 
517
    you can call the allAddresses() function to obtain just the IP
 
518
    addresses.
 
519
*/
 
520
QList<QNetworkAddressEntry> QNetworkInterface::addressEntries() const
 
521
{
 
522
    return d ? d->addressEntries : QList<QNetworkAddressEntry>();
 
523
}
 
524
 
 
525
/*!
 
526
    Returns a QNetworkInterface object for the interface named \a
 
527
    name. If no such interface exists, this function returns an
 
528
    invalid QNetworkInterface object.
 
529
 
 
530
    \sa name(), isValid()
 
531
*/
 
532
QNetworkInterface QNetworkInterface::interfaceFromName(const QString &name)
 
533
{
 
534
    QNetworkInterface result;
 
535
    result.d = manager()->interfaceFromName(name);
 
536
    return result;
 
537
}
 
538
 
 
539
/*!
 
540
    Returns a QNetworkInterface object for the interface whose internal
 
541
    ID is \a index. Network interfaces have a unique identifier called
 
542
    the "interface index" to distinguish it from other interfaces on
 
543
    the system. Often, this value is assigned progressively and
 
544
    interfaces being removed and then added again get a different
 
545
    value every time.
 
546
 
 
547
    This index is also found in the IPv6 address' scope ID field.
 
548
*/
 
549
QNetworkInterface QNetworkInterface::interfaceFromIndex(int index)
 
550
{
 
551
    QNetworkInterface result;
 
552
    result.d = manager()->interfaceFromIndex(index);
 
553
    return result;
 
554
}
 
555
 
 
556
/*!
 
557
    Returns a listing of all the network interfaces found on the host
 
558
    machine.
 
559
*/
 
560
QList<QNetworkInterface> QNetworkInterface::allInterfaces()
 
561
{
 
562
    QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces();
 
563
    QList<QNetworkInterface> result;
 
564
    foreach (const QSharedDataPointer<QNetworkInterfacePrivate> &p, privs) {
 
565
        QNetworkInterface item;
 
566
        item.d = p;
 
567
        result << item;
 
568
    }
 
569
 
 
570
    return result;
 
571
}
 
572
 
 
573
/*!
 
574
    This convenience function returns all IP addresses found on the
 
575
    host machine. It is equivalent to calling addressEntries() on all the
 
576
    objects returned by allInterfaces() to obtain lists of QHostAddress
 
577
    objects then calling QHostAddress::ip() on each of these.
 
578
*/
 
579
QList<QHostAddress> QNetworkInterface::allAddresses()
 
580
{
 
581
    QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces();
 
582
    QList<QHostAddress> result;
 
583
    foreach (const QSharedDataPointer<QNetworkInterfacePrivate> &p, privs) {
 
584
        foreach (const QNetworkAddressEntry &entry, p->addressEntries)
 
585
            result += entry.ip();
 
586
    }
 
587
 
 
588
    return result;
 
589
}
 
590
 
 
591
#ifndef QT_NO_DEBUG_STREAM
 
592
static inline QDebug flagsDebug(QDebug debug, QNetworkInterface::InterfaceFlags flags)
 
593
{
 
594
    if (flags & QNetworkInterface::IsUp)
 
595
        debug.nospace() << "IsUp ";
 
596
    if (flags & QNetworkInterface::IsRunning)
 
597
        debug.nospace() << "IsRunning ";
 
598
    if (flags & QNetworkInterface::CanBroadcast)
 
599
        debug.nospace() << "CanBroadcast ";
 
600
    if (flags & QNetworkInterface::IsLoopBack)
 
601
        debug.nospace() << "IsLoopBack ";
 
602
    if (flags & QNetworkInterface::IsPointToPoint)
 
603
        debug.nospace() << "IsPointToPoint ";
 
604
    if (flags & QNetworkInterface::CanMulticast)
 
605
        debug.nospace() << "CanMulticast ";
 
606
    return debug.nospace();
 
607
}
 
608
 
 
609
static inline QDebug operator<<(QDebug debug, const QNetworkAddressEntry &entry)
 
610
{
 
611
    debug.nospace() << "(address = " << entry.ip();
 
612
    if (!entry.netmask().isNull())
 
613
        debug.nospace() << ", netmask = " << entry.netmask();
 
614
    if (!entry.broadcast().isNull())
 
615
        debug.nospace() << ", broadcast = " << entry.broadcast();
 
616
    debug.nospace() << ')';
 
617
    return debug.space();
 
618
}
 
619
 
 
620
QDebug operator<<(QDebug debug, const QNetworkInterface &networkInterface)
 
621
{
 
622
    debug.nospace() << "QNetworkInterface(name = " << networkInterface.name()
 
623
                    << ", hardware address = " << networkInterface.hardwareAddress()
 
624
                    << ", flags = ";
 
625
    flagsDebug(debug, networkInterface.flags());
 
626
#if defined(Q_CC_RVCT)
 
627
    // RVCT gets confused with << networkInterface.addressEntries(), reason unknown.
 
628
    debug.nospace() << ")\n";
 
629
#else
 
630
    debug.nospace() << ", entries = " << networkInterface.addressEntries()
 
631
                    << ")\n";
 
632
#endif
 
633
    return debug.space();
 
634
}
 
635
#endif
 
636
 
 
637
QT_END_NAMESPACE
 
638
 
 
639
#endif // QT_NO_NETWORKINTERFACE