com.trolltech.qt.network
Class QHostAddress

java.lang.Object
  extended by com.trolltech.qt.internal.QSignalEmitterInternal
      extended by com.trolltech.qt.QSignalEmitter
          extended by com.trolltech.qt.QtJambiObject
              extended by com.trolltech.qt.network.QHostAddress
All Implemented Interfaces:
QtJambiInterface, java.lang.Cloneable

public class QHostAddress
extends QtJambiObject
implements java.lang.Cloneable

The QHostAddress class provides an IP address. This class holds an IPv4 or IPv6 address in a platform- and protocol-independent manner.

QHostAddress is normally used with the QTcpSocket, QTcpServer, and QUdpSocket to connect to a host or to set up a server.

A host address is set with setAddress(), checked for its type using isIPv4Address() or isIPv6Address(), and retrieved with toIPv4Address(), toIPv6Address(), or toString().

The class also supports common predefined addresses: Null , LocalHost , LocalHostIPv6 , Broadcast , and Any .

See also:
QTcpSocket, QTcpServer, and QUdpSocket.


Nested Class Summary
static class QHostAddress.SpecialAddress
           
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.PrivateSignal0, QSignalEmitter.PrivateSignal1, QSignalEmitter.PrivateSignal2, QSignalEmitter.PrivateSignal3, QSignalEmitter.PrivateSignal4, QSignalEmitter.PrivateSignal5, QSignalEmitter.PrivateSignal6, QSignalEmitter.PrivateSignal7, QSignalEmitter.PrivateSignal8, QSignalEmitter.PrivateSignal9, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9
 
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal
 
Field Summary
 
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
currentSender
 
Constructor Summary
QHostAddress()
          Constructs a host address object with the IP address 0.
QHostAddress(int ip4Addr)
          Constructs a host address object with the IPv4 address ip4Addr.
QHostAddress(QHostAddress.SpecialAddress address)
          Constructs a QHostAddress object for address.
QHostAddress(QHostAddress copy)
          Constructs a copy of the given address.
QHostAddress(QIPv6Address ip6Addr)
          Creates a QHostAddress from the specified ip6Addr address.
QHostAddress(java.lang.String address)
          Constructs an IPv4 or IPv6 address based on the string address (e.
 
Method Summary
 void clear()
          Sets the host address to 0.0.0.0.
 QHostAddress clone()
          This method is reimplemented for internal reasons
 boolean isInSubnet(QHostAddress subnet, int netmask)
          Returns true if this IP is in the subnet described by the network prefix subnet and netmask netmask.
 boolean isInSubnet(QPair subnet)
          This is an overloaded method provided for convenience.
 boolean isNull()
          Returns true if this host address is null (INADDR_ANY or in6addr_any).
static QPair parseSubnet(java.lang.String subnet)
          Parses the IP and subnet information contained in subnet and returns the network prefix for that network and its prefix length.
 QAbstractSocket.NetworkLayerProtocol protocol()
          Returns the network layer protocol of the host address.
 void readFrom(QDataStream arg__1)
          Reads a QHostAddress
 java.lang.String scopeId()
          Returns the scope ID of an IPv6 address.
 void setAddress(int ip4Addr)
          Set the IPv4 address specified by ip4Addr.
 void setAddress(QIPv6Address ip6Addr)
          Sets the address of this QHostAddress to ip6Addr.
 boolean setAddress(java.lang.String address)
          This is an overloaded member function, provided for convenience.
 void setScopeId(java.lang.String id)
          Sets the IPv6 scope ID of the address to id.
 int toIPv4Address()
          Returns the IPv4 address as a number.
 QIPv6Address toIPv6Address()
          Returns the IPv6 address as a Q_IPV6ADDR structure.
 java.lang.String toString()
          Returns a string representation of the this QHostAddress.
 void writeTo(QDataStream arg__1)
          Writes thisQHostAddress
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
__qt_signalInitialization
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QHostAddress

public QHostAddress()
Constructs a host address object with the IP address 0. .0.0.

See also:
clear().


QHostAddress

public QHostAddress(QHostAddress.SpecialAddress address)
Constructs a QHostAddress object for address.


QHostAddress

public QHostAddress(QHostAddress copy)
Constructs a copy of the given address.


QHostAddress

public QHostAddress(QIPv6Address ip6Addr)
Creates a QHostAddress from the specified ip6Addr address.


QHostAddress

public QHostAddress(java.lang.String address)
Constructs an IPv4 or IPv6 address based on the string address (e. ., "127.0.0.1").

See also:
setAddress().


QHostAddress

public QHostAddress(int ip4Addr)
Constructs a host address object with the IPv4 address ip4Addr.

Method Detail

clear

public final void clear()
Sets the host address to 0.0.0.0.


isInSubnet

public final boolean isInSubnet(QHostAddress subnet,
                                int netmask)
Returns true if this IP is in the subnet described by the network prefix subnet and netmask netmask.

An IP is considered to belong to a subnet if it is contained between the lowest and the highest address in that subnet. In the case of IP version 4, the lowest address is the network address, while the highest address is the broadcast address.

The subnet argument does not have to be the actual network address (the lowest address in the subnet). It can be any valid IP belonging to that subnet. In particular, if it is equal to the IP address held by this object, this function will always return true (provided the netmask is a valid value).

See also:
parseSubnet().


isInSubnet

public final boolean isInSubnet(QPair subnet)
This is an overloaded method provided for convenience.


isNull

public final boolean isNull()
Returns true if this host address is null (INADDR_ANY or in6addr_any). The default constructor creates a null address, and that address is not valid for any host or interface.


writeTo

public final void writeTo(QDataStream arg__1)
Writes thisQHostAddress


readFrom

public final void readFrom(QDataStream arg__1)
Reads a QHostAddress


protocol

public final QAbstractSocket.NetworkLayerProtocol protocol()
Returns the network layer protocol of the host address.


scopeId

public final java.lang.String scopeId()
Returns the scope ID of an IPv6 address. For IPv4 addresses, or if the address does not contain a scope ID, an empty QString is returned.

The IPv6 scope ID specifies the scope of reachability for non-global IPv6 addresses, limiting the area in which the address can be used. All IPv6 addresses are associated with such a reachability scope. The scope ID is used to disambiguate addresses that are not guaranteed to be globally unique.

IPv6 specifies the following four levels of reachability:

When using a link-local or site-local address for IPv6 connections, you must specify the scope ID. The scope ID for a link-local address is usually the same as the interface name (e.g., "eth0", "en1") or number (e.g., "1", "2").

See also:
setScopeId().


setAddress

public final void setAddress(QIPv6Address ip6Addr)
Sets the address of this QHostAddress to ip6Addr.


setAddress

public final boolean setAddress(java.lang.String address)
This is an overloaded member function, provided for convenience.

Sets the IPv4 or IPv6 address specified by the string representation specified by address (e.g. "127.0.0.1"). Returns true and sets the address if the address was successfully parsed; otherwise returns false.


setAddress

public final void setAddress(int ip4Addr)
Set the IPv4 address specified by ip4Addr.


setScopeId

public final void setScopeId(java.lang.String id)
Sets the IPv6 scope ID of the address to id. If the address protocol is not IPv6, this function does nothing.

See also:
scopeId().


toIPv4Address

public final int toIPv4Address()
Returns the IPv4 address as a number.

For example, if the address is 127.0.0.1, the returned value is 2130706433 (i.e. 0x7f000001).

This value is only valid if isIp4Addr() returns true.

See also:
toString().


toIPv6Address

public final QIPv6Address toIPv6Address()
Returns the IPv6 address as a Q_IPV6ADDR structure. The structure consists of 16 unsigned characters.
        QIPv6Address addr = hostAddr.toIPv6Address();
        // addr contains 16 unsigned characters

        for (int i = 0; i < 16; ++i) {
            // process addr.c[i]
        }
This value is only valid if isIPv6Address() returns true.

See also:
toString().


toString

public final java.lang.String toString()
Returns a string representation of the this QHostAddress.

Overrides:
toString in class java.lang.Object

parseSubnet

public static QPair parseSubnet(java.lang.String subnet)
Parses the IP and subnet information contained in subnet and returns the network prefix for that network and its prefix length.

The IP address and the netmask must be separated by a slash (/).

This function supports arguments in the form:

For IP version 4, this function accepts as well missing trailing components (i.e., less than 4 octets, like "192.168.1"), followed or not by a dot. If the netmask is also missing in that case, it is set to the number of octets actually passed (in the example above, it would be 24, for 3 octets).

See also:
isInSubnet().


clone

public QHostAddress clone()
This method is reimplemented for internal reasons

Overrides:
clone in class java.lang.Object