Fast DDS  Version 3.3.0
Fast DDS
Loading...
Searching...
No Matches
IPLocator.hpp
1// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
20#ifndef FASTDDS_UTILS__IPLOCATOR_HPP
21#define FASTDDS_UTILS__IPLOCATOR_HPP
22
23#include <fastdds/rtps/common/Types.hpp>
24#include <fastdds/dds/log/Log.hpp>
25
26#include <regex>
27#include <set>
28#include <string>
29#include <vector>
30
31namespace eprosima {
32namespace fastdds {
33namespace rtps {
34
35class Locator_t;
36
42{
43public:
44
52 FASTDDS_EXPORTED_API static void createLocator(
53 int32_t kindin,
54 const std::string& address,
55 uint32_t portin,
56 Locator_t& locator);
57
59 FASTDDS_EXPORTED_API static bool setIPv4(
60 Locator_t& locator,
61 const unsigned char* addr);
62
64 FASTDDS_EXPORTED_API static bool setIPv4(
65 Locator_t& locator,
66 octet o1,
67 octet o2,
68 octet o3,
69 octet o4);
70
72 FASTDDS_EXPORTED_API static bool setIPv4(
73 Locator_t& locator,
74 const std::string& ipv4);
75
77 FASTDDS_EXPORTED_API static bool setIPv4(
78 Locator_t& destlocator,
79 const Locator_t& origlocator);
80
82 FASTDDS_EXPORTED_API static bool setIPv4address(
83 Locator_t& destlocator,
84 const std::string& lan,
85 const std::string& wan,
86 const std::string& ipv4);
87
89 FASTDDS_EXPORTED_API static const octet* getIPv4(
90 const Locator_t& locator);
91
93 FASTDDS_EXPORTED_API static bool hasIPv4(
94 const Locator_t& locator);
95
97 FASTDDS_EXPORTED_API static std::string toIPv4string(
98 const Locator_t& locator);
99
106 FASTDDS_EXPORTED_API static bool copyIPv4(
107 const Locator_t& locator,
108 unsigned char* dest);
109
117 FASTDDS_EXPORTED_API static bool copyIPv4(
118 const Locator_t& locator,
119 Locator_t& dest);
120
121 // IPv6
123 FASTDDS_EXPORTED_API static bool setIPv6(
124 Locator_t& locator,
125 const unsigned char* addr);
126
128 FASTDDS_EXPORTED_API static bool setIPv6(
129 Locator_t& locator,
130 uint16_t group0,
131 uint16_t group1,
132 uint16_t group2,
133 uint16_t group3,
134 uint16_t group4,
135 uint16_t group5,
136 uint16_t group6,
137 uint16_t group7);
138
140 FASTDDS_EXPORTED_API static bool setIPv6(
141 Locator_t& locator,
142 const std::string& ipv6);
143
145 FASTDDS_EXPORTED_API static bool setIPv6(
146 Locator_t& destlocator,
147 const Locator_t& origlocator);
148
150 FASTDDS_EXPORTED_API static const octet* getIPv6(
151 const Locator_t& locator);
152
154 FASTDDS_EXPORTED_API static bool hasIPv6(
155 const Locator_t& locator);
156
158 FASTDDS_EXPORTED_API static std::string toIPv6string(
159 const Locator_t& locator);
160
162 FASTDDS_EXPORTED_API static bool copyIPv6(
163 const Locator_t& locator,
164 unsigned char* dest);
165
167 FASTDDS_EXPORTED_API static bool ip(
168 Locator_t& locator,
169 const std::string& ip);
170
172 FASTDDS_EXPORTED_API static std::string ip_to_string(
173 const Locator_t& locator);
174
175 // TCP
177 FASTDDS_EXPORTED_API static bool setLogicalPort(
178 Locator_t& locator,
179 uint16_t port);
180
182 FASTDDS_EXPORTED_API static uint16_t getLogicalPort(
183 const Locator_t& locator);
184
186 FASTDDS_EXPORTED_API static bool setPhysicalPort(
187 Locator_t& locator,
188 uint16_t port);
189
191 FASTDDS_EXPORTED_API static uint16_t getPhysicalPort(
192 const Locator_t& locator);
193
194 // TCPv4
196 FASTDDS_EXPORTED_API static bool setWan(
197 Locator_t& locator,
198 octet o1,
199 octet o2,
200 octet o3,
201 octet o4);
202
204 FASTDDS_EXPORTED_API static bool setWan(
205 Locator_t& locator,
206 const std::string& wan);
207
209 FASTDDS_EXPORTED_API static const octet* getWan(
210 const Locator_t& locator);
211
213 FASTDDS_EXPORTED_API static bool hasWan(
214 const Locator_t& locator);
215
217 FASTDDS_EXPORTED_API static std::string toWanstring(
218 const Locator_t& locator);
219
223 FASTDDS_EXPORTED_API static Locator_t WanToLanLocator(
224 const Locator_t& locator);
225
227 FASTDDS_EXPORTED_API static bool setLanID(
228 Locator_t& locator,
229 const std::string& lanId);
230
232 FASTDDS_EXPORTED_API static const octet* getLanID(
233 const Locator_t& locator);
234
236 FASTDDS_EXPORTED_API static std::string toLanIDstring(
237 const Locator_t& locator);
238
240 FASTDDS_EXPORTED_API static Locator_t toPhysicalLocator(
241 const Locator_t& locator);
242
244 FASTDDS_EXPORTED_API static bool ip_equals_wan(
245 const Locator_t& locator);
246
247 // Common
249 FASTDDS_EXPORTED_API static bool setPortRTPS(
250 Locator_t& locator,
251 uint16_t port);
252
254 FASTDDS_EXPORTED_API static uint16_t getPortRTPS(
255 Locator_t& locator);
256
258 FASTDDS_EXPORTED_API static bool isLocal(
259 const Locator_t& locator);
260
262 FASTDDS_EXPORTED_API static bool isAny(
263 const Locator_t& locator);
264
266 FASTDDS_EXPORTED_API static bool compareAddress(
267 const Locator_t& loc1,
268 const Locator_t& loc2,
269 bool fullAddress = false);
270
277 FASTDDS_EXPORTED_API static bool copy_address(
278 const Locator_t& loc1,
279 Locator_t& loc2);
280
282 FASTDDS_EXPORTED_API static bool compareAddressAndPhysicalPort(
283 const Locator_t& loc1,
284 const Locator_t& loc2);
285
287 FASTDDS_EXPORTED_API static std::string to_string(
288 const Locator_t& locator);
289
290 // UDP
292 FASTDDS_EXPORTED_API static bool isMulticast(
293 const Locator_t& locator);
294
296 FASTDDS_EXPORTED_API static std::pair<std::set<std::string>, std::set<std::string>> resolveNameDNS(
297 const std::string& address_name);
298
300 FASTDDS_EXPORTED_API static bool isIPv4(
301 const std::string& address);
303 FASTDDS_EXPORTED_API static bool isIPv6(
304 const std::string& address);
305
306protected:
307
308 // Checks if the locator address is equal to 0
309 // It checks the proper locator address depending on the locator kind
310 static bool isEmpty(
311 const Locator_t& locator);
312
313 // Checks if the locator address from index till the end is equal to 0
314 static bool isEmpty(
315 const Locator_t& locator,
316 uint16_t index);
317
318 // Checks if a string matches an ipv6 address
319 static bool IPv6isCorrect(
320 const std::string& ipv6);
321
322private:
323
324 IPLocator() = delete;
325 ~IPLocator() = delete;
326};
327
328} // namespace rtps
329} // namespace fastdds
330} // namespace eprosima
331
332#endif // FASTDDS_UTILS__IPLOCATOR_HPP
Class IPLocator, to provide helper functions to the IP based transports.
Definition IPLocator.hpp:42
static FASTDDS_EXPORTED_API bool isIPv4(const std::string &address)
Check whether a string contains an IPv4 format.
static FASTDDS_EXPORTED_API std::string toWanstring(const Locator_t &locator)
Retrieves a string representation of the locator's WAN address (as in RTCP protocol)
static FASTDDS_EXPORTED_API bool setIPv6(Locator_t &locator, const std::string &ipv6)
Sets locator's IPv6.
static FASTDDS_EXPORTED_API bool hasWan(const Locator_t &locator)
Checks if the locator has WAN address (as in RTCP protocol)
static FASTDDS_EXPORTED_API bool copyIPv4(const Locator_t &locator, unsigned char *dest)
Copies locator's IPv4 to a destination array.
static FASTDDS_EXPORTED_API bool copy_address(const Locator_t &loc1, Locator_t &loc2)
Copies the whole address from one locator to another.
static FASTDDS_EXPORTED_API bool setWan(Locator_t &locator, const std::string &wan)
Sets locator's WAN address (as in RTCP protocol)
static FASTDDS_EXPORTED_API bool isLocal(const Locator_t &locator)
Checks if a locator has local IP address.
static FASTDDS_EXPORTED_API const octet * getWan(const Locator_t &locator)
Gets locator's WAN address (as in RTCP protocol)
static FASTDDS_EXPORTED_API std::pair< std::set< std::string >, std::set< std::string > > resolveNameDNS(const std::string &address_name)
Resolve an address name by a DNS request and return the IP that this address references by a DNS serv...
static FASTDDS_EXPORTED_API bool compareAddress(const Locator_t &loc1, const Locator_t &loc2, bool fullAddress=false)
Checks if both locators has the same IP address.
static FASTDDS_EXPORTED_API uint16_t getLogicalPort(const Locator_t &locator)
Gets locator's logical port (as in RTCP protocol)
static FASTDDS_EXPORTED_API bool isAny(const Locator_t &locator)
Checks if a locator has any IP address.
static FASTDDS_EXPORTED_API bool hasIPv6(const Locator_t &locator)
Check if the locator has IPv6.
static bool IPv6isCorrect(const std::string &ipv6)
static FASTDDS_EXPORTED_API bool isIPv6(const std::string &address)
Check whether a string contains an IPv6 format.
static FASTDDS_EXPORTED_API const octet * getLanID(const Locator_t &locator)
Gets locator's LAN ID (as in RTCP protocol)
static FASTDDS_EXPORTED_API bool copyIPv6(const Locator_t &locator, unsigned char *dest)
Copies locator's IPv6.
static FASTDDS_EXPORTED_API bool setPhysicalPort(Locator_t &locator, uint16_t port)
Sets locator's physical port (as in RTCP protocol)
static FASTDDS_EXPORTED_API bool setIPv4(Locator_t &locator, const std::string &ipv4)
Sets locator's IPv4.
static FASTDDS_EXPORTED_API bool setIPv6(Locator_t &destlocator, const Locator_t &origlocator)
Copies locator's IPv6.
static FASTDDS_EXPORTED_API Locator_t WanToLanLocator(const Locator_t &locator)
This method is useful in the case of having a tcp client with an initial peer pointing to a WAN locat...
static bool isEmpty(const Locator_t &locator, uint16_t index)
static FASTDDS_EXPORTED_API bool isMulticast(const Locator_t &locator)
Checks if the locator has a multicast IP address.
static FASTDDS_EXPORTED_API bool setWan(Locator_t &locator, octet o1, octet o2, octet o3, octet o4)
Sets locator's WAN address (as in RTCP protocol)
static FASTDDS_EXPORTED_API bool ip(Locator_t &locator, const std::string &ip)
Sets locator's IP.
static FASTDDS_EXPORTED_API std::string ip_to_string(const Locator_t &locator)
Returns a string representation of the locator's IP.
static FASTDDS_EXPORTED_API uint16_t getPhysicalPort(const Locator_t &locator)
Gets locator's physical port (as in RTCP protocol)
static FASTDDS_EXPORTED_API bool setIPv6(Locator_t &locator, const unsigned char *addr)
Sets locator's IPv6.
static FASTDDS_EXPORTED_API Locator_t toPhysicalLocator(const Locator_t &locator)
Returns a new locator without logical port (as in RTCP protocol).
static FASTDDS_EXPORTED_API std::string toIPv6string(const Locator_t &locator)
Returns a string representation of the locator's IPv6 following RFC 5952 recommendation.
static FASTDDS_EXPORTED_API bool compareAddressAndPhysicalPort(const Locator_t &loc1, const Locator_t &loc2)
Checks if a both locators has the same IP address and physical port (as in RTCP protocol).
static FASTDDS_EXPORTED_API std::string toLanIDstring(const Locator_t &locator)
Retrieves a string representation of the locator's LAN ID (as in RTCP protocol)
static bool isEmpty(const Locator_t &locator)
static FASTDDS_EXPORTED_API bool setLogicalPort(Locator_t &locator, uint16_t port)
Sets locator's logical port (as in RTCP protocol)
static FASTDDS_EXPORTED_API bool setPortRTPS(Locator_t &locator, uint16_t port)
Sets locator's RTCP port. Physical for UDP and logical for TCP (as in RTCP protocol)
static FASTDDS_EXPORTED_API bool ip_equals_wan(const Locator_t &locator)
Checks if a locator WAN address and IP address are the same (as in RTCP protocol).
static FASTDDS_EXPORTED_API bool setIPv4(Locator_t &locator, const unsigned char *addr)
Sets locator's IPv4.
static FASTDDS_EXPORTED_API bool setIPv6(Locator_t &locator, uint16_t group0, uint16_t group1, uint16_t group2, uint16_t group3, uint16_t group4, uint16_t group5, uint16_t group6, uint16_t group7)
Sets locator's IPv6.
static FASTDDS_EXPORTED_API std::string to_string(const Locator_t &locator)
Returns a string representation of the given locator.
static FASTDDS_EXPORTED_API std::string toIPv4string(const Locator_t &locator)
Returns a string representation of the locator's IPv4.
static FASTDDS_EXPORTED_API bool hasIPv4(const Locator_t &locator)
Check if the locator has IPv4.
static FASTDDS_EXPORTED_API bool copyIPv4(const Locator_t &locator, Locator_t &dest)
Copies locator's IPv4 to a destination locator.
static FASTDDS_EXPORTED_API void createLocator(int32_t kindin, const std::string &address, uint32_t portin, Locator_t &locator)
Fills locator with the given parameters.
static FASTDDS_EXPORTED_API bool setLanID(Locator_t &locator, const std::string &lanId)
Sets locator's LAN ID (as in RTCP protocol)
static FASTDDS_EXPORTED_API const octet * getIPv6(const Locator_t &locator)
Retrieves locator's IPv6 as octet array.
static FASTDDS_EXPORTED_API bool setIPv4(Locator_t &locator, octet o1, octet o2, octet o3, octet o4)
Sets locator's IPv4.
static FASTDDS_EXPORTED_API bool setIPv4(Locator_t &destlocator, const Locator_t &origlocator)
Copies locator's IPv4.
static FASTDDS_EXPORTED_API bool setIPv4address(Locator_t &destlocator, const std::string &lan, const std::string &wan, const std::string &ipv4)
Copies locator's IPv4.
static FASTDDS_EXPORTED_API uint16_t getPortRTPS(Locator_t &locator)
Gets locator's RTCP port. Physical for UDP and logical for TCP (as in RTCP protocol)
static FASTDDS_EXPORTED_API const octet * getIPv4(const Locator_t &locator)
Retrieves locator's IPv4 as octet array.
Class Locator_t, uniquely identifies a communication channel for a particular transport.
Definition Locator.hpp:71
unsigned char octet
Definition Types.hpp:83
eProsima namespace.