diff --git a/include/tins/ip.h b/include/tins/ip.h index 6d608ac..07e23e3 100644 --- a/include/tins/ip.h +++ b/include/tins/ip.h @@ -281,6 +281,10 @@ public: /* 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 b2165c1..212a973 100644 --- a/include/tins/pdu.h +++ b/include/tins/pdu.h @@ -281,6 +281,12 @@ public: */ 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 8328ece..832d6ea 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 &) { }