2002-08-02 19:57:46 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
#ifndef CNETWORKADDRESS_H
|
|
|
|
#define CNETWORKADDRESS_H
|
|
|
|
|
2002-06-09 16:53:25 +00:00
|
|
|
#include "CString.h"
|
|
|
|
#include "BasicTypes.h"
|
2003-01-04 22:01:32 +00:00
|
|
|
#include "IArchNetwork.h"
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-07-28 19:06:52 +00:00
|
|
|
//! Network address type
|
|
|
|
/*!
|
|
|
|
This class represents a network address.
|
|
|
|
*/
|
2001-10-06 14:13:28 +00:00
|
|
|
class CNetworkAddress {
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2002-07-28 19:06:52 +00:00
|
|
|
/*!
|
|
|
|
Constructs the invalid address
|
|
|
|
*/
|
2002-06-09 16:53:25 +00:00
|
|
|
CNetworkAddress();
|
|
|
|
|
2002-07-28 19:06:52 +00:00
|
|
|
/*!
|
|
|
|
Construct the wildcard address with the given port. \c port must
|
|
|
|
not be zero.
|
|
|
|
*/
|
2003-01-04 22:01:32 +00:00
|
|
|
CNetworkAddress(int port);
|
2002-06-09 16:53:25 +00:00
|
|
|
|
2002-07-28 19:06:52 +00: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.
|
|
|
|
*/
|
2003-01-04 22:01:32 +00:00
|
|
|
CNetworkAddress(const CString& hostname, int port);
|
|
|
|
|
|
|
|
CNetworkAddress(const CNetworkAddress&);
|
2002-06-09 16:53:25 +00:00
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
~CNetworkAddress();
|
|
|
|
|
2003-01-04 22:01:32 +00:00
|
|
|
CNetworkAddress& operator=(const CNetworkAddress&);
|
|
|
|
|
2002-07-28 19:06:52 +00:00
|
|
|
//! @name accessors
|
|
|
|
//@{
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2004-02-14 14:04:36 +00:00
|
|
|
//! Check address equality
|
|
|
|
/*!
|
|
|
|
Returns true if this address is equal to \p address.
|
|
|
|
*/
|
|
|
|
bool operator==(const CNetworkAddress&) const;
|
|
|
|
|
|
|
|
//! Check address inequality
|
|
|
|
/*!
|
|
|
|
Returns true if this address is not equal to \p address.
|
|
|
|
*/
|
|
|
|
bool operator!=(const CNetworkAddress&) const;
|
|
|
|
|
2002-07-28 19:06:52 +00:00
|
|
|
//! Check address validity
|
|
|
|
/*!
|
|
|
|
Returns true if this is not the invalid address.
|
|
|
|
*/
|
2002-06-09 16:53:25 +00:00
|
|
|
bool isValid() const;
|
|
|
|
|
2002-07-28 19:06:52 +00:00
|
|
|
//! Get address
|
|
|
|
/*!
|
|
|
|
Returns the address in the platform's native network address
|
|
|
|
structure.
|
|
|
|
*/
|
2003-01-04 22:01:32 +00:00
|
|
|
const CArchNetAddress& getAddress() const;
|
2002-07-28 19:06:52 +00:00
|
|
|
|
2003-01-04 22:01:32 +00:00
|
|
|
//! Get port
|
2002-07-28 19:06:52 +00:00
|
|
|
/*!
|
2003-01-04 22:01:32 +00:00
|
|
|
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-07-28 19:06:52 +00:00
|
|
|
*/
|
2003-01-04 22:01:32 +00:00
|
|
|
int getPort() const;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-07-28 19:06:52 +00:00
|
|
|
//! Get hostname
|
|
|
|
/*!
|
|
|
|
Returns the hostname passed to the c'tor sans the port suffix.
|
|
|
|
*/
|
2002-06-09 16:53:25 +00:00
|
|
|
CString getHostname() const;
|
2002-07-28 19:06:52 +00:00
|
|
|
|
|
|
|
//@}
|
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
private:
|
2003-01-04 22:01:32 +00:00
|
|
|
CArchNetAddress m_address;
|
2002-06-09 16:53:25 +00:00
|
|
|
CString m_hostname;
|
2001-10-06 14:13:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|