PcapPlusPlus  21.05
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 
65  uint16_t getSrcPort() const;
66 
70  uint16_t getDstPort() const;
71 
77  uint16_t calculateChecksum(bool writeResultToPacket);
78 
79  // implement abstract methods
80 
85  void parseNextLayer();
86 
90  size_t getHeaderLen() const { return sizeof(udphdr); }
91 
95  void computeCalculateFields();
96 
97  std::string toString() const;
98 
100  };
101 
102 } // namespace pcpp
103 
104 #endif /* PACKETPP_UDP_LAYER */
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:253
uint16_t portSrc
Definition: UdpLayer.h:22
const ProtocolType UDP
Definition: ProtocolType.h:53
Definition: UdpLayer.h:20
Definition: Layer.h:70
Definition: Packet.h:26
Definition: UdpLayer.h:37
size_t getHeaderLen() const
Definition: UdpLayer.h:90
udphdr * getUdpHeader() const
Definition: UdpLayer.h:60
Definition: ProtocolType.h:262
uint16_t length
Definition: UdpLayer.h:26
uint16_t portDst
Definition: UdpLayer.h:24
UdpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: UdpLayer.h:47
OsiModelLayer getOsiModelLayer() const
Definition: UdpLayer.h:99
uint16_t headerChecksum
Definition: UdpLayer.h:28