PcapPlusPlus  19.12
UdpLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_UDP_LAYER
2 #define PACKETPP_UDP_LAYER
3 
4 #include "Layer.h"
5 
7 
12 namespace pcpp
13 {
14 
19 #pragma pack(push,1)
20  struct udphdr {
22  uint16_t portSrc;
24  uint16_t portDst;
26  uint16_t length;
28  uint16_t headerChecksum;
29  };
30 #pragma pack(pop)
31 
32 
37  class UdpLayer : public Layer
38  {
39  public:
47  UdpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = UDP; }
48 
54  UdpLayer(uint16_t portSrc, uint16_t portDst);
55 
60  udphdr* getUdpHeader() const { return (udphdr*)m_Data; }
61 
67  uint16_t calculateChecksum(bool writeResultToPacket);
68 
69  // implement abstract methods
70 
75  void parseNextLayer();
76 
80  size_t getHeaderLen() const { return sizeof(udphdr); }
81 
86 
87  std::string toString() const;
88 
90  };
91 
92 } // namespace pcpp
93 
94 #endif /* PACKETPP_UDP_LAYER */
pcpp::OsiModelLayer
OsiModelLayer
Definition: ProtocolType.h:224
pcpp::Packet
Definition: Packet.h:26
pcpp::udphdr
Definition: UdpLayer.h:20
pcpp::udphdr::portSrc
uint16_t portSrc
Definition: UdpLayer.h:22
Layer.h
pcpp::UdpLayer::toString
std::string toString() const
pcpp::UdpLayer::computeCalculateFields
void computeCalculateFields()
pcpp::UdpLayer::getHeaderLen
size_t getHeaderLen() const
Definition: UdpLayer.h:80
pcpp::UdpLayer::UdpLayer
UdpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: UdpLayer.h:47
pcpp::UdpLayer
Definition: UdpLayer.h:37
pcpp::UdpLayer::calculateChecksum
uint16_t calculateChecksum(bool writeResultToPacket)
pcpp::OsiModelTransportLayer
Definition: ProtocolType.h:233
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::UdpLayer::getOsiModelLayer
OsiModelLayer getOsiModelLayer() const
Definition: UdpLayer.h:89
pcpp::Layer
Definition: Layer.h:70
pcpp::UdpLayer::getUdpHeader
udphdr * getUdpHeader() const
Definition: UdpLayer.h:60
pcpp::udphdr::headerChecksum
uint16_t headerChecksum
Definition: UdpLayer.h:28
pcpp::UDP
Definition: ProtocolType.h:51
pcpp::udphdr::length
uint16_t length
Definition: UdpLayer.h:26
pcpp::udphdr::portDst
uint16_t portDst
Definition: UdpLayer.h:24
pcpp::UdpLayer::parseNextLayer
void parseNextLayer()