core: ignore non-Ethernet AF_LINK addresses when enumerating NICs.

Also modernize the code with some C++11 features.

Change-Id: Ibd29b39c37fdce8f87f917ab0cf48750e631e76c
diff --git a/.waf-tools/type_traits.py b/.waf-tools/type_traits.py
index fc1ffbf..07eb129 100644
--- a/.waf-tools/type_traits.py
+++ b/.waf-tools/type_traits.py
@@ -6,12 +6,23 @@
 
 from waflib import Configure
 
+IS_DEFAULT_CONSTRUCTIBLE_CHECK = '''
+#include <type_traits>
+static_assert(std::is_default_constructible<int>::value, "");
+'''
+
 IS_MOVE_CONSTRUCTIBLE_CHECK = '''
 #include <type_traits>
 static_assert(std::is_move_constructible<int>::value, "");
 '''
 
 def configure(conf):
+    if conf.check_cxx(msg='Checking for std::is_default_constructible',
+                      fragment=IS_DEFAULT_CONSTRUCTIBLE_CHECK,
+                      features='cxx', mandatory=False):
+        conf.define('HAVE_IS_DEFAULT_CONSTRUCTIBLE', 1)
+        conf.env['HAVE_IS_DEFAULT_CONSTRUCTIBLE'] = True
+
     if conf.check_cxx(msg='Checking for std::is_move_constructible',
                       fragment=IS_MOVE_CONSTRUCTIBLE_CHECK,
                       features='cxx', mandatory=False):
diff --git a/core/network-interface.cpp b/core/network-interface.cpp
index df47ac5..d7eebbd 100644
--- a/core/network-interface.cpp
+++ b/core/network-interface.cpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  Regents of the University of California,
- *                     Arizona Board of Regents,
- *                     Colorado State University,
- *                     University Pierre & Marie Curie, Sorbonne University,
- *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology
+ * Copyright (c) 2014,  Regents of the University of California,
+ *                      Arizona Board of Regents,
+ *                      Colorado State University,
+ *                      University Pierre & Marie Curie, Sorbonne University,
+ *                      Washington University in St. Louis,
+ *                      Beijing Institute of Technology,
+ *                      The University of Memphis
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,12 +21,15 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
 #include "network-interface.hpp"
 #include "core/logger.hpp"
 
-#include <boost/foreach.hpp>
+#include <cerrno>
+#include <cstring>
+#include <type_traits>
+#include <unordered_map>
 
 #include <arpa/inet.h>   // for inet_ntop()
 #include <netinet/in.h>  // for struct sockaddr_in{,6}
@@ -36,104 +40,120 @@
 #include <netpacket/packet.h>  // for struct sockaddr_ll
 #elif defined(__APPLE__) || defined(__FreeBSD__)
 #include <net/if_dl.h>         // for struct sockaddr_dl
-#else
-#error Platform not supported
+#include <net/if_types.h>      // for IFT_* constants
 #endif
 
 NFD_LOG_INIT("NetworkInterfaceInfo");
 
 namespace nfd {
 
-std::list< shared_ptr<NetworkInterfaceInfo> >
+static_assert(std::is_standard_layout<NetworkInterfaceInfo>::value,
+              "NetworkInterfaceInfo must be a standard layout type");
+#ifdef HAVE_IS_DEFAULT_CONSTRUCTIBLE
+static_assert(std::is_default_constructible<NetworkInterfaceInfo>::value,
+              "NetworkInterfaceInfo must provide a default constructor");
+#endif
+
+std::vector<NetworkInterfaceInfo>
 listNetworkInterfaces()
 {
-  typedef std::map< std::string, shared_ptr<NetworkInterfaceInfo> > InterfacesMap;
-  InterfacesMap ifmap;
+  using namespace boost::asio::ip;
+  using std::strerror;
 
-  ifaddrs* ifa_list;
+  std::unordered_map<std::string, NetworkInterfaceInfo> ifmap;
+  ifaddrs* ifa_list = nullptr;
+
   if (::getifaddrs(&ifa_list) < 0)
-    throw std::runtime_error("getifaddrs() failed");
+    throw std::runtime_error(std::string("getifaddrs() failed: ") + strerror(errno));
 
-  for (ifaddrs* ifa = ifa_list; ifa != 0; ifa = ifa->ifa_next)
-    {
-      shared_ptr<NetworkInterfaceInfo> netif;
-      std::string ifname(ifa->ifa_name);
-      InterfacesMap::iterator i = ifmap.find(ifname);
-      if (i == ifmap.end())
-        {
-          netif = make_shared<NetworkInterfaceInfo>();
-          netif->name = ifname;
-          netif->flags = ifa->ifa_flags;
-          ifmap[ifname] = netif;
-        }
+  for (ifaddrs* ifa = ifa_list; ifa != nullptr; ifa = ifa->ifa_next) {
+    std::string ifname(ifa->ifa_name);
+    NetworkInterfaceInfo& netif = ifmap[ifname];
+    netif.name = ifa->ifa_name;
+    netif.flags = ifa->ifa_flags;
+
+    if (ifa->ifa_addr == nullptr)
+      continue;
+
+    switch (ifa->ifa_addr->sa_family) {
+
+    case AF_INET: {
+      const sockaddr_in* sin = reinterpret_cast<sockaddr_in*>(ifa->ifa_addr);
+      char address[INET_ADDRSTRLEN];
+      if (::inet_ntop(AF_INET, &sin->sin_addr, address, sizeof(address))) {
+        netif.ipv4Addresses.push_back(address_v4::from_string(address));
+        NFD_LOG_TRACE(ifname << ": added IPv4 address " << address);
+      }
       else
-        {
-          netif = i->second;
-        }
-
-      if (!ifa->ifa_addr)
-        continue;
-
-      switch (ifa->ifa_addr->sa_family)
-        {
-        case AF_INET: {
-            const sockaddr_in* sin = reinterpret_cast<sockaddr_in*>(ifa->ifa_addr);
-            char address[INET_ADDRSTRLEN];
-            if (::inet_ntop(AF_INET, &sin->sin_addr, address, sizeof(address)))
-              netif->ipv4Addresses.push_back(boost::asio::ip::address_v4::from_string(address));
-            else
-              NFD_LOG_WARN("inet_ntop() failed on " << ifname);
-          }
-          break;
-        case AF_INET6: {
-            const sockaddr_in6* sin6 = reinterpret_cast<sockaddr_in6*>(ifa->ifa_addr);
-            char address[INET6_ADDRSTRLEN];
-            if (::inet_ntop(AF_INET6, &sin6->sin6_addr, address, sizeof(address)))
-              netif->ipv6Addresses.push_back(boost::asio::ip::address_v6::from_string(address));
-            else
-              NFD_LOG_WARN("inet_ntop() failed on " << ifname);
-          }
-          break;
-#if defined(__linux__)
-        case AF_PACKET: {
-            const sockaddr_ll* sll = reinterpret_cast<sockaddr_ll*>(ifa->ifa_addr);
-            netif->index = sll->sll_ifindex;
-            if (sll->sll_hatype == ARPHRD_ETHER && sll->sll_halen == ethernet::ADDR_LEN)
-              netif->etherAddress = ethernet::Address(sll->sll_addr);
-            else if (sll->sll_hatype != ARPHRD_LOOPBACK)
-              NFD_LOG_WARN("Unrecognized hardware address on " << ifname);
-          }
-          break;
-#elif defined(__APPLE__) || defined(__FreeBSD__)
-        case AF_LINK: {
-            const sockaddr_dl* sdl = reinterpret_cast<sockaddr_dl*>(ifa->ifa_addr);
-            netif->index = sdl->sdl_index;
-            netif->etherAddress = ethernet::Address(reinterpret_cast<uint8_t*>(LLADDR(sdl)));
-          }
-          break;
-#endif
-        }
-
-      if (netif->isBroadcastCapable() && ifa->ifa_broadaddr != 0)
-        {
-          const sockaddr_in* sin = reinterpret_cast<sockaddr_in*>(ifa->ifa_broadaddr);
-
-          char address[INET_ADDRSTRLEN];
-          if (::inet_ntop(AF_INET, &sin->sin_addr, address, sizeof(address)))
-            netif->broadcastAddress = boost::asio::ip::address_v4::from_string(address);
-          else
-            NFD_LOG_WARN("inet_ntop() failed on " << ifname);
-        }
+        NFD_LOG_WARN(ifname << ": inet_ntop(AF_INET) failed: " << strerror(errno));
+      break;
     }
 
+    case AF_INET6: {
+      const sockaddr_in6* sin6 = reinterpret_cast<sockaddr_in6*>(ifa->ifa_addr);
+      char address[INET6_ADDRSTRLEN];
+      if (::inet_ntop(AF_INET6, &sin6->sin6_addr, address, sizeof(address))) {
+        netif.ipv6Addresses.push_back(address_v6::from_string(address));
+        NFD_LOG_TRACE(ifname << ": added IPv6 address " << address);
+      }
+      else
+        NFD_LOG_WARN(ifname << ": inet_ntop(AF_INET6) failed: " << strerror(errno));
+      break;
+    }
+
+#if defined(__linux__)
+    case AF_PACKET: {
+      const sockaddr_ll* sll = reinterpret_cast<sockaddr_ll*>(ifa->ifa_addr);
+      netif.index = sll->sll_ifindex;
+      if (sll->sll_hatype == ARPHRD_ETHER && sll->sll_halen == ethernet::ADDR_LEN) {
+        netif.etherAddress = ethernet::Address(sll->sll_addr);
+        NFD_LOG_TRACE(ifname << ": added Ethernet address " << netif.etherAddress);
+      }
+      else if (sll->sll_hatype != ARPHRD_LOOPBACK) {
+        NFD_LOG_DEBUG(ifname << ": ignoring link-layer address for unhandled hardware type "
+                      << sll->sll_hatype);
+      }
+      break;
+    }
+
+#elif defined(__APPLE__) || defined(__FreeBSD__)
+    case AF_LINK: {
+      const sockaddr_dl* sdl = reinterpret_cast<sockaddr_dl*>(ifa->ifa_addr);
+      netif.index = sdl->sdl_index;
+      if (sdl->sdl_type == IFT_ETHER && sdl->sdl_alen == ethernet::ADDR_LEN) {
+        netif.etherAddress = ethernet::Address(reinterpret_cast<uint8_t*>(LLADDR(sdl)));
+        NFD_LOG_TRACE(ifname << ": added Ethernet address " << netif.etherAddress);
+      }
+      else if (sdl->sdl_type != IFT_LOOP) {
+        NFD_LOG_DEBUG(ifname << ": ignoring link-layer address for unhandled interface type "
+                      << sdl->sdl_type);
+      }
+      break;
+    }
+#endif
+    }
+
+    if (netif.isBroadcastCapable() && ifa->ifa_broadaddr != nullptr) {
+      const sockaddr_in* sin = reinterpret_cast<sockaddr_in*>(ifa->ifa_broadaddr);
+      char address[INET_ADDRSTRLEN];
+      if (::inet_ntop(AF_INET, &sin->sin_addr, address, sizeof(address))) {
+        netif.broadcastAddress = address_v4::from_string(address);
+        NFD_LOG_TRACE(ifname << ": added IPv4 broadcast address " << address);
+      }
+      else
+        NFD_LOG_WARN(ifname << ": inet_ntop(AF_INET) for broadaddr failed: " << strerror(errno));
+    }
+  }
+
   ::freeifaddrs(ifa_list);
 
-  std::list< shared_ptr<NetworkInterfaceInfo> > list;
-  BOOST_FOREACH(InterfacesMap::value_type elem, ifmap) {
-    list.push_back(elem.second);
+  std::vector<NetworkInterfaceInfo> v;
+  v.reserve(ifmap.size());
+  for (auto&& element : ifmap) {
+    v.push_back(element.second);
   }
 
-  return list;
+  return v;
 }
 
 } // namespace nfd
diff --git a/core/network-interface.hpp b/core/network-interface.hpp
index c5296a1..8519db1 100644
--- a/core/network-interface.hpp
+++ b/core/network-interface.hpp
@@ -28,10 +28,10 @@
 
 #include "common.hpp"
 
-#include <net/if.h>
-
 #include <ndn-cxx/util/ethernet.hpp>
 
+#include <net/if.h>
+
 namespace nfd {
 
 namespace ethernet = ndn::util::ethernet;
@@ -88,7 +88,7 @@
   return (flags & IFF_UP) != 0;
 }
 
-std::list< shared_ptr<NetworkInterfaceInfo> >
+std::vector<NetworkInterfaceInfo>
 listNetworkInterfaces();
 
 } // namespace nfd
diff --git a/daemon/face/ethernet-face.cpp b/daemon/face/ethernet-face.cpp
index 2fc24ab..ea9e522 100644
--- a/daemon/face/ethernet-face.cpp
+++ b/daemon/face/ethernet-face.cpp
@@ -49,12 +49,12 @@
 NFD_LOG_INIT("EthernetFace");
 
 EthernetFace::EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket,
-                           const shared_ptr<NetworkInterfaceInfo>& interface,
+                           const NetworkInterfaceInfo& interface,
                            const ethernet::Address& address)
-  : Face(FaceUri(address), FaceUri::fromDev(interface->name))
+  : Face(FaceUri(address), FaceUri::fromDev(interface.name))
   , m_socket(socket)
-  , m_interfaceName(interface->name)
-  , m_srcAddress(interface->etherAddress)
+  , m_interfaceName(interface.name)
+  , m_srcAddress(interface.etherAddress)
   , m_destAddress(address)
 {
   NFD_LOG_INFO("Creating ethernet face on " << m_interfaceName << ": "
diff --git a/daemon/face/ethernet-face.hpp b/daemon/face/ethernet-face.hpp
index 8f44eab..4383246 100644
--- a/daemon/face/ethernet-face.hpp
+++ b/daemon/face/ethernet-face.hpp
@@ -56,7 +56,7 @@
   };
 
   EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket,
-               const shared_ptr<NetworkInterfaceInfo>& interface,
+               const NetworkInterfaceInfo& interface,
                const ethernet::Address& address);
 
   virtual
diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp
index b96a0b4..314614e 100644
--- a/daemon/face/ethernet-factory.cpp
+++ b/daemon/face/ethernet-factory.cpp
@@ -35,14 +35,13 @@
 NFD_LOG_INIT("EthernetFactory");
 
 shared_ptr<EthernetFace>
-EthernetFactory::createMulticastFace(const shared_ptr<NetworkInterfaceInfo> &interface,
+EthernetFactory::createMulticastFace(const NetworkInterfaceInfo& interface,
                                      const ethernet::Address &address)
 {
   if (!address.isMulticast())
     throw Error(address.toString() + " is not a multicast address");
 
-  const std::string& name = interface->name;
-  shared_ptr<EthernetFace> face = findMulticastFace(name, address);
+  shared_ptr<EthernetFace> face = findMulticastFace(interface.name, address);
   if (face)
     return face;
 
@@ -51,8 +50,8 @@
 
   face = make_shared<EthernetFace>(socket, interface, address);
   face->onFail += bind(&EthernetFactory::afterFaceFailed,
-                       this, name, address);
-  m_multicastFaces[std::make_pair(name, address)] = face;
+                       this, interface.name, address);
+  m_multicastFaces[std::make_pair(interface.name, address)] = face;
 
   return face;
 }
diff --git a/daemon/face/ethernet-factory.hpp b/daemon/face/ethernet-factory.hpp
index f7f6588..b7d5ec0 100644
--- a/daemon/face/ethernet-factory.hpp
+++ b/daemon/face/ethernet-factory.hpp
@@ -72,7 +72,7 @@
    * \throws EthernetFactory::Error or EthernetFace::Error
    */
   shared_ptr<EthernetFace>
-  createMulticastFace(const shared_ptr<NetworkInterfaceInfo>& interface,
+  createMulticastFace(const NetworkInterfaceInfo& interface,
                       const ethernet::Address& address);
 
   /**
diff --git a/daemon/face/tcp-factory.cpp b/daemon/face/tcp-factory.cpp
index 792068b..bdc8c24 100644
--- a/daemon/face/tcp-factory.cpp
+++ b/daemon/face/tcp-factory.cpp
@@ -35,7 +35,6 @@
 TcpFactory::TcpFactory(const std::string& defaultPort/* = "6363"*/)
   : m_defaultPort(defaultPort)
 {
-
 }
 
 void
@@ -68,22 +67,11 @@
 {
   using namespace boost::asio::ip;
 
-  const std::list<shared_ptr<NetworkInterfaceInfo> > nicList(listNetworkInterfaces());
-
-  for (std::list<shared_ptr<NetworkInterfaceInfo> >::const_iterator i = nicList.begin();
-       i != nicList.end();
-       ++i)
-    {
-      const shared_ptr<NetworkInterfaceInfo>& nic = *i;
-      const std::vector<address_v4>& ipv4Addresses = nic->ipv4Addresses;
-
-      for (std::vector<address_v4>::const_iterator j = ipv4Addresses.begin();
-           j != ipv4Addresses.end();
-           ++j)
-        {
-          prohibitEndpoint(tcp::Endpoint(*j, port));
-        }
+  for (const NetworkInterfaceInfo& nic : listNetworkInterfaces()) {
+    for (const address_v4& addr : nic.ipv4Addresses) {
+      prohibitEndpoint(tcp::Endpoint(addr, port));
     }
+  }
 }
 
 void
@@ -91,29 +79,18 @@
 {
   using namespace boost::asio::ip;
 
-  const std::list<shared_ptr<NetworkInterfaceInfo> > nicList(listNetworkInterfaces());
-
-  for (std::list<shared_ptr<NetworkInterfaceInfo> >::const_iterator i = nicList.begin();
-       i != nicList.end();
-       ++i)
-    {
-      const shared_ptr<NetworkInterfaceInfo>& nic = *i;
-      const std::vector<address_v6>& ipv6Addresses = nic->ipv6Addresses;
-
-      for (std::vector<address_v6>::const_iterator j = ipv6Addresses.begin();
-           j != ipv6Addresses.end();
-           ++j)
-        {
-          prohibitEndpoint(tcp::Endpoint(*j, port));
-        }
+  for (const NetworkInterfaceInfo& nic : listNetworkInterfaces()) {
+    for (const address_v6& addr : nic.ipv6Addresses) {
+      prohibitEndpoint(tcp::Endpoint(addr, port));
     }
+  }
 }
 
 shared_ptr<TcpChannel>
 TcpFactory::createChannel(const tcp::Endpoint& endpoint)
 {
   shared_ptr<TcpChannel> channel = findChannel(endpoint);
-  if(static_cast<bool>(channel))
+  if (static_cast<bool>(channel))
     return channel;
 
   channel = make_shared<TcpChannel>(endpoint);
diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp
index d6954af..dcb819d 100644
--- a/daemon/face/udp-factory.cpp
+++ b/daemon/face/udp-factory.cpp
@@ -43,8 +43,6 @@
 {
 }
 
-
-
 void
 UdpFactory::prohibitEndpoint(const udp::Endpoint& endpoint)
 {
@@ -77,29 +75,18 @@
 
   static const address_v4 INVALID_BROADCAST(address_v4::from_string("0.0.0.0"));
 
-  const std::list<shared_ptr<NetworkInterfaceInfo> > nicList(listNetworkInterfaces());
-
-  for (std::list<shared_ptr<NetworkInterfaceInfo> >::const_iterator i = nicList.begin();
-       i != nicList.end();
-       ++i)
-    {
-      const shared_ptr<NetworkInterfaceInfo>& nic = *i;
-      const std::vector<address_v4>& ipv4Addresses = nic->ipv4Addresses;
-
-      for (std::vector<address_v4>::const_iterator j = ipv4Addresses.begin();
-           j != ipv4Addresses.end();
-           ++j)
-        {
-          prohibitEndpoint(udp::Endpoint(*j, port));
-        }
-
-      if (nic->isBroadcastCapable() && nic->broadcastAddress != INVALID_BROADCAST)
-        {
-          NFD_LOG_TRACE("prohibiting broadcast address: " << nic->broadcastAddress.to_string());
-          prohibitEndpoint(udp::Endpoint(nic->broadcastAddress, port));
-        }
+  for (const NetworkInterfaceInfo& nic : listNetworkInterfaces()) {
+    for (const address_v4& addr : nic.ipv4Addresses) {
+      prohibitEndpoint(udp::Endpoint(addr, port));
     }
 
+    if (nic.isBroadcastCapable() && nic.broadcastAddress != INVALID_BROADCAST)
+    {
+      NFD_LOG_TRACE("prohibiting broadcast address: " << nic.broadcastAddress.to_string());
+      prohibitEndpoint(udp::Endpoint(nic.broadcastAddress, port));
+    }
+  }
+
   prohibitEndpoint(udp::Endpoint(address::from_string("255.255.255.255"), port));
 }
 
@@ -108,35 +95,23 @@
 {
   using namespace boost::asio::ip;
 
-  const std::list<shared_ptr<NetworkInterfaceInfo> > nicList(listNetworkInterfaces());
-
-  for (std::list<shared_ptr<NetworkInterfaceInfo> >::const_iterator i = nicList.begin();
-       i != nicList.end();
-       ++i)
-    {
-      const shared_ptr<NetworkInterfaceInfo>& nic = *i;
-      const std::vector<address_v6>& ipv6Addresses = nic->ipv6Addresses;
-
-      for (std::vector<address_v6>::const_iterator j = ipv6Addresses.begin();
-           j != ipv6Addresses.end();
-           ++j)
-        {
-          prohibitEndpoint(udp::Endpoint(*j, port));
-        }
+  for (const NetworkInterfaceInfo& nic : listNetworkInterfaces()) {
+    for (const address_v6& addr : nic.ipv6Addresses) {
+      prohibitEndpoint(udp::Endpoint(addr, port));
     }
+  }
 }
 
 shared_ptr<UdpChannel>
 UdpFactory::createChannel(const udp::Endpoint& endpoint,
                           const time::seconds& timeout)
 {
-  NFD_LOG_DEBUG("Creating unicast " << endpoint);
+  NFD_LOG_DEBUG("Creating unicast channel " << endpoint);
 
   shared_ptr<UdpChannel> channel = findChannel(endpoint);
   if (static_cast<bool>(channel))
     return channel;
 
-
   //checking if the endpoint is already in use for multicast face
   shared_ptr<MulticastUdpFace> multicast = findMulticastFace(endpoint);
   if (static_cast<bool>(multicast))
@@ -161,8 +136,7 @@
                           const std::string& localPort,
                           const time::seconds& timeout)
 {
-  return createChannel(UdpResolver::syncResolve(localHost, localPort),
-                       timeout);
+  return createChannel(UdpResolver::syncResolve(localHost, localPort), timeout);
 }
 
 shared_ptr<MulticastUdpFace>
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index 712d096..c88329c 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -166,55 +166,53 @@
   bool hasSeenEther = false;
   bool hasSeenWebSocket = false;
 
-  const std::list<shared_ptr<NetworkInterfaceInfo> > nicList(listNetworkInterfaces());
+  const std::vector<NetworkInterfaceInfo> nicList(listNetworkInterfaces());
 
-  for (ConfigSection::const_iterator item = configSection.begin();
-       item != configSection.end();
-       ++item)
+  for (const auto& item : configSection)
     {
-      if (item->first == "unix")
+      if (item.first == "unix")
         {
           if (hasSeenUnix)
             throw Error("Duplicate \"unix\" section");
           hasSeenUnix = true;
 
-          processSectionUnix(item->second, isDryRun);
+          processSectionUnix(item.second, isDryRun);
         }
-      else if (item->first == "tcp")
+      else if (item.first == "tcp")
         {
           if (hasSeenTcp)
             throw Error("Duplicate \"tcp\" section");
           hasSeenTcp = true;
 
-          processSectionTcp(item->second, isDryRun);
+          processSectionTcp(item.second, isDryRun);
         }
-      else if (item->first == "udp")
+      else if (item.first == "udp")
         {
           if (hasSeenUdp)
             throw Error("Duplicate \"udp\" section");
           hasSeenUdp = true;
 
-          processSectionUdp(item->second, isDryRun, nicList);
+          processSectionUdp(item.second, isDryRun, nicList);
         }
-      else if (item->first == "ether")
+      else if (item.first == "ether")
         {
           if (hasSeenEther)
             throw Error("Duplicate \"ether\" section");
           hasSeenEther = true;
 
-          processSectionEther(item->second, isDryRun, nicList);
+          processSectionEther(item.second, isDryRun, nicList);
         }
-      else if (item->first == "websocket")
+      else if (item.first == "websocket")
         {
           if (hasSeenWebSocket)
             throw Error("Duplicate \"websocket\" section");
           hasSeenWebSocket = true;
 
-          processSectionWebSocket(item->second, isDryRun);
+          processSectionWebSocket(item.second, isDryRun);
         }
       else
         {
-          throw Error("Unrecognized option \"" + item->first + "\"");
+          throw Error("Unrecognized option \"" + item.first + "\"");
         }
     }
 }
@@ -342,7 +340,7 @@
           return;
         }
 
-      shared_ptr<TcpFactory> factory = ndn::make_shared<TcpFactory>(port);
+      shared_ptr<TcpFactory> factory = make_shared<TcpFactory>(port);
       m_factories.insert(std::make_pair("tcp", factory));
 
       if (enableV4)
@@ -376,7 +374,7 @@
 void
 FaceManager::processSectionUdp(const ConfigSection& configSection,
                                bool isDryRun,
-                               const std::list<shared_ptr<NetworkInterfaceInfo> >& nicList)
+                               const std::vector<NetworkInterfaceInfo>& nicList)
 {
   // ; the udp section contains settings of UDP faces and channels
   // udp
@@ -520,7 +518,7 @@
         factory = static_pointer_cast<UdpFactory>(m_factories["udp"]);
       }
       else {
-        factory = ndn::make_shared<UdpFactory>(port);
+        factory = make_shared<UdpFactory>(port);
         m_factories.insert(std::make_pair("udp", factory));
       }
 
@@ -547,25 +545,21 @@
 
       if (useMcast && enableV4)
         {
-          std::list<shared_ptr<NetworkInterfaceInfo> > ipv4MulticastInterfaces;
-          for (std::list<shared_ptr<NetworkInterfaceInfo> >::const_iterator i = nicList.begin();
-               i != nicList.end();
-               ++i)
+          std::vector<NetworkInterfaceInfo> ipv4MulticastInterfaces;
+          for (const auto& nic : nicList)
             {
-              const shared_ptr<NetworkInterfaceInfo>& nic = *i;
-              if (nic->isUp() && nic->isMulticastCapable() && !nic->ipv4Addresses.empty())
+              if (nic.isUp() && nic.isMulticastCapable() && !nic.ipv4Addresses.empty())
                 {
                   ipv4MulticastInterfaces.push_back(nic);
                 }
             }
 
           bool isNicNameNecessary = false;
-
 #if defined(__linux__)
           if (ipv4MulticastInterfaces.size() > 1)
             {
-              //On Linux, if we have more than one MulticastUdpFace we need to specify
-              //the name of the interface
+              // On Linux if we have more than one MulticastUdpFace
+              // we need to specify the name of the interface
               isNicNameNecessary = true;
             }
 #endif
@@ -579,18 +573,13 @@
               multicastFacesToRemove.push_back(i->second);
             }
 
-          for (std::list<shared_ptr<NetworkInterfaceInfo> >::const_iterator i =
-                 ipv4MulticastInterfaces.begin();
-               i != ipv4MulticastInterfaces.end();
-               ++i)
+          for (const auto& nic : ipv4MulticastInterfaces)
             {
-              const shared_ptr<NetworkInterfaceInfo>& nic = *i;
               shared_ptr<MulticastUdpFace> newFace;
-              newFace = factory->createMulticastFace(nic->ipv4Addresses[0].to_string(),
+              newFace = factory->createMulticastFace(nic.ipv4Addresses[0].to_string(),
                                                      mcastGroup,
                                                      mcastPort,
-                                                     isNicNameNecessary ? nic->name : "");
-
+                                                     isNicNameNecessary ? nic.name : "");
               addCreatedFaceToForwarder(newFace);
               multicastFacesToRemove.remove(newFace);
             }
@@ -628,7 +617,7 @@
 void
 FaceManager::processSectionEther(const ConfigSection& configSection,
                                  bool isDryRun,
-                                 const std::list<shared_ptr<NetworkInterfaceInfo> >& nicList)
+                                 const std::vector<NetworkInterfaceInfo>& nicList)
 {
   // ; the ether section contains settings of Ethernet faces and channels
   // ether
@@ -639,11 +628,8 @@
   // }
 
 #if defined(HAVE_LIBPCAP)
-
-  using ethernet::Address;
-
   bool useMcast = true;
-  Address mcastGroup(ethernet::getDefaultMulticastAddress());
+  ethernet::Address mcastGroup(ethernet::getDefaultMulticastAddress());
 
   for (ConfigSection::const_iterator i = configSection.begin();
        i != configSection.end();
@@ -656,7 +642,7 @@
 
       else if (i->first == "mcast_group")
         {
-          mcastGroup = Address::fromString(i->second.get_value<std::string>());
+          mcastGroup = ethernet::Address::fromString(i->second.get_value<std::string>());
           if (mcastGroup.isNull())
             {
               throw ConfigFile::Error("Invalid value for option \"" +
@@ -676,7 +662,7 @@
         factory = static_pointer_cast<EthernetFactory>(m_factories["ether"]);
       }
       else {
-        factory = ndn::make_shared<EthernetFactory>();
+        factory = make_shared<EthernetFactory>();
         m_factories.insert(std::make_pair("ether", factory));
       }
 
@@ -691,12 +677,9 @@
               multicastFacesToRemove.push_back(i->second);
             }
 
-          for (std::list<shared_ptr<NetworkInterfaceInfo> >::const_iterator i = nicList.begin();
-               i != nicList.end();
-               ++i)
+          for (const auto& nic : nicList)
             {
-              const shared_ptr<NetworkInterfaceInfo>& nic = *i;
-              if (nic->isUp() && nic->isMulticastCapable())
+              if (nic.isUp() && nic.isMulticastCapable())
                 {
                   try
                     {
@@ -825,7 +808,7 @@
           return;
         }
 
-      shared_ptr<WebSocketFactory> factory = ndn::make_shared<WebSocketFactory>(port);
+      shared_ptr<WebSocketFactory> factory = make_shared<WebSocketFactory>(port);
       m_factories.insert(std::make_pair("websocket", factory));
 
       if (enableV6 && enableV4)
@@ -1190,5 +1173,4 @@
     return shared_ptr<ProtocolFactory>();
 }
 
-
 } // namespace nfd
diff --git a/daemon/mgmt/face-manager.hpp b/daemon/mgmt/face-manager.hpp
index bb06f2b..d4d979b 100644
--- a/daemon/mgmt/face-manager.hpp
+++ b/daemon/mgmt/face-manager.hpp
@@ -60,7 +60,6 @@
   /**
    * \throws FaceManager::Error if localPort is an invalid port number
    */
-
   FaceManager(FaceTable& faceTable,
               shared_ptr<InternalFace> face,
               ndn::KeyChain& keyChain);
@@ -90,7 +89,6 @@
   findFactory(const std::string& protocol);
 
 PROTECTED_WITH_TESTS_ELSE_PRIVATE:
-
   void
   onValidatedFaceRequest(const shared_ptr<const Interest>& request);
 
@@ -150,12 +148,12 @@
   void
   processSectionUdp(const ConfigSection& configSection,
                     bool isDryRun,
-                    const std::list<shared_ptr<NetworkInterfaceInfo> >& nicList);
+                    const std::vector<NetworkInterfaceInfo>& nicList);
 
   void
   processSectionEther(const ConfigSection& configSection,
                       bool isDryRun,
-                      const std::list<shared_ptr<NetworkInterfaceInfo> >& nicList);
+                      const std::vector<NetworkInterfaceInfo>& nicList);
 
   void
   processSectionWebSocket(const ConfigSection& configSection, bool isDryRun);
@@ -170,8 +168,7 @@
              const std::string& sectionName);
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
-  typedef std::map< std::string/*protocol*/, shared_ptr<ProtocolFactory> > FactoryMap;
-
+  typedef std::map<std::string/*protocol*/, shared_ptr<ProtocolFactory>> FactoryMap;
   FactoryMap m_factories;
 
 private:
@@ -192,7 +189,6 @@
   typedef std::map<Name::Component, UnsignedVerbProcessor> UnsignedVerbDispatchTable;
   typedef std::pair<Name::Component, UnsignedVerbProcessor> UnsignedVerbAndProcessor;
 
-
   const SignedVerbDispatchTable m_signedVerbDispatch;
   const UnsignedVerbDispatchTable m_unsignedVerbDispatch;
 
@@ -239,7 +235,6 @@
   throw ConfigFile::Error("Invalid value for option \"" +
                           optionName + "\" in \"" +
                           sectionName + "\" section");
-
 }
 
 inline void
diff --git a/tests/core/network-interface.cpp b/tests/core/network-interface.cpp
index 2fb9c0b..5ac5a31 100644
--- a/tests/core/network-interface.cpp
+++ b/tests/core/network-interface.cpp
@@ -25,8 +25,6 @@
 #include "core/network-interface.hpp"
 #include "tests/test-common.hpp"
 
-#include <boost/foreach.hpp>
-
 namespace nfd {
 namespace tests {
 
@@ -34,20 +32,19 @@
 
 BOOST_AUTO_TEST_CASE(ListNetworkInterfaces)
 {
-  std::list< shared_ptr<NetworkInterfaceInfo> > netifs;
+  std::vector<NetworkInterfaceInfo> netifs;
   BOOST_CHECK_NO_THROW(netifs = listNetworkInterfaces());
 
-  BOOST_FOREACH(shared_ptr<NetworkInterfaceInfo> netif, netifs)
-  {
-    BOOST_TEST_MESSAGE(netif->index << ": " << netif->name);
-    BOOST_TEST_MESSAGE("\tether " << netif->etherAddress);
-    BOOST_FOREACH(boost::asio::ip::address_v4 address, netif->ipv4Addresses)
+  for (const auto& netif : netifs) {
+    BOOST_TEST_MESSAGE(netif.index << ": " << netif.name);
+    BOOST_TEST_MESSAGE("\tether " << netif.etherAddress);
+    for (const auto& address : netif.ipv4Addresses)
       BOOST_TEST_MESSAGE("\tinet  " << address);
-    BOOST_FOREACH(boost::asio::ip::address_v6 address, netif->ipv6Addresses)
+    for (const auto& address : netif.ipv6Addresses)
       BOOST_TEST_MESSAGE("\tinet6 " << address);
-    BOOST_TEST_MESSAGE("\tloopback  : " << netif->isLoopback());
-    BOOST_TEST_MESSAGE("\tmulticast : " << netif->isMulticastCapable());
-    BOOST_TEST_MESSAGE("\tup        : " << netif->isUp());
+    BOOST_TEST_MESSAGE("\tloopback  : " << netif.isLoopback());
+    BOOST_TEST_MESSAGE("\tmulticast : " << netif.isMulticastCapable());
+    BOOST_TEST_MESSAGE("\tup        : " << netif.isUp());
   }
 }
 
diff --git a/tests/daemon/face/ethernet.cpp b/tests/daemon/face/ethernet.cpp
index b5c0cc4..2f872f1 100644
--- a/tests/daemon/face/ethernet.cpp
+++ b/tests/daemon/face/ethernet.cpp
@@ -37,7 +37,7 @@
 {
   EthernetFactory factory;
 
-  std::list<shared_ptr<const Channel> > channels = factory.getChannels();
+  auto channels = factory.getChannels();
   BOOST_CHECK_EQUAL(channels.empty(), true);
 }
 
@@ -48,27 +48,22 @@
   {
     EthernetFactory factory;
 
-    std::list< shared_ptr<NetworkInterfaceInfo> > ifs = listNetworkInterfaces();
-    for (std::list< shared_ptr<NetworkInterfaceInfo> >::const_iterator i = ifs.begin();
-         i != ifs.end();
-         ++i)
-      {
-        if (!(*i)->isLoopback() && (*i)->isUp())
-          {
-            try {
-              factory.createMulticastFace(*i, ethernet::getBroadcastAddress());
-            }
-            catch (Face::Error&) {
-              continue;
-            }
+    for (const auto& netif : listNetworkInterfaces()) {
+      if (!netif.isLoopback() && netif.isUp()) {
+        try {
+          factory.createMulticastFace(netif, ethernet::getBroadcastAddress());
+        }
+        catch (Face::Error&) {
+          continue;
+        }
 
-            m_interfaces.push_back(*i);
-          }
+        m_interfaces.push_back(netif);
       }
+    }
   }
 
 protected:
-  std::list< shared_ptr<NetworkInterfaceInfo> > m_interfaces;
+  std::vector<NetworkInterfaceInfo> m_interfaces;
 };
 
 
@@ -88,17 +83,15 @@
                                                                   ethernet::getBroadcastAddress());
   BOOST_CHECK_EQUAL(face1, face1bis);
 
-  if (m_interfaces.size() > 1)
-    {
-      shared_ptr<EthernetFace> face2 = factory.createMulticastFace(m_interfaces.back(),
-                                                                   ethernet::getBroadcastAddress());
-      BOOST_CHECK_NE(face1, face2);
-    }
-  else
-    {
-      BOOST_WARN_MESSAGE(false, "Cannot test second EthernetFace creation, "
-                         "only one interface available");
-    }
+  if (m_interfaces.size() > 1) {
+    shared_ptr<EthernetFace> face2 = factory.createMulticastFace(m_interfaces.back(),
+                                                                 ethernet::getBroadcastAddress());
+    BOOST_CHECK_NE(face1, face2);
+  }
+  else {
+    BOOST_WARN_MESSAGE(false, "Cannot test second EthernetFace creation, "
+                       "only one interface available");
+  }
 
   shared_ptr<EthernetFace> face3 = factory.createMulticastFace(m_interfaces.front(),
                                      ethernet::getDefaultMulticastAddress());
@@ -117,15 +110,14 @@
 
   shared_ptr<EthernetFace> face = factory.createMulticastFace(m_interfaces.front(),
                                     ethernet::getDefaultMulticastAddress());
-
   BOOST_REQUIRE(static_cast<bool>(face));
 
   BOOST_CHECK(!face->isOnDemand());
   BOOST_CHECK_EQUAL(face->isLocal(), false);
   BOOST_CHECK_EQUAL(face->getRemoteUri().toString(),
-                    "ether://[" + ethernet::getDefaultMulticastAddress().toString()+"]");
+                    "ether://[" + ethernet::getDefaultMulticastAddress().toString() + "]");
   BOOST_CHECK_EQUAL(face->getLocalUri().toString(),
-                    "dev://" + m_interfaces.front()->name);
+                    "dev://" + m_interfaces.front().name);
 
   shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
   shared_ptr<Data>     data1     = makeData("ndn:/KfczhUqVix");
diff --git a/tests/daemon/face/tcp.cpp b/tests/daemon/face/tcp.cpp
index a391edc..99c2d5b 100644
--- a/tests/daemon/face/tcp.cpp
+++ b/tests/daemon/face/tcp.cpp
@@ -60,22 +60,16 @@
   TcpFactory factory;
   BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true);
 
-  std::vector<shared_ptr<const Channel> > expectedChannels;
+  std::vector<shared_ptr<const Channel>> expectedChannels;
   expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070"));
   expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071"));
   expectedChannels.push_back(factory.createChannel("::1", "20071"));
 
-  std::list<shared_ptr<const Channel> > channels = factory.getChannels();
-  for (std::list<shared_ptr<const Channel> >::const_iterator i = channels.begin();
-       i != channels.end(); ++i)
-    {
-      std::vector<shared_ptr<const Channel> >::iterator pos =
-        std::find(expectedChannels.begin(), expectedChannels.end(), *i);
-
-      BOOST_REQUIRE(pos != expectedChannels.end());
-      expectedChannels.erase(pos);
-    }
-
+  for (const auto& ch : factory.getChannels()) {
+    auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), ch);
+    BOOST_REQUIRE(pos != expectedChannels.end());
+    expectedChannels.erase(pos);
+  }
   BOOST_CHECK_EQUAL(expectedChannels.size(), 0);
 }
 
@@ -115,7 +109,6 @@
   factory.createFace(FaceUri("tcp4://127.0.0.1/path"),
                      bind(&FaceCreateFixture::ignore, this),
                      bind(&FaceCreateFixture::checkError, this, _1, "Invalid URI"));
-
 }
 
 class EndToEndFixture : protected BaseFixture
@@ -254,7 +247,7 @@
   std::vector<Interest> face2_receivedInterests;
   std::vector<Data> face2_receivedDatas;
 
-  std::list< shared_ptr<Face> > faces;
+  std::list<shared_ptr<Face>> faces;
 };
 
 BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture)
@@ -493,8 +486,6 @@
 }
 
 
-
-
 class SimpleEndToEndFixture : protected BaseFixture
 {
 public:
@@ -580,23 +571,17 @@
 {
   // tests with non-local Face
   std::string someIpv4Address;
-  std::list< shared_ptr<NetworkInterfaceInfo> > ifs = listNetworkInterfaces();
-  for (std::list< shared_ptr<NetworkInterfaceInfo> >::const_iterator i = ifs.begin();
-       i != ifs.end();
-       ++i)
-    {
-      if (!(*i)->isLoopback() && (*i)->isUp() && !(*i)->ipv4Addresses.empty())
-        {
-          someIpv4Address = (*i)->ipv4Addresses[0].to_string();
-          break;
-        }
+  for (const auto& netif : listNetworkInterfaces()) {
+    if (!netif.isLoopback() && netif.isUp() && !netif.ipv4Addresses.empty()) {
+      someIpv4Address = netif.ipv4Addresses[0].to_string();
+      break;
     }
-  if (someIpv4Address.empty())
-    {
-      BOOST_TEST_MESSAGE("Test with non-local Face cannot be run "
-                         "(no non-local interface with IPv4 address available)");
-      return;
-    }
+  }
+  if (someIpv4Address.empty()) {
+    BOOST_TEST_MESSAGE("Test with non-local Face cannot be run "
+                       "(no non-local interface with IPv4 address available)");
+    return;
+  }
 
   TcpFactory factory;
 
@@ -605,7 +590,6 @@
                   bind(&SimpleEndToEndFixture::onConnectFailed, this, _1));
   BOOST_REQUIRE_EQUAL(channel->isListening(), true);
 
-
   DummyStreamSender<boost::asio::ip::tcp, Dataset> sender;
   sender.start(Resolver<boost::asio::ip::tcp>::syncResolve(someIpv4Address, "20070"));
 
diff --git a/wscript b/wscript
index eb9ca79..8baa805 100644
--- a/wscript
+++ b/wscript
@@ -66,6 +66,9 @@
     conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
                    uselib_store='NDN_CXX', mandatory=True)
 
+    conf.checkDependency(name='librt', lib='rt', mandatory=False)
+    conf.checkDependency(name='libresolv', lib='resolv', mandatory=False)
+
     boost_libs = 'system chrono program_options random'
     if conf.options.with_tests:
         conf.env['WITH_TESTS'] = 1
@@ -85,9 +88,6 @@
     conf.load('unix-socket')
     conf.checkWebsocket(mandatory=True)
 
-    conf.checkDependency(name='librt', lib='rt', mandatory=False)
-    conf.checkDependency(name='libresolv', lib='resolv', mandatory=False)
-
     if not conf.options.without_libpcap:
         conf.check_asio_pcap_support()
         if conf.env['HAVE_ASIO_PCAP_SUPPORT']: