# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

NLNET::CInetAddress Class Reference

Internet address (IP + port). More...

#include <inet_address.h>

List of all members.

Public Methods

 CInetAddress ()
 Default Constructor. The address is set to INADDR_ANY. More...

 CInetAddress (const std::string &hostName, uint16 port)
 Alternate constructor (calls setByName()). More...

 CInetAddress (const std::string &hostNameAndPort)
 Alternate constructor (calls setByName()) example: CInetAddress("www.nevrax.com:80"). More...

 CInetAddress (const CInetAddress &other)
 Copy constructor. More...

CInetAddress & operator= (const CInetAddress &other)
 Assignment operator. More...

 ~CInetAddress ()
 Destructor. More...

CInetAddress & setByName (const std::string &hostname)
 Resolves a name. More...

void setPort (uint16 port)
 Sets port. More...

void setNameAndPort (const std::string &hostNameAndPort)
 Sets hostname and port (ex: www.nevrax.com:80). More...

void setSockAddr (const sockaddr_in *saddr)
 Sets internal socket address directly (contents is copied). More...

bool isValid () const
 Returns if object (address and port) is valid. More...

const sockaddr_in * sockAddr () const
 Returns internal socket address (read only). More...

uint32 internalIPAddress () const
 Returns internal IP address. More...

uint32 internalNetAddress () const
 Returns the internal network address (it s the network address for example 192.168.0.0 for a C class). More...

std::string ipAddress () const
 Returns readable IP address. (ex: "195.68.21.195"). More...

const std::string & hostName () const
 Returns hostname. (ex: "www.nevrax.org"). More...

uint16 port () const
 Returns port. More...

std::string asString () const
 Returns hostname and port as a string. (ex: "www.nevrax.org:80 (195.68.21.195)"). More...

std::string asIPString () const
 Returns IP address and port as a string. (ex: "195.68.21.195:80"). More...

void serial (NLMISC::IStream &s)
 Serialize. More...

bool is127001 () const
 Returns true if this CInetAddress is 127.0.0.1. More...


Static Public Methods

CInetAddress localHost ()
 Creates a CInetAddress object with local host address, port=0. More...

std::vector< CInetAddress > localAddresses ()
 Returns the list of the local host addresses (with port=0) (especially useful if the host is multihomed). More...


Static Public Attributes

bool RetrieveNames = false
 If true, setSockAddr() always tries to retrieve the host name from the address. More...


Protected Methods

 CInetAddress (const in_addr *ip)
 Constructor with ip address, port=0. More...


Private Methods

void init ()

Private Attributes

std::string _HostName
sockaddr_in * _SockAddr
bool _Valid

Friends

bool operator== (const CInetAddress &a1, const CInetAddress &a2)
 Comparison == operator. More...

bool operator< (const CInetAddress &a1, const CInetAddress &a2)
 Comparison < operator. More...


Detailed Description

Internet address (IP + port).

The structure sockaddr_in is internally in network byte order

Todo:
cado: Test big/little endian transfers to check if byte ordering is ok.
Author:
Olivier Cado , Nevrax France
Date:
2000

Definition at line 64 of file inet_address.h.


Constructor & Destructor Documentation

NLNET::CInetAddress::CInetAddress  
 

Default Constructor. The address is set to INADDR_ANY.

Definition at line 64 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 98 of file inet_address.cpp.

References hostName, init, port, setByName, and setPort.

NLNET::CInetAddress::CInetAddress const std::string &    hostNameAndPort
 

Alternate constructor (calls setByName()) example: CInetAddress("www.nevrax.com:80").

Definition at line 109 of file inet_address.cpp.

References init, and setNameAndPort.

NLNET::CInetAddress::CInetAddress const CInetAddress &    other
 

Copy constructor.

Definition at line 119 of file inet_address.cpp.

References _HostName, _SockAddr, _Valid, and init.

NLNET::CInetAddress::~CInetAddress  
 

Destructor.

Definition at line 195 of file inet_address.cpp.

References _SockAddr.

NLNET::CInetAddress::CInetAddress const in_addr *    ip [protected]
 

Constructor with ip address, port=0.

Definition at line 75 of file inet_address.cpp.

References _HostName, _SockAddr, _Valid, init, and ipAddress.


Member Function Documentation

std::string NLNET::CInetAddress::asIPString   const
 

Returns IP address and port as a string. (ex: "195.68.21.195:80").

Definition at line 396 of file inet_address.cpp.

References ipAddress, and port.

Referenced by serial.

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 385 of file inet_address.cpp.

References hostName, ipAddress, and port.

Referenced by NLNET::CUnifiedNetwork::update.

const string & NLNET::CInetAddress::hostName   const
 

Returns hostname. (ex: "www.nevrax.org").

Definition at line 367 of file inet_address.cpp.

References _HostName.

Referenced by asString, CInetAddress, and setByName.

void NLNET::CInetAddress::init   [private]
 

Definition at line 180 of file inet_address.cpp.

References _SockAddr, and _Valid.

Referenced by CInetAddress.

uint32 NLNET::CInetAddress::internalIPAddress   const
 

Returns internal IP address.

Definition at line 315 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 320 of file inet_address.cpp.

References internalIPAddress.

string NLNET::CInetAddress::ipAddress   const
 

Returns readable IP address. (ex: "195.68.21.195").

Definition at line 355 of file inet_address.cpp.

References _SockAddr.

Referenced by asIPString, asString, CInetAddress, and setSockAddr.

bool NLNET::CInetAddress::is127001   const
 

Returns true if this CInetAddress is 127.0.0.1.

Definition at line 496 of file inet_address.cpp.

References internalIPAddress.

bool NLNET::CInetAddress::isValid   const
 

Returns if object (address and port) is valid.

Definition at line 297 of file inet_address.cpp.

References _SockAddr, and _Valid.

Referenced by NLNET::CUnifiedNetwork::update.

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 465 of file inet_address.cpp.

References CInetAddress.

CInetAddress NLNET::CInetAddress::localHost   [static]
 

Creates a CInetAddress object with local host address, port=0.

Definition at line 445 of file inet_address.cpp.

References CInetAddress, and nlwarning.

CInetAddress & NLNET::CInetAddress::operator= const CInetAddress &    other
 

Assignment operator.

Definition at line 131 of file inet_address.cpp.

References _HostName, _SockAddr, and _Valid.

uint16 NLNET::CInetAddress::port   const
 

Returns port.

Definition at line 376 of file inet_address.cpp.

References _SockAddr.

Referenced by asIPString, asString, CInetAddress, and setPort.

void NLNET::CInetAddress::serial NLMISC::IStream   s
 

Serialize.

Definition at line 407 of file inet_address.cpp.

References _SockAddr, _Valid, asIPString, NLMISC::IStream::isReading, s, 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 224 of file inet_address.cpp.

References _HostName, _SockAddr, _Valid, hostName, and nldebug.

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 204 of file inet_address.cpp.

References setByName, and setPort.

Referenced by CInetAddress, and serial.

void NLNET::CInetAddress::setPort uint16    port
 

Sets port.

Definition at line 262 of file inet_address.cpp.

References _SockAddr, and port.

Referenced by CInetAddress, 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 272 of file inet_address.cpp.

References _HostName, _SockAddr, _Valid, and ipAddress.

Referenced by serial.

const sockaddr_in * NLNET::CInetAddress::sockAddr   const
 

Returns internal socket address (read only).

Definition at line 306 of file inet_address.cpp.

References _SockAddr.


Friends And Related Function Documentation

bool operator< const CInetAddress &    a1,
const CInetAddress &    a2
[friend]
 

Comparison < operator.

Definition at line 153 of file inet_address.cpp.

bool operator== const CInetAddress &    a1,
const CInetAddress &    a2
[friend]
 

Comparison == operator.

Definition at line 143 of file inet_address.cpp.


Member Data Documentation

std::string NLNET::CInetAddress::_HostName [private]
 

Definition at line 161 of file inet_address.h.

Referenced by CInetAddress, hostName, operator=, setByName, and setSockAddr.

sockaddr_in* NLNET::CInetAddress::_SockAddr [private]
 

Definition at line 162 of file inet_address.h.

Referenced by CInetAddress, init, internalIPAddress, ipAddress, isValid, operator=, port, serial, setByName, setPort, setSockAddr, sockAddr, and ~CInetAddress.

bool NLNET::CInetAddress::_Valid [private]
 

Definition at line 163 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 58 of file inet_address.cpp.


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