30 #if BOOST_VERSION < 105800 31 #include <boost/algorithm/string.hpp> 32 #include <boost/lexical_cast.hpp> 34 #endif // BOOST_VERSION < 105800 44 char buffer[IFNAMSIZ];
45 auto scopeName = if_indextoname(scopeId, buffer);
46 if (scopeName !=
nullptr) {
47 return std::string(scopeName);
52 #if BOOST_VERSION < 105800 56 auto id = if_nametoindex(scope.c_str());
63 return boost::lexical_cast<
unsigned int>(scope);
65 catch (
const boost::bad_lexical_cast&) {
72 boost::asio::ip::address
addr;
79 std::vector<std::string> parseResult;
80 boost::algorithm::split(parseResult, address, boost::is_any_of(
"%"));
81 auto addr = boost::asio::ip::address::from_string(parseResult[0], ec);
83 switch (parseResult.size()) {
89 if (!ec && addr.is_v6() && addr.to_v6().is_link_local()) {
90 return {addr, parseResult[1]};
94 ec = boost::asio::error::invalid_argument;
98 #endif // BOOST_VERSION < 105800 100 boost::asio::ip::address
104 #if BOOST_VERSION < 105800 106 if (ec || parsedAddress.addr.is_v4()) {
107 return parsedAddress.addr;
109 auto addr = parsedAddress.addr.to_v6();
113 return boost::asio::ip::address::from_string(address, ec);
114 #endif // BOOST_VERSION < 105800 117 boost::asio::ip::address
120 boost::system::error_code ec;
123 BOOST_THROW_EXCEPTION(boost::system::system_error(ec));
128 boost::asio::ip::address_v6
132 if (ec || addr.is_v4()) {
133 ec = boost::asio::error::invalid_argument;
139 boost::asio::ip::address_v6
142 boost::system::error_code ec;
145 BOOST_THROW_EXCEPTION(boost::system::system_error(ec));
constexpr nullopt_t nullopt
Copyright (c) 2011-2015 Regents of the University of California.
static unsigned int scopeIdFromString(const std::string &scope)
static ParsedAddress parseAddressFromString(const std::string &address, boost::system::error_code &ec)
boost::asio::ip::address addressFromString(const std::string &address, boost::system::error_code &ec)
parse and convert the input string into an IP address
#define NDN_CXX_FALLTHROUGH
boost::asio::ip::address_v6 addressV6FromString(const std::string &address, boost::system::error_code &ec)
parse and convert the input string into an IPv6 address
optional< std::string > scopeNameFromId(unsigned int scopeId)
Convert scope ID of IPv6 address into interface name.
boost::asio::ip::address addr