Fast RTPS  Version 2.14.5
Fast RTPS
IPFinder.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 IPFINDER_H_
21 #define IPFINDER_H_
22 
23 
24 
25 #include <vector>
26 #include <string>
27 
28 #include <fastdds/rtps/common/Locator.h>
29 #include <fastdds/rtps/common/LocatorWithMask.hpp>
30 
31 namespace eprosima {
32 namespace fastrtps {
33 namespace rtps {
38 class IPFinder
39 {
40 public:
41 
42 #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
46  enum IPTYPE
47  {
48  IP4,
49  IP6,
51  IP6_LOCAL
52  };
56  typedef struct info_IP
57  {
59  std::string name;
60  std::string dev;
61  Locator_t locator;
62  fastdds::rtps::LocatorWithMask masked_locator;
64 
68  typedef struct info_MAC
69  {
70  unsigned char address[6];
71 
73  const info_MAC& other)
74  {
75  return memcmp(address, other.address, 6) == 0;
76  }
77 
79 
80 #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
82  virtual ~IPFinder();
83 
84  RTPS_DllAPI static bool getIPs(
85  std::vector<info_IP>* vec_name,
86  bool return_loopback = false);
87 
92  RTPS_DllAPI static bool getIP4Address(
93  LocatorList_t* locators);
98  RTPS_DllAPI static bool getIP6Address(
99  LocatorList_t* locators);
104  RTPS_DllAPI static bool getAllIPAddress(
105  LocatorList_t* locators);
110  RTPS_DllAPI static bool parseIP4(
111  info_IP& info);
116  RTPS_DllAPI static bool parseIP6(
117  info_IP& info);
118 
119  RTPS_DllAPI static std::string getIPv4Address(
120  const std::string& name);
121  RTPS_DllAPI static std::string getIPv6Address(
122  const std::string& name);
123 
129  RTPS_DllAPI static bool getAllMACAddress(
130  std::vector<info_MAC>* macs);
131 };
132 
133 } // namespace rtps
134 } // namespace fastrtps
135 } /* namespace eprosima */
136 
137 #endif /* IPFINDER_H_ */
Class IPFinder, to determine the IP of the NICs.
Definition: IPFinder.h:39
static RTPS_DllAPI bool getIP6Address(LocatorList_t *locators)
Get the IP6Adresses in all interfaces.
static RTPS_DllAPI std::string getIPv6Address(const std::string &name)
static RTPS_DllAPI bool getAllIPAddress(LocatorList_t *locators)
Get all IP Adresses in all interfaces.
static RTPS_DllAPI bool getIPs(std::vector< info_IP > *vec_name, bool return_loopback=false)
struct eprosima::fastrtps::rtps::IPFinder::info_IP info_IP
Structure info_IP with information about a specific IP obtained from a NIC.
IPTYPE
Enum IPTYPE, to define the type of IP obtained from the NICs.
Definition: IPFinder.h:47
@ IP4_LOCAL
IP4_LOCAL.
Definition: IPFinder.h:50
@ IP4
IP4.
Definition: IPFinder.h:48
@ IP6_LOCAL
IP6_LOCAL.
Definition: IPFinder.h:51
@ IP6
IP6.
Definition: IPFinder.h:49
static RTPS_DllAPI bool parseIP4(info_IP &info)
Parses an IP4 string, populating a info_IP with its value.
struct eprosima::fastrtps::rtps::IPFinder::info_MAC info_MAC
Structure info_MAC with information about a specific MAC obtained from a NIC.
static RTPS_DllAPI std::string getIPv4Address(const std::string &name)
static RTPS_DllAPI bool getIP4Address(LocatorList_t *locators)
Get the IP4Adresses in all interfaces.
static RTPS_DllAPI bool parseIP6(info_IP &info)
Parses an IP6 string, populating a info_IP with its value.
static RTPS_DllAPI bool getAllMACAddress(std::vector< info_MAC > *macs)
Get all MAC Adresses of all interfaces.
eProsima namespace.
Definition: LibrarySettingsAttributes.h:23
Structure info_IP with information about a specific IP obtained from a NIC.
Definition: IPFinder.h:57
std::string dev
Definition: IPFinder.h:60
fastdds::rtps::LocatorWithMask masked_locator
Definition: IPFinder.h:62
std::string name
Definition: IPFinder.h:59
IPTYPE type
Definition: IPFinder.h:58
Locator_t locator
Definition: IPFinder.h:61
Structure info_MAC with information about a specific MAC obtained from a NIC.
Definition: IPFinder.h:69
bool operator==(const info_MAC &other)
Definition: IPFinder.h:72
unsigned char address[6]
Definition: IPFinder.h:70