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*>(ðertype), ethernet::TYPE_LEN);
buffer.prependByteArray(m_srcAddress.data(), m_srcAddress.size());
buffer.prependByteArray(m_destAddress.data(), m_destAddress.size());