PcapPlusPlus  22.11
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
21  {
23  uint16_t portSrc;
25  uint16_t portDst;
27  uint16_t length;
29  uint16_t headerChecksum;
30  };
31 #pragma pack(pop)
32 
33 
38  class UdpLayer : public Layer
39  {
40  public:
48  UdpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = UDP; }
49 
55  UdpLayer(uint16_t portSrc, uint16_t portDst);
56 
61  udphdr* getUdpHeader() const { return (udphdr*)m_Data; }
62 
66  uint16_t getSrcPort() const;
67 
71  uint16_t getDstPort() const;
72 
78  uint16_t calculateChecksum(bool writeResultToPacket);
79 
80  // implement abstract methods
81 
86  void parseNextLayer();
87 
91  size_t getHeaderLen() const { return sizeof(udphdr); }
92 
96  void computeCalculateFields();
97 
98  std::string toString() const;
99 
101  };
102 
103 } // namespace pcpp
104 
105 #endif /* PACKETPP_UDP_LAYER */
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:298
uint16_t portSrc
Definition: UdpLayer.h:23
const ProtocolType UDP
Definition: ProtocolType.h:53
Definition: UdpLayer.h:20
Definition: Layer.h:70
Definition: Packet.h:26
Definition: UdpLayer.h:38
size_t getHeaderLen() const
Definition: UdpLayer.h:91
udphdr * getUdpHeader() const
Definition: UdpLayer.h:61
Definition: ProtocolType.h:307
uint16_t length
Definition: UdpLayer.h:27
uint16_t portDst
Definition: UdpLayer.h:25
UdpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: UdpLayer.h:48
OsiModelLayer getOsiModelLayer() const
Definition: UdpLayer.h:100
uint16_t headerChecksum
Definition: UdpLayer.h:29