/src/Fast-DDS/include/fastrtps/utils/IPFinder.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
15 | | /** |
16 | | * @file IPFinder.h |
17 | | * |
18 | | */ |
19 | | |
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 | | |
30 | | namespace eprosima { |
31 | | namespace fastrtps { |
32 | | namespace rtps { |
33 | | /** |
34 | | * Class IPFinder, to determine the IP of the NICs. |
35 | | * @ingroup UTILITIES_MODULE |
36 | | */ |
37 | | class IPFinder |
38 | | { |
39 | | public: |
40 | | |
41 | | #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC |
42 | | /** |
43 | | * Enum IPTYPE, to define the type of IP obtained from the NICs. |
44 | | */ |
45 | | enum IPTYPE |
46 | | { |
47 | | IP4, //!< IP4 |
48 | | IP6, //!< IP6 |
49 | | IP4_LOCAL, //!< IP4_LOCAL |
50 | | IP6_LOCAL //!< IP6_LOCAL |
51 | | }; |
52 | | /** |
53 | | * Structure info_IP with information about a specific IP obtained from a NIC. |
54 | | */ |
55 | | typedef struct info_IP |
56 | | { |
57 | | IPTYPE type; |
58 | | std::string name; |
59 | | std::string dev; |
60 | | Locator_t locator; |
61 | | }info_IP; |
62 | | |
63 | | /** |
64 | | * Structure info_MAC with information about a specific MAC obtained from a NIC. |
65 | | */ |
66 | | typedef struct info_MAC |
67 | | { |
68 | | unsigned char address[6]; |
69 | | |
70 | | bool operator == ( |
71 | | const info_MAC& other) |
72 | 0 | { |
73 | 0 | return memcmp(address, other.address, 6) == 0; |
74 | 0 | } |
75 | | |
76 | | }info_MAC; |
77 | | |
78 | | #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC |
79 | | IPFinder(); |
80 | | virtual ~IPFinder(); |
81 | | |
82 | | RTPS_DllAPI static bool getIPs( |
83 | | std::vector<info_IP>* vec_name, |
84 | | bool return_loopback = false); |
85 | | |
86 | | /** |
87 | | * Get the IP4Adresses in all interfaces. |
88 | | * @param[out] locators List of locators to be populated with the IP4 addresses. |
89 | | */ |
90 | | RTPS_DllAPI static bool getIP4Address( |
91 | | LocatorList_t* locators); |
92 | | /** |
93 | | * Get the IP6Adresses in all interfaces. |
94 | | * @param[out] locators List of locators to be populated with the IP6 addresses. |
95 | | */ |
96 | | RTPS_DllAPI static bool getIP6Address( |
97 | | LocatorList_t* locators); |
98 | | /** |
99 | | * Get all IP Adresses in all interfaces. |
100 | | * @param[out] locators List of locators to be populated with the addresses. |
101 | | */ |
102 | | RTPS_DllAPI static bool getAllIPAddress( |
103 | | LocatorList_t* locators); |
104 | | /** |
105 | | * Parses an IP4 string, populating a info_IP with its value. |
106 | | * @param[out] info info_IP to populate. |
107 | | * */ |
108 | | RTPS_DllAPI static bool parseIP4( |
109 | | info_IP& info); |
110 | | /** |
111 | | * Parses an IP6 string, populating a info_IP with its value. |
112 | | * @param[out] info info_IP to populate. |
113 | | * */ |
114 | | RTPS_DllAPI static bool parseIP6( |
115 | | info_IP& info); |
116 | | |
117 | | RTPS_DllAPI static std::string getIPv4Address( |
118 | | const std::string& name); |
119 | | RTPS_DllAPI static std::string getIPv6Address( |
120 | | const std::string& name); |
121 | | |
122 | | /** |
123 | | * Get all MAC Adresses of all interfaces. |
124 | | * Will return all unique MAC addresses for eadh of the interfaces returned by getAllIPAddress |
125 | | * @param[out] macs List of MAC addresses. |
126 | | */ |
127 | | RTPS_DllAPI static bool getAllMACAddress( |
128 | | std::vector<info_MAC>* macs); |
129 | | }; |
130 | | |
131 | | } // namespace rtps |
132 | | } // namespace fastrtps |
133 | | } /* namespace eprosima */ |
134 | | |
135 | | #endif /* IPFINDER_H_ */ |