OpenVPN 3 Core Library
Loading...
Searching...
No Matches
peeraddr.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#ifndef OPENVPN_SERVER_PEERADDR_H
13#define OPENVPN_SERVER_PEERADDR_H
14
15#include <cstdint> // for std::uint32_t, uint64_t, etc.
16
17#include <openvpn/common/rc.hpp>
20#include <openvpn/addr/ip.hpp>
21
22namespace openvpn {
24{
26 : port(0)
27 {
28 }
29
30 std::string to_string() const
31 {
33 }
34
35#ifdef HAVE_JSON
36 Json::Value to_json(bool convert_mapped_addresses = false) const
37 {
38 Json::Value jret(Json::objectValue);
39 if (convert_mapped_addresses && addr.is_mapped_address())
40 {
41 auto v4addr = addr.to_v4_addr();
42 jret["addr"] = Json::Value(v4addr.to_string());
43 }
44 else
45 {
46 jret["addr"] = Json::Value(addr.to_string());
47 }
48 jret["port"] = Json::Value(port);
49 return jret;
50 }
51#endif
52
54 std::uint16_t port;
55};
56
57struct PeerAddr : public RCCopyable<thread_unsafe_refcount>
58{
60
62 : tcp(false)
63 {
64 }
65
66 std::string to_string() const
67 {
68 std::string proto;
69 if (tcp)
70 proto = "TCP ";
71 else
72 proto = "UDP ";
73 return proto + remote.to_string() + " -> " + local.to_string();
74 }
75
76#ifdef HAVE_JSON
77 Json::Value to_json(bool convert_mapped_addresses = false) const
78 {
79 Json::Value jret(Json::objectValue);
80 jret["tcp"] = Json::Value(tcp);
81 jret["local"] = local.to_json(convert_mapped_addresses);
82 jret["remote"] = remote.to_json(convert_mapped_addresses);
83 return jret;
84 }
85#endif
86
89 bool tcp;
90};
91} // namespace openvpn
92
93#endif
std::string to_string() const
Definition ip.hpp:528
std::string to_string_bracket_ipv6() const
Definition ip.hpp:539
IP::Addr to_v4_addr() const
Definition ip.hpp:866
bool is_mapped_address() const
Definition ip.hpp:858
Reference count base class for objects tracked by RCPtr. Allows copying and assignment.
Definition rc.hpp:979
The smart pointer class.
Definition rc.hpp:119
std::string to_string(const T &t)
Convert a value to a string.
Definition to_string.hpp:45
std::string to_string() const
Definition peeraddr.hpp:30
Json::Value to_json(bool convert_mapped_addresses=false) const
Definition peeraddr.hpp:36
std::uint16_t port
Definition peeraddr.hpp:54
Json::Value to_json(bool convert_mapped_addresses=false) const
Definition peeraddr.hpp:77
std::string to_string() const
Definition peeraddr.hpp:66
RCPtr< PeerAddr > Ptr
Definition peeraddr.hpp:59