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

TCP options now use PDUOption<>::length_field when it is != from data_size.

This commit is contained in:
Matias Fontanini
2013-04-10 18:44:00 -03:00
parent fee938b46d
commit 1fbef641da
2 changed files with 14 additions and 10 deletions

View File

@@ -101,6 +101,8 @@ public:
* when this option is serialized. Note that this can be different * when this option is serialized. Note that this can be different
* to std::distance(start, end). * to std::distance(start, end).
* *
* \sa length_field
*
* \param opt The option type. * \param opt The option type.
* \param length The length of this option. * \param length The length of this option.
* \param start The beginning of the option data. * \param start The beginning of the option data.
@@ -153,12 +155,12 @@ public:
/** /**
* \brief Retrieves the data length field. * \brief Retrieves the data length field.
* *
* This may be different to the actual size of the data. Note that * This is what the size field will contain when this option is
* in some protocols, such as TCP, the size of the length and the * serialized. It can differ from the actual data size.
* identifier fields is added to this field before serializing. *
* Therefore, if on one of such protocols, an option's length_field * This will be equal to data_size unless the constructor that takes
* returns X, then the actual length included in the serialized * both a data length and two iterators is used.
* option will be X + C, where C is the size of those fields.
* *
* \sa data_size. * \sa data_size.
*/ */

View File

@@ -346,10 +346,12 @@ uint8_t *TCP::write_option(const option &opt, uint8_t *buffer) {
} }
else { else {
buffer[0] = opt.option(); buffer[0] = opt.option();
buffer[1] = opt.length_field() + (sizeof(uint8_t) << 1); buffer[1] = opt.length_field();
if(opt.data_size() != 0) // only add the identifier and size field sizes if the length
std::copy(opt.data_ptr(), opt.data_ptr() + opt.data_size(), buffer + 2); // field hasn't been spoofed.
return buffer + opt.data_size() + (sizeof(uint8_t) << 1); if(opt.length_field() == opt.data_size())
buffer[1] += (sizeof(uint8_t) << 1);
return std::copy(opt.data_ptr(), opt.data_ptr() + opt.data_size(), buffer + 2);
} }
} }