|
OpenTop 1.3 | |||||
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) const Tests if two InetAddress instances refer to the same IP address. |
static RefPtr< InetAddress > |
FromNetworkAddress(const struct sockaddr* pAddr, size_t addrlen) Creates an InetAddress instance from a sockaddr structure. |
virtual const Byte* |
getAddress() const Returns a pointer to a byte array containing the internal IP address. |
virtual size_t |
getAddressLength() const Returns 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() const Returns the IP address in dotted decimal notation. |
virtual String |
getHostName() const Returns 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) const Tests if two InetAddress instances refer to different IP addresses. |
InetAddress& |
operator=(const InetAddress& rhs) Assignment operator. |
bool |
operator==(const InetAddress& rhs) const Tests if two InetAddress instances refer to the same IP address. |
virtual String |
toString() const Returns a String representation of this InetAddress. |
Methods inherited from class ot::ManagedObject |
addRef, getRefCount, onFinalRelease, operator=, 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 struct sockaddr* 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
|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |