face+tools: use Boost.Endian for endianness conversions

Change-Id: Ia9c8777cc16130ace9f1ca478624d71e6a11fadd
diff --git a/daemon/face/ethernet-protocol.cpp b/daemon/face/ethernet-protocol.cpp
index 2ec0bb7..e5e9a69 100644
--- a/daemon/face/ethernet-protocol.cpp
+++ b/daemon/face/ethernet-protocol.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -25,7 +25,7 @@
 
 #include "ethernet-protocol.hpp"
 
-#include <arpa/inet.h>  // for ntohs()
+#include <boost/endian/conversion.hpp>
 
 namespace nfd {
 namespace ethernet {
@@ -41,8 +41,9 @@
 
   // in some cases VLAN-tagged frames may survive the BPF filter,
   // make sure we do not process those frames (see #3348)
-  if (ntohs(eh->ether_type) != ETHERTYPE_NDN)
-    return {nullptr, "Received frame with wrong ethertype: " + to_string(ntohs(eh->ether_type))};
+  uint16_t ethertype = boost::endian::big_to_native(eh->ether_type);
+  if (ethertype != ETHERTYPE_NDN)
+    return {nullptr, "Received frame with wrong ethertype: " + to_string(ethertype)};
 
 #ifdef _DEBUG
   Address shost(eh->ether_shost);
diff --git a/daemon/face/ethernet-transport.cpp b/daemon/face/ethernet-transport.cpp
index e2ba043..7d1f7cb 100644
--- a/daemon/face/ethernet-transport.cpp
+++ b/daemon/face/ethernet-transport.cpp
@@ -29,8 +29,9 @@
 
 #include <pcap/pcap.h>
 
-#include <arpa/inet.h>  // for htons()
-#include <cstring>      // for memcpy()
+#include <cstring> // for memcpy()
+
+#include <boost/endian/conversion.hpp>
 
 namespace nfd {
 namespace face {
@@ -101,7 +102,7 @@
   }
 
   // construct and prepend the ethernet header
-  static uint16_t ethertype = htons(ethernet::ETHERTYPE_NDN);
+  uint16_t ethertype = boost::endian::native_to_big(ethernet::ETHERTYPE_NDN);
   buffer.prependByteArray(reinterpret_cast<const uint8_t*>(&ethertype), ethernet::TYPE_LEN);
   buffer.prependByteArray(m_srcAddress.data(), m_srcAddress.size());
   buffer.prependByteArray(m_destAddress.data(), m_destAddress.size());
diff --git a/tools/ndn-autoconfig/dns-srv.cpp b/tools/ndn-autoconfig/dns-srv.cpp
index f432e2c..f099295 100644
--- a/tools/ndn-autoconfig/dns-srv.cpp
+++ b/tools/ndn-autoconfig/dns-srv.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2017,  Regents of the University of California,
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -26,9 +26,9 @@
 #include "dns-srv.hpp"
 
 #include <sys/types.h>
+#include <arpa/nameser.h>
 #include <netinet/in.h>
 #include <resolv.h>
-#include <arpa/nameser.h>
 
 #ifdef __APPLE__
 #include <arpa/nameser_compat.h>
@@ -36,10 +36,14 @@
 
 #include <iostream>
 
+#include <boost/endian/conversion.hpp>
+
 namespace ndn {
 namespace tools {
 namespace autoconfig {
 
+using namespace std::string_literals;
+
 union QueryAnswer
 {
   HEADER header;
@@ -72,12 +76,12 @@
     uint8_t* target;
   };
 
-  if (ntohs(queryAnswer.header.ancount) == 0) {
+  uint16_t ancount = queryAnswer.header.ancount;
+  if (boost::endian::big_to_native(ancount) == 0) {
     BOOST_THROW_EXCEPTION(DnsSrvError("SRV record cannot be parsed"));
   }
 
   const uint8_t* blob = queryAnswer.buf + NS_HFIXEDSZ;
-
   blob += dn_skipname(blob, queryAnswer.buf + answerSize) + NS_QFIXEDSZ;
 
   char srvName[NS_MAXDNAME];
@@ -91,7 +95,7 @@
   }
 
   const srv_t* server = reinterpret_cast<const srv_t*>(&blob[sizeof(rechdr)]);
-  uint16_t convertedPort = be16toh(server->port);
+  uint16_t port = boost::endian::big_to_native(server->port);
 
   blob += serverNameSize + NS_HFIXEDSZ + NS_QFIXEDSZ;
 
@@ -105,12 +109,7 @@
     BOOST_THROW_EXCEPTION(DnsSrvError("SRV record cannot be parsed (error decoding host name)"));
   }
 
-  std::string uri = "udp://";
-  uri.append(hostName);
-  uri.append(":");
-  uri.append(to_string(convertedPort));
-
-  return uri;
+  return "udp://"s + hostName + ":" + to_string(port);
 }
 
 std::string