36#include <tins/macros.h>
37#include <tins/cxxstd.h>
38#include <tins/exceptions.h>
185 USER_DEFINED_PDU = 1000
237 : inner_pdu_(0), parent_pdu_(0) {
238 std::swap(inner_pdu_, rhs.inner_pdu_);
240 inner_pdu_->parent_pdu(
this);
252 std::swap(inner_pdu_, rhs.inner_pdu_);
254 inner_pdu_->parent_pdu(
this);
284 uint32_t size()
const;
290 virtual uint32_t advertised_size()
const;
321 PDU* release_inner_pdu();
331 void inner_pdu(
PDU* next_pdu);
340 void inner_pdu(
const PDU& next_pdu);
351 serialization_type serialize();
366 return static_cast<T*
>(pdu);
516 void serialize(uint8_t* buffer, uint32_t total_sz);
596template<
typename T,
typename U>
598 typedef typename Internals::remove_pointer<T>::type TrueT;
599 return pdu && (TrueT::pdu_flag == pdu->pdu_type()) ?
600 static_cast<T
>(pdu) : 0;
603template<
typename T,
typename U>
604T& tins_cast(U& pdu) {
605 T* ptr = tins_cast<T*>(&pdu);
607 throw bad_tins_cast();
Abstraction of a network interface.
Definition network_interface.h:47
Base class for protocol data units.
Definition pdu.h:107
endian_type
Definition pdu.h:117
static const endian_type endianness
Definition pdu.h:192
PDU()
Default constructor.
Definition pdu.cpp:50
void copy_inner_pdu(const PDU &pdu)
Copy other PDU's inner PDU(if any).
Definition pdu.cpp:69
PDU(PDU &&rhs) TINS_NOEXCEPT
Move constructor.
Definition pdu.h:236
virtual uint32_t header_size() const =0
The header's size.
virtual PDU * clone() const =0
Clones this packet.
byte_array serialization_type
Definition pdu.h:112
virtual void write_serialization(uint8_t *buffer, uint32_t total_sz)=0
Serializes this TCP PDU.
virtual void prepare_for_serialize()
Prepares this PDU for serialization.
Definition pdu.cpp:75
PDUType
Enum which identifies each type of PDU.
Definition pdu.h:127
PDU * parent_pdu() const
Definition pdu.h:304
const T * find_pdu(PDUType type=T::pdu_flag) const
Finds and returns the first PDU that matches the given flag.
Definition pdu.h:379
virtual uint32_t trailer_size() const
Trailer's size.
Definition pdu.h:276
T * find_pdu(PDUType type=T::pdu_flag)
Finds and returns the first PDU that matches the given flag.
Definition pdu.h:362
T & rfind_pdu(PDUType type=T::pdu_flag)
Finds and returns the first PDU that matches the given flag.
Definition pdu.h:393
virtual PDUType pdu_type() const =0
Getter for the PDU's type.
serialization_type serialize()
Serializes the whole chain of PDU's, including this one.
Definition pdu.cpp:129
const T & rfind_pdu(PDUType type=T::pdu_flag) const
Finds and returns the first PDU that matches the given flag.
Definition pdu.h:407
PDU * inner_pdu() const
Getter for the inner PDU.
Definition pdu.h:296
virtual PDU * recv_response(PacketSender &sender, const NetworkInterface &iface)
Receives a matching response for this packet.
Definition pdu.cpp:100
virtual bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition pdu.h:470
PDU & operator=(PDU &&rhs) TINS_NOEXCEPT
Move assignment operator.
Definition pdu.h:249
virtual bool matches_response(const uint8_t *ptr, uint32_t total_sz) const
Check whether ptr points to a valid response for this PDU.
Definition pdu.cpp:104
virtual void send(PacketSender &sender, const NetworkInterface &iface)
Send the stack of PDUs through a PacketSender.
Definition pdu.cpp:96
Sends packets through a network interface.
Definition packet_sender.h:118
Exception thrown when a PDU is not found when using PDU::rfind_pdu.
Definition exceptions.h:98
The Tins namespace.
Definition address_range.h:38
std::vector< uint8_t > byte_array
Definition pdu.h:50
T & operator/=(T &lop, const PDU &rop)
Concatenation operator.
Definition pdu.h:553
AddressRange< HWAddress< n > > operator/(const HWAddress< n > &addr, int mask)
Constructs an AddressRange from a base address and a mask.
Definition address_range.h:308