]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2902] Defined constant replacing ETHERTYPE_IP.
authorMarcin Siodelski <marcin@isc.org>
Wed, 22 May 2013 18:07:12 +0000 (20:07 +0200)
committerMarcin Siodelski <marcin@isc.org>
Wed, 22 May 2013 18:07:12 +0000 (20:07 +0200)
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.

src/lib/dhcp/protocol_util.cc
src/lib/dhcp/protocol_util.h
src/lib/dhcp/tests/protocol_util_unittest.cc

index a57311da3e421ae511ac317c3110d3f920652dfc..d93f8c4954d546ec3ec9d740a68aa6ee190d1ac2 100644 (file)
@@ -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
index 582938e207d415eeef1f5a5333843f5264229db7..b3f8085f5a0b970eaace52f5ca02f76b0c08b0ee 100644 (file)
@@ -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;
index 61bb6f6753a186b3885d37c1ca5fe5e2fd0eb6d4..eee98e6d4f903ee2b110d6e7708bfb78939167a8 100644 (file)
@@ -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);