36 #include <tins/macros.h>
37 #include <tins/cxxstd.h>
38 #include <tins/exceptions.h>
45 class NetworkInterface;
186 USER_DEFINED_PDU = 1000
238 : inner_pdu_(0), parent_pdu_(0) {
239 std::swap(inner_pdu_, rhs.inner_pdu_);
241 inner_pdu_->parent_pdu(
this);
253 std::swap(inner_pdu_, rhs.inner_pdu_);
255 inner_pdu_->parent_pdu(
this);
285 uint32_t size()
const;
291 virtual uint32_t advertised_size()
const;
322 PDU* release_inner_pdu();
332 void inner_pdu(
PDU* next_pdu);
341 void inner_pdu(
const PDU& next_pdu);
352 serialization_type serialize();
367 return static_cast<T*
>(pdu);
381 return const_cast<PDU*
>(
this)->find_pdu<T>(type);
395 T* ptr = find_pdu<T>(type);
409 return const_cast<PDU*
>(
this)->rfind_pdu<T>(type);
461 virtual bool matches_response(
const uint8_t* ptr, uint32_t total_sz)
const;
472 return flag == pdu_type();
490 PDU& operator=(
const PDU& other);
496 void copy_inner_pdu(
const PDU& pdu);
509 virtual void prepare_for_serialize();
517 void serialize(uint8_t* buffer, uint32_t total_sz);
529 void parent_pdu(
PDU* parent);
585 namespace Internals {
597 template<
typename T,
typename U>
598 T tins_cast(U* pdu) {
599 typedef typename Internals::remove_pointer<T>::type TrueT;
600 return pdu && (TrueT::pdu_flag == pdu->pdu_type()) ?
601 static_cast<T
>(pdu) : 0;
604 template<
typename T,
typename U>
605 T& tins_cast(U& pdu) {
606 T* ptr = tins_cast<T*>(&pdu);
608 throw bad_tins_cast();
Represents an ARP PDU.
Definition: arp.h:50
Represents the DHCP PDU.
Definition: dhcp.h:67
Represents a DHCPv6 PDU.
Definition: dhcpv6.h:52
Represents a DNS PDU.
Definition: dns.h:85
Class representing an IEEE 802.3 PDU.
Definition: dot3.h:46
Represents the EAP encapsulation over LAN.
Definition: eapol.h:56
Class that represents an ICMP PDU.
Definition: icmp.h:65
Represents an ICMPv6 PDU.
Definition: icmpv6.h:58
Class that represents an IP PDU.
Definition: ip.h:63
Representing a LLC frame.
Definition: llc.h:47
Represents an MPLS PDU.
Definition: mpls.h:46
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
const T & rfind_pdu(PDUType type=T::pdu_flag) const
Finds and returns the first PDU that matches the given flag.
Definition: pdu.h:408
PDU * parent_pdu() const
Definition: pdu.h:305
PDU(PDU &&rhs) TINS_NOEXCEPT
Move constructor.
Definition: pdu.h:237
virtual uint32_t header_size() const =0
The header's size.
const T * find_pdu(PDUType type=T::pdu_flag) const
Finds and returns the first PDU that matches the given flag.
Definition: pdu.h:380
byte_array serialization_type
Definition: pdu.h:112
virtual void write_serialization(uint8_t *buffer, uint32_t total_sz)=0
Serializes this TCP PDU.
PDU & operator=(PDU &&rhs) TINS_NOEXCEPT
Move assignment operator.
Definition: pdu.h:250
PDUType
Enum which identifies each type of PDU.
Definition: pdu.h:127
virtual uint32_t trailer_size() const
Trailer's size.
Definition: pdu.h:277
virtual PDU * clone() const =0
Clones this packet.
virtual PDUType pdu_type() const =0
Getter for the PDU's type.
T * find_pdu(PDUType type=T::pdu_flag)
Finds and returns the first PDU that matches the given flag.
Definition: pdu.h:363
T & rfind_pdu(PDUType type=T::pdu_flag)
Finds and returns the first PDU that matches the given flag.
Definition: pdu.h:394
PDU * inner_pdu() const
Getter for the inner PDU.
Definition: pdu.h:297
virtual bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition: pdu.h:471
Sends packets through a network interface.
Definition: packet_sender.h:118
Class that represents the RC4 EAPOL PDU.
Definition: eapol.h:198
Class that represents the RSN EAPOL PDU.
Definition: eapol.h:397
Represents a RTP PDU.
Definition: rtp.h:19
Represents a Linux cooked-mode capture (SLL) PDU.
Definition: sll.h:45
Represents a SNAP frame.
Definition: snap.h:48
Represents a Spanning Tree Protocol PDU.
Definition: stp.h:44
Represents a TCP PDU.
Definition: tcp.h:76
Represents an UDP PDU.
Definition: udp.h:63
Represents a VXLAN PDU.
Definition: vxlan.h:17
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:45
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
T & operator/=(T &lop, const PDU &rop)
Concatenation operator.
Definition: pdu.h:554