net: deprecate ndn::ip::address{,V6}FromString
Change-Id: I32b26b70ab35e5f365bdb3fbfaad3c4e5f9d6a99
diff --git a/src/net/address-converter.cpp b/src/net/address-converter.cpp
index e29c0c0..05936b0 100644
--- a/src/net/address-converter.cpp
+++ b/src/net/address-converter.cpp
@@ -27,22 +27,9 @@
#include "address-converter.hpp"
-#include <net/if.h> // for if_indextoname()
-
namespace ndn {
namespace ip {
-optional<std::string>
-scopeNameFromId(unsigned int scopeId)
-{
- char buffer[IFNAMSIZ];
- auto scopeName = if_indextoname(scopeId, buffer);
- if (scopeName != nullptr) {
- return std::string(scopeName);
- }
- return nullopt;
-}
-
boost::asio::ip::address
addressFromString(const std::string& address, boost::system::error_code& ec)
{
@@ -52,34 +39,19 @@
boost::asio::ip::address
addressFromString(const std::string& address)
{
- boost::system::error_code ec;
- auto addr = addressFromString(address, ec);
- if (ec) {
- BOOST_THROW_EXCEPTION(boost::system::system_error(ec));
- }
- return addr;
+ return boost::asio::ip::address::from_string(address);
}
boost::asio::ip::address_v6
addressV6FromString(const std::string& address, boost::system::error_code& ec)
{
- auto addr = addressFromString(address, ec);
- if (ec || addr.is_v4()) {
- ec = boost::asio::error::invalid_argument;
- return {};
- }
- return addr.to_v6();
+ return boost::asio::ip::address_v6::from_string(address, ec);
}
boost::asio::ip::address_v6
addressV6FromString(const std::string& address)
{
- boost::system::error_code ec;
- auto addr = addressV6FromString(address, ec);
- if (ec) {
- BOOST_THROW_EXCEPTION(boost::system::system_error(ec));
- }
- return addr;
+ return boost::asio::ip::address_v6::from_string(address);
}
} // namespace ip
diff --git a/src/net/address-converter.hpp b/src/net/address-converter.hpp
index b58cfff..0ea945e 100644
--- a/src/net/address-converter.hpp
+++ b/src/net/address-converter.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2017 Regents of the University of California,
+ * Copyright (c) 2013-2018 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -37,14 +37,6 @@
namespace ip {
/**
- * \brief Convert scope ID of IPv6 address into interface name
- *
- * \return interface name, or ndn::nullopt if \p scopeId cannot be converted
- */
-optional<std::string>
-scopeNameFromId(unsigned int scopeId);
-
-/**
* \brief parse and convert the input string into an IP address
*
* \param str the string to parse
@@ -52,6 +44,7 @@
* \return the converted IP address
* \throw boost::system::system_error in case of failure
*/
+[[deprecated("use boost::asio::ip::address::from_string")]]
boost::asio::ip::address
addressFromString(const std::string& str);
@@ -64,6 +57,7 @@
* \return the converted IP address, or a default-constructed
* `boost::asio::ip::address` in case of failure
*/
+[[deprecated("use boost::asio::ip::address::from_string")]]
boost::asio::ip::address
addressFromString(const std::string& str, boost::system::error_code& ec);
@@ -75,6 +69,7 @@
* \return the converted IPv6 address
* \throw boost::system::system_error in case of failure
*/
+[[deprecated("use boost::asio::ip::address_v6::from_string")]]
boost::asio::ip::address_v6
addressV6FromString(const std::string& str);
@@ -87,6 +82,7 @@
* \return the converted IPv6 address, or a default-constructed
* `boost::asio::ip::address_v6` in case of failure
*/
+[[deprecated("use boost::asio::ip::address_v6::from_string")]]
boost::asio::ip::address_v6
addressV6FromString(const std::string& str, boost::system::error_code& ec);
diff --git a/tests/unit-tests/net/address-converter.t.cpp b/tests/unit-tests/net/address-converter.t.cpp
index 712bf6d..f77c541 100644
--- a/tests/unit-tests/net/address-converter.t.cpp
+++ b/tests/unit-tests/net/address-converter.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2017 Regents of the University of California,
+ * Copyright (c) 2013-2018 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -43,20 +43,6 @@
BOOST_CHECK_EQUAL(address, addrV6); \
} while (false)
-BOOST_AUTO_TEST_CASE(ScopeNameFromId)
-{
- const auto& networkInterfaces = net::tests::collectNetworkInterfaces();
- if (!networkInterfaces.empty()) {
- const auto& netif = networkInterfaces.front();
- auto index = netif->getIndex();
- auto name = netif->getName();
-
- BOOST_CHECK_EQUAL(scopeNameFromId(index).value(), name);
- }
-
- BOOST_CHECK(!scopeNameFromId(std::numeric_limits<unsigned int>::max()));
-}
-
BOOST_AUTO_TEST_CASE(AddressFromString)
{
boost::asio::ip::address addr;