Kea 2.7.6
protocol_util.h
Go to the documentation of this file.
1// Copyright (C) 2013-2024 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
15namespace isc {
16namespace dhcp {
17
23public:
24 InvalidPacketHeader(const char* file, size_t line, const char* what) :
25 isc::Exception(file, line, what) { }
26};
27
29static const size_t ETHERNET_HEADER_LEN = 14;
32static const size_t ETHERNET_PACKET_TYPE_OFFSET = 12;
40static const uint16_t ETHERNET_TYPE_IP = 0x0800;
41
43static const size_t MIN_IP_HEADER_LEN = 20;
45static const size_t IP_FLAGS_OFFSET = 6;
48static const size_t IP_PROTO_TYPE_OFFSET = 9;
50static const size_t IP_SRC_ADDR_OFFSET = 12;
52static const size_t IP_DEST_ADDR_OFFSET = 16;
53
55static const size_t UDP_HEADER_LEN = 8;
57static const size_t UDP_DEST_PORT = 2;
58
77
96
105void writeEthernetHeader(const Pkt4Ptr& pkt,
106 util::OutputBuffer& out_buf);
107
121void writeIpUdpHeader(const Pkt4Ptr& pkt, util::OutputBuffer& out_buf);
122
142uint16_t calcChecksum(const uint8_t* buf, const uint32_t buf_size,
143 uint32_t sum = 0);
144
145}
146}
147#endif // PROTOCOL_UTIL_H
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Exception thrown when error occurred during parsing packet's headers.
InvalidPacketHeader(const char *file, size_t line, const char *what)
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition buffer.h:81
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:343
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition pkt4.h:555
void decodeEthernetHeader(InputBuffer &buf, Pkt4Ptr &pkt)
Decode the Ethernet header.
void writeEthernetHeader(const Pkt4Ptr &pkt, OutputBuffer &out_buf)
Writes ethernet frame header into a buffer.
void decodeIpUdpHeader(InputBuffer &buf, Pkt4Ptr &pkt)
Decode IP and UDP header.
uint16_t calcChecksum(const uint8_t *buf, const uint32_t buf_size, uint32_t sum)
Calculates checksum for provided buffer.
void writeIpUdpHeader(const Pkt4Ptr &pkt, util::OutputBuffer &out_buf)
Writes both IP and UDP header into output buffer.
Defines the logger used by the top-level component of kea-lfc.