deskflow/src/lib/arch/unix/ArchNetworkBSD.h

144 lines
4.8 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
#include "arch/IArchNetwork.h"
#include "arch/IArchMultithread.h"
2012-06-10 16:50:54 +00:00
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
2012-06-10 16:50:54 +00:00
#endif
#if HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#else
struct sockaddr_storage {
unsigned char ss_len; /* address length */
unsigned char ss_family; /* [XSI] address family */
char __ss_pad1[_SS_PAD1SIZE];
long long __ss_align; /* force structure storage alignment */
char __ss_pad2[_SS_PAD2SIZE];
};
2012-06-10 16:50:54 +00:00
#endif
#if !HAVE_SOCKLEN_T
typedef int socklen_t;
#endif
#if HAVE_POLL
# include <poll.h>
#else
# if HAVE_SYS_SELECT_H
# include <sys/select.h>
# endif
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# endif
#endif
2012-06-10 16:50:54 +00:00
// old systems may use char* for [gs]etsockopt()'s optval argument.
// this should be void on modern systems but char is forwards
// compatible so we always use it.
typedef char optval_t;
2014-11-11 13:51:47 +00:00
#define ARCH_NETWORK ArchNetworkBSD
2018-03-20 13:53:38 +00:00
#define TYPED_ADDR(type_, addr_) (reinterpret_cast<type_*>(&addr_->m_addr))
2012-06-10 16:50:54 +00:00
2014-11-11 13:51:47 +00:00
class ArchSocketImpl {
2012-06-10 16:50:54 +00:00
public:
int m_fd;
int m_refCount;
2012-06-10 16:50:54 +00:00
};
2014-11-11 13:51:47 +00:00
class ArchNetAddressImpl {
2012-06-10 16:50:54 +00:00
public:
ArchNetAddressImpl() : m_len(sizeof(m_addr)) { }
2012-06-10 16:50:54 +00:00
public:
2018-03-20 13:53:38 +00:00
struct sockaddr_storage m_addr;
socklen_t m_len;
2012-06-10 16:50:54 +00:00
};
//! Berkeley (BSD) sockets implementation of IArchNetwork
2014-11-11 13:51:47 +00:00
class ArchNetworkBSD : public IArchNetwork {
2012-06-10 16:50:54 +00:00
public:
ArchNetworkBSD();
2020-11-03 10:52:56 +00:00
ArchNetworkBSD(ArchNetworkBSD const &) =delete;
ArchNetworkBSD(ArchNetworkBSD &&) =delete;
virtual ~ArchNetworkBSD();
2020-11-03 10:52:56 +00:00
ArchNetworkBSD& operator=(ArchNetworkBSD const &) =delete;
ArchNetworkBSD& operator=(ArchNetworkBSD &&) =delete;
virtual void init();
// IArchNetwork overrides
virtual ArchSocket newSocket(EAddressFamily, ESocketType);
2020-11-03 15:31:32 +00:00
virtual ArchSocket copySocket(ArchSocket s);
virtual void closeSocket(ArchSocket s);
virtual void closeSocketForRead(ArchSocket s);
virtual void closeSocketForWrite(ArchSocket s);
virtual void bindSocket(ArchSocket s, ArchNetAddress addr);
virtual void listenOnSocket(ArchSocket s);
virtual ArchSocket acceptSocket(ArchSocket s, ArchNetAddress* addr);
virtual bool connectSocket(ArchSocket s, ArchNetAddress name);
virtual int pollSocket(PollEntry[], int num, double timeout);
virtual void unblockPollSocket(ArchThread thread);
virtual size_t readSocket(ArchSocket s, void* buf, size_t len);
virtual size_t writeSocket(ArchSocket s,
const void* buf, size_t len);
virtual void throwErrorOnSocket(ArchSocket);
virtual bool setNoDelayOnSocket(ArchSocket, bool noDelay);
virtual bool setReuseAddrOnSocket(ArchSocket, bool reuse);
virtual std::string getHostName();
virtual ArchNetAddress newAnyAddr(EAddressFamily);
virtual ArchNetAddress copyAddr(ArchNetAddress);
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
virtual std::vector<ArchNetAddress> nameToAddr(const std::string&);
virtual void closeAddr(ArchNetAddress);
virtual std::string addrToName(ArchNetAddress);
virtual std::string addrToString(ArchNetAddress);
virtual EAddressFamily getAddrFamily(ArchNetAddress);
virtual void setAddrPort(ArchNetAddress, int port);
virtual int getAddrPort(ArchNetAddress);
virtual bool isAnyAddr(ArchNetAddress);
virtual bool isEqualAddr(ArchNetAddress, ArchNetAddress);
2012-06-10 16:50:54 +00:00
struct Connectors
{
#if HAVE_POLL
int (*poll_impl)(struct pollfd *, nfds_t, int);
#endif // HAVE_POLL
Connectors() {
#if HAVE_POLL
poll_impl = poll;
#endif // HAVE_POLL
}
};
static Connectors s_connectors;
2012-06-10 16:50:54 +00:00
private:
const int* getUnblockPipe();
const int* getUnblockPipeForThread(ArchThread);
void setBlockingOnSocket(int fd, bool blocking);
void throwError(int);
void throwNameError(int);
2012-06-10 16:50:54 +00:00
private:
ArchMutex m_mutex {};
2012-06-10 16:50:54 +00:00
};