Skip to content

Commit

Permalink
add advertised_size method
Browse files Browse the repository at this point in the history
  • Loading branch information
pepper-jk committed Jan 22, 2019
1 parent 776ae4e commit 2a8101e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/tins/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ class TINS_API IP : public PDU {

/* Getters */

uint32_t advertised_size() const {
return static_cast<uint32_t>(tot_len());
}

/**
* \brief Getter for the header length field.
*
Expand Down
6 changes: 6 additions & 0 deletions include/tins/pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions src/pdu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &) {

}
Expand Down

0 comments on commit 2a8101e

Please sign in to comment.