Fast RTPS  Version 2.14.5
Fast RTPS
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 
31 namespace eprosima {
32 namespace fastrtps {
33 namespace rtps {
34 
35 class Locator_t;
36 
41 class IPLocator
42 {
43 public:
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 
106  RTPS_DllAPI static bool copyIPv4(
107  const Locator_t& locator,
108  unsigned char* dest);
109 
117  RTPS_DllAPI static bool copyIPv4(
118  const Locator_t& locator,
119  Locator_t& dest);
120 
121  // IPv6
123  RTPS_DllAPI static bool setIPv6(
124  Locator_t& locator,
125  const unsigned char* addr);
126 
128  RTPS_DllAPI 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  RTPS_DllAPI static bool setIPv6(
141  Locator_t& locator,
142  const std::string& ipv6);
143 
145  RTPS_DllAPI static bool setIPv6(
146  Locator_t& destlocator,
147  const Locator_t& origlocator);
148 
150  RTPS_DllAPI static const octet* getIPv6(
151  const Locator_t& locator);
152 
154  RTPS_DllAPI static bool hasIPv6(
155  const Locator_t& locator);
156 
158  RTPS_DllAPI static std::string toIPv6string(
159  const Locator_t& locator);
160 
162  RTPS_DllAPI static bool copyIPv6(
163  const Locator_t& locator,
164  unsigned char* dest);
165 
167  RTPS_DllAPI static bool ip(
168  Locator_t& locator,
169  const std::string& ip);
170 
172  RTPS_DllAPI static std::string ip_to_string(
173  const Locator_t& locator);
174 
175  // TCP
177  RTPS_DllAPI static bool setLogicalPort(
178  Locator_t& locator,
179  uint16_t port);
180 
182  RTPS_DllAPI static uint16_t getLogicalPort(
183  const Locator_t& locator);
184 
186  RTPS_DllAPI static bool setPhysicalPort(
187  Locator_t& locator,
188  uint16_t port);
189 
191  RTPS_DllAPI static uint16_t getPhysicalPort(
192  const Locator_t& locator);
193 
194  // TCPv4
196  RTPS_DllAPI static bool setWan(
197  Locator_t& locator,
198  octet o1,
199  octet o2,
200  octet o3,
201  octet o4);
202 
204  RTPS_DllAPI static bool setWan(
205  Locator_t& locator,
206  const std::string& wan);
207 
209  RTPS_DllAPI static const octet* getWan(
210  const Locator_t& locator);
211 
213  RTPS_DllAPI static bool hasWan(
214  const Locator_t& locator);
215 
217  RTPS_DllAPI static std::string toWanstring(
218  const Locator_t& locator);
219 
223  RTPS_DllAPI static Locator_t WanToLanLocator(
224  const Locator_t& locator);
225 
227  RTPS_DllAPI static bool setLanID(
228  Locator_t& locator,
229  const std::string& lanId);
230 
232  RTPS_DllAPI static const octet* getLanID(
233  const Locator_t& locator);
234 
236  RTPS_DllAPI static std::string toLanIDstring(
237  const Locator_t& locator);
238 
240  RTPS_DllAPI static Locator_t toPhysicalLocator(
241  const Locator_t& locator);
242 
244  RTPS_DllAPI static bool ip_equals_wan(
245  const Locator_t& locator);
246 
247  // Common
249  RTPS_DllAPI static bool setPortRTPS(
250  Locator_t& locator,
251  uint16_t port);
252 
254  RTPS_DllAPI static uint16_t getPortRTPS(
255  Locator_t& locator);
256 
258  RTPS_DllAPI static bool isLocal(
259  const Locator_t& locator);
260 
262  RTPS_DllAPI static bool isAny(
263  const Locator_t& locator);
264 
266  RTPS_DllAPI static bool compareAddress(
267  const Locator_t& loc1,
268  const Locator_t& loc2,
269  bool fullAddress = false);
270 
277  RTPS_DllAPI static bool copy_address(
278  const Locator_t& loc1,
279  Locator_t& loc2);
280 
282  RTPS_DllAPI static bool compareAddressAndPhysicalPort(
283  const Locator_t& loc1,
284  const Locator_t& loc2);
285 
287  RTPS_DllAPI static std::string to_string(
288  const Locator_t& locator);
289 
290  // UDP
292  RTPS_DllAPI static bool isMulticast(
293  const Locator_t& locator);
294 
296  RTPS_DllAPI static std::pair<std::set<std::string>, std::set<std::string>> resolveNameDNS(
297  const std::string& address_name);
298 
300  RTPS_DllAPI static bool isIPv4(
301  const std::string& address);
303  RTPS_DllAPI static bool isIPv6(
304  const std::string& address);
305 
306 protected:
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 
322 private:
323 
324  IPLocator() = delete;
325  ~IPLocator() = delete;
326 };
327 
328 } // namespace rtps
329 } // namespace fastrtps
330 } /* namespace eprosima */
331 
332 #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 const octet * getWan(const Locator_t &locator)
Gets locator's WAN address (as in RTCP protocol)
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 const octet * getIPv4(const Locator_t &locator)
Retrieves locator's IPv4 as octet array.
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 isLocal(const Locator_t &locator)
Checks if a locator has local IP address.
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 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 const octet * getLanID(const Locator_t &locator)
Gets locator's LAN ID (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 const octet * getIPv6(const Locator_t &locator)
Retrieves locator's IPv6 as octet array.
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 to a destination array.
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 bool copyIPv4(const Locator_t &locator, Locator_t &dest)
Copies locator's IPv4 to a destination locator.
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 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 bool copy_address(const Locator_t &loc1, Locator_t &loc2)
Copies the whole address from one locator to another.
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 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