PcapPlusPlus  Next
IgmpLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 #include "IpAddress.h"
5 #include <vector>
6 
8 
13 namespace pcpp
14 {
15 
20  struct igmp_header
21  {
23  uint8_t type;
25  uint8_t maxResponseTime;
27  uint16_t checksum;
30  uint32_t groupAddress;
31  };
32 
38  {
40  uint8_t type;
42  uint8_t maxResponseTime;
44  uint16_t checksum;
47  uint32_t groupAddress;
49  uint8_t s_qrv;
51  uint8_t qqic;
53  uint16_t numOfSources;
54  };
55 
61  {
63  uint8_t type;
65  uint8_t reserved1;
67  uint16_t checksum;
69  uint16_t reserved2;
72  };
73 
80  {
82  uint8_t recordType;
85  uint8_t auxDataLen;
87  uint16_t numOfSources;
89  uint32_t multicastAddress;
91  uint8_t sourceAddresses[];
92 
97  {
98  return multicastAddress;
99  }
100 
104  uint16_t getSourceAddressCount() const;
105 
113 
117  size_t getRecordLen() const;
118  };
119 
123  enum IgmpType
124  {
153  };
154 
161  class IgmpLayer : public Layer
162  {
163  protected:
164  IgmpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ProtocolType igmpVer)
165  : Layer(data, dataLen, prevLayer, packet, igmpVer)
166  {}
167 
168  IgmpLayer(IgmpType type, const IPv4Address& groupAddr, uint8_t maxResponseTime, ProtocolType igmpVer);
169 
170  uint16_t calculateChecksum();
171 
172  size_t getHeaderSizeByVerAndType(ProtocolType igmpVer, IgmpType igmpType) const;
173 
174  public:
175  ~IgmpLayer() override = default;
176 
183  {
184  return reinterpret_cast<igmp_header*>(m_Data);
185  }
186 
191  {
192  return getIgmpHeader()->groupAddress;
193  }
194 
199  void setGroupAddress(const IPv4Address& groupAddr);
200 
205  IgmpType getType() const;
206 
211  void setType(IgmpType type);
212 
221  static ProtocolType getIGMPVerFromData(uint8_t* data, size_t dataLen, bool& isQuery);
222 
223  // implement abstract methods
224 
228  void parseNextLayer() override
229  {}
230 
234  size_t getHeaderLen() const override
235  {
236  return sizeof(igmp_header);
237  }
238 
239  std::string toString() const override;
240 
242  {
243  return OsiModelNetworkLayer;
244  }
245  };
246 
252  class IgmpV1Layer : public IgmpLayer
253  {
254  public:
261  IgmpV1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
262  : IgmpLayer(data, dataLen, prevLayer, packet, IGMPv1)
263  {}
264 
271  explicit IgmpV1Layer(IgmpType type, const IPv4Address& groupAddr = IPv4Address())
272  : IgmpLayer(type, groupAddr, 0, IGMPv1)
273  {}
274 
278  ~IgmpV1Layer() override = default;
279 
280  // implement abstract methods
281 
285  void computeCalculateFields() override;
286  };
287 
293  class IgmpV2Layer : public IgmpLayer
294  {
295  public:
302  IgmpV2Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
303  : IgmpLayer(data, dataLen, prevLayer, packet, IGMPv2)
304  {}
305 
314  explicit IgmpV2Layer(IgmpType type, const IPv4Address& groupAddr = IPv4Address(), uint8_t maxResponseTime = 0)
315  : IgmpLayer(type, groupAddr, maxResponseTime, IGMPv2)
316  {}
317 
321  ~IgmpV2Layer() override = default;
322 
323  // implement abstract methods
324 
328  void computeCalculateFields() override;
329  };
330 
336  {
337  public:
344  IgmpV3QueryLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
345 
356  explicit IgmpV3QueryLayer(const IPv4Address& multicastAddr = IPv4Address(), uint8_t maxResponseTime = 0,
357  uint8_t s_qrv = 0);
358 
365  {
366  return reinterpret_cast<igmpv3_query_header*>(m_Data);
367  }
368 
373  uint16_t getSourceAddressCount() const;
374 
382 
390  bool addSourceAddress(const IPv4Address& addr);
391 
400  bool addSourceAddressAtIndex(const IPv4Address& addr, int index);
401 
409  bool removeSourceAddressAtIndex(int index);
410 
417 
418  // implement abstract methods
419 
423  void computeCalculateFields() override;
424 
429  size_t getHeaderLen() const override;
430  };
431 
437  {
438  private:
439  igmpv3_group_record* addGroupRecordAt(uint8_t recordType, const IPv4Address& multicastAddress,
440  const std::vector<IPv4Address>& sourceAddresses, int offset);
441 
442  public:
449  IgmpV3ReportLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
450  : IgmpLayer(data, dataLen, prevLayer, packet, IGMPv3)
451  {}
452 
457  {}
458 
465  {
466  return reinterpret_cast<igmpv3_report_header*>(m_Data);
467  }
468 
473  uint16_t getGroupRecordCount() const;
474 
480 
490 
501  igmpv3_group_record* addGroupRecord(uint8_t recordType, const IPv4Address& multicastAddress,
502  const std::vector<IPv4Address>& sourceAddresses);
503 
515  igmpv3_group_record* addGroupRecordAtIndex(uint8_t recordType, const IPv4Address& multicastAddress,
516  const std::vector<IPv4Address>& sourceAddresses, int index);
517 
525  bool removeGroupRecordAtIndex(int index);
526 
533 
534  // implement abstract methods
535 
539  void computeCalculateFields() override;
540 
545  size_t getHeaderLen() const override
546  {
547  return m_DataLen;
548  }
549  };
550 
551 } // namespace pcpp
Definition: IpAddress.h:32
Definition: IgmpLayer.h:162
IPv4Address getGroupAddress() const
Definition: IgmpLayer.h:190
std::string toString() const override
void setGroupAddress(const IPv4Address &groupAddr)
igmp_header * getIgmpHeader() const
Definition: IgmpLayer.h:182
static ProtocolType getIGMPVerFromData(uint8_t *data, size_t dataLen, bool &isQuery)
size_t getHeaderLen() const override
Definition: IgmpLayer.h:234
void parseNextLayer() override
Definition: IgmpLayer.h:228
IgmpType getType() const
void setType(IgmpType type)
OsiModelLayer getOsiModelLayer() const override
Definition: IgmpLayer.h:241
Definition: IgmpLayer.h:253
void computeCalculateFields() override
IgmpV1Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IgmpLayer.h:261
~IgmpV1Layer() override=default
IgmpV1Layer(IgmpType type, const IPv4Address &groupAddr=IPv4Address())
Definition: IgmpLayer.h:271
Definition: IgmpLayer.h:294
void computeCalculateFields() override
~IgmpV2Layer() override=default
IgmpV2Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IgmpLayer.h:302
IgmpV2Layer(IgmpType type, const IPv4Address &groupAddr=IPv4Address(), uint8_t maxResponseTime=0)
Definition: IgmpLayer.h:314
Definition: IgmpLayer.h:336
uint16_t getSourceAddressCount() const
bool addSourceAddressAtIndex(const IPv4Address &addr, int index)
bool addSourceAddress(const IPv4Address &addr)
size_t getHeaderLen() const override
IgmpV3QueryLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
bool removeSourceAddressAtIndex(int index)
IPv4Address getSourceAddressAtIndex(int index) const
IgmpV3QueryLayer(const IPv4Address &multicastAddr=IPv4Address(), uint8_t maxResponseTime=0, uint8_t s_qrv=0)
void computeCalculateFields() override
igmpv3_query_header * getIgmpV3QueryHeader() const
Definition: IgmpLayer.h:364
Definition: IgmpLayer.h:437
igmpv3_group_record * addGroupRecord(uint8_t recordType, const IPv4Address &multicastAddress, const std::vector< IPv4Address > &sourceAddresses)
igmpv3_group_record * addGroupRecordAtIndex(uint8_t recordType, const IPv4Address &multicastAddress, const std::vector< IPv4Address > &sourceAddresses, int index)
IgmpV3ReportLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: IgmpLayer.h:449
size_t getHeaderLen() const override
Definition: IgmpLayer.h:545
bool removeGroupRecordAtIndex(int index)
igmpv3_report_header * getReportHeader() const
Definition: IgmpLayer.h:464
uint16_t getGroupRecordCount() const
void computeCalculateFields() override
IgmpV3ReportLayer()
Definition: IgmpLayer.h:456
igmpv3_group_record * getFirstGroupRecord() const
igmpv3_group_record * getNextGroupRecord(igmpv3_group_record *groupRecord) const
Definition: Layer.h:69
Definition: Packet.h:27
The main namespace for the PcapPlusPlus lib.
uint8_t ProtocolType
Definition: ProtocolType.h:17
const ProtocolType IGMPv2
Definition: ProtocolType.h:163
const ProtocolType IGMPv3
Definition: ProtocolType.h:168
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelNetworkLayer
Definition: ProtocolType.h:370
const ProtocolType IGMPv1
Definition: ProtocolType.h:158
IgmpType
Definition: IgmpLayer.h:124
@ IgmpType_MulticastRouterTermination
Definition: IgmpLayer.h:152
@ IgmpType_Unknown
Definition: IgmpLayer.h:126
@ IgmpType_MembershipReportV2
Definition: IgmpLayer.h:138
@ IgmpType_DVMRP
Definition: IgmpLayer.h:132
@ IgmpType_MembershipReportV3
Definition: IgmpLayer.h:146
@ IgmpType_MulticastTraceroute
Definition: IgmpLayer.h:144
@ IgmpType_P1Mv1
Definition: IgmpLayer.h:134
@ IgmpType_LeaveGroup
Definition: IgmpLayer.h:140
@ IgmpType_MembershipReportV1
Definition: IgmpLayer.h:130
@ IgmpType_MulticastRouterAdvertisement
Definition: IgmpLayer.h:148
@ IgmpType_MulticastRouterSolicitation
Definition: IgmpLayer.h:150
@ IgmpType_CiscoTrace
Definition: IgmpLayer.h:136
@ IgmpType_MembershipQuery
Definition: IgmpLayer.h:128
@ IgmpType_MulticastTracerouteResponse
Definition: IgmpLayer.h:142
Definition: IgmpLayer.h:21
uint8_t type
Definition: IgmpLayer.h:23
uint16_t checksum
Definition: IgmpLayer.h:27
uint32_t groupAddress
Definition: IgmpLayer.h:30
uint8_t maxResponseTime
Definition: IgmpLayer.h:25
Definition: IgmpLayer.h:80
uint8_t sourceAddresses[]
Definition: IgmpLayer.h:91
size_t getRecordLen() const
uint32_t multicastAddress
Definition: IgmpLayer.h:89
uint8_t auxDataLen
Definition: IgmpLayer.h:85
uint8_t recordType
Definition: IgmpLayer.h:82
IPv4Address getMulticastAddress() const
Definition: IgmpLayer.h:96
uint16_t numOfSources
Definition: IgmpLayer.h:87
IPv4Address getSourceAddressAtIndex(int index) const
uint16_t getSourceAddressCount() const
Definition: IgmpLayer.h:38
uint8_t type
Definition: IgmpLayer.h:40
uint32_t groupAddress
Definition: IgmpLayer.h:47
uint8_t qqic
Definition: IgmpLayer.h:51
uint16_t numOfSources
Definition: IgmpLayer.h:53
uint8_t s_qrv
Definition: IgmpLayer.h:49
uint16_t checksum
Definition: IgmpLayer.h:44
uint8_t maxResponseTime
Definition: IgmpLayer.h:42
Definition: IgmpLayer.h:61
uint16_t numOfGroupRecords
Definition: IgmpLayer.h:71
uint8_t type
Definition: IgmpLayer.h:63
uint8_t reserved1
Definition: IgmpLayer.h:65
uint16_t reserved2
Definition: IgmpLayer.h:69
uint16_t checksum
Definition: IgmpLayer.h:67