-
Notifications
You must be signed in to change notification settings - Fork 2
/
MySocketProtect.hpp
42 lines (38 loc) · 951 Bytes
/
MySocketProtect.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef MY_SOCKET_API
#define MY_SOCKET_API
#include "OpenVPNClientBase.hpp"
#include <openvpn/transport/socket_protect.hpp>
namespace openvpn
{
class MySocketProtect : public SocketProtect
{
public:
MySocketProtect() : parent(nullptr) {}
void set_parent(libopenvpn::OpenVPNClientBase *parent_arg)
{
parent = parent_arg;
}
bool socket_protect(int socket, IP::Addr endpoint) override
{
if (parent)
{
#if defined(OPENVPN_COMMAND_AGENT) && defined(OPENVPN_PLATFORM_WIN)
return WinCommandAgent::add_bypass_route(endpoint);
#elif defined(OPENVPN_COMMAND_AGENT) && defined(OPENVPN_PLATFORM_MAC)
return UnixCommandAgent::add_bypass_route(endpoint);
#else
return parent->socket_protect(socket, endpoint.to_string(), endpoint.is_ipv6());
#endif
}
else
return true;
}
void detach_from_parent()
{
parent = nullptr;
}
private:
libopenvpn::OpenVPNClientBase *parent;
};
} // namespace openvpn
#endif