IPFinder.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * @file IPFinder.h
  16. *
  17. */
  18. #ifndef IPFINDER_H_
  19. #define IPFINDER_H_
  20. #include <vector>
  21. #include <string>
  22. #include <fastdds/rtps/common/Locator.h>
  23. namespace eprosima {
  24. namespace fastrtps {
  25. namespace rtps {
  26. /**
  27. * Class IPFinder, to determine the IP of the NICs.
  28. * @ingroup UTILITIES_MODULE
  29. */
  30. class IPFinder
  31. {
  32. public:
  33. #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
  34. /**
  35. * Enum IPTYPE, to define the type of IP obtained from the NICs.
  36. */
  37. enum IPTYPE
  38. {
  39. IP4, //!< IP4
  40. IP6, //!< IP6
  41. IP4_LOCAL,//!< IP4_LOCAL
  42. IP6_LOCAL //!< IP6_LOCAL
  43. };
  44. /**
  45. * Structure info_IP with information about a specific IP obtained from a NIC.
  46. */
  47. typedef struct info_IP
  48. {
  49. IPTYPE type;
  50. std::string name;
  51. std::string dev;
  52. Locator_t locator;
  53. }info_IP;
  54. #endif
  55. IPFinder();
  56. virtual ~IPFinder();
  57. RTPS_DllAPI static bool getIPs(std::vector<info_IP>* vec_name, bool return_loopback = false);
  58. /**
  59. * Get the IP4Adresses in all interfaces.
  60. * @param[out] locators List of locators to be populated with the IP4 addresses.
  61. */
  62. RTPS_DllAPI static bool getIP4Address(LocatorList_t* locators);
  63. /**
  64. * Get the IP6Adresses in all interfaces.
  65. * @param[out] locators List of locators to be populated with the IP6 addresses.
  66. */
  67. RTPS_DllAPI static bool getIP6Address(LocatorList_t* locators);
  68. /**
  69. * Get all IP Adresses in all interfaces.
  70. * @param[out] locators List of locators to be populated with the addresses.
  71. */
  72. RTPS_DllAPI static bool getAllIPAddress(LocatorList_t* locators);
  73. /**
  74. * Parses an IP4 string, populating a info_IP with its value.
  75. * @param[out] info info_IP to populate.
  76. * */
  77. RTPS_DllAPI static bool parseIP4(info_IP& info);
  78. /**
  79. * Parses an IP6 string, populating a info_IP with its value.
  80. * @param[out] info info_IP to populate.
  81. * */
  82. RTPS_DllAPI static bool parseIP6(info_IP& info);
  83. RTPS_DllAPI static std::string getIPv4Address(const std::string &name);
  84. RTPS_DllAPI static std::string getIPv6Address(const std::string &name);
  85. };
  86. }
  87. }
  88. } /* namespace eprosima */
  89. #endif /* IPFINDER_H_ */