Fast RTPS  Version 2.14.1
Fast RTPS
Loading...
Searching...
No Matches
IPLocator.h
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 IP_LOCATOR_H_
21#define IP_LOCATOR_H_
22
23#include <fastdds/rtps/common/Types.h>
24#include <fastdds/dds/log/Log.hpp>
25
26#include <regex>
27#include <set>
28#include <string>
29#include <vector>
30
31namespace eprosima {
32namespace fastrtps {
33namespace rtps {
34
35class Locator_t;
36
42{
43public:
44
52 RTPS_DllAPI static void createLocator(
53 int32_t kindin,
54 const std::string& address,
55 uint32_t portin,
56 Locator_t& locator);
57
59 RTPS_DllAPI static bool setIPv4(
60 Locator_t& locator,
61 const unsigned char* addr);
62
64 RTPS_DllAPI static bool setIPv4(
65 Locator_t& locator,
66 octet o1,
67 octet o2,
68 octet o3,
69 octet o4);
70
72 RTPS_DllAPI static bool setIPv4(
73 Locator_t& locator,
74 const std::string& ipv4);
75
77 RTPS_DllAPI static bool setIPv4(
78 Locator_t& destlocator,
79 const Locator_t& origlocator);
80
82 RTPS_DllAPI static bool setIPv4address(
83 Locator_t& destlocator,
84 const std::string& lan,
85 const std::string& wan,
86 const std::string& ipv4);
87
89 RTPS_DllAPI static const octet* getIPv4(
90 const Locator_t& locator);
91
93 RTPS_DllAPI static bool hasIPv4(
94 const Locator_t& locator);
95
97 RTPS_DllAPI static std::string toIPv4string(
98 const Locator_t& locator);
99
101 RTPS_DllAPI static bool copyIPv4(
102 const Locator_t& locator,
103 unsigned char* dest);
104
105 // IPv6
107 RTPS_DllAPI static bool setIPv6(
108 Locator_t& locator,
109 const unsigned char* addr);
110
112 RTPS_DllAPI static bool setIPv6(
113 Locator_t& locator,
114 uint16_t group0,
115 uint16_t group1,
116 uint16_t group2,
117 uint16_t group3,
118 uint16_t group4,
119 uint16_t group5,
120 uint16_t group6,
121 uint16_t group7);
122
124 RTPS_DllAPI static bool setIPv6(
125 Locator_t& locator,
126 const std::string& ipv6);
127
129 RTPS_DllAPI static bool setIPv6(
130 Locator_t& destlocator,
131 const Locator_t& origlocator);
132
134 RTPS_DllAPI static const octet* getIPv6(
135 const Locator_t& locator);
136
138 RTPS_DllAPI static bool hasIPv6(
139 const Locator_t& locator);
140
142 RTPS_DllAPI static std::string toIPv6string(
143 const Locator_t& locator);
144
146 RTPS_DllAPI static bool copyIPv6(
147 const Locator_t& locator,
148 unsigned char* dest);
149
151 RTPS_DllAPI static bool ip(
152 Locator_t& locator,
153 const std::string& ip);
154
156 RTPS_DllAPI static std::string ip_to_string(
157 const Locator_t& locator);
158
159 // TCP
161 RTPS_DllAPI static bool setLogicalPort(
162 Locator_t& locator,
163 uint16_t port);
164
166 RTPS_DllAPI static uint16_t getLogicalPort(
167 const Locator_t& locator);
168
170 RTPS_DllAPI static bool setPhysicalPort(
171 Locator_t& locator,
172 uint16_t port);
173
175 RTPS_DllAPI static uint16_t getPhysicalPort(
176 const Locator_t& locator);
177
178 // TCPv4
180 RTPS_DllAPI static bool setWan(
181 Locator_t& locator,
182 octet o1,
183 octet o2,
184 octet o3,
185 octet o4);
186
188 RTPS_DllAPI static bool setWan(
189 Locator_t& locator,
190 const std::string& wan);
191
193 RTPS_DllAPI static const octet* getWan(
194 const Locator_t& locator);
195
197 RTPS_DllAPI static bool hasWan(
198 const Locator_t& locator);
199
201 RTPS_DllAPI static std::string toWanstring(
202 const Locator_t& locator);
203
207 RTPS_DllAPI static Locator_t WanToLanLocator(
208 const Locator_t& locator);
209
211 RTPS_DllAPI static bool setLanID(
212 Locator_t& locator,
213 const std::string& lanId);
214
216 RTPS_DllAPI static const octet* getLanID(
217 const Locator_t& locator);
218
220 RTPS_DllAPI static std::string toLanIDstring(
221 const Locator_t& locator);
222
224 RTPS_DllAPI static Locator_t toPhysicalLocator(
225 const Locator_t& locator);
226
228 RTPS_DllAPI static bool ip_equals_wan(
229 const Locator_t& locator);
230
231 // Common
233 RTPS_DllAPI static bool setPortRTPS(
234 Locator_t& locator,
235 uint16_t port);
236
238 RTPS_DllAPI static uint16_t getPortRTPS(
239 Locator_t& locator);
240
242 RTPS_DllAPI static bool isLocal(
243 const Locator_t& locator);
244
246 RTPS_DllAPI static bool isAny(
247 const Locator_t& locator);
248
250 RTPS_DllAPI static bool compareAddress(
251 const Locator_t& loc1,
252 const Locator_t& loc2,
253 bool fullAddress = false);
254
256 RTPS_DllAPI static bool compareAddressAndPhysicalPort(
257 const Locator_t& loc1,
258 const Locator_t& loc2);
259
261 RTPS_DllAPI static std::string to_string(
262 const Locator_t& locator);
263
264 // UDP
266 RTPS_DllAPI static bool isMulticast(
267 const Locator_t& locator);
268
270 RTPS_DllAPI static std::pair<std::set<std::string>, std::set<std::string>> resolveNameDNS(
271 const std::string& address_name);
272
274 RTPS_DllAPI static bool isIPv4(
275 const std::string& address);
277 RTPS_DllAPI static bool isIPv6(
278 const std::string& address);
279
280protected:
281
282 // Checks if the locator address is equal to 0
283 // It checks the proper locator address depending on the locator kind
284 static bool isEmpty(
285 const Locator_t& locator);
286
287 // Checks if the locator address from index till the end is equal to 0
288 static bool isEmpty(
289 const Locator_t& locator,
290 uint16_t index);
291
292 // Checks if a string matches an ipv6 address
293 static bool IPv6isCorrect(
294 const std::string& ipv6);
295
296private:
297
298 IPLocator() = delete;
299 ~IPLocator() = delete;
300};
301
302} // namespace rtps
303} // namespace fastrtps
304} /* namespace eprosima */
305
306#endif /* IP_LOCATOR_H_ */
Class IPLocator, to provide helper functions to the IP based transports.
Definition IPLocator.h:42
static RTPS_DllAPI bool setIPv6(Locator_t &destlocator, const Locator_t &origlocator)
Copies locator's IPv6.
static RTPS_DllAPI bool hasIPv6(const Locator_t &locator)
Check if the locator has IPv6.
static RTPS_DllAPI bool copyIPv6(const Locator_t &locator, unsigned char *dest)
Copies locator's IPv6.
static RTPS_DllAPI 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 RTPS_DllAPI bool setIPv4address(Locator_t &destlocator, const std::string &lan, const std::string &wan, const std::string &ipv4)
Copies locator's IPv4.
static RTPS_DllAPI 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 RTPS_DllAPI bool isLocal(const Locator_t &locator)
Checks if a locator has local IP address.
static RTPS_DllAPI 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 RTPS_DllAPI bool setIPv6(Locator_t &locator, const std::string &ipv6)
Sets locator's IPv6.
static RTPS_DllAPI std::string toIPv6string(const Locator_t &locator)
Returns a string representation of the locator's IPv6 following RFC 5952 recommendation.
static bool IPv6isCorrect(const std::string &ipv6)
static RTPS_DllAPI uint16_t getLogicalPort(const Locator_t &locator)
Gets locator's logical port (as in RTCP protocol)
static RTPS_DllAPI bool setIPv4(Locator_t &destlocator, const Locator_t &origlocator)
Copies locator's IPv4.
static RTPS_DllAPI bool setWan(Locator_t &locator, octet o1, octet o2, octet o3, octet o4)
Sets locator's WAN address (as in RTCP protocol)
static RTPS_DllAPI 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 bool isEmpty(const Locator_t &locator, uint16_t index)
static RTPS_DllAPI bool hasWan(const Locator_t &locator)
Checks if the locator has WAN address (as in RTCP protocol)
static RTPS_DllAPI const octet * getWan(const Locator_t &locator)
Gets locator's WAN address (as in RTCP protocol)
static RTPS_DllAPI const octet * getIPv4(const Locator_t &locator)
Retrieves locator's IPv4 as octet array.
static RTPS_DllAPI 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 RTPS_DllAPI std::string ip_to_string(const Locator_t &locator)
Returns a string representation of the locator's IP.
static RTPS_DllAPI bool setLogicalPort(Locator_t &locator, uint16_t port)
Sets locator's logical port (as in RTCP protocol)
static RTPS_DllAPI bool setLanID(Locator_t &locator, const std::string &lanId)
Sets locator's LAN ID (as in RTCP protocol)
static RTPS_DllAPI bool setIPv6(Locator_t &locator, const unsigned char *addr)
Sets locator's IPv6.
static RTPS_DllAPI bool isMulticast(const Locator_t &locator)
Checks if the locator has a multicast IP address.
static bool isEmpty(const Locator_t &locator)
static RTPS_DllAPI bool copyIPv4(const Locator_t &locator, unsigned char *dest)
Copies locator's IPv4.
static RTPS_DllAPI bool isIPv6(const std::string &address)
Check whether a string contains an IPv6 format.
static RTPS_DllAPI bool hasIPv4(const Locator_t &locator)
Check if the locator has IPv4.
static RTPS_DllAPI bool setIPv4(Locator_t &locator, octet o1, octet o2, octet o3, octet o4)
Sets locator's IPv4.
static RTPS_DllAPI bool setPhysicalPort(Locator_t &locator, uint16_t port)
Sets locator's physical port (as in RTCP protocol)
static RTPS_DllAPI bool isIPv4(const std::string &address)
Check whether a string contains an IPv4 format.
static RTPS_DllAPI std::string toLanIDstring(const Locator_t &locator)
Retrieves a string representation of the locator's LAN ID (as in RTCP protocol)
static RTPS_DllAPI const octet * getIPv6(const Locator_t &locator)
Retrieves locator's IPv6 as octet array.
static RTPS_DllAPI bool isAny(const Locator_t &locator)
Checks if a locator has any IP address.
static RTPS_DllAPI uint16_t getPortRTPS(Locator_t &locator)
Gets locator's RTCP port. Physical for UDP and logical for TCP (as in RTCP protocol)
static RTPS_DllAPI std::string toWanstring(const Locator_t &locator)
Retrieves a string representation of the locator's WAN address (as in RTCP protocol)
static RTPS_DllAPI const octet * getLanID(const Locator_t &locator)
Gets locator's LAN ID (as in RTCP protocol)
static RTPS_DllAPI Locator_t toPhysicalLocator(const Locator_t &locator)
Returns a new locator without logical port (as in RTCP protocol).
static RTPS_DllAPI bool setIPv4(Locator_t &locator, const unsigned char *addr)
Sets locator's IPv4.
static RTPS_DllAPI bool setWan(Locator_t &locator, const std::string &wan)
Sets locator's WAN address (as in RTCP protocol)
static RTPS_DllAPI std::string toIPv4string(const Locator_t &locator)
Returns a string representation of the locator's IPv4.
static RTPS_DllAPI bool compareAddress(const Locator_t &loc1, const Locator_t &loc2, bool fullAddress=false)
Checks if both locators has the same IP address.
static RTPS_DllAPI std::string to_string(const Locator_t &locator)
Returns a string representation of the given locator.
static RTPS_DllAPI uint16_t getPhysicalPort(const Locator_t &locator)
Gets locator's physical port (as in RTCP protocol)
static RTPS_DllAPI 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 RTPS_DllAPI void createLocator(int32_t kindin, const std::string &address, uint32_t portin, Locator_t &locator)
Fills locator with the given parameters.
static RTPS_DllAPI bool setIPv4(Locator_t &locator, const std::string &ipv4)
Sets locator's IPv4.
static RTPS_DllAPI bool ip(Locator_t &locator, const std::string &ip)
Sets locator's IP.
eProsima namespace.
Definition LibrarySettingsAttributes.h:23