1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Optimized TCP, IP and PDUOption<>.

This commit is contained in:
Matias Fontanini
2013-03-23 13:44:33 -03:00
parent 16a99ef35b
commit 584fe81f04
4 changed files with 11 additions and 12 deletions

View File

@@ -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;
};
}

View File

@@ -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<typename ForwardIterator>
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

View File

@@ -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;
};
}

View File

@@ -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....