deskflow/src/lib/net/NetworkAddress.h

126 lines
3.6 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* synergy -- mouse and keyboard sharing utility
2016-09-07 14:24:00 +00:00
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2002 Chris Schoeneman
2012-06-10 16:50:54 +00:00
*
* 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 LICENSE that should have accompanied this file.
2012-06-10 16:50:54 +00:00
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
2012-06-10 16:50:54 +00:00
#include "base/String.h"
#include "base/EventTypes.h"
#include "arch/IArchNetwork.h"
2012-06-10 16:50:54 +00:00
//! Network address type
/*!
This class represents a network address.
*/
2014-11-11 13:51:47 +00:00
class NetworkAddress {
2012-06-10 16:50:54 +00:00
public:
/*!
Constructs the invalid address
*/
SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 (#7008) * SYNERGY-970 Synergy1. User is not able to connect to server using ipv6 without wrapping IP in square quotes *Fix connection without brackets *Fix config screen bug * SYNERGY-970 Synergy1. User is not able to connect to server using ipv6 without wrapping IP in square quotes *Update changelog * SYNERGY-970 Mac client listens on ipv4 only but attempts to connect on ipv6 #6964 *Add logging in case of several IP of hostname * Synergy 970 synergy1. user is not able to connect to server using ipv6 without wrapping ip in square quotes *Update changelog * SYNERGY-885 Mac client listens on ipv4 only but attempts to connect on ipv6 *Fix Sonar warnings * SUNERGY-885-Mac client listens on ipv4 only but attempts to connect on ipv6 *Update Changelog * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix include * Sunergy-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix sonar warnings * SYNERGY-885 Mac client listens on ipv4 only but attempts to connect on ipv6 *Add loggic to connect to first from reachable server addresses * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix unix compilation * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix unix compilation * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix code smells * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix build * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix memory leak * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Added logic for temporary ipv6 filtering from connect * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Temporary disable ipv6 parsing and resolving tests Co-authored-by: Andrii Batyiev <andrii-external@symless.com>
2021-05-20 16:59:05 +00:00
NetworkAddress() = default;
/*!
Construct the wildcard address with the given port. \c port must
not be zero.
*/
NetworkAddress(int port);
/*!
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 it's used as a host name. If \c hostname ends
in ":[0-9]+" then that suffix is extracted and used as the port,
overridding the port parameter. The resulting port must be a valid
port number (zero is not a valid port number) otherwise \c XSocketAddress
is thrown with an error of \c XSocketAddress::kBadPort. The hostname
is not resolved by the c'tor; use \c resolve to do that.
*/
NetworkAddress(const String& hostname, int port = 0);
NetworkAddress(const NetworkAddress&);
~NetworkAddress();
NetworkAddress& operator=(const NetworkAddress&);
//! @name manipulators
//@{
//! Resolve address
/*!
Resolves the hostname to an address. This can be done any number of
times and is done automatically by the c'tor taking a hostname.
Throws XSocketAddress if resolution is unsuccessful, after which
\c isValid returns false until the next call to this method.
SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 (#7008) * SYNERGY-970 Synergy1. User is not able to connect to server using ipv6 without wrapping IP in square quotes *Fix connection without brackets *Fix config screen bug * SYNERGY-970 Synergy1. User is not able to connect to server using ipv6 without wrapping IP in square quotes *Update changelog * SYNERGY-970 Mac client listens on ipv4 only but attempts to connect on ipv6 #6964 *Add logging in case of several IP of hostname * Synergy 970 synergy1. user is not able to connect to server using ipv6 without wrapping ip in square quotes *Update changelog * SYNERGY-885 Mac client listens on ipv4 only but attempts to connect on ipv6 *Fix Sonar warnings * SUNERGY-885-Mac client listens on ipv4 only but attempts to connect on ipv6 *Update Changelog * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix include * Sunergy-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix sonar warnings * SYNERGY-885 Mac client listens on ipv4 only but attempts to connect on ipv6 *Add loggic to connect to first from reachable server addresses * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix unix compilation * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix unix compilation * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix code smells * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix build * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix memory leak * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Added logic for temporary ipv6 filtering from connect * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Temporary disable ipv6 parsing and resolving tests Co-authored-by: Andrii Batyiev <andrii-external@symless.com>
2021-05-20 16:59:05 +00:00
index - determine index of IP we would like to use from resolved addresses
Returns count of successfully resolved addressed.
*/
SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 (#7008) * SYNERGY-970 Synergy1. User is not able to connect to server using ipv6 without wrapping IP in square quotes *Fix connection without brackets *Fix config screen bug * SYNERGY-970 Synergy1. User is not able to connect to server using ipv6 without wrapping IP in square quotes *Update changelog * SYNERGY-970 Mac client listens on ipv4 only but attempts to connect on ipv6 #6964 *Add logging in case of several IP of hostname * Synergy 970 synergy1. user is not able to connect to server using ipv6 without wrapping ip in square quotes *Update changelog * SYNERGY-885 Mac client listens on ipv4 only but attempts to connect on ipv6 *Fix Sonar warnings * SUNERGY-885-Mac client listens on ipv4 only but attempts to connect on ipv6 *Update Changelog * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix include * Sunergy-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix sonar warnings * SYNERGY-885 Mac client listens on ipv4 only but attempts to connect on ipv6 *Add loggic to connect to first from reachable server addresses * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix unix compilation * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix unix compilation * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix code smells * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix build * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix memory leak * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Added logic for temporary ipv6 filtering from connect * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Temporary disable ipv6 parsing and resolving tests Co-authored-by: Andrii Batyiev <andrii-external@symless.com>
2021-05-20 16:59:05 +00:00
size_t resolve(size_t index = 0);
//@}
//! @name accessors
//@{
//! Check address equality
/*!
Returns true if this address is equal to \p address.
*/
bool operator==(const NetworkAddress& address) const;
//! Check address inequality
/*!
Returns true if this address is not equal to \p address.
*/
bool operator!=(const NetworkAddress& address) const;
//! Check address validity
/*!
Returns true if this is not the invalid address.
*/
bool isValid() const;
//! Get address
/*!
Returns the address in the platform's native network address
structure.
*/
const ArchNetAddress& getAddress() const;
//! 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.
*/
int getPort() const;
//! Get hostname
/*!
Returns the hostname passed to the c'tor sans any port suffix.
*/
String getHostname() const;
//@}
2012-06-10 16:50:54 +00:00
private:
void checkPort();
2012-06-10 16:50:54 +00:00
private:
SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 (#7008) * SYNERGY-970 Synergy1. User is not able to connect to server using ipv6 without wrapping IP in square quotes *Fix connection without brackets *Fix config screen bug * SYNERGY-970 Synergy1. User is not able to connect to server using ipv6 without wrapping IP in square quotes *Update changelog * SYNERGY-970 Mac client listens on ipv4 only but attempts to connect on ipv6 #6964 *Add logging in case of several IP of hostname * Synergy 970 synergy1. user is not able to connect to server using ipv6 without wrapping ip in square quotes *Update changelog * SYNERGY-885 Mac client listens on ipv4 only but attempts to connect on ipv6 *Fix Sonar warnings * SUNERGY-885-Mac client listens on ipv4 only but attempts to connect on ipv6 *Update Changelog * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix include * Sunergy-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix sonar warnings * SYNERGY-885 Mac client listens on ipv4 only but attempts to connect on ipv6 *Add loggic to connect to first from reachable server addresses * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix unix compilation * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix unix compilation * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix code smells * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix build * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Fix memory leak * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Added logic for temporary ipv6 filtering from connect * SYNERGY-885 mac client listens on ipv4 only but attempts to connect on ipv6 *Temporary disable ipv6 parsing and resolving tests Co-authored-by: Andrii Batyiev <andrii-external@symless.com>
2021-05-20 16:59:05 +00:00
ArchNetAddress m_address = nullptr;
String m_hostname;
int m_port = 0;
2012-06-10 16:50:54 +00:00
};