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

#include <qhostaddress_p.h>

Inheritance diagram for QNetmaskAddress:
QHostAddress

Public Functions

int prefixLength () const
 
 QNetmaskAddress ()
 
bool setAddress (const QString &address)
 
bool setAddress (const QHostAddress &address)
 
void setPrefixLength (QAbstractSocket::NetworkLayerProtocol proto, int len)
 
- Public Functions inherited from QHostAddress
void clear ()
 Sets the host address to 0.0.0.0. More...
 
bool isInSubnet (const QHostAddress &subnet, int netmask) const
 Returns true if this IP is in the subnet described by the network prefix subnet and netmask netmask. More...
 
bool isInSubnet (const QPair< QHostAddress, int > &subnet) const
 Returns true if this IP is in the subnet described by subnet. More...
 
bool isNull () const
 Returns true if this host address is null (INADDR_ANY or in6addr_any). More...
 
bool operator!= (const QHostAddress &address) const
 Returns true if this host address is not the same as the other address given; otherwise returns false. More...
 
bool operator!= (SpecialAddress address) const
 Returns true if this host address is not the same as the other address given; otherwise returns false. More...
 
QHostAddressoperator= (const QHostAddress &other)
 Assigns another host address to this object, and returns a reference to this object. More...
 
QHostAddressoperator= (const QString &address)
 Assigns the host address address to this object, and returns a reference to this object. More...
 
bool operator== (const QHostAddress &address) const
 Returns true if this host address is the same as the other address given; otherwise returns false. More...
 
bool operator== (SpecialAddress address) const
 Returns true if this host address is the same as the other address given; otherwise returns false. More...
 
QAbstractSocket::NetworkLayerProtocol protocol () const
 Returns the network layer protocol of the host address. More...
 
 QHostAddress ()
 Constructs a host address object with the IP address 0.0.0.0. More...
 
 QHostAddress (quint32 ip4Addr)
 Constructs a host address object with the IPv4 address ip4Addr. More...
 
 QHostAddress (quint8 *ip6Addr)
 Constructs a host address object with the IPv6 address ip6Addr. More...
 
 QHostAddress (const Q_IPV6ADDR &ip6Addr)
 Constructs a host address object with the IPv6 address ip6Addr. More...
 
 QHostAddress (const sockaddr *sockaddr)
 Constructs an IPv4 or IPv6 address using the address specified by the native structure sockaddr. More...
 
 QHostAddress (const QString &address)
 Constructs an IPv4 or IPv6 address based on the string address (e.g., "127.0.0.1"). More...
 
 QHostAddress (const QHostAddress &copy)
 Constructs a copy of the given address. More...
 
 QHostAddress (SpecialAddress address)
 Constructs a QHostAddress object for address. More...
 
QString scopeId () const
 Returns the scope ID of an IPv6 address. More...
 
void setAddress (quint32 ip4Addr)
 Set the IPv4 address specified by ip4Addr. More...
 
void setAddress (quint8 *ip6Addr)
 Set the IPv6 address specified by ip6Addr. More...
 
void setAddress (const Q_IPV6ADDR &ip6Addr)
 Set the IPv6 address specified by ip6Addr. More...
 
void setAddress (const sockaddr *sockaddr)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the IPv4 or IPv6 address specified by the native structure sockaddr. More...
 
bool setAddress (const QString &address)
 Sets the IPv4 or IPv6 address specified by the string representation specified by address (e. More...
 
void setScopeId (const QString &id)
 Sets the IPv6 scope ID of the address to id. More...
 
quint32 toIPv4Address () const
 Returns the IPv4 address as a number. More...
 
Q_IPV6ADDR toIPv6Address () const
 Returns the IPv6 address as a Q_IPV6ADDR structure. More...
 
QString toString () const
 Returns the address as a string. More...
 
 ~QHostAddress ()
 Destroys the host address object. More...
 

Properties

int length
 

Additional Inherited Members

- Public Types inherited from QHostAddress
enum  SpecialAddress {
  Null, Broadcast, LocalHost, LocalHostIPv6,
  Any, AnyIPv6
}
 
- Static Public Functions inherited from QHostAddress
static QPair< QHostAddress, int > parseSubnet (const QString &subnet)
 Parses the IP and subnet information contained in subnet and returns the network prefix for that network and its prefix length. More...
 
- Protected Variables inherited from QHostAddress
QScopedPointer< QHostAddressPrivated
 

Detailed Description

Definition at line 61 of file qhostaddress_p.h.

Constructors and Destructors

◆ QNetmaskAddress()

QNetmaskAddress::QNetmaskAddress ( )
inline

Definition at line 65 of file qhostaddress_p.h.

65 : QHostAddress(), length(-1) { }
QHostAddress()
Constructs a host address object with the IP address 0.0.0.0.

Functions

◆ prefixLength()

int QNetmaskAddress::prefixLength ( ) const

Definition at line 388 of file qhostaddress.cpp.

Referenced by QHostAddress::parseSubnet(), QNetworkAddressEntry::prefixLength(), and QNetmaskAddress().

389 {
390  return length;
391 }

◆ setAddress() [1/2]

bool QNetmaskAddress::setAddress ( const QString address)

Definition at line 299 of file qhostaddress.cpp.

Referenced by QHostAddress::parseSubnet(), QNetmaskAddress(), and QNetworkAddressEntry::setNetmask().

300 {
301  length = -1;
302  QHostAddress other;
303  return other.setAddress(address) && setAddress(other);
304 }
void setAddress(quint32 ip4Addr)
Set the IPv4 address specified by ip4Addr.
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70
bool setAddress(const QString &address)

◆ setAddress() [2/2]

bool QNetmaskAddress::setAddress ( const QHostAddress address)

Definition at line 306 of file qhostaddress.cpp.

307 {
308  static const quint8 zeroes[16] = { 0 };
309  union {
310  quint32 v4;
311  quint8 v6[16];
312  } ip;
313 
314  int netmask = 0;
315  quint8 *ptr = ip.v6;
316  quint8 *end;
317  length = -1;
318 
319  QHostAddress::operator=(address);
320 
322  ip.v4 = qToBigEndian(d->a);
323  end = ptr + 4;
324  } else if (d->protocol == QAbstractSocket::IPv6Protocol) {
325  memcpy(ip.v6, d->a6.c, 16);
326  end = ptr + 16;
327  } else {
328  d->clear();
329  return false;
330  }
331 
332  while (ptr < end) {
333  switch (*ptr) {
334  case 255:
335  netmask += 8;
336  ++ptr;
337  continue;
338 
339  default:
340  d->clear();
341  return false; // invalid IP-style netmask
342 
343  // the rest always falls through
344  case 254:
345  ++netmask;
346  case 252:
347  ++netmask;
348  case 248:
349  ++netmask;
350  case 240:
351  ++netmask;
352  case 224:
353  ++netmask;
354  case 192:
355  ++netmask;
356  case 128:
357  ++netmask;
358  case 0:
359  break;
360  }
361  break;
362  }
363 
364  // confirm that the rest is only zeroes
365  if (ptr < end && memcmp(ptr + 1, zeroes, end - ptr - 1) != 0) {
366  d->clear();
367  return false;
368  }
369 
370  length = netmask;
371  return true;
372 }
quint8 c[16]
Definition: qhostaddress.h:65
QHostAddress & operator=(const QHostAddress &other)
Assigns another host address to this object, and returns a reference to this object.
QScopedPointer< QHostAddressPrivate > d
Definition: qhostaddress.h:134
QAbstractSocket::NetworkLayerProtocol protocol
unsigned char quint8
Definition: qglobal.h:934
T qToBigEndian(T source)
Definition: qendian.h:337
const T * ptr(const T &t)
unsigned int quint32
Definition: qglobal.h:938
static const KeyPair *const end

◆ setPrefixLength()

void QNetmaskAddress::setPrefixLength ( QAbstractSocket::NetworkLayerProtocol  proto,
int  len 
)

Definition at line 393 of file qhostaddress.cpp.

Referenced by QNetmaskAddress(), and QNetworkAddressEntry::setPrefixLength().

394 {
395  length = newLength;
396  if (length < 0 || length > (proto == QAbstractSocket::IPv4Protocol ? 32 :
397  proto == QAbstractSocket::IPv6Protocol ? 128 : -1)) {
398  // invalid information, reject
400  length = -1;
401  return;
402  }
403 
404  d->protocol = proto;
406  if (length == 0) {
407  d->a = 0;
408  } else if (length == 32) {
409  d->a = quint32(0xffffffff);
410  } else {
411  d->a = quint32(0xffffffff) >> (32 - length) << (32 - length);
412  }
413  } else {
414  memset(d->a6.c, 0xFF, sizeof(d->a6));
415  clearBits(d->a6.c, length, 128);
416  }
417 }
quint8 c[16]
Definition: qhostaddress.h:65
QScopedPointer< QHostAddressPrivate > d
Definition: qhostaddress.h:134
QAbstractSocket::NetworkLayerProtocol protocol
unsigned int quint32
Definition: qglobal.h:938
static void clearBits(quint8 *where, int start, int end)

Properties

◆ length

int QNetmaskAddress::length
private

Definition at line 63 of file qhostaddress_p.h.


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