Kea  2.3.4-git
protocol_util.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2021 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef PROTOCOL_UTIL_H
8 #define PROTOCOL_UTIL_H
9 
10 #include <dhcp/pkt4.h>
11 #include <util/buffer.h>
12 
13 #include <stdint.h>
14 
15 namespace isc {
16 namespace dhcp {
17 
23 public:
24  InvalidPacketHeader(const char* file, size_t line, const char* what) :
25  isc::Exception(file, line, what) { };
26 };
27 
29 static const size_t ETHERNET_HEADER_LEN = 14;
32 static const size_t ETHERNET_PACKET_TYPE_OFFSET = 12;
40 static const uint16_t ETHERNET_TYPE_IP = 0x0800;
41 
43 static const size_t MIN_IP_HEADER_LEN = 20;
45 static const size_t IP_FLAGS_OFFSET = 6;
48 static const size_t IP_PROTO_TYPE_OFFSET = 9;
50 static const size_t IP_SRC_ADDR_OFFSET = 12;
52 static const size_t IP_DEST_ADDR_OFFSET = 16;
53 
55 static const size_t UDP_HEADER_LEN = 8;
57 static const size_t UDP_DEST_PORT = 2;
58 
77 
96 
105 void writeEthernetHeader(const Pkt4Ptr& pkt,
106  util::OutputBuffer& out_buf);
107 
121 void writeIpUdpHeader(const Pkt4Ptr& pkt, util::OutputBuffer& out_buf);
122 
142 uint16_t calcChecksum(const uint8_t* buf, const uint32_t buf_size,
143  uint32_t sum = 0);
144 
145 }
146 }
147 #endif // PROTOCOL_UTIL_H
void writeEthernetHeader(const Pkt4Ptr &pkt, OutputBuffer &out_buf)
Writes ethernet frame header into a buffer.
InvalidPacketHeader(const char *file, size_t line, const char *what)
Definition: protocol_util.h:24
uint16_t calcChecksum(const uint8_t *buf, const uint32_t buf_size, uint32_t sum)
Calculates checksum for provided buffer.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void decodeEthernetHeader(InputBuffer &buf, Pkt4Ptr &pkt)
Decode the Ethernet header.
void writeIpUdpHeader(const Pkt4Ptr &pkt, util::OutputBuffer &out_buf)
Writes both IP and UDP header into output buffer.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition: pkt4.h:544
Exception thrown when error occurred during parsing packet&#39;s headers.
Definition: protocol_util.h:22
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition: buffer.h:81
void decodeIpUdpHeader(InputBuffer &buf, Pkt4Ptr &pkt)
Decode IP and UDP header.