From 584fe81f048b5b9d0f1e32e4cf1290ebb6185d07 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 23 Mar 2013 13:44:33 -0300 Subject: [PATCH] Optimized TCP, IP and PDUOption<>. --- include/ip.h | 2 +- include/pdu_option.h | 16 +++++++--------- include/tcp.h | 2 +- src/tcp.cpp | 3 ++- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/ip.h b/include/ip.h index 688f892..f6b13f6 100644 --- a/include/ip.h +++ b/include/ip.h @@ -627,8 +627,8 @@ namespace Tins { generic_route_option_type search_route_option(option_identifier id) const; iphdr _ip; + uint16_t _options_size, _padded_options_size; options_type _ip_options; - uint32_t _options_size, _padded_options_size; }; } diff --git a/include/pdu_option.h b/include/pdu_option.h index 36b4ae9..6eaf8d8 100644 --- a/include/pdu_option.h +++ b/include/pdu_option.h @@ -75,10 +75,8 @@ public: * \param data The option's data(if any). */ PDUOption(option_type opt = option_type(), size_t length = 0, const data_type *data = 0) - : option_(opt) { - value_.push_back(length); - if(data) - value_.insert(value_.end(), data, data + length); + : option_(opt), size_(length), value_(data, data + (data ? length : 0)) { + } /** @@ -91,9 +89,8 @@ public: */ template PDUOption(option_type opt, ForwardIterator start, ForwardIterator end) - : option_(opt) { - value_.push_back(std::distance(start, end)); - value_.insert(value_.end(), start, end); + : option_(opt), size_(std::distance(start, end)), value_(start, end) { + } /** @@ -122,17 +119,18 @@ public: * \return const data_type& containing this option's value. */ const data_type *data_ptr() const { - return &*(++value_.begin()); + return &*value_.begin(); } /** * Retrieves the length of this option's data. */ size_t data_size() const { - return value_.empty() ? 0 : (value_.size() - 1); + return size_; } private: option_type option_; + uint16_t size_; container_type value_; }; } // namespace Tins diff --git a/include/tcp.h b/include/tcp.h index 246007a..0cece7c 100644 --- a/include/tcp.h +++ b/include/tcp.h @@ -443,8 +443,8 @@ namespace Tins { uint8_t *write_option(const tcp_option &opt, uint8_t *buffer); tcphdr _tcp; + uint16_t _options_size, _total_options_size; options_type _options; - uint32_t _options_size, _total_options_size; }; } diff --git a/src/tcp.cpp b/src/tcp.cpp index 65e9317..6efb6bc 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -264,7 +264,8 @@ void TCP::set_flag(Flags tcp_flag, small_uint<1> value) { void TCP::add_option(Option option, uint8_t length, const uint8_t *data) { uint8_t padding; - _options.push_back(tcp_option(option, length, data)); + //_options.push_back(tcp_option(option, length, data)); + _options.push_back(tcp_option(option, data, data + length)); _options_size += sizeof(uint8_t); // SACK_OK contains length but not data....