PcapPlusPlus  21.05
IgmpLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_IGMP_LAYER
2 #define PACKETPP_IGMP_LAYER
3 
4 #include "Layer.h"
5 #include "IpAddress.h"
6 #include <vector>
7 
9 
14 namespace pcpp
15 {
16 
22 {
24  uint8_t type;
26  uint8_t maxResponseTime;
28  uint16_t checksum;
30  uint32_t groupAddress;
31 };
32 
33 
39 {
41  uint8_t type;
43  uint8_t maxResponseTime;
45  uint16_t checksum;
47  uint32_t groupAddress;
49  uint8_t s_qrv;
51  uint8_t qqic;
53  uint16_t numOfSources;
54 };
55 
56 
62 {
64  uint8_t type;
66  uint8_t reserved1;
68  uint16_t checksum;
70  uint16_t reserved2;
73 };
74 
75 
82 {
84  uint8_t recordType;
86  uint8_t auxDataLen;
88  uint16_t numOfSources;
90  uint32_t multicastAddress;
92  uint8_t sourceAddresses[];
93 
97  IPv4Address getMulticastAddress() const { return multicastAddress; }
98 
102  uint16_t getSourceAddressCount() const;
103 
110  IPv4Address getSourceAddressAtIndex(int index) const;
111 
115  size_t getRecordLen() const;
116 };
117 
118 
123 {
152 };
153 
154 
161 class IgmpLayer : public Layer
162 {
163 protected:
164 
165  IgmpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ProtocolType igmpVer) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = igmpVer; }
166 
167  IgmpLayer(IgmpType type, const IPv4Address& groupAddr, uint8_t maxResponseTime, ProtocolType igmpVer);
168 
169  uint16_t calculateChecksum();
170 
171  size_t getHeaderSizeByVerAndType(ProtocolType igmpVer, IgmpType igmpType) const;
172 public:
173 
174  virtual ~IgmpLayer() {}
175 
180  igmp_header* getIgmpHeader() const { return (igmp_header*)m_Data; }
181 
185  IPv4Address getGroupAddress() const { return getIgmpHeader()->groupAddress; }
186 
191  void setGroupAddress(const IPv4Address& groupAddr);
192 
197  IgmpType getType() const;
198 
203  void setType(IgmpType type);
204 
213  static ProtocolType getIGMPVerFromData(uint8_t* data, size_t dataLen, bool& isQuery);
214 
215 
216  // implement abstract methods
217 
221  void parseNextLayer() {}
222 
226  size_t getHeaderLen() const { return sizeof(igmp_header); }
227 
228  std::string toString() const;
229 
231 };
232 
233 
238 class IgmpV1Layer : public IgmpLayer
239 {
240 public:
247  IgmpV1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
248  : IgmpLayer(data, dataLen, prevLayer, packet, IGMPv1) {}
249 
257  : IgmpLayer(type, groupAddr, 0, IGMPv1) {}
258 
263 
264 
265  // implement abstract methods
266 
270  void computeCalculateFields();
271 
272 };
273 
274 
279 class IgmpV2Layer : public IgmpLayer
280 {
281 public:
288  IgmpV2Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
289  : IgmpLayer(data, dataLen, prevLayer, packet, IGMPv2) {}
290 
297  IgmpV2Layer(IgmpType type, const IPv4Address& groupAddr = IPv4Address(), uint8_t maxResponseTime = 0)
298  : IgmpLayer(type, groupAddr, maxResponseTime, IGMPv2) {}
299 
304 
305 
306  // implement abstract methods
307 
311  void computeCalculateFields();
312 };
313 
314 
320 {
321 public:
322 
329  IgmpV3QueryLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
330 
339  IgmpV3QueryLayer(const IPv4Address& multicastAddr = IPv4Address(), uint8_t maxResponseTime = 0, uint8_t s_qrv = 0);
340 
347 
351  uint16_t getSourceAddressCount() const;
352 
358  IPv4Address getSourceAddressAtIndex(int index) const;
359 
366  bool addSourceAddress(const IPv4Address& addr);
367 
375  bool addSourceAddressAtIndex(const IPv4Address& addr, int index);
376 
383  bool removeSourceAddressAtIndex(int index);
384 
390  bool removeAllSourceAddresses();
391 
392  // implement abstract methods
393 
397  void computeCalculateFields();
398 
402  size_t getHeaderLen() const;
403 };
404 
405 
411 {
412 private:
413  igmpv3_group_record* addGroupRecordAt(uint8_t recordType, const IPv4Address& multicastAddress, const std::vector<IPv4Address>& sourceAddresses, int offset);
414 
415 public:
416 
423  IgmpV3ReportLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
424  : IgmpLayer(data, dataLen, prevLayer, packet, IGMPv3) {}
425 
430 
437 
441  uint16_t getGroupRecordCount() const;
442 
447  igmpv3_group_record* getFirstGroupRecord() const;
448 
457  igmpv3_group_record* getNextGroupRecord(igmpv3_group_record* groupRecord) const;
458 
469  igmpv3_group_record* addGroupRecord(uint8_t recordType, const IPv4Address& multicastAddress, const std::vector<IPv4Address>& sourceAddresses);
470 
482  igmpv3_group_record* addGroupRecordAtIndex(uint8_t recordType, const IPv4Address& multicastAddress, const std::vector<IPv4Address>& sourceAddresses, int index);
483 
490  bool removeGroupRecordAtIndex(int index);
491 
497  bool removeAllGroupRecords();
498 
499  // implement abstract methods
500 
504  void computeCalculateFields();
505 
509  size_t getHeaderLen() const { return m_DataLen; }
510 };
511 
512 }
513 
514 #endif // PACKETPP_IGMP_LAYER
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:253
Definition: IgmpLayer.h:279
Definition: IgmpLayer.h:161
const ProtocolType IGMPv2
Definition: ProtocolType.h:163
OsiModelLayer getOsiModelLayer() const
Definition: IgmpLayer.h:230
uint8_t type
Definition: IgmpLayer.h:41
Definition: Layer.h:70
Definition: IgmpLayer.h:410
Definition: IgmpLayer.h:21
uint8_t maxResponseTime
Definition: IgmpLayer.h:26
uint16_t checksum
Definition: IgmpLayer.h:68
Definition: IgmpLayer.h:139
Definition: IgmpLayer.h:38
Definition: Packet.h:26
uint16_t numOfGroupRecords
Definition: IgmpLayer.h:72
~IgmpV2Layer()
Definition: IgmpLayer.h:303
igmpv3_report_header * getReportHeader() const
Definition: IgmpLayer.h:436
uint16_t reserved2
Definition: IgmpLayer.h:70
Definition: IgmpLayer.h:143
Definition: IgmpLayer.h:131
IPv4Address getMulticastAddress() const
Definition: IgmpLayer.h:97
uint8_t type
Definition: IgmpLayer.h:64
Definition: IgmpLayer.h:127
Definition: ProtocolType.h:260
uint8_t recordType
Definition: IgmpLayer.h:84
uint64_t ProtocolType
Definition: ProtocolType.h:18
uint32_t groupAddress
Definition: IgmpLayer.h:30
Definition: IgmpLayer.h:125
Definition: IgmpLayer.h:137
uint8_t reserved1
Definition: IgmpLayer.h:66
void parseNextLayer()
Definition: IgmpLayer.h:221
uint8_t qqic
Definition: IgmpLayer.h:51
IgmpV3ReportLayer()
Definition: IgmpLayer.h:429
uint16_t checksum
Definition: IgmpLayer.h:45
IgmpV1Layer(IgmpType type, const IPv4Address &groupAddr=IPv4Address())
Definition: IgmpLayer.h:256
~IgmpV1Layer()
Definition: IgmpLayer.h:262
Definition: IgmpLayer.h:145
Definition: IgmpLayer.h:81
igmpv3_query_header * getIgmpV3QueryHeader() const
Definition: IgmpLayer.h:346
Definition: IpAddress.h:26
uint16_t numOfSources
Definition: IgmpLayer.h:88
Definition: IgmpLayer.h:319
Definition: IgmpLayer.h:135
Definition: IgmpLayer.h:133
uint8_t s_qrv
Definition: IgmpLayer.h:49
uint16_t numOfSources
Definition: IgmpLayer.h:53
uint8_t type
Definition: IgmpLayer.h:24
const ProtocolType IGMPv1
Definition: ProtocolType.h:158
IgmpType
Definition: IgmpLayer.h:122
uint32_t groupAddress
Definition: IgmpLayer.h:47
igmp_header * getIgmpHeader() const
Definition: IgmpLayer.h:180
IgmpV2Layer(IgmpType type, const IPv4Address &groupAddr=IPv4Address(), uint8_t maxResponseTime=0)
Definition: IgmpLayer.h:297
size_t getHeaderLen() const
Definition: IgmpLayer.h:226
uint8_t auxDataLen
Definition: IgmpLayer.h:86
IgmpV1Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IgmpLayer.h:247
Definition: IgmpLayer.h:129
Definition: IgmpLayer.h:238
const ProtocolType IGMPv3
Definition: ProtocolType.h:168
Definition: IgmpLayer.h:61
uint32_t multicastAddress
Definition: IgmpLayer.h:90
IgmpV2Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IgmpLayer.h:288
uint8_t maxResponseTime
Definition: IgmpLayer.h:43
IPv4Address getGroupAddress() const
Definition: IgmpLayer.h:185
size_t getHeaderLen() const
Definition: IgmpLayer.h:509
uint16_t checksum
Definition: IgmpLayer.h:28
IgmpV3ReportLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IgmpLayer.h:423