Commit 454afa98 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[2902] Defined constant replacing ETHERTYPE_IP.

The ETHERTYPE_IP is defined in different header files on different OSes.
Since it is just a single constant that is needed, it is not practical
to locate the proper header file in configure.ac to pull single constant.
parent 32931752
......@@ -16,7 +16,6 @@
#include <dhcp/dhcp6.h>
#include <dhcp/protocol_util.h>
#include <boost/static_assert.hpp>
#include <net/ethernet.h>
// in_systm.h is required on some some BSD systems
// complaining that n_time is undefined but used
// in ip.h.
......@@ -162,7 +161,7 @@ writeEthernetHeader(const Pkt4Ptr& pkt, OutputBuffer& out_buf) {
}
// Type IP.
out_buf.writeUint16(ETHERTYPE_IP);
out_buf.writeUint16(ETHERNET_TYPE_IP);
}
void
......
......@@ -38,6 +38,14 @@ static const size_t ETHERNET_HEADER_LEN = 14;
/// Offset of the 2-byte word in the Ethernet packet which
/// holds the type of the protocol it encapsulates.
static const size_t ETHERNET_PACKET_TYPE_OFFSET = 12;
/// This value is held in the Ethertype field of Ethernet frame
/// and indicates that an IP packet is encapsulated with this
/// frame. In the standard headers, there is an ETHERTYPE_IP,
/// constant which serves the same purpose. However, it is more
/// convenient to have our constant because we avoid
/// inclusion of additional headers, which have different names
/// and locations on different OSes.
static const uint16_t ETHERNET_TYPE_IP = 0x0800;
/// Minimal IPv4 header length.
static const size_t MIN_IP_HEADER_LEN = 20;
......
......@@ -85,7 +85,7 @@ TEST(ProtocolUtilTest, decodeEthernetHeader) {
OutputBuffer buf(1);
buf.writeData(dest_hw_addr, sizeof(dest_hw_addr));
buf.writeData(src_hw_addr, sizeof(src_hw_addr));
buf.writeUint16(0x800);
buf.writeUint16(ETHERNET_TYPE_IP);
// Append dummy data. We will later check that this data is not
// removed or corrupted when reading the ethernet header.
buf.writeUint32(0x01020304);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment