32                   const size_t transid_offset,
 
   33                   const uint32_t transid,
 
   39    out_buffer.
writeData(&in_buffer[0], in_buffer.size());
 
   41    uint8_t transid_len = (universe == 
Option::V6) ? 3 : 4;
 
   43    if ((transid_offset + transid_len >= in_buffer.size()) ||
 
   44        (transid_offset == 0)) {
 
   45        cout << 
"Failed to build packet: provided transaction id offset: " 
   46             << transid_offset <<  
" is out of bounds (expected 1.." 
   47             << in_buffer.size()-1 << 
")." << endl;
 
   52        size_t offset_ptr = transid_offset;
 
   54            out_buffer.
writeUint8At(transid >> 24 & 0xFF, offset_ptr++);
 
   56        out_buffer.
writeUint8At(transid >> 16 & 0xFF, offset_ptr++);
 
   57        out_buffer.
writeUint8At(transid >> 8 & 0xFF, offset_ptr++);
 
   63        PktTransform::packOptions(in_buffer, options, out_buffer);
 
   65        cout << 
"Building packet failed: " << e.
what() << endl;
 
 
   75                     const size_t transid_offset,
 
   78    uint8_t transid_len = (universe == 
Option::V6) ? 3 : 4;
 
   81    if ((transid_offset + transid_len + 1 > in_buffer.size()) ||
 
   82        (transid_offset == 0)) {
 
   83        cout << 
"Failed to parse packet: provided transaction id offset: " 
   84             << transid_offset <<  
" is out of bounds (expected 1.." 
   85             << in_buffer.size()-1 << 
")." << endl;
 
   94    for (
int i = 0; i < transid_len; ++i, ++it) {
 
   97        transid += *it << (transid_len - i - 1) * 8;
 
  101        PktTransform::unpackOptions(in_buffer, options);
 
  104        cout << 
"Packet parsing failed: " << e.
what() << endl;
 
 
  119        for (
auto const& it : options) {
 
  121            boost::shared_ptr<LocalizedOption> option =
 
  122                boost::dynamic_pointer_cast<LocalizedOption>(it.second);
 
  123            if (option == NULL) {
 
  126            uint32_t offset = option->getOffset();
 
  128                (offset + option->len() > in_buffer.size())) {
 
  130                          "option offset for option: " << option->getType()
 
  131                          << 
" is out of bounds (expected 1.." 
  132                          << in_buffer.size() - option->len() << 
")");
 
  142            const uint8_t *buf_data = buf.getData();
 
  143            for (
size_t i = 0; i < buf.getLength(); ++i) {
 
  147    } 
catch (
const Exception&) {
 
  148        isc_throw(isc::BadValue, 
"failed to pack options into buffer.");
 
  153PktTransform::unpackOptions(
const OptionBuffer& in_buffer,
 
  155    for (
auto const& it : options) {
 
  157        boost::shared_ptr<LocalizedOption> option =
 
  158            boost::dynamic_pointer_cast<LocalizedOption>(it.second);
 
  159        if (option == NULL) {
 
  160            isc_throw(isc::BadValue, 
"option is null");
 
  162        size_t opt_pos = option->getOffset();
 
  164            isc_throw(isc::BadValue, 
"failed to unpack packet from raw buffer " 
  165                      "(Option position not specified)");
 
  166        } 
else if (opt_pos + option->getHeaderLen() > in_buffer.size()) {
 
  168                      "failed to unpack options from from raw buffer " 
  169                      "(Option position out of bounds)");
 
  172        size_t offset = opt_pos;
 
  173        size_t offset_step = 1;
 
  174        uint16_t opt_type = 0;
 
  178            opt_type = in_buffer[offset] * 256 + in_buffer[offset + 1];
 
  181            opt_type = in_buffer[offset];
 
  184        if (opt_type != option->getType()) {
 
  186                      "failed to unpack option from raw buffer " 
  187                      "(option type mismatch)");
 
  191        offset += offset_step;
 
  192        const uint16_t opt_len =
 
  194            in_buffer[offset] * 256 + in_buffer[offset + 1] :
 
  198        if (offset + option->getHeaderLen() + opt_len > in_buffer.size()) {
 
  200                      "failed to unpack option from raw buffer " 
  201                      "(option truncated)");
 
  205        offset += offset_step;
 
  206        option->setData(in_buffer.begin() + offset,
 
  207                        in_buffer.begin() + offset + opt_len);
 
  213                      dhcp::OptionBuffer::iterator first,
 
  214                      dhcp::OptionBuffer::iterator last) {
 
  215    memcpy(&in_buffer[dest_pos], &(*first), std::distance(first, last));
 
 
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Universe
defines option universe DHCPv4 or DHCPv6
static int malformed_pkts_
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
void clear()
Clear buffer content.
void writeUint8At(uint8_t data, size_t position)
Write an unsigned 8-bit integer into the buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Defines the logger used by the top-level component of kea-lfc.