1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-29 13:04:28 +01:00

Calculate IP option sizes properly

Fixes #288
This commit is contained in:
Matias Fontanini
2018-04-08 08:12:52 -07:00
parent fa79582b89
commit 63603b8ac8
2 changed files with 36 additions and 2 deletions

View File

@@ -321,7 +321,12 @@ void IP::add_option(const option& opt) {
uint32_t IP::calculate_options_size() const {
uint32_t options_size = 0;
for (options_type::const_iterator iter = options_.begin(); iter != options_.end(); ++iter) {
options_size += 1 + iter->data_size();
options_size += sizeof(uint8_t);
const option_identifier option_id = iter->option();
// Only add length field and data size for non [NOOP, EOL] options
if (option_id.op_class != CONTROL || option_id.number > NOOP) {
options_size += sizeof(uint8_t) + iter->data_size();
}
}
return options_size;
}