1 #pragma once 2 3 #include <boost/asio/ip/address.hpp> 4 5 #include <string> 6 7 namespace redfish 8 { 9 namespace ip_util 10 { 11 12 /** 13 * @brief Converts boost::asio::ip::address to string 14 * Will automatically convert IPv4-mapped IPv6 address back to IPv4. 15 * 16 * @param[in] ipAddr IP address to convert 17 * 18 * @return IP address string 19 */ 20 inline std::string toString(const boost::asio::ip::address& ipAddr) 21 { 22 if (ipAddr.is_v6() && ipAddr.to_v6().is_v4_mapped()) 23 { 24 return boost::asio::ip::make_address_v4(boost::asio::ip::v4_mapped, 25 ipAddr.to_v6()) 26 .to_string(); 27 } 28 return ipAddr.to_string(); 29 } 30 31 } // namespace ip_util 32 } // namespace redfish 33