Qt 4.8
Public Functions | Properties | List of all members
QNetworkAddressEntry Class Reference

The QNetworkAddressEntry class stores one IP address supported by a network interface, along with its associated netmask and broadcast address. More...

#include <qnetworkinterface.h>

Public Functions

QHostAddress broadcast () const
 Returns the broadcast address associated with the IPv4 address and netmask. More...
 
QHostAddress ip () const
 This function returns one IPv4 or IPv6 address found, that was found in a network interface. More...
 
QHostAddress netmask () const
 Returns the netmask associated with the IP address. More...
 
bool operator!= (const QNetworkAddressEntry &other) const
 Returns true if this network address entry is different from other. More...
 
QNetworkAddressEntryoperator= (const QNetworkAddressEntry &other)
 Makes a copy of the QNetworkAddressEntry object other. More...
 
bool operator== (const QNetworkAddressEntry &other) const
 Returns true if this network address entry is the same as other. More...
 
int prefixLength () const
 Returns the prefix length of this IP address. More...
 
 QNetworkAddressEntry ()
 Constructs an empty QNetworkAddressEntry object. More...
 
 QNetworkAddressEntry (const QNetworkAddressEntry &other)
 Constructs a QNetworkAddressEntry object that is a copy of the object other. More...
 
void setBroadcast (const QHostAddress &newBroadcast)
 Sets the broadcast IP address of this QNetworkAddressEntry object to newBroadcast. More...
 
void setIp (const QHostAddress &newIp)
 Sets the IP address the QNetworkAddressEntry object contains to newIp. More...
 
void setNetmask (const QHostAddress &newNetmask)
 Sets the netmask that this QNetworkAddressEntry object contains to newNetmask. More...
 
void setPrefixLength (int length)
 Sets the prefix length of this IP address to length. More...
 
 ~QNetworkAddressEntry ()
 Destroys this QNetworkAddressEntry object. More...
 

Properties

QScopedPointer< QNetworkAddressEntryPrivated
 

Detailed Description

The QNetworkAddressEntry class stores one IP address supported by a network interface, along with its associated netmask and broadcast address.

Since
4.2
Note
This class or function is reentrant.

Each network interface can contain zero or more IP addresses, which in turn can be associated with a netmask and/or a broadcast address (depending on support from the operating system).

This class represents one such group.

Definition at line 60 of file qnetworkinterface.h.

Constructors and Destructors

◆ QNetworkAddressEntry() [1/2]

QNetworkAddressEntry::QNetworkAddressEntry ( )

Constructs an empty QNetworkAddressEntry object.

Definition at line 166 of file qnetworkinterface.cpp.

168 {
169 }
QScopedPointer< QNetworkAddressEntryPrivate > d

◆ QNetworkAddressEntry() [2/2]

QNetworkAddressEntry::QNetworkAddressEntry ( const QNetworkAddressEntry other)

Constructs a QNetworkAddressEntry object that is a copy of the object other.

Definition at line 175 of file qnetworkinterface.cpp.

176  : d(new QNetworkAddressEntryPrivate(*other.d.data()))
177 {
178 }
T * data() const
Returns the value of the pointer referenced by this object.
QScopedPointer< QNetworkAddressEntryPrivate > d

◆ ~QNetworkAddressEntry()

QNetworkAddressEntry::~QNetworkAddressEntry ( )

Destroys this QNetworkAddressEntry object.

Definition at line 192 of file qnetworkinterface.cpp.

193 {
194 }

Functions

◆ broadcast()

QHostAddress QNetworkAddressEntry::broadcast ( ) const

Returns the broadcast address associated with the IPv4 address and netmask.

It can usually be derived from those two by setting to 1 the bits of the IP address where the netmask contains a 0. (In other words, by bitwise-OR'ing the IP address with the inverse of the netmask)

This member is always empty for IPv6 addresses, since the concept of broadcast has been abandoned in that system in favor of multicast. In particular, the group of hosts corresponding to all the nodes in the local network can be reached by the "all-nodes" special multicast group (address FF02::1).

Definition at line 326 of file qnetworkinterface.cpp.

Referenced by operator<<().

327 {
328  return d->broadcast;
329 }
QScopedPointer< QNetworkAddressEntryPrivate > d

◆ ip()

QHostAddress QNetworkAddressEntry::ip ( ) const

This function returns one IPv4 or IPv6 address found, that was found in a network interface.

Definition at line 223 of file qnetworkinterface.cpp.

Referenced by QNetworkInterface::allAddresses(), interfaceListing(), interfaceListingWinXP(), isBypassed(), multicastMembershipHelper(), QNativeSocketEnginePrivate::nativeMulticastInterface(), QNativeSocketEnginePrivate::nativeSetMulticastInterface(), operator<<(), and setNetmask().

224 {
225  return d->address;
226 }
QScopedPointer< QNetworkAddressEntryPrivate > d

◆ netmask()

QHostAddress QNetworkAddressEntry::netmask ( ) const

Returns the netmask associated with the IP address.

The netmask is expressed in the form of an IP address, such as 255.255.0.0.

For IPv6 addresses, the prefix length is converted to an address where the number of bits set to 1 is equal to the prefix length. For a prefix length of 64 bits (the most common value), the netmask will be expressed as a QHostAddress holding the address FFFF:FFFF:FFFF:FFFF::

See also
prefixLength()

Definition at line 250 of file qnetworkinterface.cpp.

Referenced by operator<<().

251 {
252  return d->netmask;
253 }
QScopedPointer< QNetworkAddressEntryPrivate > d

◆ operator!=()

bool QNetworkAddressEntry::operator!= ( const QNetworkAddressEntry other) const
inline

Returns true if this network address entry is different from other.

Definition at line 68 of file qnetworkinterface.h.

69  { return !(*this == other); }

◆ operator=()

QNetworkAddressEntry & QNetworkAddressEntry::operator= ( const QNetworkAddressEntry other)

Makes a copy of the QNetworkAddressEntry object other.

Definition at line 183 of file qnetworkinterface.cpp.

184 {
185  *d.data() = *other.d.data();
186  return *this;
187 }
T * data() const
Returns the value of the pointer referenced by this object.
QScopedPointer< QNetworkAddressEntryPrivate > d

◆ operator==()

bool QNetworkAddressEntry::operator== ( const QNetworkAddressEntry other) const

Returns true if this network address entry is the same as other.

Definition at line 200 of file qnetworkinterface.cpp.

201 {
202  if (d == other.d) return true;
203  if (!d || !other.d) return false;
204  return d->address == other.d->address &&
205  d->netmask == other.d->netmask &&
206  d->broadcast == other.d->broadcast;
207 }
QScopedPointer< QNetworkAddressEntryPrivate > d

◆ prefixLength()

int QNetworkAddressEntry::prefixLength ( ) const

Returns the prefix length of this IP address.

Since
4.5 The prefix length matches the number of bits set to 1 in the netmask (see netmask()). For IPv4 addresses, the value is between 0 and 32. For IPv6 addresses, it's contained between 0 and 128 and is the preferred form of representing addresses.

This function returns -1 if the prefix length could not be determined (i.e., netmask() returns a null QHostAddress()).

See also
netmask()

Definition at line 288 of file qnetworkinterface.cpp.

Referenced by isBypassed().

289 {
290  return d->netmask.prefixLength();
291 }
QScopedPointer< QNetworkAddressEntryPrivate > d
int prefixLength() const

◆ setBroadcast()

void QNetworkAddressEntry::setBroadcast ( const QHostAddress newBroadcast)

Sets the broadcast IP address of this QNetworkAddressEntry object to newBroadcast.

Definition at line 335 of file qnetworkinterface.cpp.

Referenced by convertFlags(), and interfaceListing().

336 {
337  d->broadcast = newBroadcast;
338 }
QScopedPointer< QNetworkAddressEntryPrivate > d

◆ setIp()

void QNetworkAddressEntry::setIp ( const QHostAddress newIp)

Sets the IP address the QNetworkAddressEntry object contains to newIp.

Definition at line 232 of file qnetworkinterface.cpp.

Referenced by convertFlags(), interfaceListing(), interfaceListingWin2k(), and interfaceListingWinXP().

233 {
234  d->address = newIp;
235 }
QScopedPointer< QNetworkAddressEntryPrivate > d

◆ setNetmask()

void QNetworkAddressEntry::setNetmask ( const QHostAddress newNetmask)

Sets the netmask that this QNetworkAddressEntry object contains to newNetmask.

Setting the netmask also sets the prefix length to match the new netmask.

See also
setPrefixLength()

Definition at line 262 of file qnetworkinterface.cpp.

Referenced by convertFlags(), interfaceListing(), interfaceListingWin2k(), and interfaceListingWinXP().

263 {
264  if (newNetmask.protocol() != ip().protocol()) {
266  return;
267  }
268 
269  d->netmask.setAddress(newNetmask);
270 }
QHostAddress ip() const
This function returns one IPv4 or IPv6 address found, that was found in a network interface...
QScopedPointer< QNetworkAddressEntryPrivate > d
QAbstractSocket::NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
bool setAddress(const QString &address)

◆ setPrefixLength()

void QNetworkAddressEntry::setPrefixLength ( int  length)

Sets the prefix length of this IP address to length.

Since
4.5 The value of length must be valid for this type of IP address: between 0 and 32 for IPv4 addresses, between 0 and 128 for IPv6 addresses. Setting to any invalid value is equivalent to setting to -1, which means "no prefix length".

Setting the prefix length also sets the netmask (see netmask()).

See also
setNetmask()

Definition at line 308 of file qnetworkinterface.cpp.

Referenced by interfaceListingWinXP().

309 {
310  d->netmask.setPrefixLength(d->address.protocol(), length);
311 }
QScopedPointer< QNetworkAddressEntryPrivate > d
QAbstractSocket::NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
void setPrefixLength(QAbstractSocket::NetworkLayerProtocol proto, int len)

Properties

◆ d

QScopedPointer<QNetworkAddressEntryPrivate> QNetworkAddressEntry::d
private

The documentation for this class was generated from the following files: