PcapPlusPlus  24.09
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 (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 
92 
96  size_t getHeaderLen() const
97  {
98  return sizeof(udphdr);
99  }
100 
105 
106  std::string toString() const;
107 
109  {
110  return OsiModelTransportLayer;
111  }
112  };
113 
114 } // namespace pcpp
Definition: Layer.h:70
Definition: Packet.h:27
Definition: UdpLayer.h:37
udphdr * getUdpHeader() const
Definition: UdpLayer.h:62
OsiModelLayer getOsiModelLayer() const
Definition: UdpLayer.h:108
void parseNextLayer()
uint16_t getDstPort() const
uint16_t getSrcPort() const
std::string toString() const
uint16_t calculateChecksum(bool writeResultToPacket)
UdpLayer(uint16_t portSrc, uint16_t portDst)
void computeCalculateFields()
UdpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: UdpLayer.h:46
size_t getHeaderLen() const
Definition: UdpLayer.h:96
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelTransportLayer
Definition: ProtocolType.h:362
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