+++ /dev/null
-// Copyright (c) 2003-2010 Christopher M. Kohlhoff
-// Modifications (c) 2011 by Guilherme Maciel Ferreira / Intra2net AG
-//
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef CHECKSUM_HPP
-#define CHECKSUM_HPP
-
-#include <stdint.h>
-
-//-----------------------------------------------------------------------------
-// Checksum
-//-----------------------------------------------------------------------------
-
-/**
- * @brief Class that provides checksum calculation.
- */
-template<typename Iterator>
-class Checksum
-{
-public:
- Checksum(
- const Iterator &body_begin,
- const Iterator &body_end
- );
-
- // TODO common checksum
- // The <typename Message> must have a method which returns an array of words
- // this way the checksum calculator can be used with any ICMP, TCP, UDP...
- // uint16_t compute( const Message &message ) const
- // {
- // message.get_word_array() -> uint16_t *word_array
- //
- //
- uint16_t compute(
- uint8_t type,
- uint8_t code,
- uint16_t identifier,
- uint16_t sequence_number
- ) const;
-
-private:
- Iterator BodyBegin;
- Iterator BodyEnd;
-
-};
-
-template<typename Iterator>
- Checksum<Iterator>::Checksum(
- const Iterator &body_begin,
- const Iterator &body_end
- ) :
- BodyBegin( body_begin ),
- BodyEnd( body_end )
- {
- }
-
-template<typename Iterator>
- uint16_t Checksum<Iterator>::compute(
- uint8_t type,
- uint8_t code,
- uint16_t identifier,
- uint16_t sequence_number
- ) const
- {
- uint32_t sum = (type << 8) + code + identifier + sequence_number;
-
- Iterator body_iter = BodyBegin;
- while ( body_iter != BodyEnd )
- {
- sum += (static_cast<uint8_t>( *body_iter++ ) << 8);
- if ( body_iter != BodyEnd )
- sum += static_cast<uint8_t>( *body_iter++ );
- }
-
- sum = (sum >> 16) + (sum & 0xFFFF);
- sum += (sum >> 16);
-
- uint16_t checksum = static_cast<uint16_t>( ~sum );
-
- return checksum;
- }
-
-#endif // CHECKSUM_HPP
BOOST_ASSERT( current_byte_index == last_byte_index );
} //lint !e1762
+void MessagePayload::encode_string( const int first_byte_index,
+ const std::string value
+)
+{
+ int length = static_cast<int>(value.length());
+
+ BOOST_ASSERT( 0 < PayloadSizeInBytes );
+ BOOST_ASSERT( Payload.capacity() == PayloadSizeInBytes );
+ BOOST_ASSERT( ( 0 <= first_byte_index ) && ( first_byte_index < static_cast<int>(PayloadSizeInBytes) ) );
+ BOOST_ASSERT( first_byte_index +length < static_cast<int>(PayloadSizeInBytes) );
+
+ const uint8_t *data_converted = reinterpret_cast<const uint8_t *>(&value[0]);
+ for (int index=0; index<length; ++index)
+ Payload[first_byte_index + index] = data_converted[index];
+}
+
+
/**
* @brief Read/Extract all the data from the input stream @a is and stores it
* in the payload buffer.
return os;
}
+
+uint32_t MessagePayload::calc_checksum_part() const
+{
+ uint32_t sum = 0;
+
+ std::vector<uint8_t>::const_iterator iter = Payload.begin();
+ std::vector<uint8_t>::const_iterator end = Payload.end();
+ while ( iter != end )
+ {
+ sum += (static_cast<uint8_t>( *iter++ ) << 8);
+ if ( iter != end )
+ sum += static_cast<uint8_t>( *iter++ );
+ }
+
+ return sum;
+}
const int last_byte,
const uint32_t value
);
+ void encode_string( const int first_byte,
+ const std::string value
+ );
std::istream& read( std::istream &is );
std::ostream& write( std::ostream &os ) const;
+ uint32_t calc_checksum_part() const;
+
private:
/// The size of the payload buffer
std::size_t PayloadSizeInBytes;
+++ /dev/null
-// Copyright (c) 2003-2010 Christopher M. Kohlhoff
-// Modifications (c) 2011 by Guilherme Maciel Ferreira / Intra2net AG
-//
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef ICMP_CHECKSUM_H
-#define ICMP_CHECKSUM_H
-
-#include "host/checksum.hpp"
-#include "icmp/icmpdata.h"
-
-//-----------------------------------------------------------------------------
-// IcmpChecksum
-//-----------------------------------------------------------------------------
-
-typedef Checksum<IcmpData::const_iterator> IcmpChecksum;
-
-#endif // ICMP_CHECKSUM_H