2001-10-06 18:13:28 +04:00
|
|
|
#ifndef CNETWORKADDRESS_H
|
|
|
|
#define CNETWORKADDRESS_H
|
|
|
|
|
2001-11-19 03:33:36 +03:00
|
|
|
#include "CNetwork.h"
|
2002-06-09 20:53:25 +04:00
|
|
|
#include "CString.h"
|
|
|
|
#include "BasicTypes.h"
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-07-28 23:06:52 +04:00
|
|
|
//! Network address type
|
|
|
|
/*!
|
|
|
|
This class represents a network address.
|
|
|
|
*/
|
2001-10-06 18:13:28 +04:00
|
|
|
class CNetworkAddress {
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2002-07-28 23:06:52 +04:00
|
|
|
/*!
|
|
|
|
Constructs the invalid address
|
|
|
|
*/
|
2002-06-09 20:53:25 +04:00
|
|
|
CNetworkAddress();
|
|
|
|
|
2002-07-28 23:06:52 +04:00
|
|
|
/*!
|
|
|
|
Construct the wildcard address with the given port. \c port must
|
|
|
|
not be zero.
|
|
|
|
*/
|
2001-10-14 20:58:01 +04:00
|
|
|
CNetworkAddress(UInt16 port);
|
2002-06-09 20:53:25 +04:00
|
|
|
|
2002-07-28 23:06:52 +04:00
|
|
|
/*!
|
|
|
|
Construct the network address for the given \c hostname and \c port.
|
|
|
|
If \c hostname can be parsed as a numerical address then that's how
|
|
|
|
it's used, otherwise the host name is looked up. If the lookup fails
|
|
|
|
then this throws XSocketAddress. If \c hostname ends in ":[0-9]+" then
|
|
|
|
that suffix is extracted and used as the port, overridding the port
|
|
|
|
parameter. Neither the extracted port or \c port may be zero.
|
|
|
|
*/
|
2001-10-14 20:58:01 +04:00
|
|
|
CNetworkAddress(const CString& hostname, UInt16 port);
|
2002-06-09 20:53:25 +04:00
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
~CNetworkAddress();
|
|
|
|
|
2002-07-28 23:06:52 +04:00
|
|
|
//! @name accessors
|
|
|
|
//@{
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-07-28 23:06:52 +04:00
|
|
|
//! Check address validity
|
|
|
|
/*!
|
|
|
|
Returns true if this is not the invalid address.
|
|
|
|
*/
|
2002-06-09 20:53:25 +04:00
|
|
|
bool isValid() const;
|
|
|
|
|
2002-07-28 23:06:52 +04:00
|
|
|
//! Get address
|
|
|
|
/*!
|
|
|
|
Returns the address in the platform's native network address
|
|
|
|
structure.
|
|
|
|
*/
|
2001-11-19 03:33:36 +03:00
|
|
|
const CNetwork::Address* getAddress() const;
|
2002-07-28 23:06:52 +04:00
|
|
|
|
|
|
|
//! Get address length
|
|
|
|
/*!
|
|
|
|
Returns the length of the address in the platform's native network
|
|
|
|
address structure.
|
|
|
|
*/
|
2001-11-19 03:33:36 +03:00
|
|
|
CNetwork::AddressLength getAddressLength() const;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-07-28 23:06:52 +04:00
|
|
|
//! Get hostname
|
|
|
|
/*!
|
|
|
|
Returns the hostname passed to the c'tor sans the port suffix.
|
|
|
|
*/
|
2002-06-09 20:53:25 +04:00
|
|
|
CString getHostname() const;
|
2002-07-28 23:06:52 +04:00
|
|
|
|
|
|
|
//! Get port
|
|
|
|
/*!
|
|
|
|
Returns the port passed to the c'tor as a suffix to the hostname,
|
|
|
|
if that existed, otherwise as passed directly to the c'tor.
|
|
|
|
*/
|
2002-06-09 20:53:25 +04:00
|
|
|
UInt16 getPort() const;
|
|
|
|
|
2002-07-28 23:06:52 +04:00
|
|
|
//@}
|
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
2001-11-19 03:33:36 +03:00
|
|
|
CNetwork::Address m_address;
|
2002-06-09 20:53:25 +04:00
|
|
|
CString m_hostname;
|
|
|
|
UInt16 m_port;
|
2001-10-06 18:13:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|