|
OpenTop 1.5 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||||
#include "ot/net/InetAddress.h"

This class provides static methods for resolving host names into IP addresses. Presently, only IPv4 addresses are supported, but future versions of OpenTop will support IPv6 addresses also.
The following example resolves a hostname into an IP address using the GetByName() static member function:-
#include "ot/net/InetAddress.h"
#include "ot/io/Console.h"
using namespace ot;
using namespace ot::io;
using namespace ot::net;
int main(int argc, char* argv[])
{
try
{
// Get the IP address for 'www.elcel.com'
RefPtr<InetAddress> rpAddr = InetAddress::GetByName(OT_T("www.elcel.com"));
Console::cout() << OT_T("The IP Address for ") << rpAddr->getHostName()
<< OT_T(" is ") << rpAddr->getHostAddress() << endl;
}
catch(Exception& e)
{
Console::cerr() << e.toString() << endl;
}
return 0;
}
| Constructor/Destructor Summary | |
InetAddress()Protected default constructor. | |
InetAddress(const InetAddress& rhs)Copy constructor. | |
~InetAddress()Destructor. | |
| Method Summary | |
virtual bool |
equals(const InetAddress& rhs) constTests if two InetAddress instances refer to the same IP address. |
static RefPtr< InetAddress > |
FromNetworkAddress(const void* pAddr, size_t addrlen)Creates an InetAddress instance from a sockaddr structure. |
virtual const Byte* |
getAddress() constReturns a pointer to a byte array containing the internal IP address. |
virtual size_t |
getAddressLength() constReturns the length of the byte array returned when calling getAddress(). |
static RefPtr< InetAddress > |
GetAnyHost()Returns a special InetAddress that does not pertain to any particular Internet host. |
static RefPtr< InetAddress > |
GetByName(const String& host)Returns an InetAddress by performing a look-up of a host's name. |
virtual String |
getHostAddress() constReturns the IP address in dotted decimal notation. |
virtual String |
getHostName() constReturns the host name for this InetAddress. |
static RefPtr< InetAddress > |
GetLocalBroadcast()Returns a special InetAddress that can be used to broadcast UDP datagrams to all hosts on the local subnet. |
static RefPtr< InetAddress > |
GetLocalHost()Returns an InetAddress instance pertaining to the local host. |
bool |
operator!=(const InetAddress& rhs) constTests if two InetAddress instances refer to different IP addresses. |
InetAddress& |
operator=(const InetAddress& rhs)Assignment operator. |
bool |
operator==(const InetAddress& rhs) constTests if two InetAddress instances refer to the same IP address. |
virtual String |
toString() constReturns a String representation of this InetAddress. |
virtual String |
toStringLite() constReturns a String representation of this InetAddress without performing any additional name look-ups. |
| Methods inherited from class ot::ManagedObject |
addRef(), getRefCount(), onFinalRelease(), operator=(const ManagedObject&), release() |
| Constructor/Destructor Detail |
protected InetAddress()
InetAddress(const InetAddress& rhs)
rhs - ~InetAddress()
| Method Detail |
virtual bool equals(const InetAddress& rhs) const
rhs - static RefPtr< InetAddress > FromNetworkAddress(const void* pAddr,
size_t addrlen)
pAddr - addrlen - NullPointerException - IllegalArgumentException - virtual const Byte* getAddress() const
virtual size_t getAddressLength() const
static RefPtr< InetAddress > GetAnyHost()
static RefPtr< InetAddress > GetByName(const String& host)
host - UnknownHostException - virtual String getHostAddress() const
virtual String getHostName() const
No exceptions are thrown. If the reverse look-up fails, the IP address is returned (in dotted decimal notation) instead.
static RefPtr< InetAddress > GetLocalBroadcast()
static RefPtr< InetAddress > GetLocalHost()
bool operator!=(const InetAddress& rhs) const
rhs - InetAddress& operator=(const InetAddress& rhs)
rhs - bool operator==(const InetAddress& rhs) const
rhs - virtual String toString() const
hostname/host address
Note that the hostname component is obtained by invoking getHostname() and may therefore be delayed while a DNS reverse look-up is performed on the IP address. To avoid the potential for delay, consider using toStringLite() instead.
virtual String toStringLite() const
This function will not attempt to resolve unknown hostnames and is therefore a better choice that toString() in situations where a potential delay is unacceptable.
|
OpenTop 1.5 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||||