PcapPlusPlus  Next
UdpLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 
6 
11 namespace pcpp
12 {
13 
18 #pragma pack(push, 1)
19  struct udphdr
20  {
22  uint16_t portSrc;
24  uint16_t portDst;
26  uint16_t length;
28  uint16_t headerChecksum;
29  };
30 #pragma pack(pop)
31 
36  class UdpLayer : public Layer
37  {
38  public:
46  UdpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
47  : Layer(data, dataLen, prevLayer, packet, UDP)
48  {}
49 
55  UdpLayer(uint16_t portSrc, uint16_t portDst);
56 
63  {
64  return reinterpret_cast<udphdr*>(m_Data);
65  }
66 
70  uint16_t getSrcPort() const;
71 
75  uint16_t getDstPort() const;
76 
83  uint16_t calculateChecksum(bool writeResultToPacket);
84 
85  // implement abstract methods
86 
91  void parseNextLayer() override;
92 
96  size_t getHeaderLen() const override
97  {
98  return sizeof(udphdr);
99  }
100 
104  void computeCalculateFields() override;
105 
106  std::string toString() const override;
107 
109  {
110  return OsiModelTransportLayer;
111  }
112  };
113 
114 } // namespace pcpp
Definition: Layer.h:69
Definition: Packet.h:27
Definition: UdpLayer.h:37
udphdr * getUdpHeader() const
Definition: UdpLayer.h:62
OsiModelLayer getOsiModelLayer() const override
Definition: UdpLayer.h:108
uint16_t getDstPort() const
void computeCalculateFields() override
uint16_t getSrcPort() const
size_t getHeaderLen() const override
Definition: UdpLayer.h:96
void parseNextLayer() override
uint16_t calculateChecksum(bool writeResultToPacket)
UdpLayer(uint16_t portSrc, uint16_t portDst)
UdpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: UdpLayer.h:46
std::string toString() const override
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelTransportLayer
Definition: ProtocolType.h:372
const ProtocolType UDP
Definition: ProtocolType.h:58
Definition: UdpLayer.h:20
uint16_t length
Definition: UdpLayer.h:26
uint16_t portSrc
Definition: UdpLayer.h:22
uint16_t portDst
Definition: UdpLayer.h:24
uint16_t headerChecksum
Definition: UdpLayer.h:28