async_resolve.hpp (f8ca6d79390b7f7fac5dbb82635dd6384810c668) | async_resolve.hpp (e1452bea2809f7189a69ee562e5078e452f0a251) |
---|---|
1#pragma once 2#ifdef BMCWEB_DBUS_DNS_RESOLVER 3#include "dbus_singleton.hpp" 4#include "logging.hpp" 5 6#include <boost/asio/ip/address.hpp> 7#include <boost/asio/ip/basic_endpoint.hpp> 8#include <boost/asio/ip/tcp.hpp> 9#include <sdbusplus/message.hpp> 10 11#include <charconv> 12#include <iostream> 13#include <memory> 14 | 1#pragma once 2#ifdef BMCWEB_DBUS_DNS_RESOLVER 3#include "dbus_singleton.hpp" 4#include "logging.hpp" 5 6#include <boost/asio/ip/address.hpp> 7#include <boost/asio/ip/basic_endpoint.hpp> 8#include <boost/asio/ip/tcp.hpp> 9#include <sdbusplus/message.hpp> 10 11#include <charconv> 12#include <iostream> 13#include <memory> 14 |
15namespace crow | 15namespace async_resolve |
16{ 17 | 16{ 17 |
18namespace async_resolve | 18inline bool endpointFromResolveTuple(const std::vector<uint8_t>& ipAddress, 19 boost::asio::ip::tcp::endpoint& endpoint) |
19{ | 20{ |
21 if (ipAddress.size() == 4) // ipv4 address 22 { 23 BMCWEB_LOG_DEBUG << "ipv4 address"; 24 boost::asio::ip::address_v4 ipv4Addr( 25 {ipAddress[0], ipAddress[1], ipAddress[2], ipAddress[3]}); 26 endpoint.address(ipv4Addr); 27 } 28 else if (ipAddress.size() == 16) // ipv6 address 29 { 30 BMCWEB_LOG_DEBUG << "ipv6 address"; 31 boost::asio::ip::address_v6 ipv6Addr( 32 {ipAddress[0], ipAddress[1], ipAddress[2], ipAddress[3], 33 ipAddress[4], ipAddress[5], ipAddress[6], ipAddress[7], 34 ipAddress[8], ipAddress[9], ipAddress[10], ipAddress[11], 35 ipAddress[12], ipAddress[13], ipAddress[14], ipAddress[15]}); 36 endpoint.address(ipv6Addr); 37 } 38 else 39 { 40 BMCWEB_LOG_ERROR << "Resolve failed to fetch the IP address"; 41 return false; 42 } 43 return true; 44} |
|
20 21class Resolver 22{ 23 public: 24 // unused io param used to keep interface identical to 25 // boost::asio::tcp:::resolver 26 explicit Resolver(boost::asio::io_context& /*io*/) {} 27 --- 42 unchanged lines hidden (view full) --- 70 return; 71 } 72 BMCWEB_LOG_DEBUG << "ResolveHostname returned: " << hostName << ":" 73 << flagNum; 74 // Extract the IP address from the response 75 for (const std::tuple<int32_t, int32_t, std::vector<uint8_t>>& 76 resolveList : resp) 77 { | 45 46class Resolver 47{ 48 public: 49 // unused io param used to keep interface identical to 50 // boost::asio::tcp:::resolver 51 explicit Resolver(boost::asio::io_context& /*io*/) {} 52 --- 42 unchanged lines hidden (view full) --- 95 return; 96 } 97 BMCWEB_LOG_DEBUG << "ResolveHostname returned: " << hostName << ":" 98 << flagNum; 99 // Extract the IP address from the response 100 for (const std::tuple<int32_t, int32_t, std::vector<uint8_t>>& 101 resolveList : resp) 102 { |
78 const std::vector<uint8_t>& ipAddress = 79 std::get<2>(resolveList); | |
80 boost::asio::ip::tcp::endpoint endpoint; | 103 boost::asio::ip::tcp::endpoint endpoint; |
81 if (ipAddress.size() == 4) // ipv4 address | 104 endpoint.port(portNum); 105 if (!endpointFromResolveTuple(std::get<2>(resolveList), 106 endpoint)) |
82 { | 107 { |
83 BMCWEB_LOG_DEBUG << "ipv4 address"; 84 boost::asio::ip::address_v4 ipv4Addr( 85 {ipAddress[0], ipAddress[1], ipAddress[2], 86 ipAddress[3]}); 87 endpoint.address(ipv4Addr); | 108 boost::system::error_code ecErr = make_error_code( 109 boost::system::errc::address_not_available); 110 handler(ecErr, endpointList); |
88 } | 111 } |
89 else if (ipAddress.size() == 16) // ipv6 address 90 { 91 BMCWEB_LOG_DEBUG << "ipv6 address"; 92 boost::asio::ip::address_v6 ipv6Addr( 93 {ipAddress[0], ipAddress[1], ipAddress[2], ipAddress[3], 94 ipAddress[4], ipAddress[5], ipAddress[6], ipAddress[7], 95 ipAddress[8], ipAddress[9], ipAddress[10], 96 ipAddress[11], ipAddress[12], ipAddress[13], 97 ipAddress[14], ipAddress[15]}); 98 endpoint.address(ipv6Addr); 99 } 100 else 101 { 102 BMCWEB_LOG_ERROR 103 << "Resolve failed to fetch the IP address"; 104 handler(ec, endpointList); 105 return; 106 } 107 endpoint.port(portNum); | |
108 BMCWEB_LOG_DEBUG << "resolved endpoint is : " << endpoint; 109 endpointList.push_back(endpoint); 110 } 111 // All the resolved data is filled in the endpointList 112 handler(ec, endpointList); 113 }, 114 "org.freedesktop.resolve1", "/org/freedesktop/resolve1", 115 "org.freedesktop.resolve1.Manager", "ResolveHostname", 0, host, 116 AF_UNSPEC, flag); 117 } 118}; 119 120} // namespace async_resolve | 112 BMCWEB_LOG_DEBUG << "resolved endpoint is : " << endpoint; 113 endpointList.push_back(endpoint); 114 } 115 // All the resolved data is filled in the endpointList 116 handler(ec, endpointList); 117 }, 118 "org.freedesktop.resolve1", "/org/freedesktop/resolve1", 119 "org.freedesktop.resolve1.Manager", "ResolveHostname", 0, host, 120 AF_UNSPEC, flag); 121 } 122}; 123 124} // namespace async_resolve |
121} // namespace crow | |
122#endif | 125#endif |