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

Set ICMP payload length without padding if no extensions are present

This commit is contained in:
Matias Fontanini
2015-12-28 14:18:26 -03:00
parent 7a2ae6b7d5
commit afe778d03c

View File

@@ -212,7 +212,15 @@ void ICMP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *)
uint32_t length_value = get_adjusted_inner_pdu_size();
// If the next pdu size is greater than 128, we are forced to set the length field
if (length() != 0 || length_value > 128) {
length_value = length_value ? std::max(length_value, 128U) : 0;
if (length_value) {
// If we have extensions, we'll have at least 128 bytes.
// Otherwise, just use the length
length_value = has_extensions() ? std::max(length_value, 128U)
: length_value;
}
else {
length_value = 0;
}
// This field uses 32 bit words as the unit
_icmp.un.rfc4884.length = length_value / sizeof(uint32_t);
}