Skip to content

Commit 2499638

Browse files
committed
add advertised_size method
1 parent 776ae4e commit 2499638

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

include/tins/ip.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ class TINS_API IP : public PDU {
281281

282282
/* Getters */
283283

284+
uint32_t advertised_size() const {
285+
return static_cast<uint32_t>(tot_len());
286+
}
287+
284288
/**
285289
* \brief Getter for the header length field.
286290
*

include/tins/pdu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ class TINS_API PDU {
281281
*/
282282
uint32_t size() const;
283283

284+
/** \brief The whole chain of PDU's advertised size, including this one.
285+
*
286+
* Returns the sum of this and all children PDU's advertised size.
287+
*/
288+
virtual uint32_t advertised_size() const;
289+
284290
/**
285291
* \brief Getter for the inner PDU.
286292
* \return The current inner PDU. Might be a null pointer.

src/pdu.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ uint32_t PDU::size() const {
8585
return sz;
8686
}
8787

88+
uint32_t PDU::advertised_size() const {
89+
return header_size() + trailer_size() + inner_pdu()->advertised_size();
90+
}
91+
8892
void PDU::send(PacketSender &, const NetworkInterface &) {
8993

9094
}

0 commit comments

Comments
 (0)