Internet address (IP + port). More...
#include <inet_address.h>
Public Member Functions | |
| CInetAddress () | |
| Default Constructor. The address is set to INADDR_ANY. | |
| CInetAddress (const std::string &hostName, uint16 port) | |
| Alternate constructor (calls setByName()). | |
| CInetAddress (const std::string &hostNameAndPort) | |
| Alternate constructor (calls setByName()) example: CInetAddress("www.nevrax.com:80"). | |
| CInetAddress (const CInetAddress &other) | |
| Copy constructor. | |
| CInetAddress & | operator= (const CInetAddress &other) |
| Assignment operator. | |
| ~CInetAddress () | |
| Destructor. | |
| CInetAddress & | setByName (const std::string &hostname) |
| Resolves a name. | |
| void | setPort (uint16 port) |
| Sets port. | |
| void | setNameAndPort (const std::string &hostNameAndPort) |
| Sets hostname and port (ex: www.nevrax.com:80). | |
| void | setSockAddr (const sockaddr_in *saddr) |
| Sets internal socket address directly (contents is copied). | |
| bool | isValid () const |
| Returns if object (address and port) is valid. | |
| const sockaddr_in * | sockAddr () const |
| Returns internal socket address (read only). | |
| uint32 | internalIPAddress () const |
| Returns internal IP address. | |
| uint32 | internalNetAddress () const |
| Returns the internal network address (it s the network address for example 192.168.0.0 for a C class). | |
| std::string | ipAddress () const |
| Returns readable IP address. (ex: "195.68.21.195"). | |
| const std::string & | hostName () const |
| Returns hostname. (ex: "www.nevrax.org"). | |
| uint16 | port () const |
| Returns port. | |
| std::string | asString () const |
| Returns hostname and port as a string. (ex: "www.nevrax.org:80 (195.68.21.195)"). | |
| std::string | asIPString () const |
| Returns IP address and port as a string. (ex: "195.68.21.195:80"). | |
| void | serial (NLMISC::IStream &s) |
| Serialize. | |
| bool | is127001 () const |
| Returns true if this CInetAddress is 127.0.0.1. | |
Static Public Member Functions | |
| static CInetAddress | localHost () |
| Creates a CInetAddress object with local host address, port=0. | |
| static std::vector< CInetAddress > | localAddresses () |
| Returns the list of the local host addresses (with port=0) (especially useful if the host is multihomed). | |
Static Public Attributes | |
| static bool | RetrieveNames = false |
| If true, setSockAddr() always tries to retrieve the host name from the address. | |
Protected Member Functions | |
| CInetAddress (const in_addr *ip, const char *hostname=0) | |
| Constructor with ip address, port=0. | |
Private Member Functions | |
| void | init () |
Private Attributes | |
| std::string | _HostName |
| sockaddr_in * | _SockAddr |
| bool | _Valid |
Friends | |
| bool | operator== (const CInetAddress &a1, const CInetAddress &a2) |
| Comparison == operator. | |
| bool | operator< (const CInetAddress &a1, const CInetAddress &a2) |
| Comparison < operator. | |
Internet address (IP + port).
The structure sockaddr_in is internally in network byte order
Definition at line 61 of file inet_address.h.
| NLNET::CInetAddress::CInetAddress | ( | ) |
Default Constructor. The address is set to INADDR_ANY.
Definition at line 60 of file inet_address.cpp.
References _SockAddr, and init().
Referenced by localAddresses(), and localHost().
| NLNET::CInetAddress::CInetAddress | ( | const std::string & | hostName, | |
| uint16 | port | |||
| ) |
Alternate constructor (calls setByName()).
Definition at line 101 of file inet_address.cpp.
References init(), setByName(), and setPort().
| NLNET::CInetAddress::CInetAddress | ( | const std::string & | hostNameAndPort | ) |
Alternate constructor (calls setByName()) example: CInetAddress("www.nevrax.com:80").
Definition at line 112 of file inet_address.cpp.
References init(), and setNameAndPort().
| NLNET::CInetAddress::CInetAddress | ( | const CInetAddress & | other | ) |
| NLNET::CInetAddress::~CInetAddress | ( | ) |
| NLNET::CInetAddress::CInetAddress | ( | const in_addr * | ip, | |
| const char * | hostname = 0 | |||
| ) | [protected] |
Constructor with ip address, port=0.
Definition at line 71 of file inet_address.cpp.
References _HostName, _SockAddr, _Valid, init(), and ipAddress().
| std::string NLNET::CInetAddress::asIPString | ( | ) | const |
Returns IP address and port as a string. (ex: "195.68.21.195:80").
Definition at line 403 of file inet_address.cpp.
References ipAddress(), port(), and NLMISC::toString().
Referenced by NLNET::CLoginServer::init(), NLNET::NLMISC_CATEGORISED_DYNVARIABLE(), serial(), and NLNET::CLoginServer::setListenAddress().
| std::string NLNET::CInetAddress::asString | ( | ) | const |
Returns hostname and port as a string. (ex: "www.nevrax.org:80 (195.68.21.195)").
Definition at line 391 of file inet_address.cpp.
References hostName(), ipAddress(), port(), and NLMISC::toString().
Referenced by NLNET::CListenSock::accept(), NLNET::CUdpSock::bind(), NLNET::cbServerAskUniversalTime(), NLNET::cbShardValidation(), NLNET::CSock::close(), NLNET::CSock::connect(), NLNET::CGatewayL3ClientTransport::connect(), NLNET::CDummyTcpSock::connect(), NLNET::CTcpSock::disconnect(), NLNET::CDummyTcpSock::disconnect(), NLNET::CGatewayL3ClientTransport::dump(), NLNET::CGatewayL3ServerTransport::dump(), NLNET::ESocket::ESocket(), NLNET::CNamingClient::info(), NLNET::CListenSock::init(), NLNET::IService::main(), NLNET::CUdpSock::receive(), NLNET::CUdpSock::receivedFrom(), NLNET::CNonBlockingBufSock::receivePart(), NLNET::sendEMailCommand(), NLNET::CUdpSock::sendTo(), NLNET::CGatewayL3ClientTransport::update(), and NLNET::CSock::~CSock().
| const string & NLNET::CInetAddress::hostName | ( | ) | const |
Returns hostname. (ex: "www.nevrax.org").
Definition at line 373 of file inet_address.cpp.
References _HostName.
Referenced by asString(), NLNET::IService::main(), and NLNET::sendEmail().
| void NLNET::CInetAddress::init | ( | void | ) | [private] |
Definition at line 183 of file inet_address.cpp.
References _SockAddr, _Valid, and NLNET::CSock::initNetwork().
Referenced by CInetAddress().
| uint32 NLNET::CInetAddress::internalIPAddress | ( | ) | const |
Returns internal IP address.
Definition at line 320 of file inet_address.cpp.
References _SockAddr.
Referenced by internalNetAddress(), and is127001().
| uint32 NLNET::CInetAddress::internalNetAddress | ( | ) | const |
Returns the internal network address (it s the network address for example 192.168.0.0 for a C class).
Definition at line 325 of file inet_address.cpp.
References internalIPAddress().
| string NLNET::CInetAddress::ipAddress | ( | ) | const |
Returns readable IP address. (ex: "195.68.21.195").
Definition at line 360 of file inet_address.cpp.
References _SockAddr.
Referenced by asIPString(), asString(), CInetAddress(), localHost(), and setSockAddr().
| bool NLNET::CInetAddress::is127001 | ( | ) | const |
Returns true if this CInetAddress is 127.0.0.1.
Definition at line 508 of file inet_address.cpp.
References internalIPAddress().
| bool NLNET::CInetAddress::isValid | ( | ) | const |
Returns if object (address and port) is valid.
Definition at line 302 of file inet_address.cpp.
References _SockAddr, and _Valid.
Referenced by NLNET::CSock::connect(), NLNET::CSock::CSock(), NLNET::CUnifiedNetwork::init(), and NLNET::CListenSock::init().
| std::vector< CInetAddress > NLNET::CInetAddress::localAddresses | ( | ) | [static] |
Returns the list of the local host addresses (with port=0) (especially useful if the host is multihomed).
Definition at line 473 of file inet_address.cpp.
References CInetAddress(), and SOCKET_ERROR.
Referenced by NLNET::CNetManager::addServer(), NLNET::CUnifiedNetwork::addService(), NLNET::CUnifiedNetwork::init(), NLNET::CNetManager::init(), and NLNET::CUnifiedNetwork::isServiceLocal().
| CInetAddress NLNET::CInetAddress::localHost | ( | ) | [static] |
Creates a CInetAddress object with local host address, port=0.
Definition at line 453 of file inet_address.cpp.
References CInetAddress(), ipAddress(), and nlwarning.
Referenced by NLNET::CModuleBase::getModuleFullyQualifiedName(), NLNET::CModuleManager::getUniqueNameRoot(), NLNET::CListenSock::init(), NLNET::IService::main(), and NLNET::sendEmail().
| CInetAddress & NLNET::CInetAddress::operator= | ( | const CInetAddress & | other | ) |
Assignment operator.
Definition at line 134 of file inet_address.cpp.
| uint16 NLNET::CInetAddress::port | ( | ) | const |
Returns port.
Definition at line 382 of file inet_address.cpp.
References _SockAddr.
Referenced by asIPString(), asString(), NLNET::CListenSock::init(), NLNET::operator<(), and setNameAndPort().
| void NLNET::CInetAddress::serial | ( | NLMISC::IStream & | s | ) |
Serialize.
Definition at line 415 of file inet_address.cpp.
References _SockAddr, _Valid, asIPString(), NLMISC::IStream::isReading(), NLMISC::IStream::serial(), NLMISC::CMemStream::serial(), NLMISC::IStream::serialBuffer(), setNameAndPort(), setSockAddr(), and NLMISC::CMemStream::stringMode().
| CInetAddress & NLNET::CInetAddress::setByName | ( | const std::string & | hostname | ) |
Resolves a name.
Definition at line 229 of file inet_address.cpp.
References _HostName, _SockAddr, _Valid, and LNETL0_DEBUG.
Referenced by CInetAddress(), and setNameAndPort().
| void NLNET::CInetAddress::setNameAndPort | ( | const std::string & | hostNameAndPort | ) |
Sets hostname and port (ex: www.nevrax.com:80).
Definition at line 207 of file inet_address.cpp.
References NLNET::fromString(), port(), setByName(), and setPort().
Referenced by CInetAddress(), and serial().
| void NLNET::CInetAddress::setPort | ( | uint16 | port | ) |
Sets port.
Definition at line 267 of file inet_address.cpp.
References _SockAddr.
Referenced by NLNET::CUdpSock::bind(), CInetAddress(), NLNET::CListenSock::init(), and setNameAndPort().
| void NLNET::CInetAddress::setSockAddr | ( | const sockaddr_in * | saddr | ) |
Sets internal socket address directly (contents is copied).
It also retrieves the host name if CInetAddress::RetrieveNames is true.
Definition at line 277 of file inet_address.cpp.
References _HostName, _SockAddr, _Valid, ipAddress(), and RetrieveNames.
Referenced by NLNET::CListenSock::accept(), NLNET::CUdpSock::receivedFrom(), serial(), and NLNET::CSock::setLocalAddress().
| const sockaddr_in * NLNET::CInetAddress::sockAddr | ( | ) | const |
Returns internal socket address (read only).
Definition at line 311 of file inet_address.cpp.
References _SockAddr.
Referenced by NLNET::CUdpSock::bind(), NLNET::CSock::connect(), NLNET::CListenSock::init(), and NLNET::CUdpSock::sendTo().
| bool operator< | ( | const CInetAddress & | a1, | |
| const CInetAddress & | a2 | |||
| ) | [friend] |
Comparison < operator.
| bool operator== | ( | const CInetAddress & | a1, | |
| const CInetAddress & | a2 | |||
| ) | [friend] |
Comparison == operator.
std::string NLNET::CInetAddress::_HostName [private] |
Definition at line 158 of file inet_address.h.
Referenced by CInetAddress(), hostName(), operator=(), setByName(), and setSockAddr().
sockaddr_in* NLNET::CInetAddress::_SockAddr [private] |
Definition at line 159 of file inet_address.h.
Referenced by CInetAddress(), init(), internalIPAddress(), ipAddress(), isValid(), NLNET::operator<(), operator=(), NLNET::operator==(), port(), serial(), setByName(), setPort(), setSockAddr(), sockAddr(), and ~CInetAddress().
bool NLNET::CInetAddress::_Valid [private] |
Definition at line 160 of file inet_address.h.
Referenced by CInetAddress(), init(), isValid(), operator=(), serial(), setByName(), and setSockAddr().
bool NLNET::CInetAddress::RetrieveNames = false [static] |
If true, setSockAddr() always tries to retrieve the host name from the address.
Definition at line 146 of file inet_address.h.
Referenced by setSockAddr().
1.6.1