Fast RTPS  Version 2.6.1
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 
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 
205  RTPS_DllAPI static bool setLanID(
206  Locator_t& locator,
207  const std::string& lanId);
208 
210  RTPS_DllAPI static const octet* getLanID(
211  const Locator_t& locator);
212 
214  RTPS_DllAPI static std::string toLanIDstring(
215  const Locator_t& locator);
216 
218  RTPS_DllAPI static Locator_t toPhysicalLocator(
219  const Locator_t& locator);
220 
222  RTPS_DllAPI static bool ip_equals_wan(
223  const Locator_t& locator);
224 
225  // Common
227  RTPS_DllAPI static bool setPortRTPS(
228  Locator_t& locator,
229  uint16_t port);
230 
232  RTPS_DllAPI static uint16_t getPortRTPS(
233  Locator_t& locator);
234 
236  RTPS_DllAPI static bool isLocal(
237  const Locator_t& locator);
238 
240  RTPS_DllAPI static bool isAny(
241  const Locator_t& locator);
242 
244  RTPS_DllAPI static bool compareAddress(
245  const Locator_t& loc1,
246  const Locator_t& loc2,
247  bool fullAddress = false);
248 
250  RTPS_DllAPI static bool compareAddressAndPhysicalPort(
251  const Locator_t& loc1,
252  const Locator_t& loc2);
253 
255  RTPS_DllAPI static std::string to_string(
256  const Locator_t& locator);
257 
258  // UDP
260  RTPS_DllAPI static bool isMulticast(
261  const Locator_t& locator);
262 
264  RTPS_DllAPI static std::pair<std::set<std::string>, std::set<std::string>> resolveNameDNS(
265  const std::string& address_name);
266 
268  RTPS_DllAPI static bool isIPv4(
269  const std::string& address);
271  RTPS_DllAPI static bool isIPv6(
272  const std::string& address);
273 
274 protected:
275 
276  // Checks if the locator address is equal to 0
277  // It checks the proper locator address depending on the locator kind
278  static bool isEmpty(
279  const Locator_t& locator);
280 
281  // Checks if the locator address from index till the end is equal to 0
282  static bool isEmpty(
283  const Locator_t& locator,
284  uint16_t index);
285 
286  // Checks if a string matches an ipv6 address
287  static bool IPv6isCorrect(
288  const std::string& ipv6);
289 
290 private:
291 
292  IPLocator() = delete;
293  ~IPLocator() = delete;
294 };
295 
296 } // namespace rtps
297 } // namespace fastrtps
298 } /* namespace eprosima */
299 
300 #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.
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 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 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 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