diff --git a/include/tins/ip.h b/include/tins/ip.h index 6d608ac0..07e23e35 100644 --- a/include/tins/ip.h +++ b/include/tins/ip.h @@ -281,6 +281,10 @@ class TINS_API IP : public PDU { /* Getters */ + uint32_t advertised_size() const { + return static_cast(tot_len()); + } + /** * \brief Getter for the header length field. * diff --git a/include/tins/pdu.h b/include/tins/pdu.h index b2165c19..212a9737 100644 --- a/include/tins/pdu.h +++ b/include/tins/pdu.h @@ -281,6 +281,12 @@ class TINS_API PDU { */ uint32_t size() const; + /** \brief The whole chain of PDU's advertised size, including this one. + * + * Returns the sum of this and all children PDU's advertised size. + */ + virtual uint32_t advertised_size() const; + /** * \brief Getter for the inner PDU. * \return The current inner PDU. Might be a null pointer. diff --git a/src/pdu.cpp b/src/pdu.cpp index 8328ece2..832d6eab 100644 --- a/src/pdu.cpp +++ b/src/pdu.cpp @@ -85,6 +85,14 @@ uint32_t PDU::size() const { return sz; } +uint32_t PDU::advertised_size() const { + uint32_t result = header_size() + trailer_size(); + if (inner_pdu_) { + result += inner_pdu()->advertised_size(); + } + return result; +} + void PDU::send(PacketSender &, const NetworkInterface &) { }